annotate Libs/DF/slider.lua @ 63:3552946c0b9a tip

Added tag v8.2.0.062 for changeset d6704922ef5d
author Tercioo
date Fri, 28 Jun 2019 20:06:18 -0300
parents 0682d738499b
children
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 if (_rawget (slider.MyObject, "lockdown")) then
Tercio@11 342 return
Tercio@11 343 end
Tercio@11 344
Tercio@11 345 DetailsFrameworkSliderButtons1:ShowMe (slider)
Tercio@11 346
Tercio@39 347 local capsule = slider.MyObject
Tercio@39 348 local kill = capsule:RunHooksForWidget ("OnEnter", slider, capsule)
Tercio@39 349 if (kill) then
Tercio@39 350 return
Tercio@11 351 end
Tercio@11 352
Tercio@11 353 slider.thumb:SetAlpha (1)
Tercio@11 354
Tercio@22 355 if (slider.MyObject.onenter_backdrop_border_color) then
Tercio@22 356 slider:SetBackdropBorderColor (unpack (slider.MyObject.onenter_backdrop_border_color))
Tercio@22 357 end
Tercio@22 358
Tercio@11 359 if (slider.MyObject.have_tooltip and slider.MyObject.have_tooltip ~= "Right Click to Type the Value") then
Tercio@11 360 GameCooltip2:Preset (2)
Tercio@11 361 GameCooltip2:AddLine (slider.MyObject.have_tooltip)
Tercio@11 362 GameCooltip2:ShowCooltip (slider, "tooltip")
Tercio@11 363 else
Tercio@58 364 GameCooltip2:Preset (2)
Tercio@58 365 GameCooltip2:AddLine ("Right Click to Type the Value", "", 1, "", "", 10)
Tercio@11 366 GameCooltip2:AddIcon ([[Interface\TUTORIALFRAME\UI-TUTORIAL-FRAME]], 1, 1, 16, 16, 0.015625, 0.15671875, 0.640625, 0.798828125)
Tercio@11 367 GameCooltip2:ShowCooltip (slider, "tooltip")
Tercio@11 368 end
Tercio@11 369 end
Tercio@11 370
Tercio@11 371 local OnLeave = function (slider)
Tercio@11 372
Tercio@11 373 if (_rawget (slider.MyObject, "lockdown")) then
Tercio@11 374 return
Tercio@11 375 end
Tercio@11 376
Tercio@11 377 DetailsFrameworkSliderButtons1:PrepareToHide()
Tercio@11 378
Tercio@39 379 local capsule = slider.MyObject
Tercio@39 380 local kill = capsule:RunHooksForWidget ("OnLeave", slider, capsule)
Tercio@39 381 if (kill) then
Tercio@39 382 return
Tercio@11 383 end
Tercio@11 384
Tercio@11 385 slider.thumb:SetAlpha (.7)
Tercio@11 386
Tercio@22 387 if (slider.MyObject.onleave_backdrop_border_color) then
Tercio@22 388 slider:SetBackdropBorderColor (unpack (slider.MyObject.onleave_backdrop_border_color))
Tercio@22 389 end
Tercio@22 390
Tercio@25 391 GameCooltip2:ShowMe (false)
Tercio@25 392
Tercio@11 393 end
Tercio@11 394
Tercio@11 395
Tercio@11 396 local f = CreateFrame ("frame", "DetailsFrameworkSliderButtons1", UIParent)
Tercio@11 397 f:Hide()
Tercio@11 398 f:SetHeight (18)
Tercio@11 399
Tercio@11 400 local t = 0
Tercio@11 401 f.is_going_hide = false
Tercio@11 402 local going_hide = function (self, elapsed)
Tercio@11 403 t = t + elapsed
Tercio@11 404 if (t > 0.3) then
Tercio@11 405 f:Hide()
Tercio@11 406 f:SetScript ("OnUpdate", nil)
Tercio@11 407 f.is_going_hide = false
Tercio@11 408 end
Tercio@11 409 end
Tercio@11 410
Tercio@11 411 function f:ShowMe (host)
Tercio@11 412 f:SetPoint ("bottomleft", host, "topleft", -3, -5)
Tercio@11 413 f:SetPoint ("bottomright", host, "topright", 3, -5)
Tercio@58 414 --f:SetFrameStrata (host:GetFrameStrata())
Tercio@58 415 f:SetFrameStrata ("FULLSCREEN")
Tercio@58 416 f:SetFrameLevel (host:GetFrameLevel() + 1000)
Tercio@11 417 f:Show()
Tercio@11 418 if (f.is_going_hide) then
Tercio@11 419 f:SetScript ("OnUpdate", nil)
Tercio@11 420 f.is_going_hide = false
Tercio@11 421 end
Tercio@11 422
Tercio@11 423 f.host = host.MyObject
Tercio@11 424 end
Tercio@11 425
Tercio@11 426 function f:PrepareToHide()
Tercio@11 427 f.is_going_hide = true
Tercio@11 428 t = 0
Tercio@11 429 f:SetScript ("OnUpdate", going_hide)
Tercio@11 430 end
Tercio@11 431
Tercio@11 432 local button_plus = CreateFrame ("button", "DetailsFrameworkSliderButtonsPlusButton", f)
Tercio@11 433 local button_minor = CreateFrame ("button", "DetailsFrameworkSliderButtonsMinorButton", f)
Tercio@39 434 button_plus:SetFrameStrata (f:GetFrameStrata())
Tercio@39 435 button_minor:SetFrameStrata (f:GetFrameStrata())
Tercio@11 436
Tercio@11 437 button_plus:SetScript ("OnEnter", function (self)
Tercio@11 438 if (f.is_going_hide) then
Tercio@11 439 f:SetScript ("OnUpdate", nil)
Tercio@11 440 f.is_going_hide = false
Tercio@11 441 end
Tercio@11 442 end)
Tercio@11 443 button_minor:SetScript ("OnEnter", function (self)
Tercio@11 444 if (f.is_going_hide) then
Tercio@11 445 f:SetScript ("OnUpdate", nil)
Tercio@11 446 f.is_going_hide = false
Tercio@11 447 end
Tercio@11 448 end)
Tercio@11 449
Tercio@11 450 button_plus:SetScript ("OnLeave", function (self)
Tercio@11 451 f:PrepareToHide()
Tercio@11 452 end)
Tercio@11 453 button_minor:SetScript ("OnLeave", function (self)
Tercio@11 454 f:PrepareToHide()
Tercio@11 455 end)
Tercio@11 456
Tercio@11 457 button_plus:SetNormalTexture ([[Interface\Buttons\UI-PlusButton-Up]])
Tercio@11 458 button_minor:SetNormalTexture ([[Interface\Buttons\UI-MinusButton-Up]])
Tercio@11 459
Tercio@11 460 button_plus:SetPushedTexture ([[Interface\Buttons\UI-PlusButton-Down]])
Tercio@11 461 button_minor:SetPushedTexture ([[Interface\Buttons\UI-MinusButton-Down]])
Tercio@11 462
Tercio@11 463 button_plus:SetDisabledTexture ([[Interface\Buttons\UI-PlusButton-Disabled]])
Tercio@11 464 button_minor:SetDisabledTexture ([[Interface\Buttons\UI-MinusButton-Disabled]])
Tercio@11 465
Tercio@11 466 button_plus:SetHighlightTexture ([[Interface\Buttons\UI-PlusButton-Hilight]])
Tercio@11 467 button_minor:SetHighlightTexture ([[Interface\Buttons\UI-PlusButton-Hilight]])
Tercio@11 468
Tercio@11 469 --button_minor:SetPoint ("bottomleft", f, "bottomleft", -6, -13)
Tercio@11 470 --button_plus:SetPoint ("bottomright", f, "bottomright", 6, -13)
Tercio@11 471
Tercio@11 472 button_minor:SetPoint ("bottomright", f, "bottomright", 13, -13)
Tercio@11 473 button_plus:SetPoint ("left", button_minor, "right", -2, 0)
Tercio@11 474
Tercio@11 475 button_plus:SetSize (16, 16)
Tercio@11 476 button_minor:SetSize (16, 16)
Tercio@11 477
Tercio@11 478 local timer = 0
Tercio@11 479 local change_timer = 0
Tercio@11 480
Tercio@11 481 -- -- --
Tercio@11 482
Tercio@11 483 local plus_button_script = function()
Tercio@11 484
Tercio@11 485 local current = f.host.value
Tercio@35 486 local editbox = DFSliderMetaFunctions.editbox_typevalue
Tercio@11 487
Tercio@11 488 if (f.host.fine_tuning) then
Tercio@11 489 f.host:SetValue (current + f.host.fine_tuning)
Tercio@35 490 if (editbox and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
Tercio@35 491 DFSliderMetaFunctions.editbox_typevalue:SetText (tostring (string.format ("%.2f", current + f.host.fine_tuning)))
Tercio@11 492 end
Tercio@11 493 else
Tercio@11 494 if (f.host.useDecimals) then
Tercio@11 495 f.host:SetValue (current + 0.1)
Tercio@35 496 if (editbox and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
Tercio@35 497 DFSliderMetaFunctions.editbox_typevalue:SetText (string.format ("%.2f", current + 0.1))
Tercio@11 498 end
Tercio@11 499 else
Tercio@11 500 f.host:SetValue (current + 1)
Tercio@35 501 if (editbox and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
Tercio@35 502 DFSliderMetaFunctions.editbox_typevalue:SetText (tostring (math.floor (current + 1)))
Tercio@11 503 end
Tercio@11 504 end
Tercio@11 505 end
Tercio@11 506
Tercio@11 507 end
Tercio@11 508
Tercio@11 509 button_plus:SetScript ("OnMouseUp", function (self)
Tercio@11 510 if (not button_plus.got_click) then
Tercio@11 511 plus_button_script()
Tercio@11 512 end
Tercio@11 513 button_plus.got_click = false
Tercio@11 514 self:SetScript ("OnUpdate", nil)
Tercio@11 515 end)
Tercio@11 516
Tercio@11 517 local on_update = function (self, elapsed)
Tercio@11 518 timer = timer + elapsed
Tercio@11 519 if (timer > 0.4) then
Tercio@11 520 change_timer = change_timer + elapsed
Tercio@11 521 if (change_timer > 0.1) then
Tercio@11 522 change_timer = 0
Tercio@11 523 plus_button_script()
Tercio@11 524 button_plus.got_click = true
Tercio@11 525 end
Tercio@11 526 end
Tercio@11 527 end
Tercio@11 528 button_plus:SetScript ("OnMouseDown", function (self)
Tercio@11 529 timer = 0
Tercio@11 530 change_timer = 0
Tercio@11 531 self:SetScript ("OnUpdate", on_update)
Tercio@11 532 end)
Tercio@11 533
Tercio@11 534 -- -- --
Tercio@11 535
Tercio@11 536 local minor_button_script = function()
Tercio@11 537 local current = f.host.value
Tercio@35 538 local editbox = DFSliderMetaFunctions.editbox_typevalue
Tercio@11 539
Tercio@11 540 if (f.host.fine_tuning) then
Tercio@11 541 f.host:SetValue (current - f.host.fine_tuning)
Tercio@35 542 if (editbox and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
Tercio@35 543 DFSliderMetaFunctions.editbox_typevalue:SetText (tostring (string.format ("%.2f", current - f.host.fine_tuning)))
Tercio@11 544 end
Tercio@11 545 else
Tercio@11 546 if (f.host.useDecimals) then
Tercio@11 547 f.host:SetValue (current - 0.1)
Tercio@35 548 if (editbox and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
Tercio@35 549 DFSliderMetaFunctions.editbox_typevalue:SetText (string.format ("%.2f", current - 0.1))
Tercio@11 550 end
Tercio@11 551 else
Tercio@11 552 f.host:SetValue (current - 1)
Tercio@35 553 if (editbox and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
Tercio@35 554 DFSliderMetaFunctions.editbox_typevalue:SetText (tostring (math.floor (current - 1)))
Tercio@11 555 end
Tercio@11 556 end
Tercio@11 557 end
Tercio@11 558 end
Tercio@11 559
Tercio@11 560 button_minor:SetScript ("OnMouseUp", function (self)
Tercio@11 561 if (not button_minor.got_click) then
Tercio@11 562 minor_button_script()
Tercio@11 563 end
Tercio@11 564 button_minor.got_click = false
Tercio@11 565 self:SetScript ("OnUpdate", nil)
Tercio@11 566 end)
Tercio@11 567
Tercio@11 568 local on_update = function (self, elapsed)
Tercio@11 569 timer = timer + elapsed
Tercio@11 570 if (timer > 0.4) then
Tercio@11 571 change_timer = change_timer + elapsed
Tercio@11 572 if (change_timer > 0.1) then
Tercio@11 573 change_timer = 0
Tercio@11 574 minor_button_script()
Tercio@11 575 button_minor.got_click = true
Tercio@11 576 end
Tercio@11 577 end
Tercio@11 578 end
Tercio@11 579 button_minor:SetScript ("OnMouseDown", function (self)
Tercio@11 580 timer = 0
Tercio@11 581 change_timer = 0
Tercio@11 582 self:SetScript ("OnUpdate", on_update)
Tercio@11 583 end)
Tercio@11 584
Tercio@56 585 local do_precision = function (text)
Tercio@56 586 if (type (text) == "string" and text:find ("%.")) then
Tercio@56 587 local left, right = strsplit (".", text)
Tercio@56 588 left = tonumber (left)
Tercio@56 589 right = tonumber (right)
Tercio@56 590
Tercio@56 591 if (left and right) then
Tercio@56 592 local newString = tostring (left) .. "." .. tostring (right)
Tercio@56 593 local newNumber = tonumber (newString)
Tercio@56 594
Tercio@56 595 if (newNumber) then
Tercio@56 596 return newNumber
Tercio@56 597 end
Tercio@56 598 end
Tercio@56 599 end
Tercio@56 600
Tercio@56 601 return tonumber (text)
Tercio@56 602 end
Tercio@56 603
Tercio@35 604 function DFSliderMetaFunctions:TypeValue()
Tercio@11 605 if (not self.isSwitch) then
Tercio@11 606
Tercio@35 607 if (not DFSliderMetaFunctions.editbox_typevalue) then
Tercio@11 608
Tercio@11 609 local editbox = CreateFrame ("EditBox", "DetailsFrameworkSliderEditBox", UIParent)
Tercio@11 610
Tercio@11 611 editbox:SetSize (40, 20)
Tercio@11 612 editbox:SetJustifyH ("center")
Tercio@11 613 editbox:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]],
Tercio@11 614 edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", --edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
Tercio@11 615 tile = true, edgeSize = 8, tileSize = 5})
Tercio@11 616 editbox:SetFontObject ("GameFontHighlightSmall")
Tercio@11 617
Tercio@11 618 editbox:SetScript ("OnEnterPressed", function()
Tercio@11 619 editbox:ClearFocus()
Tercio@11 620 editbox:Hide()
Tercio@11 621 editbox:GetParent().MyObject.typing_value = false
Tercio@56 622 editbox:GetParent().MyObject.value = tonumber (editbox:GetText()) --do_precision (editbox:GetText())
Tercio@11 623 end)
Tercio@11 624
Tercio@11 625 editbox:SetScript ("OnEscapePressed", function()
Tercio@11 626 editbox:ClearFocus()
Tercio@11 627 editbox:Hide()
Tercio@11 628 editbox:GetParent().MyObject.typing_value = false
Tercio@56 629 editbox:GetParent().MyObject.value = self.typing_value_started --do_precision (self.typing_value_started)
Tercio@11 630 end)
Tercio@11 631
Tercio@11 632 editbox:SetScript ("OnTextChanged", function()
Tercio@11 633 editbox:GetParent().MyObject.typing_can_change = true
Tercio@56 634 editbox:GetParent().MyObject.value = tonumber (editbox:GetText()) --do_precision
Tercio@11 635 editbox:GetParent().MyObject.typing_can_change = false
Tercio@11 636 end)
Tercio@11 637
Tercio@35 638 DFSliderMetaFunctions.editbox_typevalue = editbox
Tercio@11 639 end
Tercio@11 640
Tercio@11 641 local pvalue = self.previous_value [2]
Tercio@11 642 self:SetValue (pvalue)
Tercio@11 643
Tercio@11 644 self.typing_value = true
Tercio@11 645 self.typing_value_started = pvalue
Tercio@11 646
Tercio@35 647 DFSliderMetaFunctions.editbox_typevalue:SetSize (self.width, self.height)
Tercio@35 648 DFSliderMetaFunctions.editbox_typevalue:SetPoint ("center", self.widget, "center")
Tercio@35 649 DFSliderMetaFunctions.editbox_typevalue:SetFocus()
Tercio@35 650 DFSliderMetaFunctions.editbox_typevalue:SetParent (self.widget)
Tercio@35 651 DFSliderMetaFunctions.editbox_typevalue:SetFrameLevel (self.widget:GetFrameLevel()+1)
Tercio@11 652
Tercio@11 653 if (self.useDecimals) then
Tercio@35 654 DFSliderMetaFunctions.editbox_typevalue:SetText (tostring (string.format ("%.1f", self.value)))
Tercio@11 655 else
Tercio@35 656 DFSliderMetaFunctions.editbox_typevalue:SetText (tostring (math.floor (self.value)))
Tercio@11 657 end
Tercio@11 658
Tercio@35 659 DFSliderMetaFunctions.editbox_typevalue:HighlightText()
Tercio@11 660
Tercio@35 661 DFSliderMetaFunctions.editbox_typevalue:Show()
Tercio@11 662 end
Tercio@11 663 end
Tercio@11 664
Tercio@11 665 local OnMouseDown = function (slider, button)
Tercio@39 666 slider.MyObject.IsValueChanging = true
Tercio@39 667
Tercio@39 668 local capsule = slider.MyObject
Tercio@39 669 local kill = capsule:RunHooksForWidget ("OnMouseDown", slider, button, capsule)
Tercio@39 670 if (kill) then
Tercio@39 671 return
Tercio@39 672 end
Tercio@39 673
Tercio@11 674 if (button == "RightButton") then
Tercio@11 675 slider.MyObject:TypeValue()
Tercio@11 676 end
Tercio@11 677 end
Tercio@11 678
Tercio@11 679 local OnMouseUp = function (slider, button)
Tercio@39 680 slider.MyObject.IsValueChanging = nil
Tercio@39 681
Tercio@39 682 local capsule = slider.MyObject
Tercio@39 683 local kill = capsule:RunHooksForWidget ("OnMouseUp", slider, button, capsule)
Tercio@39 684 if (kill) then
Tercio@39 685 return
Tercio@39 686 end
Tercio@11 687 end
Tercio@11 688
Tercio@11 689 local OnHide = function (slider)
Tercio@39 690 local capsule = slider.MyObject
Tercio@39 691 local kill = capsule:RunHooksForWidget ("OnHide", slider, capsule)
Tercio@39 692 if (kill) then
Tercio@39 693 return
Tercio@11 694 end
Tercio@11 695
Tercio@11 696 if (slider.MyObject.typing_value) then
Tercio@35 697 DFSliderMetaFunctions.editbox_typevalue:ClearFocus()
Tercio@35 698 DFSliderMetaFunctions.editbox_typevalue:SetText ("")
Tercio@11 699 slider.MyObject.typing_valu = false
Tercio@11 700 end
Tercio@11 701 end
Tercio@11 702
Tercio@11 703 local OnShow = function (slider)
Tercio@39 704 local capsule = slider.MyObject
Tercio@39 705 local kill = capsule:RunHooksForWidget ("OnShow", slider, capsule)
Tercio@39 706 if (kill) then
Tercio@39 707 return
Tercio@11 708 end
Tercio@11 709 end
Tercio@11 710
Tercio@11 711 local table_insert = table.insert
Tercio@11 712 local table_remove = table.remove
Tercio@11 713
Tercio@11 714 local OnValueChanged = function (slider)
Tercio@11 715
Tercio@12 716 local amt
Tercio@12 717 if (slider.MyObject.useDecimals) then
Tercio@12 718 amt = slider:GetValue()
Tercio@12 719 else
Tercio@56 720 amt = do_precision (slider:GetValue())
Tercio@12 721 end
Tercio@56 722
Tercio@11 723 if (slider.MyObject.typing_value and not slider.MyObject.typing_can_change) then
Tercio@11 724 slider.MyObject:SetValue (slider.MyObject.typing_value_started)
Tercio@11 725 return
Tercio@11 726 end
Tercio@56 727
Tercio@11 728 table_insert (slider.MyObject.previous_value, 1, amt)
Tercio@11 729 table_remove (slider.MyObject.previous_value, 4)
Tercio@11 730
Tercio@39 731 local capsule = slider.MyObject
Tercio@39 732 local kill = capsule:RunHooksForWidget ("OnValueChanged", slider, capsule.FixedValue, amt, capsule)
Tercio@39 733 if (kill) then
Tercio@39 734 return
Tercio@11 735 end
Tercio@39 736 local kill = capsule:RunHooksForWidget ("OnValueChange", slider, capsule.FixedValue, amt, capsule)
Tercio@39 737 if (kill) then
Tercio@39 738 return
Tercio@39 739 end
Tercio@39 740
Tercio@11 741 if (slider.MyObject.OnValueChanged) then
Tercio@11 742 slider.MyObject.OnValueChanged (slider, slider.MyObject.FixedValue, amt)
Tercio@11 743 end
Tercio@11 744
Tercio@11 745 if (amt < 10 and amt >= 1) then
Tercio@11 746 amt = "0"..amt
Tercio@11 747 end
Tercio@11 748
Tercio@11 749 if (slider.MyObject.useDecimals) then
Tercio@11 750 slider.amt:SetText (string.format ("%.2f", amt))
Tercio@11 751 else
Tercio@11 752 slider.amt:SetText (math.floor (amt))
Tercio@11 753 end
Tercio@11 754 slider.MyObject.ivalue = amt
Tercio@11 755 end
Tercio@11 756
Tercio@11 757 ------------------------------------------------------------------------------------------------------------
Tercio@11 758 --> object constructor
Tercio@11 759
Tercio@11 760 local SwitchOnClick = function (self, button, forced_value, value)
Tercio@11 761
Tercio@11 762 local slider = self.MyObject
Tercio@11 763
Tercio@11 764 if (_rawget (slider, "lockdown")) then
Tercio@11 765 return
Tercio@11 766 end
Tercio@11 767
Tercio@11 768 if (forced_value) then
Tercio@11 769 _rawset (slider, "value", not value)
Tercio@11 770 end
Tercio@11 771
Tercio@11 772 if (_rawget (slider, "value")) then --actived
Tercio@11 773 _rawset (slider, "value", false)
Tercio@11 774
Tercio@22 775 if (slider.backdrop_disabledcolor) then
Tercio@22 776 slider:SetBackdropColor (unpack (slider.backdrop_disabledcolor))
Tercio@22 777 else
Tercio@22 778 slider:SetBackdropColor (1, 0, 0, 0.4)
Tercio@22 779 end
Tercio@22 780
Tercio@22 781 if (slider.is_checkbox) then
Tercio@22 782 slider.checked_texture:Hide()
Tercio@22 783 else
Tercio@22 784 slider._text:SetText (slider._ltext)
Tercio@22 785 slider._thumb:ClearAllPoints()
Tercio@22 786 slider._thumb:SetPoint ("left", slider.widget, "left")
Tercio@22 787 end
Tercio@11 788 else
Tercio@11 789 _rawset (slider, "value", true)
Tercio@22 790 if (slider.backdrop_enabledcolor) then
Tercio@22 791 slider:SetBackdropColor (unpack (slider.backdrop_enabledcolor))
Tercio@22 792 else
Tercio@22 793 slider:SetBackdropColor (0, 0, 1, 0.4)
Tercio@22 794 end
Tercio@22 795 if (slider.is_checkbox) then
Tercio@22 796 slider.checked_texture:Show()
Tercio@22 797 else
Tercio@22 798 slider._text:SetText (slider._rtext)
Tercio@22 799 slider._thumb:ClearAllPoints()
Tercio@22 800 slider._thumb:SetPoint ("right", slider.widget, "right")
Tercio@22 801 end
Tercio@11 802 end
Tercio@11 803
Tercio@11 804 if (slider.OnSwitch and not forced_value) then
Tercio@11 805 local value = _rawget (slider, "value")
Tercio@11 806 if (slider.return_func) then
Tercio@11 807 value = slider:return_func (value)
Tercio@11 808 end
Tercio@11 809 slider.OnSwitch (slider, slider.FixedValue, value)
Tercio@11 810 end
Tercio@11 811
Tercio@11 812 end
Tercio@11 813
Tercio@11 814 local default_switch_func = function (self, passed_value)
Tercio@11 815 if (self.value) then
Tercio@11 816 return false
Tercio@11 817 else
Tercio@11 818 return true
Tercio@11 819 end
Tercio@11 820 end
Tercio@11 821
Tercio@11 822 local switch_get_value = function (self)
Tercio@11 823 return self.value
Tercio@11 824 end
Tercio@11 825
Tercio@11 826 local switch_set_value = function (self, value)
Tercio@11 827 if (self.switch_func) then
Tercio@11 828 value = self:switch_func (value)
Tercio@11 829 end
Tercio@11 830
Tercio@11 831 SwitchOnClick (self.widget, nil, true, value)
Tercio@11 832 end
Tercio@11 833
Tercio@11 834 local switch_set_fixparameter = function (self, value)
Tercio@11 835 _rawset (self, "FixedValue", value)
Tercio@11 836 end
Tercio@11 837
Tercio@11 838 local switch_disable = function (self)
Tercio@11 839
Tercio@22 840 if (self.is_checkbox) then
Tercio@22 841 self.checked_texture:Hide()
Tercio@22 842 else
Tercio@22 843 self._text:Hide()
Tercio@35 844 if (not self.lock_texture) then
Tercio@35 845 DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
Tercio@35 846 self.lock_texture:SetDesaturated (true)
Tercio@35 847 self.lock_texture:SetPoint ("center", self._thumb, "center")
Tercio@35 848 end
Tercio@35 849 self.lock_texture:Show()
Tercio@22 850 end
Tercio@22 851
Tercio@11 852 self:SetAlpha (.4)
Tercio@11 853 _rawset (self, "lockdown", true)
Tercio@11 854 end
Tercio@11 855 local switch_enable = function (self)
Tercio@22 856 if (self.is_checkbox) then
Tercio@22 857 if (_rawget (self, "value")) then
Tercio@22 858 self.checked_texture:Show()
Tercio@22 859 else
Tercio@22 860 self.checked_texture:Hide()
Tercio@22 861 end
Tercio@22 862 else
Tercio@35 863 if (not self.lock_texture) then
Tercio@35 864 DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
Tercio@35 865 self.lock_texture:SetDesaturated (true)
Tercio@35 866 self.lock_texture:SetPoint ("center", self._thumb, "center")
Tercio@35 867 end
Tercio@35 868 self.lock_texture:Hide()
Tercio@22 869 self._text:Show()
Tercio@22 870 end
Tercio@22 871
Tercio@11 872 self:SetAlpha (1)
Tercio@11 873 return _rawset (self, "lockdown", false)
Tercio@11 874 end
Tercio@11 875
Tercio@22 876 local set_as_checkbok = function (self)
Tercio@35 877 local checked = self:CreateTexture (self:GetName() .. "CheckTexture", "overlay")
Tercio@22 878 checked:SetTexture ([[Interface\Buttons\UI-CheckBox-Check]])
Tercio@22 879 checked:SetPoint ("center", self.button, "center", -1, -1)
Tercio@22 880 local size_pct = self:GetWidth()/32
Tercio@22 881 checked:SetSize (32*size_pct, 32*size_pct)
Tercio@22 882 self.checked_texture = checked
Tercio@22 883
Tercio@22 884 self._thumb:Hide()
Tercio@22 885 self._text:Hide()
Tercio@22 886
Tercio@22 887 self.is_checkbox = true
Tercio@22 888
Tercio@22 889 if (_rawget (self, "value")) then
Tercio@22 890 self.checked_texture:Show()
Tercio@22 891 if (self.backdrop_enabledcolor) then
Tercio@22 892 self:SetBackdropColor (unpack (self.backdrop_enabledcolor))
Tercio@22 893 else
Tercio@22 894 self:SetBackdropColor (0, 0, 1, 0.4)
Tercio@22 895 end
Tercio@22 896 else
Tercio@22 897 self.checked_texture:Hide()
Tercio@22 898 if (self.backdrop_disabledcolor) then
Tercio@22 899 self:SetBackdropColor (unpack (self.backdrop_disabledcolor))
Tercio@22 900 else
Tercio@22 901 self:SetBackdropColor (0, 0, 1, 0.4)
Tercio@22 902 end
Tercio@22 903 end
Tercio@35 904
Tercio@22 905 end
Tercio@22 906
Tercio@22 907 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 908 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 909 if (on_switch) then
Tercio@11 910 switch.OnSwitch = on_switch
Tercio@11 911 end
Tercio@11 912 return switch, label
Tercio@11 913 end
Tercio@11 914
Tercio@22 915 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 916
Tercio@11 917 --> early checks
Tercio@11 918 if (not name) then
Tercioo@29 919 name = "DetailsFrameWorkSlider" .. DF.SwitchCounter
Tercioo@29 920 DF.SwitchCounter = DF.SwitchCounter + 1
Tercio@11 921 elseif (not parent) then
Tercioo@29 922 return error ("Details! FrameWork: parent not found.", 2)
Tercio@11 923 end
Tercio@11 924 if (not container) then
Tercio@11 925 container = parent
Tercio@11 926 end
Tercio@56 927
Tercio@11 928 --> defaults
Tercio@11 929 ltext = ltext or "OFF"
Tercio@11 930 rtext = rtext or "ON"
Tercio@11 931
Tercio@11 932 --> build frames
Tercio@11 933
Tercio@11 934 w = w or 60
Tercio@11 935 h = h or 20
Tercio@11 936
Tercio@11 937 local slider = DF:NewButton (parent, container, name, member, w, h)
Tercio@11 938
Tercio@11 939 slider.switch_func = switch_func
Tercio@11 940 slider.return_func = return_func
Tercio@11 941 slider.SetValue = switch_set_value
Tercio@11 942 slider.GetValue = switch_get_value
Tercio@11 943 slider.SetFixedParameter = switch_set_fixparameter
Tercio@11 944 slider.Disable = switch_disable
Tercio@11 945 slider.Enable = switch_enable
Tercio@22 946 slider.SetAsCheckBox = set_as_checkbok
Tercio@35 947 slider.SetTemplate = DFSliderMetaFunctions.SetTemplate
Tercio@11 948
Tercio@11 949 if (member) then
Tercio@11 950 parent [member] = slider
Tercio@11 951 end
Tercio@11 952
Tercio@11 953 slider:SetBackdrop ({edgeFile = [[Interface\Buttons\UI-SliderBar-Border]], edgeSize = 8,
Tercio@11 954 bgFile = [[Interface\AddOns\Details\images\background]], insets = {left = 3, right = 3, top = 5, bottom = 5}})
Tercio@11 955
Tercio@11 956 local thumb = slider:CreateTexture (nil, "artwork")
Tercio@11 957 thumb:SetTexture ("Interface\\Buttons\\UI-ScrollBar-Knob")
Tercio@11 958 thumb:SetSize (34+(h*0.2), h*1.2)
Tercio@11 959 thumb:SetAlpha (0.7)
Tercio@11 960 thumb:SetPoint ("left", slider.widget, "left")
Tercio@11 961
Tercio@11 962 local text = slider:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
Tercio@11 963 text:SetTextColor (.8, .8, .8, 1)
Tercio@11 964 text:SetPoint ("center", thumb, "center")
Tercio@11 965
Tercio@11 966 slider._text = text
Tercio@11 967 slider._thumb = thumb
Tercio@11 968 slider._ltext = ltext
Tercio@11 969 slider._rtext = rtext
Tercio@11 970 slider.thumb = thumb
Tercio@11 971
Tercio@11 972 slider.invert_colors = color_inverted
Tercio@11 973
Tercio@11 974 slider:SetScript ("OnClick", SwitchOnClick)
Tercio@11 975
Tercio@11 976 slider:SetValue (default_value)
Tercio@11 977
Tercio@11 978 slider.isSwitch = true
Tercio@11 979
Tercio@22 980 if (switch_template) then
Tercio@22 981 slider:SetTemplate (switch_template)
Tercio@22 982 end
Tercio@22 983
Tercio@11 984 if (with_label) then
Tercio@11 985 local label = DF:CreateLabel (slider.widget, with_label, nil, nil, nil, "label", nil, "overlay")
Tercio@11 986 label.text = with_label
Tercio@11 987 slider.widget:SetPoint ("left", label.widget, "right", 2, 0)
Tercio@11 988 with_label = label
Tercio@22 989
Tercio@22 990 if (label_template) then
Tercio@22 991 label:SetTemplate (label_template)
Tercio@22 992 end
Tercio@11 993 end
Tercio@11 994
Tercio@11 995 return slider, with_label
Tercio@11 996 end
Tercio@11 997
Tercio@35 998 function DFSliderMetaFunctions:SetTemplate (template)
Tercio@22 999
Tercio@22 1000 --slider e switch
Tercio@22 1001 if (template.width) then
Tercio@22 1002 self:SetWidth (template.width)
Tercio@22 1003 end
Tercio@22 1004 if (template.height) then
Tercio@22 1005 self:SetHeight (template.height)
Tercio@22 1006 end
Tercio@22 1007
Tercio@22 1008 if (template.backdrop) then
Tercio@22 1009 self:SetBackdrop (template.backdrop)
Tercio@22 1010 end
Tercio@22 1011 if (template.backdropcolor) then
Tercio@22 1012 local r, g, b, a = DF:ParseColors (template.backdropcolor)
Tercio@22 1013 self:SetBackdropColor (r, g, b, a)
Tercio@22 1014 end
Tercio@22 1015 if (template.backdropbordercolor) then
Tercio@22 1016 local r, g, b, a = DF:ParseColors (template.backdropbordercolor)
Tercio@22 1017 self:SetBackdropBorderColor (r, g, b, a)
Tercio@22 1018 self.onleave_backdrop_border_color = {r, g, b, a}
Tercio@22 1019 end
Tercio@22 1020
Tercio@22 1021 if (template.onenterbordercolor) then
Tercio@22 1022 local r, g, b, a = DF:ParseColors (template.onenterbordercolor)
Tercio@22 1023 self.onenter_backdrop_border_color = {r, g, b, a}
Tercio@22 1024 end
Tercio@22 1025
Tercio@22 1026 if (template.onleavebordercolor) then
Tercio@22 1027 local r, g, b, a = DF:ParseColors (template.onleavebordercolor)
Tercio@22 1028 self.onleave_backdrop_border_color = {r, g, b, a}
Tercio@22 1029 end
Tercio@22 1030
Tercio@22 1031 if (template.thumbtexture) then
Tercio@22 1032 if (self.thumb) then
Tercio@22 1033 self.thumb:SetTexture (template.thumbtexture)
Tercio@22 1034 end
Tercio@22 1035 end
Tercio@22 1036 if (template.thumbwidth) then
Tercio@22 1037 if (self.thumb) then
Tercio@22 1038 self.thumb:SetWidth (template.thumbwidth)
Tercio@22 1039 end
Tercio@22 1040 end
Tercio@22 1041 if (template.thumbheight) then
Tercio@22 1042 if (self.thumb) then
Tercio@22 1043 self.thumb:SetHeight (template.thumbheight)
Tercio@22 1044 end
Tercio@22 1045 end
Tercio@22 1046 if (template.thumbcolor) then
Tercio@22 1047 if (self.thumb) then
Tercio@22 1048 local r, g, b, a = DF:ParseColors (template.thumbcolor)
Tercio@22 1049 self.thumb:SetVertexColor (r, g, b, a)
Tercio@22 1050 end
Tercio@22 1051 end
Tercio@22 1052
Tercio@22 1053 --switch only
Tercio@22 1054 if (template.enabled_backdropcolor) then
Tercio@22 1055 local r, g, b, a = DF:ParseColors (template.enabled_backdropcolor)
Tercio@22 1056 self.backdrop_enabledcolor = {r, g, b, a}
Tercio@22 1057 end
Tercio@22 1058 if (template.disabled_backdropcolor) then
Tercio@22 1059 local r, g, b, a = DF:ParseColors (template.disabled_backdropcolor)
Tercio@22 1060 self.backdrop_disabledcolor = {r, g, b, a}
Tercio@22 1061 end
Tercio@22 1062 end
Tercio@22 1063
Tercio@22 1064 function DF:CreateSlider (parent, w, h, min, max, step, defaultv, isDecemal, member, name, with_label, slider_template, label_template)
Tercio@22 1065 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 1066 return slider, label
Tercio@11 1067 end
Tercio@11 1068
Tercio@22 1069 function DF:NewSlider (parent, container, name, member, w, h, min, max, step, defaultv, isDecemal, isSwitch, with_label, slider_template, label_template)
Tercio@11 1070
Tercio@11 1071 --> early checks
Tercio@11 1072 if (not name) then
Tercio@11 1073 name = "DetailsFrameworkSlider" .. DF.SliderCounter
Tercio@11 1074 DF.SliderCounter = DF.SliderCounter + 1
Tercio@11 1075 end
Tercio@11 1076 if (not parent) then
Tercioo@29 1077 return error ("Details! FrameWork: parent not found.", 2)
Tercio@11 1078 end
Tercio@11 1079 if (not container) then
Tercio@11 1080 container = parent
Tercio@11 1081 end
Tercio@11 1082
Tercio@11 1083 if (name:find ("$parent")) then
Tercioo@29 1084 local parentName = DF.GetParentName (parent)
Tercioo@29 1085 name = name:gsub ("$parent", parentName)
Tercio@11 1086 end
Tercio@11 1087
Tercio@11 1088 local SliderObject = {type = "slider", dframework = true}
Tercio@11 1089
Tercio@11 1090 if (member) then
Tercio@11 1091 parent [member] = SliderObject
Tercio@11 1092 end
Tercio@11 1093
Tercio@11 1094 if (parent.dframework) then
Tercio@11 1095 parent = parent.widget
Tercio@11 1096 end
Tercio@11 1097 if (container.dframework) then
Tercio@11 1098 container = container.widget
Tercio@11 1099 end
Tercio@11 1100
Tercio@11 1101 --> defaults
Tercio@11 1102 min = min or 1
Tercio@11 1103 max = max or 2
Tercio@11 1104 step = step or 1
Tercio@11 1105 defaultv = defaultv or min
Tercio@11 1106
Tercio@11 1107 w = w or 130
Tercio@11 1108 h = h or 19
Tercio@11 1109
Tercio@11 1110 --> default members:
Tercio@11 1111 SliderObject.lockdown = false
Tercio@11 1112 SliderObject.container = container
Tercio@11 1113
Tercio@11 1114 SliderObject.slider = CreateFrame ("slider", name, parent)
Tercio@11 1115 SliderObject.widget = SliderObject.slider
Tercio@11 1116
Tercio@56 1117 SliderObject.useDecimals = isDecemal or false
Tercio@56 1118
Tercio@56 1119 if (SliderObject.useDecimals) then
Tercio@56 1120 SliderObject.slider:SetValueStep (0.01)
Tercio@56 1121 else
Tercio@56 1122 SliderObject.slider:SetValueStep (step)
Tercio@56 1123 end
Tercio@56 1124
Tercio@11 1125 if (not APISliderFunctions) then
Tercio@11 1126 APISliderFunctions = true
Tercio@11 1127 local idx = getmetatable (SliderObject.slider).__index
Tercio@11 1128 for funcName, funcAddress in pairs (idx) do
Tercio@35 1129 if (not DFSliderMetaFunctions [funcName]) then
Tercio@35 1130 DFSliderMetaFunctions [funcName] = function (object, ...)
Tercio@20 1131 local x = loadstring ( "return _G['"..object.slider:GetName().."']:"..funcName.."(...)")
Tercio@11 1132 return x (...)
Tercio@11 1133 end
Tercio@11 1134 end
Tercio@11 1135 end
Tercio@11 1136 end
Tercio@11 1137
Tercio@11 1138 SliderObject.slider.MyObject = SliderObject
Tercio@11 1139 SliderObject.slider:SetWidth (w)
Tercio@11 1140 SliderObject.slider:SetHeight (h)
Tercio@11 1141 SliderObject.slider:SetOrientation ("horizontal")
Tercio@11 1142 SliderObject.slider:SetMinMaxValues (min, max)
Tercio@11 1143 SliderObject.slider:SetValue (defaultv)
Tercio@11 1144 SliderObject.ivalue = defaultv
Tercio@11 1145
Tercio@11 1146 SliderObject.slider:SetBackdrop ({edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", edgeSize = 8})
Tercio@11 1147 SliderObject.slider:SetBackdropColor (0.9, 0.7, 0.7, 1.0)
Tercio@11 1148
Tercio@11 1149 SliderObject.thumb = SliderObject.slider:CreateTexture (nil, "artwork")
Tercio@11 1150 SliderObject.thumb:SetTexture ("Interface\\Buttons\\UI-ScrollBar-Knob")
Tercio@11 1151 SliderObject.thumb:SetSize (30+(h*0.2), h*1.2)
Tercio@11 1152 SliderObject.thumb:SetAlpha (0.7)
Tercio@11 1153 SliderObject.slider:SetThumbTexture (SliderObject.thumb)
Tercio@11 1154 SliderObject.slider.thumb = SliderObject.thumb
Tercio@11 1155
Tercio@11 1156 if (not isSwitch) then
Tercio@11 1157 SliderObject.have_tooltip = "Right Click to Type the Value"
Tercio@11 1158 end
Tercio@11 1159
Tercio@11 1160 SliderObject.amt = SliderObject.slider:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
Tercio@11 1161
Tercio@11 1162 local amt = defaultv
Tercio@11 1163 if (amt < 10 and amt >= 1) then
Tercio@11 1164 amt = "0"..amt
Tercio@11 1165 end
Tercio@11 1166
Tercio@11 1167 if (SliderObject.useDecimals) then
Tercio@11 1168 SliderObject.amt:SetText (string.format ("%.2f", amt))
Tercio@11 1169 else
Tercio@11 1170 SliderObject.amt:SetText (math.floor (amt))
Tercio@11 1171 end
Tercio@11 1172
Tercio@11 1173 SliderObject.amt:SetTextColor (.8, .8, .8, 1)
Tercio@11 1174 SliderObject.amt:SetPoint ("center", SliderObject.thumb, "center")
Tercio@11 1175 SliderObject.slider.amt = SliderObject.amt
Tercio@11 1176
Tercio@11 1177 SliderObject.previous_value = {defaultv or 0, 0, 0}
Tercio@11 1178
Tercio@11 1179 --> hooks
Tercio@39 1180 SliderObject.HookList = {
Tercio@39 1181 OnEnter = {},
Tercio@39 1182 OnLeave = {},
Tercio@39 1183 OnHide = {},
Tercio@39 1184 OnShow = {},
Tercio@39 1185 OnMouseDown = {},
Tercio@39 1186 OnMouseUp = {},
Tercio@11 1187
Tercio@39 1188 OnValueChange = {},
Tercio@39 1189 OnValueChanged = {},
Tercio@39 1190 }
Tercio@39 1191
Tercio@39 1192 SliderObject.slider:SetScript ("OnEnter", OnEnter)
Tercio@39 1193 SliderObject.slider:SetScript ("OnLeave", OnLeave)
Tercio@39 1194 SliderObject.slider:SetScript ("OnHide", OnHide)
Tercio@39 1195 SliderObject.slider:SetScript ("OnShow", OnShow)
Tercio@39 1196 SliderObject.slider:SetScript ("OnValueChanged", OnValueChanged)
Tercio@39 1197 SliderObject.slider:SetScript ("OnMouseDown", OnMouseDown)
Tercio@39 1198 SliderObject.slider:SetScript ("OnMouseUp", OnMouseUp)
Tercio@39 1199
Tercio@35 1200 _setmetatable (SliderObject, DFSliderMetaFunctions)
Tercio@11 1201
Tercio@11 1202 if (with_label) then
Tercio@11 1203 local label = DF:CreateLabel (SliderObject.slider, with_label, nil, nil, nil, "label", nil, "overlay")
Tercio@11 1204 label.text = with_label
Tercio@11 1205 SliderObject.slider:SetPoint ("left", label.widget, "right", 2, 0)
Tercio@11 1206 with_label = label
Tercio@22 1207
Tercio@22 1208 if (label_template) then
Tercio@22 1209 label:SetTemplate (label_template)
Tercio@22 1210 end
Tercio@22 1211 end
Tercio@22 1212
Tercio@22 1213 if (slider_template) then
Tercio@22 1214 SliderObject:SetTemplate (slider_template)
Tercio@11 1215 end
Tercio@11 1216
Tercio@11 1217 return SliderObject, with_label
Tercio@11 1218
Tercio@58 1219 end