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