annotate Libs/DF/slider.lua @ 56:7c0f819a85c6 v7.3.5.056

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