annotate Libs/DF/slider.lua @ 35:a9c4a360ccfe

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