annotate Libs/DF/slider.lua @ 22:dbd417f413a8

- framework update.
author Tercio
date Tue, 08 Sep 2015 13:16:49 -0300
parents dc1c77254f80
children 6bb668a41455
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@20 6
Tercio@11 7 local _
Tercio@11 8 local _rawset = rawset --> lua local
Tercio@11 9 local _rawget = rawget --> lua local
Tercio@11 10 local _setmetatable = setmetatable --> lua local
Tercio@11 11 local _unpack = unpack --> lua local
Tercio@11 12 local _type = type --> lua local
Tercio@11 13 local _math_floor = math.floor --> lua local
Tercio@11 14 local loadstring = loadstring --> lua local
Tercio@11 15
Tercio@11 16 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0")
Tercio@11 17
Tercio@11 18 local cleanfunction = function() end
Tercio@11 19 local APISliderFunctions = false
Tercio@11 20 local SliderMetaFunctions = {}
Tercio@11 21 local NameLessSlider = 1
Tercio@11 22
Tercio@11 23 ------------------------------------------------------------------------------------------------------------
Tercio@11 24 --> metatables
Tercio@11 25
Tercio@11 26 SliderMetaFunctions.__call = function (_table, value)
Tercio@11 27 if (not value) then
Tercio@11 28 if (_table.isSwitch) then
Tercio@11 29
Tercio@11 30 if (type (value) == "boolean") then --> false
Tercio@11 31 return _table.slider:SetValue (1)
Tercio@11 32 end
Tercio@11 33
Tercio@11 34 if (_table.slider:GetValue() == 1) then
Tercio@11 35 return false
Tercio@11 36 else
Tercio@11 37 return true
Tercio@11 38 end
Tercio@11 39 end
Tercio@11 40 return _table.slider:GetValue()
Tercio@11 41 else
Tercio@11 42 if (_table.isSwitch) then
Tercio@11 43 if (type (value) == "boolean") then
Tercio@11 44 if (value) then
Tercio@11 45 _table.slider:SetValue (2)
Tercio@11 46 else
Tercio@11 47 _table.slider:SetValue (1)
Tercio@11 48 end
Tercio@11 49 else
Tercio@11 50 _table.slider:SetValue (value)
Tercio@11 51 end
Tercio@11 52 return
Tercio@11 53 end
Tercio@11 54
Tercio@11 55 return _table.slider:SetValue (value)
Tercio@11 56 end
Tercio@11 57 end
Tercio@11 58
Tercio@11 59 ------------------------------------------------------------------------------------------------------------
Tercio@11 60 --> members
Tercio@11 61
Tercio@11 62 --> tooltip
Tercio@11 63 local gmember_tooltip = function (_object)
Tercio@11 64 return _object:GetTooltip()
Tercio@11 65 end
Tercio@11 66 --> shown
Tercio@11 67 local gmember_shown = function (_object)
Tercio@11 68 return _object:IsShown()
Tercio@11 69 end
Tercio@11 70 --> frame width
Tercio@11 71 local gmember_width = function (_object)
Tercio@11 72 return _object.slider:GetWidth()
Tercio@11 73 end
Tercio@11 74 --> frame height
Tercio@11 75 local gmember_height = function (_object)
Tercio@11 76 return _object.slider:GetHeight()
Tercio@11 77 end
Tercio@11 78 --> locked
Tercio@11 79 local gmember_locked = function (_object)
Tercio@11 80 return _rawget (_object, "lockdown")
Tercio@11 81 end
Tercio@11 82 --> fractional
Tercio@11 83 local gmember_fractional = function (_object)
Tercio@11 84 return _rawget (_object, "useDecimals")
Tercio@11 85 end
Tercio@11 86 --> value
Tercio@11 87 local gmember_value = function (_object)
Tercio@11 88 return _object()
Tercio@11 89 end
Tercio@11 90
Tercio@11 91 local get_members_function_index = {
Tercio@11 92 ["tooltip"] = gmember_tooltip,
Tercio@11 93 ["shown"] = gmember_shown,
Tercio@11 94 ["width"] = gmember_width,
Tercio@11 95 ["height"] = gmember_height,
Tercio@11 96 ["locked"] = gmember_locked,
Tercio@11 97 ["fractional"] = gmember_fractional,
Tercio@11 98 ["value"] = gmember_value,
Tercio@11 99 }
Tercio@11 100
Tercio@11 101 SliderMetaFunctions.__index = function (_table, _member_requested)
Tercio@11 102
Tercio@11 103 local func = get_members_function_index [_member_requested]
Tercio@11 104 if (func) then
Tercio@11 105 return func (_table, _member_requested)
Tercio@11 106 end
Tercio@11 107
Tercio@11 108 local fromMe = _rawget (_table, _member_requested)
Tercio@11 109 if (fromMe) then
Tercio@11 110 return fromMe
Tercio@11 111 end
Tercio@11 112
Tercio@11 113 return SliderMetaFunctions [_member_requested]
Tercio@11 114 end
Tercio@11 115
Tercio@11 116 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 117
Tercio@11 118 --> tooltip
Tercio@11 119 local smember_tooltip = function (_object, _value)
Tercio@11 120 return _object:SetTooltip (_value)
Tercio@11 121 end
Tercio@11 122 --> show
Tercio@11 123 local smember_show = function (_object, _value)
Tercio@11 124 if (_value) then
Tercio@11 125 return _object:Show()
Tercio@11 126 else
Tercio@11 127 return _object:Hide()
Tercio@11 128 end
Tercio@11 129 end
Tercio@11 130 --> hide
Tercio@11 131 local smember_hide = function (_object, _value)
Tercio@11 132 if (not _value) then
Tercio@11 133 return _object:Show()
Tercio@11 134 else
Tercio@11 135 return _object:Hide()
Tercio@11 136 end
Tercio@11 137 end
Tercio@11 138 --> frame width
Tercio@11 139 local smember_width = function (_object, _value)
Tercio@11 140 return _object.slider:SetWidth (_value)
Tercio@11 141 end
Tercio@11 142 --> frame height
Tercio@11 143 local smember_height = function (_object, _value)
Tercio@11 144 return _object.slider:SetHeight (_value)
Tercio@11 145 end
Tercio@11 146 --> locked
Tercio@11 147 local smember_locked = function (_object, _value)
Tercio@11 148 if (_value) then
Tercio@11 149 return self:Disable()
Tercio@11 150 else
Tercio@11 151 return self:Enable()
Tercio@11 152 end
Tercio@11 153 end
Tercio@11 154 --> backdrop
Tercio@11 155 local smember_backdrop = function (_object, _value)
Tercio@11 156 return _object.slider:SetBackdrop (_value)
Tercio@11 157 end
Tercio@11 158 --> fractional
Tercio@11 159 local smember_fractional = function (_object, _value)
Tercio@11 160 return _rawset (_object, "useDecimals", _value)
Tercio@11 161 end
Tercio@11 162 --> value
Tercio@11 163 local smember_value = function (_object, _value)
Tercio@11 164 _object (_value)
Tercio@11 165 end
Tercio@11 166
Tercio@11 167 local set_members_function_index = {
Tercio@11 168 ["tooltip"] = smember_tooltip,
Tercio@11 169 ["show"] = smember_show,
Tercio@11 170 ["hide"] = smember_hide,
Tercio@11 171 ["backdrop"] = smember_backdrop,
Tercio@11 172 ["width"] = smember_width,
Tercio@11 173 ["height"] = smember_height,
Tercio@11 174 ["locked"] = smember_locked,
Tercio@11 175 ["fractional"] = smember_fractional,
Tercio@11 176 ["value"] = smember_value,
Tercio@11 177 }
Tercio@11 178
Tercio@11 179 SliderMetaFunctions.__newindex = function (_table, _key, _value)
Tercio@11 180 local func = set_members_function_index [_key]
Tercio@11 181 if (func) then
Tercio@11 182 return func (_table, _value)
Tercio@11 183 else
Tercio@11 184 return _rawset (_table, _key, _value)
Tercio@11 185 end
Tercio@11 186 end
Tercio@11 187
Tercio@11 188 ------------------------------------------------------------------------------------------------------------
Tercio@11 189 --> methods
Tercio@11 190
Tercio@11 191 --> show & hide
Tercio@11 192 function SliderMetaFunctions:IsShown()
Tercio@11 193 return self.slider:IsShown()
Tercio@11 194 end
Tercio@11 195 function SliderMetaFunctions:Show()
Tercio@11 196 return self.slider:Show()
Tercio@11 197 end
Tercio@11 198 function SliderMetaFunctions:Hide()
Tercio@11 199 return self.slider:Hide()
Tercio@11 200 end
Tercio@11 201
Tercio@11 202 --> fixed value
Tercio@11 203 function SliderMetaFunctions:SetFixedParameter (value)
Tercio@11 204 _rawset (self, "FixedValue", value)
Tercio@11 205 end
Tercio@11 206
Tercio@11 207 --> set value
Tercio@11 208 function SliderMetaFunctions:SetValue (value)
Tercio@11 209 return self (value)
Tercio@11 210 end
Tercio@11 211
Tercio@11 212 -- thumb size
Tercio@11 213 function SliderMetaFunctions:SetThumbSize (w, h)
Tercio@11 214 if (not w) then
Tercio@11 215 w = self.thumb:GetWidth()
Tercio@11 216 end
Tercio@11 217 if (not h) then
Tercio@11 218 h = self.thumb:GetHeight()
Tercio@11 219 end
Tercio@11 220 return self.thumb:SetSize (w, h)
Tercio@11 221 end
Tercio@11 222
Tercio@11 223
Tercio@11 224 -- setpoint
Tercio@11 225 function SliderMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 226 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
Tercio@11 227 if (not v1) then
Tercio@11 228 print ("Invalid parameter for SetPoint")
Tercio@11 229 return
Tercio@11 230 end
Tercio@11 231 return self.widget:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 232 end
Tercio@11 233
Tercio@11 234 -- sizes
Tercio@11 235 function SliderMetaFunctions:SetSize (w, h)
Tercio@11 236 if (w) then
Tercio@11 237 self.slider:SetWidth (w)
Tercio@11 238 end
Tercio@11 239 if (h) then
Tercio@11 240 return self.slider:SetHeight (h)
Tercio@11 241 end
Tercio@11 242 end
Tercio@11 243
Tercio@11 244 -- tooltip
Tercio@11 245 function SliderMetaFunctions:SetTooltip (tooltip)
Tercio@11 246 if (tooltip) then
Tercio@11 247 return _rawset (self, "have_tooltip", tooltip)
Tercio@11 248 else
Tercio@11 249 return _rawset (self, "have_tooltip", nil)
Tercio@11 250 end
Tercio@11 251 end
Tercio@11 252 function SliderMetaFunctions:GetTooltip()
Tercio@11 253 return _rawget (self, "have_tooltip")
Tercio@11 254 end
Tercio@11 255
Tercio@11 256 -- frame levels
Tercio@11 257 function SliderMetaFunctions:GetFrameLevel()
Tercio@11 258 return self.slider:GetFrameLevel()
Tercio@11 259 end
Tercio@11 260 function SliderMetaFunctions:SetFrameLevel (level, frame)
Tercio@11 261 if (not frame) then
Tercio@11 262 return self.slider:SetFrameLevel (level)
Tercio@11 263 else
Tercio@11 264 local framelevel = frame:GetFrameLevel (frame) + level
Tercio@11 265 return self.slider:SetFrameLevel (framelevel)
Tercio@11 266 end
Tercio@11 267 end
Tercio@11 268
Tercio@11 269 -- frame stratas
Tercio@11 270 function SliderMetaFunctions:SetFrameStrata()
Tercio@11 271 return self.slider:GetFrameStrata()
Tercio@11 272 end
Tercio@11 273 function SliderMetaFunctions:SetFrameStrata (strata)
Tercio@11 274 if (_type (strata) == "table") then
Tercio@11 275 self.slider:SetFrameStrata (strata:GetFrameStrata())
Tercio@11 276 else
Tercio@11 277 self.slider:SetFrameStrata (strata)
Tercio@11 278 end
Tercio@11 279 end
Tercio@11 280
Tercio@11 281 -- enabled
Tercio@11 282 function SliderMetaFunctions:IsEnabled()
Tercio@11 283 return not _rawget (self, "lockdown")
Tercio@11 284 end
Tercio@11 285 function SliderMetaFunctions:Enable()
Tercio@11 286 self.slider:Enable()
Tercio@11 287 if (not self.lock_texture) then
Tercio@11 288 DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
Tercio@11 289 self.lock_texture:SetDesaturated (true)
Tercio@11 290 self.lock_texture:SetPoint ("center", self.amt, "center")
Tercio@11 291 end
Tercio@11 292 self.lock_texture:Hide()
Tercio@11 293 self.slider.amt:Show()
Tercio@11 294 self:SetAlpha (1)
Tercio@11 295 return _rawset (self, "lockdown", false)
Tercio@11 296 end
Tercio@11 297
Tercio@11 298 function SliderMetaFunctions:Disable()
Tercio@11 299
Tercio@11 300 self.slider:Disable()
Tercio@11 301 self.slider.amt:Hide()
Tercio@11 302 self:SetAlpha (.4)
Tercio@11 303
Tercio@11 304 if (not self.lock_texture) then
Tercio@11 305 DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
Tercio@11 306 self.lock_texture:SetDesaturated (true)
Tercio@11 307 self.lock_texture:SetPoint ("center", self.amt, "center")
Tercio@11 308 end
Tercio@11 309 self.lock_texture:Show()
Tercio@11 310
Tercio@11 311 return _rawset (self, "lockdown", true)
Tercio@11 312 end
Tercio@11 313
Tercio@11 314 --> hooks
Tercio@11 315 function SliderMetaFunctions:SetHook (hookType, func)
Tercio@11 316 if (func) then
Tercio@11 317 _rawset (self, hookType.."Hook", func)
Tercio@11 318 else
Tercio@11 319 _rawset (self, hookType.."Hook", nil)
Tercio@11 320 end
Tercio@11 321 end
Tercio@11 322
Tercio@11 323 ------------------------------------------------------------------------------------------------------------
Tercio@11 324 --> scripts
Tercio@11 325
Tercio@11 326 local OnEnter = function (slider)
Tercio@11 327
Tercio@11 328 if (_rawget (slider.MyObject, "lockdown")) then
Tercio@11 329 return
Tercio@11 330 end
Tercio@11 331
Tercio@11 332 DetailsFrameworkSliderButtons1:ShowMe (slider)
Tercio@11 333
Tercio@11 334 if (slider.MyObject.OnEnterHook) then
Tercio@11 335 local interrupt = slider.MyObject.OnEnterHook (slider)
Tercio@11 336 if (interrupt) then
Tercio@11 337 return
Tercio@11 338 end
Tercio@11 339 end
Tercio@11 340
Tercio@11 341 slider.thumb:SetAlpha (1)
Tercio@11 342
Tercio@22 343 if (slider.MyObject.onenter_backdrop_border_color) then
Tercio@22 344 slider:SetBackdropBorderColor (unpack (slider.MyObject.onenter_backdrop_border_color))
Tercio@22 345 end
Tercio@22 346
Tercio@11 347 if (slider.MyObject.have_tooltip and slider.MyObject.have_tooltip ~= "Right Click to Type the Value") then
Tercio@11 348 GameCooltip2:Preset (2)
Tercio@11 349 GameCooltip2:AddLine (slider.MyObject.have_tooltip)
Tercio@11 350 GameCooltip2:ShowCooltip (slider, "tooltip")
Tercio@11 351 else
Tercio@11 352 GameCooltip2:Preset (1)
Tercio@11 353 GameCooltip2:AddLine ("Right Click to Type the Value")
Tercio@11 354 GameCooltip2:AddIcon ([[Interface\TUTORIALFRAME\UI-TUTORIAL-FRAME]], 1, 1, 16, 16, 0.015625, 0.15671875, 0.640625, 0.798828125)
Tercio@11 355 GameCooltip2:ShowCooltip (slider, "tooltip")
Tercio@11 356 end
Tercio@11 357 end
Tercio@11 358
Tercio@11 359 local OnLeave = function (slider)
Tercio@11 360
Tercio@11 361 if (_rawget (slider.MyObject, "lockdown")) then
Tercio@11 362 return
Tercio@11 363 end
Tercio@11 364
Tercio@11 365 DetailsFrameworkSliderButtons1:PrepareToHide()
Tercio@11 366
Tercio@11 367 if (slider.MyObject.OnLeaveHook) then
Tercio@11 368 local interrupt = slider.MyObject.OnLeaveHook (slider)
Tercio@11 369 if (interrupt) then
Tercio@11 370 return
Tercio@11 371 end
Tercio@11 372 end
Tercio@11 373
Tercio@11 374 slider.thumb:SetAlpha (.7)
Tercio@11 375
Tercio@22 376 if (slider.MyObject.onleave_backdrop_border_color) then
Tercio@22 377 slider:SetBackdropBorderColor (unpack (slider.MyObject.onleave_backdrop_border_color))
Tercio@22 378 end
Tercio@22 379
Tercio@11 380 if (slider.MyObject.have_tooltip) then
Tercio@11 381 GameCooltip2:ShowMe (false)
Tercio@11 382 end
Tercio@11 383
Tercio@11 384 end
Tercio@11 385
Tercio@11 386
Tercio@11 387 local f = CreateFrame ("frame", "DetailsFrameworkSliderButtons1", UIParent)
Tercio@11 388 f:Hide()
Tercio@11 389 --f:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]], tile = true, tileSize = 5})
Tercio@11 390 f:SetHeight (18)
Tercio@11 391
Tercio@11 392 local t = 0
Tercio@11 393 f.is_going_hide = false
Tercio@11 394 local going_hide = function (self, elapsed)
Tercio@11 395 t = t + elapsed
Tercio@11 396 if (t > 0.3) then
Tercio@11 397 f:Hide()
Tercio@11 398 f:SetScript ("OnUpdate", nil)
Tercio@11 399 f.is_going_hide = false
Tercio@11 400 end
Tercio@11 401 end
Tercio@11 402
Tercio@11 403 function f:ShowMe (host)
Tercio@11 404 f:SetPoint ("bottomleft", host, "topleft", -3, -5)
Tercio@11 405 f:SetPoint ("bottomright", host, "topright", 3, -5)
Tercio@11 406 f:SetFrameStrata (host:GetFrameStrata())
Tercio@11 407 f:SetFrameLevel (host:GetFrameLevel())
Tercio@11 408 f:Show()
Tercio@11 409 if (f.is_going_hide) then
Tercio@11 410 f:SetScript ("OnUpdate", nil)
Tercio@11 411 f.is_going_hide = false
Tercio@11 412 end
Tercio@11 413
Tercio@11 414 f.host = host.MyObject
Tercio@11 415 end
Tercio@11 416
Tercio@11 417 function f:PrepareToHide()
Tercio@11 418 f.is_going_hide = true
Tercio@11 419 t = 0
Tercio@11 420 f:SetScript ("OnUpdate", going_hide)
Tercio@11 421 end
Tercio@11 422
Tercio@11 423 local button_plus = CreateFrame ("button", "DetailsFrameworkSliderButtonsPlusButton", f)
Tercio@11 424 local button_minor = CreateFrame ("button", "DetailsFrameworkSliderButtonsMinorButton", f)
Tercio@11 425
Tercio@11 426 button_plus:SetScript ("OnEnter", function (self)
Tercio@11 427 if (f.is_going_hide) then
Tercio@11 428 f:SetScript ("OnUpdate", nil)
Tercio@11 429 f.is_going_hide = false
Tercio@11 430 end
Tercio@11 431 end)
Tercio@11 432 button_minor:SetScript ("OnEnter", function (self)
Tercio@11 433 if (f.is_going_hide) then
Tercio@11 434 f:SetScript ("OnUpdate", nil)
Tercio@11 435 f.is_going_hide = false
Tercio@11 436 end
Tercio@11 437 end)
Tercio@11 438
Tercio@11 439 button_plus:SetScript ("OnLeave", function (self)
Tercio@11 440 f:PrepareToHide()
Tercio@11 441 end)
Tercio@11 442 button_minor:SetScript ("OnLeave", function (self)
Tercio@11 443 f:PrepareToHide()
Tercio@11 444 end)
Tercio@11 445
Tercio@11 446 button_plus:SetNormalTexture ([[Interface\Buttons\UI-PlusButton-Up]])
Tercio@11 447 button_minor:SetNormalTexture ([[Interface\Buttons\UI-MinusButton-Up]])
Tercio@11 448
Tercio@11 449 button_plus:SetPushedTexture ([[Interface\Buttons\UI-PlusButton-Down]])
Tercio@11 450 button_minor:SetPushedTexture ([[Interface\Buttons\UI-MinusButton-Down]])
Tercio@11 451
Tercio@11 452 button_plus:SetDisabledTexture ([[Interface\Buttons\UI-PlusButton-Disabled]])
Tercio@11 453 button_minor:SetDisabledTexture ([[Interface\Buttons\UI-MinusButton-Disabled]])
Tercio@11 454
Tercio@11 455 button_plus:SetHighlightTexture ([[Interface\Buttons\UI-PlusButton-Hilight]])
Tercio@11 456 button_minor:SetHighlightTexture ([[Interface\Buttons\UI-PlusButton-Hilight]])
Tercio@11 457
Tercio@11 458 --button_minor:SetPoint ("bottomleft", f, "bottomleft", -6, -13)
Tercio@11 459 --button_plus:SetPoint ("bottomright", f, "bottomright", 6, -13)
Tercio@11 460
Tercio@11 461 button_minor:SetPoint ("bottomright", f, "bottomright", 13, -13)
Tercio@11 462 button_plus:SetPoint ("left", button_minor, "right", -2, 0)
Tercio@11 463
Tercio@11 464 button_plus:SetSize (16, 16)
Tercio@11 465 button_minor:SetSize (16, 16)
Tercio@11 466
Tercio@11 467 local timer = 0
Tercio@11 468 local change_timer = 0
Tercio@11 469
Tercio@11 470 -- -- --
Tercio@11 471
Tercio@11 472 local plus_button_script = function()
Tercio@11 473
Tercio@11 474 local current = f.host.value
Tercio@11 475 local editbox = SliderMetaFunctions.editbox_typevalue
Tercio@11 476
Tercio@11 477 if (f.host.fine_tuning) then
Tercio@11 478 f.host:SetValue (current + f.host.fine_tuning)
Tercio@11 479 if (editbox and SliderMetaFunctions.editbox_typevalue:IsShown()) then
Tercio@11 480 SliderMetaFunctions.editbox_typevalue:SetText (tostring (string.format ("%.2f", current + f.host.fine_tuning)))
Tercio@11 481 end
Tercio@11 482 else
Tercio@11 483 if (f.host.useDecimals) then
Tercio@11 484 f.host:SetValue (current + 0.1)
Tercio@11 485 if (editbox and SliderMetaFunctions.editbox_typevalue:IsShown()) then
Tercio@11 486 SliderMetaFunctions.editbox_typevalue:SetText (string.format ("%.2f", current + 0.1))
Tercio@11 487 end
Tercio@11 488 else
Tercio@11 489 f.host:SetValue (current + 1)
Tercio@11 490 if (editbox and SliderMetaFunctions.editbox_typevalue:IsShown()) then
Tercio@11 491 SliderMetaFunctions.editbox_typevalue:SetText (tostring (math.floor (current + 1)))
Tercio@11 492 end
Tercio@11 493 end
Tercio@11 494 end
Tercio@11 495
Tercio@11 496 end
Tercio@11 497
Tercio@11 498 button_plus:SetScript ("OnMouseUp", function (self)
Tercio@11 499 if (not button_plus.got_click) then
Tercio@11 500 plus_button_script()
Tercio@11 501 end
Tercio@11 502 button_plus.got_click = false
Tercio@11 503 self:SetScript ("OnUpdate", nil)
Tercio@11 504 end)
Tercio@11 505
Tercio@11 506 local on_update = function (self, elapsed)
Tercio@11 507 timer = timer + elapsed
Tercio@11 508 if (timer > 0.4) then
Tercio@11 509 change_timer = change_timer + elapsed
Tercio@11 510 if (change_timer > 0.1) then
Tercio@11 511 change_timer = 0
Tercio@11 512 plus_button_script()
Tercio@11 513 button_plus.got_click = true
Tercio@11 514 end
Tercio@11 515 end
Tercio@11 516 end
Tercio@11 517 button_plus:SetScript ("OnMouseDown", function (self)
Tercio@11 518 timer = 0
Tercio@11 519 change_timer = 0
Tercio@11 520 self:SetScript ("OnUpdate", on_update)
Tercio@11 521 end)
Tercio@11 522
Tercio@11 523 -- -- --
Tercio@11 524
Tercio@11 525 local minor_button_script = function()
Tercio@11 526 local current = f.host.value
Tercio@11 527 local editbox = SliderMetaFunctions.editbox_typevalue
Tercio@11 528
Tercio@11 529 if (f.host.fine_tuning) then
Tercio@11 530 f.host:SetValue (current - f.host.fine_tuning)
Tercio@11 531 if (editbox and SliderMetaFunctions.editbox_typevalue:IsShown()) then
Tercio@11 532 SliderMetaFunctions.editbox_typevalue:SetText (tostring (string.format ("%.2f", current - f.host.fine_tuning)))
Tercio@11 533 end
Tercio@11 534 else
Tercio@11 535 if (f.host.useDecimals) then
Tercio@11 536 f.host:SetValue (current - 0.1)
Tercio@11 537 if (editbox and SliderMetaFunctions.editbox_typevalue:IsShown()) then
Tercio@11 538 SliderMetaFunctions.editbox_typevalue:SetText (string.format ("%.2f", current - 0.1))
Tercio@11 539 end
Tercio@11 540 else
Tercio@11 541 f.host:SetValue (current - 1)
Tercio@11 542 if (editbox and SliderMetaFunctions.editbox_typevalue:IsShown()) then
Tercio@11 543 SliderMetaFunctions.editbox_typevalue:SetText (tostring (math.floor (current - 1)))
Tercio@11 544 end
Tercio@11 545 end
Tercio@11 546 end
Tercio@11 547 end
Tercio@11 548
Tercio@11 549 button_minor:SetScript ("OnMouseUp", function (self)
Tercio@11 550 if (not button_minor.got_click) then
Tercio@11 551 minor_button_script()
Tercio@11 552 end
Tercio@11 553 button_minor.got_click = false
Tercio@11 554 self:SetScript ("OnUpdate", nil)
Tercio@11 555 end)
Tercio@11 556
Tercio@11 557 local on_update = function (self, elapsed)
Tercio@11 558 timer = timer + elapsed
Tercio@11 559 if (timer > 0.4) then
Tercio@11 560 change_timer = change_timer + elapsed
Tercio@11 561 if (change_timer > 0.1) then
Tercio@11 562 change_timer = 0
Tercio@11 563 minor_button_script()
Tercio@11 564 button_minor.got_click = true
Tercio@11 565 end
Tercio@11 566 end
Tercio@11 567 end
Tercio@11 568 button_minor:SetScript ("OnMouseDown", function (self)
Tercio@11 569 timer = 0
Tercio@11 570 change_timer = 0
Tercio@11 571 self:SetScript ("OnUpdate", on_update)
Tercio@11 572 end)
Tercio@11 573
Tercio@11 574 function SliderMetaFunctions:TypeValue()
Tercio@11 575 if (not self.isSwitch) then
Tercio@11 576
Tercio@11 577 if (not SliderMetaFunctions.editbox_typevalue) then
Tercio@11 578
Tercio@11 579 local editbox = CreateFrame ("EditBox", "DetailsFrameworkSliderEditBox", UIParent)
Tercio@11 580
Tercio@11 581 editbox:SetSize (40, 20)
Tercio@11 582 editbox:SetJustifyH ("center")
Tercio@11 583 editbox:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]],
Tercio@11 584 edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", --edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
Tercio@11 585 tile = true, edgeSize = 8, tileSize = 5})
Tercio@11 586 editbox:SetFontObject ("GameFontHighlightSmall")
Tercio@11 587
Tercio@11 588 editbox:SetScript ("OnEnterPressed", function()
Tercio@11 589 editbox:ClearFocus()
Tercio@11 590 editbox:Hide()
Tercio@11 591 editbox:GetParent().MyObject.typing_value = false
Tercio@11 592 editbox:GetParent().MyObject.value = tonumber (editbox:GetText())
Tercio@11 593 end)
Tercio@11 594
Tercio@11 595 editbox:SetScript ("OnEscapePressed", function()
Tercio@11 596 editbox:ClearFocus()
Tercio@11 597 editbox:Hide()
Tercio@11 598 editbox:GetParent().MyObject.typing_value = false
Tercio@11 599 editbox:GetParent().MyObject.value = tonumber (self.typing_value_started)
Tercio@11 600 end)
Tercio@11 601
Tercio@11 602 editbox:SetScript ("OnTextChanged", function()
Tercio@11 603 editbox:GetParent().MyObject.typing_can_change = true
Tercio@11 604 editbox:GetParent().MyObject.value = tonumber (editbox:GetText())
Tercio@11 605 editbox:GetParent().MyObject.typing_can_change = false
Tercio@11 606
Tercio@11 607 -- esse self fica como o primeiro a ser alterado
Tercio@11 608 --print ("text changed", self:GetName())
Tercio@11 609 --print ()
Tercio@11 610 end)
Tercio@11 611
Tercio@11 612 SliderMetaFunctions.editbox_typevalue = editbox
Tercio@11 613 end
Tercio@11 614
Tercio@11 615 local pvalue = self.previous_value [2]
Tercio@11 616 self:SetValue (pvalue)
Tercio@11 617
Tercio@11 618 self.typing_value = true
Tercio@11 619 self.typing_value_started = pvalue
Tercio@11 620
Tercio@11 621 SliderMetaFunctions.editbox_typevalue:SetSize (self.width, self.height)
Tercio@11 622 SliderMetaFunctions.editbox_typevalue:SetPoint ("center", self.widget, "center")
Tercio@11 623 SliderMetaFunctions.editbox_typevalue:SetFocus()
Tercio@11 624 SliderMetaFunctions.editbox_typevalue:SetParent (self.widget)
Tercio@11 625 SliderMetaFunctions.editbox_typevalue:SetFrameLevel (self.widget:GetFrameLevel()+1)
Tercio@11 626
Tercio@11 627 if (self.useDecimals) then
Tercio@11 628 SliderMetaFunctions.editbox_typevalue:SetText (tostring (string.format ("%.1f", self.value)))
Tercio@11 629 else
Tercio@11 630 SliderMetaFunctions.editbox_typevalue:SetText (tostring (math.floor (self.value)))
Tercio@11 631 end
Tercio@11 632
Tercio@11 633 SliderMetaFunctions.editbox_typevalue:HighlightText()
Tercio@11 634
Tercio@11 635 SliderMetaFunctions.editbox_typevalue:Show()
Tercio@11 636 end
Tercio@11 637 end
Tercio@11 638
Tercio@11 639 local OnMouseDown = function (slider, button)
Tercio@11 640 if (button == "RightButton") then
Tercio@11 641 slider.MyObject:TypeValue()
Tercio@11 642 end
Tercio@11 643 end
Tercio@11 644
Tercio@11 645 local OnMouseUp = function (slider, button)
Tercio@11 646 --if (button == "RightButton") then
Tercio@11 647 -- if (slider.MyObject.typing_value) then
Tercio@11 648 -- slider.MyObject:SetValue (slider.MyObject.previous_value [2])
Tercio@11 649 -- end
Tercio@11 650 --end
Tercio@11 651 end
Tercio@11 652
Tercio@11 653 local OnHide = function (slider)
Tercio@11 654 if (slider.MyObject.OnHideHook) then
Tercio@11 655 local interrupt = slider.MyObject.OnHideHook (slider)
Tercio@11 656 if (interrupt) then
Tercio@11 657 return
Tercio@11 658 end
Tercio@11 659 end
Tercio@11 660
Tercio@11 661 if (slider.MyObject.typing_value) then
Tercio@11 662 SliderMetaFunctions.editbox_typevalue:ClearFocus()
Tercio@11 663 SliderMetaFunctions.editbox_typevalue:SetText ("")
Tercio@11 664 slider.MyObject.typing_valu = false
Tercio@11 665 end
Tercio@11 666 end
Tercio@11 667
Tercio@11 668 local OnShow = function (slider)
Tercio@11 669 if (slider.MyObject.OnShowHook) then
Tercio@11 670 local interrupt = slider.MyObject.OnShowHook (slider)
Tercio@11 671 if (interrupt) then
Tercio@11 672 return
Tercio@11 673 end
Tercio@11 674 end
Tercio@11 675 end
Tercio@11 676
Tercio@11 677 local table_insert = table.insert
Tercio@11 678 local table_remove = table.remove
Tercio@11 679
Tercio@11 680 local OnValueChanged = function (slider)
Tercio@11 681
Tercio@12 682 local amt
Tercio@12 683 if (slider.MyObject.useDecimals) then
Tercio@12 684 amt = slider:GetValue()
Tercio@12 685 else
Tercio@12 686 amt = _math_floor (slider:GetValue())
Tercio@12 687 end
Tercio@11 688
Tercio@11 689 if (slider.MyObject.typing_value and not slider.MyObject.typing_can_change) then
Tercio@11 690 slider.MyObject:SetValue (slider.MyObject.typing_value_started)
Tercio@11 691 return
Tercio@11 692 end
Tercio@11 693
Tercio@11 694 table_insert (slider.MyObject.previous_value, 1, amt)
Tercio@11 695 table_remove (slider.MyObject.previous_value, 4)
Tercio@11 696
Tercio@11 697 if (slider.MyObject.OnValueChangeHook) then
Tercio@11 698 local interrupt = slider.MyObject.OnValueChangeHook (slider, slider.MyObject.FixedValue, amt)
Tercio@11 699 if (interrupt) then
Tercio@11 700 return
Tercio@11 701 end
Tercio@11 702 end
Tercio@11 703
Tercio@11 704 if (slider.MyObject.OnValueChanged) then
Tercio@11 705 slider.MyObject.OnValueChanged (slider, slider.MyObject.FixedValue, amt)
Tercio@11 706 end
Tercio@11 707
Tercio@11 708 if (amt < 10 and amt >= 1) then
Tercio@11 709 amt = "0"..amt
Tercio@11 710 end
Tercio@11 711
Tercio@11 712 if (slider.MyObject.useDecimals) then
Tercio@11 713 slider.amt:SetText (string.format ("%.2f", amt))
Tercio@11 714 else
Tercio@11 715 slider.amt:SetText (math.floor (amt))
Tercio@11 716 end
Tercio@11 717 slider.MyObject.ivalue = amt
Tercio@11 718 end
Tercio@11 719
Tercio@11 720 ------------------------------------------------------------------------------------------------------------
Tercio@11 721 --> object constructor
Tercio@11 722
Tercio@11 723 local SwitchOnClick = function (self, button, forced_value, value)
Tercio@11 724
Tercio@11 725 local slider = self.MyObject
Tercio@11 726
Tercio@11 727 if (_rawget (slider, "lockdown")) then
Tercio@11 728 return
Tercio@11 729 end
Tercio@11 730
Tercio@11 731 if (forced_value) then
Tercio@11 732 _rawset (slider, "value", not value)
Tercio@11 733 end
Tercio@11 734
Tercio@11 735 if (_rawget (slider, "value")) then --actived
Tercio@11 736 _rawset (slider, "value", false)
Tercio@11 737
Tercio@22 738 if (slider.backdrop_disabledcolor) then
Tercio@22 739 slider:SetBackdropColor (unpack (slider.backdrop_disabledcolor))
Tercio@22 740 else
Tercio@22 741 slider:SetBackdropColor (1, 0, 0, 0.4)
Tercio@22 742 end
Tercio@22 743
Tercio@22 744 if (slider.is_checkbox) then
Tercio@22 745 slider.checked_texture:Hide()
Tercio@22 746 else
Tercio@22 747 slider._text:SetText (slider._ltext)
Tercio@22 748 slider._thumb:ClearAllPoints()
Tercio@22 749 slider._thumb:SetPoint ("left", slider.widget, "left")
Tercio@22 750 end
Tercio@11 751 else
Tercio@11 752 _rawset (slider, "value", true)
Tercio@22 753 if (slider.backdrop_enabledcolor) then
Tercio@22 754 slider:SetBackdropColor (unpack (slider.backdrop_enabledcolor))
Tercio@22 755 else
Tercio@22 756 slider:SetBackdropColor (0, 0, 1, 0.4)
Tercio@22 757 end
Tercio@22 758 if (slider.is_checkbox) then
Tercio@22 759 slider.checked_texture:Show()
Tercio@22 760 else
Tercio@22 761 slider._text:SetText (slider._rtext)
Tercio@22 762 slider._thumb:ClearAllPoints()
Tercio@22 763 slider._thumb:SetPoint ("right", slider.widget, "right")
Tercio@22 764 end
Tercio@11 765 end
Tercio@11 766
Tercio@11 767 if (slider.OnSwitch and not forced_value) then
Tercio@11 768 local value = _rawget (slider, "value")
Tercio@11 769 if (slider.return_func) then
Tercio@11 770 value = slider:return_func (value)
Tercio@11 771 end
Tercio@11 772 slider.OnSwitch (slider, slider.FixedValue, value)
Tercio@11 773 end
Tercio@11 774
Tercio@11 775 end
Tercio@11 776
Tercio@11 777 local default_switch_func = function (self, passed_value)
Tercio@11 778 if (self.value) then
Tercio@11 779 return false
Tercio@11 780 else
Tercio@11 781 return true
Tercio@11 782 end
Tercio@11 783 end
Tercio@11 784
Tercio@11 785 local switch_get_value = function (self)
Tercio@11 786 return self.value
Tercio@11 787 end
Tercio@11 788
Tercio@11 789 local switch_set_value = function (self, value)
Tercio@11 790 if (self.switch_func) then
Tercio@11 791 value = self:switch_func (value)
Tercio@11 792 end
Tercio@11 793
Tercio@11 794 SwitchOnClick (self.widget, nil, true, value)
Tercio@11 795 end
Tercio@11 796
Tercio@11 797 local switch_set_fixparameter = function (self, value)
Tercio@11 798 _rawset (self, "FixedValue", value)
Tercio@11 799 end
Tercio@11 800
Tercio@11 801 local switch_disable = function (self)
Tercio@11 802 if (not self.lock_texture) then
Tercio@11 803 DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
Tercio@11 804 self.lock_texture:SetDesaturated (true)
Tercio@11 805 self.lock_texture:SetPoint ("center", self._thumb, "center")
Tercio@11 806 end
Tercio@11 807
Tercio@22 808 if (self.is_checkbox) then
Tercio@22 809 self.checked_texture:Hide()
Tercio@22 810 else
Tercio@22 811 self._text:Hide()
Tercio@22 812 end
Tercio@22 813
Tercio@11 814 self.lock_texture:Show()
Tercio@11 815 self:SetAlpha (.4)
Tercio@11 816 _rawset (self, "lockdown", true)
Tercio@11 817 end
Tercio@11 818 local switch_enable = function (self)
Tercio@11 819 if (not self.lock_texture) then
Tercio@11 820 DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
Tercio@11 821 self.lock_texture:SetDesaturated (true)
Tercio@11 822 self.lock_texture:SetPoint ("center", self._thumb, "center")
Tercio@11 823 end
Tercio@11 824
Tercio@22 825 if (self.is_checkbox) then
Tercio@22 826 if (_rawget (self, "value")) then
Tercio@22 827 self.checked_texture:Show()
Tercio@22 828 else
Tercio@22 829 self.checked_texture:Hide()
Tercio@22 830 end
Tercio@22 831 else
Tercio@22 832 self._text:Show()
Tercio@22 833 end
Tercio@22 834
Tercio@11 835 self.lock_texture:Hide()
Tercio@11 836 self:SetAlpha (1)
Tercio@11 837 return _rawset (self, "lockdown", false)
Tercio@11 838 end
Tercio@11 839
Tercio@22 840 local set_as_checkbok = function (self)
Tercio@22 841 local checked = self:CreateTexture (nil, "overlay")
Tercio@22 842 checked:SetTexture ([[Interface\Buttons\UI-CheckBox-Check]])
Tercio@22 843 checked:SetPoint ("center", self.button, "center", -1, -1)
Tercio@22 844 local size_pct = self:GetWidth()/32
Tercio@22 845 checked:SetSize (32*size_pct, 32*size_pct)
Tercio@22 846 self.checked_texture = checked
Tercio@22 847
Tercio@22 848 self._thumb:Hide()
Tercio@22 849 self._text:Hide()
Tercio@22 850
Tercio@22 851 self.is_checkbox = true
Tercio@22 852
Tercio@22 853 if (_rawget (self, "value")) then
Tercio@22 854 self.checked_texture:Show()
Tercio@22 855 if (self.backdrop_enabledcolor) then
Tercio@22 856 self:SetBackdropColor (unpack (self.backdrop_enabledcolor))
Tercio@22 857 else
Tercio@22 858 self:SetBackdropColor (0, 0, 1, 0.4)
Tercio@22 859 end
Tercio@22 860 else
Tercio@22 861 self.checked_texture:Hide()
Tercio@22 862 if (self.backdrop_disabledcolor) then
Tercio@22 863 self:SetBackdropColor (unpack (self.backdrop_disabledcolor))
Tercio@22 864 else
Tercio@22 865 self:SetBackdropColor (0, 0, 1, 0.4)
Tercio@22 866 end
Tercio@22 867 end
Tercio@22 868 end
Tercio@22 869
Tercio@22 870 function DF:CreateSwitch (parent, on_switch, default_value, w, h, ltext, rtext, member, name, color_inverted, switch_func, return_func, with_label, switch_template, label_template)
Tercio@22 871 local switch, label = DF:NewSwitch (parent, parent, name, member, w or 60, h or 20, ltext, rtext, default_value, color_inverted, switch_func, return_func, with_label, switch_template, label_template)
Tercio@11 872 if (on_switch) then
Tercio@11 873 switch.OnSwitch = on_switch
Tercio@11 874 end
Tercio@11 875 return switch, label
Tercio@11 876 end
Tercio@11 877
Tercio@22 878 function DF:NewSwitch (parent, container, name, member, w, h, ltext, rtext, default_value, color_inverted, switch_func, return_func, with_label, switch_template, label_template)
Tercio@11 879
Tercio@11 880 --> early checks
Tercio@11 881 if (not name) then
Tercio@11 882 name = "DetailsFrameWorkSlider" .. NameLessSlider
Tercio@11 883 NameLessSlider = NameLessSlider + 1
Tercio@11 884 elseif (not parent) then
Tercio@11 885 return nil
Tercio@11 886 end
Tercio@11 887 if (not container) then
Tercio@11 888 container = parent
Tercio@11 889 end
Tercio@11 890
Tercio@11 891 --> defaults
Tercio@11 892 ltext = ltext or "OFF"
Tercio@11 893 rtext = rtext or "ON"
Tercio@11 894
Tercio@11 895 --> build frames
Tercio@11 896
Tercio@11 897 w = w or 60
Tercio@11 898 h = h or 20
Tercio@11 899
Tercio@11 900 local slider = DF:NewButton (parent, container, name, member, w, h)
Tercio@11 901
Tercio@11 902 slider.switch_func = switch_func
Tercio@11 903 slider.return_func = return_func
Tercio@11 904 slider.SetValue = switch_set_value
Tercio@11 905 slider.GetValue = switch_get_value
Tercio@11 906 slider.SetFixedParameter = switch_set_fixparameter
Tercio@11 907 slider.Disable = switch_disable
Tercio@11 908 slider.Enable = switch_enable
Tercio@22 909 slider.SetAsCheckBox = set_as_checkbok
Tercio@22 910 slider.SetTemplate = SliderMetaFunctions.SetTemplate
Tercio@11 911
Tercio@11 912 if (member) then
Tercio@11 913 parent [member] = slider
Tercio@11 914 end
Tercio@11 915
Tercio@11 916 slider:SetBackdrop ({edgeFile = [[Interface\Buttons\UI-SliderBar-Border]], edgeSize = 8,
Tercio@11 917 bgFile = [[Interface\AddOns\Details\images\background]], insets = {left = 3, right = 3, top = 5, bottom = 5}})
Tercio@11 918
Tercio@11 919 local thumb = slider:CreateTexture (nil, "artwork")
Tercio@11 920 thumb:SetTexture ("Interface\\Buttons\\UI-ScrollBar-Knob")
Tercio@11 921 thumb:SetSize (34+(h*0.2), h*1.2)
Tercio@11 922 thumb:SetAlpha (0.7)
Tercio@11 923 thumb:SetPoint ("left", slider.widget, "left")
Tercio@11 924
Tercio@11 925 local text = slider:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
Tercio@11 926 text:SetTextColor (.8, .8, .8, 1)
Tercio@11 927 text:SetPoint ("center", thumb, "center")
Tercio@11 928
Tercio@11 929 slider._text = text
Tercio@11 930 slider._thumb = thumb
Tercio@11 931 slider._ltext = ltext
Tercio@11 932 slider._rtext = rtext
Tercio@11 933 slider.thumb = thumb
Tercio@11 934
Tercio@11 935 slider.invert_colors = color_inverted
Tercio@11 936
Tercio@11 937 slider:SetScript ("OnClick", SwitchOnClick)
Tercio@11 938
Tercio@11 939 slider:SetValue (default_value)
Tercio@11 940
Tercio@11 941 slider.isSwitch = true
Tercio@11 942
Tercio@22 943 if (switch_template) then
Tercio@22 944 slider:SetTemplate (switch_template)
Tercio@22 945 end
Tercio@22 946
Tercio@11 947 if (with_label) then
Tercio@11 948 local label = DF:CreateLabel (slider.widget, with_label, nil, nil, nil, "label", nil, "overlay")
Tercio@11 949 label.text = with_label
Tercio@11 950 slider.widget:SetPoint ("left", label.widget, "right", 2, 0)
Tercio@11 951 with_label = label
Tercio@22 952
Tercio@22 953 if (label_template) then
Tercio@22 954 label:SetTemplate (label_template)
Tercio@22 955 end
Tercio@11 956 end
Tercio@11 957
Tercio@11 958 return slider, with_label
Tercio@11 959 end
Tercio@11 960
Tercio@22 961 function SliderMetaFunctions:SetTemplate (template)
Tercio@22 962
Tercio@22 963 --slider e switch
Tercio@22 964 if (template.width) then
Tercio@22 965 self:SetWidth (template.width)
Tercio@22 966 end
Tercio@22 967 if (template.height) then
Tercio@22 968 self:SetHeight (template.height)
Tercio@22 969 end
Tercio@22 970
Tercio@22 971 if (template.backdrop) then
Tercio@22 972 self:SetBackdrop (template.backdrop)
Tercio@22 973 end
Tercio@22 974 if (template.backdropcolor) then
Tercio@22 975 local r, g, b, a = DF:ParseColors (template.backdropcolor)
Tercio@22 976 self:SetBackdropColor (r, g, b, a)
Tercio@22 977 end
Tercio@22 978 if (template.backdropbordercolor) then
Tercio@22 979 local r, g, b, a = DF:ParseColors (template.backdropbordercolor)
Tercio@22 980 self:SetBackdropBorderColor (r, g, b, a)
Tercio@22 981 self.onleave_backdrop_border_color = {r, g, b, a}
Tercio@22 982 end
Tercio@22 983
Tercio@22 984 if (template.onenterbordercolor) then
Tercio@22 985 local r, g, b, a = DF:ParseColors (template.onenterbordercolor)
Tercio@22 986 self.onenter_backdrop_border_color = {r, g, b, a}
Tercio@22 987 end
Tercio@22 988
Tercio@22 989 if (template.onleavebordercolor) then
Tercio@22 990 local r, g, b, a = DF:ParseColors (template.onleavebordercolor)
Tercio@22 991 self.onleave_backdrop_border_color = {r, g, b, a}
Tercio@22 992 end
Tercio@22 993
Tercio@22 994 if (template.thumbtexture) then
Tercio@22 995 if (self.thumb) then
Tercio@22 996 self.thumb:SetTexture (template.thumbtexture)
Tercio@22 997 end
Tercio@22 998 end
Tercio@22 999 if (template.thumbwidth) then
Tercio@22 1000 if (self.thumb) then
Tercio@22 1001 self.thumb:SetWidth (template.thumbwidth)
Tercio@22 1002 end
Tercio@22 1003 end
Tercio@22 1004 if (template.thumbheight) then
Tercio@22 1005 if (self.thumb) then
Tercio@22 1006 self.thumb:SetHeight (template.thumbheight)
Tercio@22 1007 end
Tercio@22 1008 end
Tercio@22 1009 if (template.thumbcolor) then
Tercio@22 1010 if (self.thumb) then
Tercio@22 1011 local r, g, b, a = DF:ParseColors (template.thumbcolor)
Tercio@22 1012 self.thumb:SetVertexColor (r, g, b, a)
Tercio@22 1013 end
Tercio@22 1014 end
Tercio@22 1015
Tercio@22 1016 --switch only
Tercio@22 1017 if (template.enabled_backdropcolor) then
Tercio@22 1018 local r, g, b, a = DF:ParseColors (template.enabled_backdropcolor)
Tercio@22 1019 self.backdrop_enabledcolor = {r, g, b, a}
Tercio@22 1020 end
Tercio@22 1021 if (template.disabled_backdropcolor) then
Tercio@22 1022 local r, g, b, a = DF:ParseColors (template.disabled_backdropcolor)
Tercio@22 1023 self.backdrop_disabledcolor = {r, g, b, a}
Tercio@22 1024 end
Tercio@22 1025 end
Tercio@22 1026
Tercio@22 1027 function DF:CreateSlider (parent, w, h, min, max, step, defaultv, isDecemal, member, name, with_label, slider_template, label_template)
Tercio@22 1028 local slider, label = DF:NewSlider (parent, parent, name, member, w, h, min, max, step, defaultv, isDecemal, false, with_label, slider_template, label_template)
Tercio@11 1029 return slider, label
Tercio@11 1030 end
Tercio@11 1031
Tercio@22 1032 function DF:NewSlider (parent, container, name, member, w, h, min, max, step, defaultv, isDecemal, isSwitch, with_label, slider_template, label_template)
Tercio@11 1033
Tercio@11 1034 --> early checks
Tercio@11 1035 if (not name) then
Tercio@11 1036 name = "DetailsFrameworkSlider" .. DF.SliderCounter
Tercio@11 1037 DF.SliderCounter = DF.SliderCounter + 1
Tercio@11 1038 end
Tercio@11 1039 if (not parent) then
Tercio@11 1040 return nil
Tercio@11 1041 end
Tercio@11 1042 if (not container) then
Tercio@11 1043 container = parent
Tercio@11 1044 end
Tercio@11 1045
Tercio@11 1046 if (name:find ("$parent")) then
Tercio@11 1047 name = name:gsub ("$parent", parent:GetName())
Tercio@11 1048 end
Tercio@11 1049
Tercio@11 1050 local SliderObject = {type = "slider", dframework = true}
Tercio@11 1051
Tercio@11 1052 if (member) then
Tercio@11 1053 parent [member] = SliderObject
Tercio@11 1054 end
Tercio@11 1055
Tercio@11 1056 if (parent.dframework) then
Tercio@11 1057 parent = parent.widget
Tercio@11 1058 end
Tercio@11 1059 if (container.dframework) then
Tercio@11 1060 container = container.widget
Tercio@11 1061 end
Tercio@11 1062
Tercio@11 1063 --> defaults
Tercio@11 1064 min = min or 1
Tercio@11 1065 max = max or 2
Tercio@11 1066 step = step or 1
Tercio@11 1067 defaultv = defaultv or min
Tercio@11 1068
Tercio@11 1069 w = w or 130
Tercio@11 1070 h = h or 19
Tercio@11 1071
Tercio@11 1072 --> default members:
Tercio@11 1073 --> hooks
Tercio@11 1074 SliderObject.OnEnterHook = nil
Tercio@11 1075 SliderObject.OnLeaveHook = nil
Tercio@11 1076 SliderObject.OnHideHook = nil
Tercio@11 1077 SliderObject.OnShowHook = nil
Tercio@11 1078 SliderObject.OnValueChangeHook = nil
Tercio@11 1079 --> misc
Tercio@11 1080 SliderObject.lockdown = false
Tercio@11 1081 SliderObject.container = container
Tercio@11 1082 SliderObject.have_tooltip = nil
Tercio@11 1083 SliderObject.FixedValue = nil
Tercio@11 1084 SliderObject.useDecimals = isDecemal or false
Tercio@11 1085
Tercio@11 1086 SliderObject.slider = CreateFrame ("slider", name, parent)
Tercio@11 1087 SliderObject.widget = SliderObject.slider
Tercio@11 1088
Tercio@11 1089 if (not APISliderFunctions) then
Tercio@11 1090 APISliderFunctions = true
Tercio@11 1091 local idx = getmetatable (SliderObject.slider).__index
Tercio@11 1092 for funcName, funcAddress in pairs (idx) do
Tercio@11 1093 if (not SliderMetaFunctions [funcName]) then
Tercio@11 1094 SliderMetaFunctions [funcName] = function (object, ...)
Tercio@20 1095 local x = loadstring ( "return _G['"..object.slider:GetName().."']:"..funcName.."(...)")
Tercio@11 1096 return x (...)
Tercio@11 1097 end
Tercio@11 1098 end
Tercio@11 1099 end
Tercio@11 1100 end
Tercio@11 1101
Tercio@11 1102 SliderObject.slider.MyObject = SliderObject
Tercio@11 1103 SliderObject.slider:SetWidth (w)
Tercio@11 1104 SliderObject.slider:SetHeight (h)
Tercio@11 1105 SliderObject.slider:SetOrientation ("horizontal")
Tercio@11 1106 SliderObject.slider:SetMinMaxValues (min, max)
Tercio@11 1107 SliderObject.slider:SetValueStep (step)
Tercio@11 1108 SliderObject.slider:SetValue (defaultv)
Tercio@11 1109 SliderObject.ivalue = defaultv
Tercio@11 1110
Tercio@11 1111 SliderObject.slider:SetBackdrop ({edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", edgeSize = 8})
Tercio@11 1112 SliderObject.slider:SetBackdropColor (0.9, 0.7, 0.7, 1.0)
Tercio@11 1113
Tercio@11 1114 SliderObject.thumb = SliderObject.slider:CreateTexture (nil, "artwork")
Tercio@11 1115 SliderObject.thumb:SetTexture ("Interface\\Buttons\\UI-ScrollBar-Knob")
Tercio@11 1116 SliderObject.thumb:SetSize (30+(h*0.2), h*1.2)
Tercio@11 1117 SliderObject.thumb:SetAlpha (0.7)
Tercio@11 1118 SliderObject.slider:SetThumbTexture (SliderObject.thumb)
Tercio@11 1119 SliderObject.slider.thumb = SliderObject.thumb
Tercio@11 1120
Tercio@11 1121 if (not isSwitch) then
Tercio@11 1122 SliderObject.have_tooltip = "Right Click to Type the Value"
Tercio@11 1123 end
Tercio@11 1124
Tercio@11 1125 SliderObject.amt = SliderObject.slider:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
Tercio@11 1126
Tercio@11 1127 local amt = defaultv
Tercio@11 1128 if (amt < 10 and amt >= 1) then
Tercio@11 1129 amt = "0"..amt
Tercio@11 1130 end
Tercio@11 1131
Tercio@11 1132 if (SliderObject.useDecimals) then
Tercio@11 1133 SliderObject.amt:SetText (string.format ("%.2f", amt))
Tercio@11 1134 else
Tercio@11 1135 SliderObject.amt:SetText (math.floor (amt))
Tercio@11 1136 end
Tercio@11 1137
Tercio@11 1138 SliderObject.amt:SetTextColor (.8, .8, .8, 1)
Tercio@11 1139 SliderObject.amt:SetPoint ("center", SliderObject.thumb, "center")
Tercio@11 1140 SliderObject.slider.amt = SliderObject.amt
Tercio@11 1141
Tercio@11 1142 SliderObject.previous_value = {defaultv or 0, 0, 0}
Tercio@11 1143
Tercio@11 1144 --> hooks
Tercio@11 1145 SliderObject.slider:SetScript ("OnEnter", OnEnter)
Tercio@11 1146 SliderObject.slider:SetScript ("OnLeave", OnLeave)
Tercio@11 1147 SliderObject.slider:SetScript ("OnHide", OnHide)
Tercio@11 1148 SliderObject.slider:SetScript ("OnShow", OnShow)
Tercio@11 1149 SliderObject.slider:SetScript ("OnValueChanged", OnValueChanged)
Tercio@11 1150 SliderObject.slider:SetScript ("OnMouseDown", OnMouseDown)
Tercio@11 1151 SliderObject.slider:SetScript ("OnMouseUp", OnMouseUp)
Tercio@11 1152
Tercio@11 1153
Tercio@11 1154 _setmetatable (SliderObject, SliderMetaFunctions)
Tercio@11 1155
Tercio@11 1156 if (with_label) then
Tercio@11 1157 local label = DF:CreateLabel (SliderObject.slider, with_label, nil, nil, nil, "label", nil, "overlay")
Tercio@11 1158 label.text = with_label
Tercio@11 1159 SliderObject.slider:SetPoint ("left", label.widget, "right", 2, 0)
Tercio@11 1160 with_label = label
Tercio@22 1161
Tercio@22 1162 if (label_template) then
Tercio@22 1163 label:SetTemplate (label_template)
Tercio@22 1164 end
Tercio@22 1165 end
Tercio@22 1166
Tercio@22 1167 if (slider_template) then
Tercio@22 1168 SliderObject:SetTemplate (slider_template)
Tercio@11 1169 end
Tercio@11 1170
Tercio@11 1171 return SliderObject, with_label
Tercio@11 1172
Tercio@11 1173 end