annotate Libs/DF/scrollbar.lua @ 32:8368036a4abf

- updated the addon name.
author Tercioo
date Thu, 25 Feb 2016 08:53:07 -0300
parents dc1c77254f80
children 0682d738499b
rev   line source
Tercio@11 1
Tercio@11 2 local DF = _G ["DetailsFramework"]
Tercio@20 3 if (not DF or not DetailsFrameworkCanLoad) then
Tercio@20 4 return
Tercio@20 5 end
Tercio@11 6
Tercio@11 7 function DF:CreateScrollBar (master, slave, x, y)
Tercio@11 8 return DF:NewScrollBar (master, slave, x, y)
Tercio@11 9 end
Tercio@11 10
Tercio@11 11 function DF:NewScrollBar (master, slave, x, y)
Tercio@11 12
Tercio@11 13 local new_slider = CreateFrame ("Slider", nil, master)
Tercio@11 14 new_slider.scrollMax = 560 --default - tamanho da janela de fundo
Tercio@11 15
Tercio@11 16 -- ///// SLIDER /////
Tercio@11 17 new_slider:SetPoint ("TOPLEFT", master, "TOPRIGHT", x, y)
Tercio@11 18 new_slider.ativo = true
Tercio@11 19
Tercio@11 20 new_slider.bg = new_slider:CreateTexture (nil, "BACKGROUND")
Tercio@11 21 new_slider.bg:SetAllPoints (true)
Tercio@11 22 new_slider.bg:SetTexture (0, 0, 0, 0)
Tercio@11 23 --coisinha do meio
Tercio@11 24 new_slider.thumb = new_slider:CreateTexture (nil, "OVERLAY")
Tercio@11 25 new_slider.thumb:SetTexture ("Interface\\Buttons\\UI-ScrollBar-Knob")
Tercio@11 26 new_slider.thumb:SetSize (29, 30)
Tercio@11 27 new_slider:SetThumbTexture (new_slider.thumb)
Tercio@11 28
Tercio@11 29 new_slider:SetOrientation ("VERTICAL")
Tercio@11 30 new_slider:SetSize(16, 100)
Tercio@11 31 new_slider:SetMinMaxValues(0, new_slider.scrollMax)
Tercio@11 32 new_slider:SetValue(0)
Tercio@11 33 new_slider.ultimo = 0
Tercio@11 34
Tercio@11 35 local botao_cima = CreateFrame ("Button", nil, master)
Tercio@11 36
Tercio@11 37 botao_cima:SetPoint ("BOTTOM", new_slider, "TOP", 0, -12)
Tercio@11 38 botao_cima.x = 0
Tercio@11 39 botao_cima.y = -12
Tercio@11 40
Tercio@11 41 botao_cima:SetWidth (29)
Tercio@11 42 botao_cima:SetHeight (32)
Tercio@11 43 botao_cima:SetNormalTexture ("Interface\\BUTTONS\\UI-ScrollBar-ScrollUpButton-Up")
Tercio@11 44 botao_cima:SetPushedTexture ("Interface\\BUTTONS\\UI-ScrollBar-ScrollUpButton-Down")
Tercio@11 45 botao_cima:SetDisabledTexture ("Interface\\BUTTONS\\UI-ScrollBar-ScrollUpButton-Disabled")
Tercio@11 46 botao_cima:Show()
Tercio@11 47 botao_cima:Disable()
Tercio@11 48
Tercio@11 49 local botao_baixo = CreateFrame ("Button", nil, master)
Tercio@11 50 botao_baixo:SetPoint ("TOP", new_slider, "BOTTOM", 0, 12)
Tercio@11 51 botao_baixo.x = 0
Tercio@11 52 botao_baixo.y = 12
Tercio@11 53
Tercio@11 54 botao_baixo:SetWidth (29)
Tercio@11 55 botao_baixo:SetHeight (32)
Tercio@11 56 botao_baixo:SetNormalTexture ("Interface\\BUTTONS\\UI-ScrollBar-ScrollDownButton-Up")
Tercio@11 57 botao_baixo:SetPushedTexture ("Interface\\BUTTONS\\UI-ScrollBar-ScrollDownButton-Down")
Tercio@11 58 botao_baixo:SetDisabledTexture ("Interface\\BUTTONS\\UI-ScrollBar-ScrollDownButton-Disabled")
Tercio@11 59 botao_baixo:Show()
Tercio@11 60 botao_baixo:Disable()
Tercio@11 61
Tercio@11 62 master.baixo = botao_baixo
Tercio@11 63 master.cima = botao_cima
Tercio@11 64 master.slider = new_slider
Tercio@11 65
Tercio@11 66 botao_baixo:SetScript ("OnMouseDown", function(self)
Tercio@11 67 if (not new_slider:IsEnabled()) then
Tercio@11 68 return
Tercio@11 69 end
Tercio@11 70
Tercio@11 71 local current = new_slider:GetValue()
Tercio@11 72 local minValue, maxValue = new_slider:GetMinMaxValues()
Tercio@11 73 if (current+5 < maxValue) then
Tercio@11 74 new_slider:SetValue (current+5)
Tercio@11 75 else
Tercio@11 76 new_slider:SetValue (maxValue)
Tercio@11 77 end
Tercio@11 78 self.precionado = true
Tercio@11 79 self.last_up = -0.3
Tercio@11 80 self:SetScript ("OnUpdate", function(self, elapsed)
Tercio@11 81 self.last_up = self.last_up + elapsed
Tercio@11 82 if (self.last_up > 0.03) then
Tercio@11 83 self.last_up = 0
Tercio@11 84 local current = new_slider:GetValue()
Tercio@11 85 local minValue, maxValue = new_slider:GetMinMaxValues()
Tercio@11 86 if (current+2 < maxValue) then
Tercio@11 87 new_slider:SetValue (current+2)
Tercio@11 88 else
Tercio@11 89 new_slider:SetValue (maxValue)
Tercio@11 90 end
Tercio@11 91 end
Tercio@11 92 end)
Tercio@11 93 end)
Tercio@11 94 botao_baixo:SetScript ("OnMouseUp", function(self)
Tercio@11 95 self.precionado = false
Tercio@11 96 self:SetScript ("OnUpdate", nil)
Tercio@11 97 end)
Tercio@11 98
Tercio@11 99 botao_cima:SetScript ("OnMouseDown", function(self)
Tercio@11 100 if (not new_slider:IsEnabled()) then
Tercio@11 101 return
Tercio@11 102 end
Tercio@11 103
Tercio@11 104 local current = new_slider:GetValue()
Tercio@11 105 if (current-5 > 0) then
Tercio@11 106 new_slider:SetValue (current-5)
Tercio@11 107 else
Tercio@11 108 new_slider:SetValue (0)
Tercio@11 109 end
Tercio@11 110 self.precionado = true
Tercio@11 111 self.last_up = -0.3
Tercio@11 112 self:SetScript ("OnUpdate", function(self, elapsed)
Tercio@11 113 self.last_up = self.last_up + elapsed
Tercio@11 114 if (self.last_up > 0.03) then
Tercio@11 115 self.last_up = 0
Tercio@11 116 local current = new_slider:GetValue()
Tercio@11 117 if (current-2 > 0) then
Tercio@11 118 new_slider:SetValue (current-2)
Tercio@11 119 else
Tercio@11 120 new_slider:SetValue (0)
Tercio@11 121 end
Tercio@11 122 end
Tercio@11 123 end)
Tercio@11 124 end)
Tercio@11 125 botao_cima:SetScript ("OnMouseUp", function(self)
Tercio@11 126 self.precionado = false
Tercio@11 127 self:SetScript ("OnUpdate", nil)
Tercio@11 128 end)
Tercio@11 129 --> isso aqui pra quando o slider ativar, o scroll fica na posição zero
Tercio@11 130 botao_cima:SetScript ("OnEnable", function (self)
Tercio@11 131 local current = new_slider:GetValue()
Tercio@11 132 if (current == 0) then
Tercio@11 133 botao_cima:Disable()
Tercio@11 134 end
Tercio@11 135 end)
Tercio@11 136
Tercio@11 137 new_slider:SetScript ("OnValueChanged", function (self)
Tercio@11 138 local current = self:GetValue()
Tercio@11 139 master:SetVerticalScroll (current)
Tercio@11 140
Tercio@11 141 local minValue, maxValue = new_slider:GetMinMaxValues()
Tercio@11 142
Tercio@11 143 if (current == minValue) then
Tercio@11 144 botao_cima:Disable()
Tercio@11 145 elseif (not botao_cima:IsEnabled()) then
Tercio@11 146 botao_cima:Enable()
Tercio@11 147 end
Tercio@11 148
Tercio@11 149 if (current == maxValue) then
Tercio@11 150 botao_baixo:Disable()
Tercio@11 151 elseif (not botao_baixo:IsEnabled()) then
Tercio@11 152 botao_baixo:Enable()
Tercio@11 153 end
Tercio@11 154
Tercio@11 155 end)
Tercio@11 156
Tercio@11 157 new_slider:SetScript ("OnShow", function (self)
Tercio@11 158 botao_cima:Show()
Tercio@11 159 botao_baixo:Show()
Tercio@11 160 end)
Tercio@11 161
Tercio@11 162 new_slider:SetScript ("OnDisable", function (self)
Tercio@11 163 botao_cima:Disable()
Tercio@11 164 botao_baixo:Disable()
Tercio@11 165 end)
Tercio@11 166
Tercio@11 167 new_slider:SetScript ("OnEnable", function (self)
Tercio@11 168 botao_cima:Enable()
Tercio@11 169 botao_baixo:Enable()
Tercio@11 170 end)
Tercio@11 171
Tercio@11 172 master:SetScript ("OnMouseWheel", function (self, delta)
Tercio@11 173 if (not new_slider:IsEnabled()) then
Tercio@11 174 return
Tercio@11 175 end
Tercio@11 176
Tercio@11 177 local current = new_slider:GetValue()
Tercio@11 178 if (delta < 0) then
Tercio@11 179 --baixo
Tercio@11 180 local minValue, maxValue = new_slider:GetMinMaxValues()
Tercio@11 181 if (current + (master.wheel_jump or 20) < maxValue) then
Tercio@11 182 new_slider:SetValue (current + (master.wheel_jump or 20))
Tercio@11 183 else
Tercio@11 184 new_slider:SetValue (maxValue)
Tercio@11 185 end
Tercio@11 186 elseif (delta > 0) then
Tercio@11 187 --cima
Tercio@11 188 if (current + (master.wheel_jump or 20) > 0) then
Tercio@11 189 new_slider:SetValue (current - (master.wheel_jump or 20))
Tercio@11 190 else
Tercio@11 191 new_slider:SetValue (0)
Tercio@11 192 end
Tercio@11 193 end
Tercio@11 194 end)
Tercio@11 195
Tercio@11 196 function new_slider:Altura (h)
Tercio@11 197 self:SetHeight (h)
Tercio@11 198 end
Tercio@11 199
Tercio@11 200 function new_slider:Update (desativar)
Tercio@11 201
Tercio@11 202 if (desativar) then
Tercio@11 203 new_slider:Disable()
Tercio@11 204 new_slider:SetValue(0)
Tercio@11 205 new_slider.ativo = false
Tercio@11 206 master:EnableMouseWheel (false)
Tercio@11 207 return
Tercio@11 208 end
Tercio@11 209
Tercio@11 210 self.scrollMax = slave:GetHeight()-master:GetHeight()
Tercio@11 211 if (self.scrollMax > 0) then
Tercio@11 212 new_slider:SetMinMaxValues (0, self.scrollMax)
Tercio@11 213 if (not new_slider.ativo) then
Tercio@11 214 new_slider:Enable()
Tercio@11 215 new_slider.ativo = true
Tercio@11 216 master:EnableMouseWheel (true)
Tercio@11 217 end
Tercio@11 218 else
Tercio@11 219 new_slider:Disable()
Tercio@11 220 new_slider:SetValue(0)
Tercio@11 221 new_slider.ativo = false
Tercio@11 222 master:EnableMouseWheel (false)
Tercio@11 223 end
Tercio@11 224 end
Tercio@11 225
Tercio@11 226 function new_slider:cimaPoint (x, y)
Tercio@11 227 botao_cima:SetPoint ("BOTTOM", new_slider, "TOP", x, (y)-12)
Tercio@11 228 end
Tercio@11 229
Tercio@11 230 function new_slider:baixoPoint (x, y)
Tercio@11 231 botao_baixo:SetPoint ("TOP", new_slider, "BOTTOM", x, (y)+12)
Tercio@11 232 end
Tercio@11 233
Tercio@11 234 return new_slider
Tercio@11 235 end