annotate Libs/DF/split_bar.lua @ 11:2f09fe4be15c

Added an Options Panel.
author Tercio
date Mon, 20 Apr 2015 16:34:18 -0300
parents
children dc1c77254f80
rev   line source
Tercio@11 1
Tercio@11 2
Tercio@11 3
Tercio@11 4 local DF = _G ["DetailsFramework"]
Tercio@11 5 local _
Tercio@11 6
Tercio@11 7 local _rawset = rawset --> lua local
Tercio@11 8 local _rawget = rawget --> lua local
Tercio@11 9 local _setmetatable = setmetatable --> lua local
Tercio@11 10 local _unpack = unpack --> lua local
Tercio@11 11 local _type = type --> lua local
Tercio@11 12 local _math_floor = math.floor --> lua local
Tercio@11 13
Tercio@11 14 local cleanfunction = function() end
Tercio@11 15 local SplitBarMetaFunctions = {}
Tercio@11 16 local APISplitBarFunctions
Tercio@11 17
Tercio@11 18 ------------------------------------------------------------------------------------------------------------
Tercio@11 19 --> metatables
Tercio@11 20
Tercio@11 21 SplitBarMetaFunctions.__call = function (_table, value)
Tercio@11 22 if (not value) then
Tercio@11 23 return _table.statusbar:GetValue()
Tercio@11 24 else
Tercio@11 25 _table.div:SetPoint ("left", _table.statusbar, "left", value * (_table.statusbar:GetWidth()/100) - 18, 0)
Tercio@11 26 return _table.statusbar:SetValue (value)
Tercio@11 27 end
Tercio@11 28 end
Tercio@11 29
Tercio@11 30 SplitBarMetaFunctions.__add = function (v1, v2)
Tercio@11 31 if (_type (v1) == "table") then
Tercio@11 32 local v = v1.statusbar:GetValue()
Tercio@11 33 v = v + v2
Tercio@11 34 v1.div:SetPoint ("left", v1.statusbar, "left", value * (v1.statusbar:GetWidth()/100) - 18, 0)
Tercio@11 35 v1.statusbar:SetValue (v)
Tercio@11 36 else
Tercio@11 37 local v = v2.statusbar:GetValue()
Tercio@11 38 v = v + v1
Tercio@11 39 v2.div:SetPoint ("left", v2.statusbar, "left", value * (v2.statusbar:GetWidth()/100) - 18, 0)
Tercio@11 40 v2.statusbar:SetValue (v)
Tercio@11 41 end
Tercio@11 42 end
Tercio@11 43
Tercio@11 44 SplitBarMetaFunctions.__sub = function (v1, v2)
Tercio@11 45 if (_type (v1) == "table") then
Tercio@11 46 local v = v1.statusbar:GetValue()
Tercio@11 47 v = v - v2
Tercio@11 48 v1.div:SetPoint ("left", v1.statusbar, "left", value * (v1.statusbar:GetWidth()/100) - 18, 0)
Tercio@11 49 v1.statusbar:SetValue (v)
Tercio@11 50 else
Tercio@11 51 local v = v2.statusbar:GetValue()
Tercio@11 52 v = v - v1
Tercio@11 53 v2.div:SetPoint ("left", v2.statusbar, "left", value * (v2.statusbar:GetWidth()/100) - 18, 0)
Tercio@11 54 v2.statusbar:SetValue (v)
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 function gmember_tooltip (_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.statusbar:IsShown()
Tercio@11 68 end
Tercio@11 69 --> frame width
Tercio@11 70 local gmember_width = function (_object)
Tercio@11 71 return _object.statusbar:GetWidth()
Tercio@11 72 end
Tercio@11 73 --> frame height
Tercio@11 74 local gmember_height = function (_object)
Tercio@11 75 return _object.statusbar:GetHeight()
Tercio@11 76 end
Tercio@11 77 --> value
Tercio@11 78 local gmember_value = function (_object)
Tercio@11 79 return _object.statusbar:GetValue()
Tercio@11 80 end
Tercio@11 81 --> right text
Tercio@11 82 local gmember_rtext = function (_object)
Tercio@11 83 return _object.textright:GetText()
Tercio@11 84 end
Tercio@11 85 --> left text
Tercio@11 86 local gmember_ltext = function (_object)
Tercio@11 87 return _object.textleft:GetText()
Tercio@11 88 end
Tercio@11 89 --> right color
Tercio@11 90 local gmember_rcolor = function (_object)
Tercio@11 91 return _object.background.original_colors
Tercio@11 92 end
Tercio@11 93 --> left color
Tercio@11 94 local gmember_lcolor = function (_object)
Tercio@11 95 return _object.texture.original_colors
Tercio@11 96 end
Tercio@11 97 --> right icon
Tercio@11 98 local gmember_ricon = function (_object)
Tercio@11 99 return _object.iconright:GetTexture()
Tercio@11 100 end
Tercio@11 101 --> left icon
Tercio@11 102 local gmember_licon = function (_object)
Tercio@11 103 return _object.iconleft:GetTexture()
Tercio@11 104 end
Tercio@11 105 --> texture
Tercio@11 106 local gmember_texture = function (_object)
Tercio@11 107 return _object.texture:GetTexture()
Tercio@11 108 end
Tercio@11 109 --> font size
Tercio@11 110 local gmember_textsize = function (_object)
Tercio@11 111 local _, fontsize = _object.textleft:GetFont()
Tercio@11 112 return fontsize
Tercio@11 113 end
Tercio@11 114 --> font face
Tercio@11 115 local gmember_textfont = function (_object)
Tercio@11 116 local fontface = _object.textleft:GetFont()
Tercio@11 117 return fontface
Tercio@11 118 end
Tercio@11 119 --> font color
Tercio@11 120 local gmember_textcolor = function (_object)
Tercio@11 121 return _object.textleft:GetTextColor()
Tercio@11 122 end
Tercio@11 123
Tercio@11 124 local get_members_function_index = {
Tercio@11 125 ["tooltip"] = gmember_tooltip,
Tercio@11 126 ["shown"] = gmember_shown,
Tercio@11 127 ["width"] = gmember_width,
Tercio@11 128 ["height"] = gmember_height,
Tercio@11 129 ["value"] = gmember_value,
Tercio@11 130 ["righttext"] = gmember_rtext,
Tercio@11 131 ["lefttext"] = gmember_ltext,
Tercio@11 132 ["rightcolor"] = gmember_rcolor,
Tercio@11 133 ["leftcolor"] = gmember_lcolor,
Tercio@11 134 ["righticon"] = gmember_ricon,
Tercio@11 135 ["lefticon"] = gmember_licon,
Tercio@11 136 ["texture"] = gmember_texture,
Tercio@11 137 ["fontsize"] = gmember_textsize,
Tercio@11 138 ["fontface"] = gmember_textfont,
Tercio@11 139 ["fontcolor"] = gmember_textcolor,
Tercio@11 140 ["textsize"] = gmember_textsize, --alias
Tercio@11 141 ["textfont"] = gmember_textfont, --alias
Tercio@11 142 ["textcolor"] = gmember_textcolor --alias
Tercio@11 143 }
Tercio@11 144
Tercio@11 145 SplitBarMetaFunctions.__index = function (_table, _member_requested)
Tercio@11 146
Tercio@11 147 local func = get_members_function_index [_member_requested]
Tercio@11 148 if (func) then
Tercio@11 149 return func (_table, _member_requested)
Tercio@11 150 end
Tercio@11 151
Tercio@11 152 local fromMe = _rawget (_table, _member_requested)
Tercio@11 153 if (fromMe) then
Tercio@11 154 return fromMe
Tercio@11 155 end
Tercio@11 156
Tercio@11 157 return SplitBarMetaFunctions [_member_requested]
Tercio@11 158 end
Tercio@11 159
Tercio@11 160 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 161
Tercio@11 162 --> tooltip
Tercio@11 163 local smember_tooltip = function (_object, _value)
Tercio@11 164 return _object:SetTooltip (_value)
Tercio@11 165 end
Tercio@11 166 --> show
Tercio@11 167 local smember_shown = function (_object, _value)
Tercio@11 168 if (_value) then
Tercio@11 169 return _object:Show()
Tercio@11 170 else
Tercio@11 171 return _object:Hide()
Tercio@11 172 end
Tercio@11 173 end
Tercio@11 174 --> hide
Tercio@11 175 local smember_hide = function (_object, _value)
Tercio@11 176 if (_value) then
Tercio@11 177 return _object:Hide()
Tercio@11 178 else
Tercio@11 179 return _object:Show()
Tercio@11 180 end
Tercio@11 181 end
Tercio@11 182 --> width
Tercio@11 183 local smember_width = function (_object, _value)
Tercio@11 184 return _object.statusbar:SetWidth (_value)
Tercio@11 185 end
Tercio@11 186 --> height
Tercio@11 187 local smember_height = function (_object, _value)
Tercio@11 188 return _object.statusbar:SetHeight (_value)
Tercio@11 189 end
Tercio@11 190 --> statusbar value
Tercio@11 191 local smember_value = function (_object, _value)
Tercio@11 192 _object.statusbar:SetValue (_value)
Tercio@11 193 return _object.div:SetPoint ("left", _object.statusbar, "left", _value * (_object.statusbar:GetWidth()/100) - 18, 0)
Tercio@11 194 end
Tercio@11 195 --> right text
Tercio@11 196 local smember_rtext = function (_object, _value)
Tercio@11 197 return _object.textright:SetText (_value)
Tercio@11 198 end
Tercio@11 199 --> left text
Tercio@11 200 local smember_ltext = function (_object, _value)
Tercio@11 201 return _object.textleft:SetText (_value)
Tercio@11 202 end
Tercio@11 203 --> right color
Tercio@11 204 local smember_rcolor = function (_object, _value)
Tercio@11 205 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value)
Tercio@11 206 _object.background.original_colors = {_value1, _value2, _value3, _value4}
Tercio@11 207 return _object.background:SetVertexColor (_value1, _value2, _value3, _value4)
Tercio@11 208 end
Tercio@11 209 --> left color
Tercio@11 210 local smember_lcolor = function (_object, _value)
Tercio@11 211 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value)
Tercio@11 212
Tercio@11 213 _object.statusbar:SetStatusBarColor (_value1, _value2, _value3, _value4)
Tercio@11 214 _object.texture.original_colors = {_value1, _value2, _value3, _value4}
Tercio@11 215 return _object.texture:SetVertexColor (_value1, _value2, _value3, _value4)
Tercio@11 216 end
Tercio@11 217 --> right icon
Tercio@11 218 local smember_ricon = function (_object, _value)
Tercio@11 219 if (type (_value) == "table") then
Tercio@11 220 local _value1, _value2 = _unpack (_value)
Tercio@11 221 _object.iconright:SetTexture (_value1)
Tercio@11 222 if (_value2) then
Tercio@11 223 _object.iconright:SetTexCoord (_unpack (_value2))
Tercio@11 224 end
Tercio@11 225 else
Tercio@11 226 _object.iconright:SetTexture (_value)
Tercio@11 227 end
Tercio@11 228 return
Tercio@11 229 end
Tercio@11 230 --> left icon
Tercio@11 231 local smember_licon = function (_object, _value)
Tercio@11 232 if (type (_value) == "table") then
Tercio@11 233 local _value1, _value2 = _unpack (_value)
Tercio@11 234 _object.iconleft:SetTexture (_value1)
Tercio@11 235 if (_value2) then
Tercio@11 236 _object.iconleft:SetTexCoord (_unpack (_value2))
Tercio@11 237 end
Tercio@11 238 else
Tercio@11 239 _object.iconleft:SetTexture (_value)
Tercio@11 240 end
Tercio@11 241 return
Tercio@11 242 end
Tercio@11 243 --> texture
Tercio@11 244 local smember_texture = function (_object, _value)
Tercio@11 245 if (type (_value) == "table") then
Tercio@11 246 local _value1, _value2 = _unpack (_value)
Tercio@11 247 _object.texture:SetTexture (_value1)
Tercio@11 248 _object.background:SetTexture (_value1)
Tercio@11 249 if (_value2) then
Tercio@11 250 _object.texture:SetTexCoord (_unpack (_value2))
Tercio@11 251 _object.background:SetTexCoord (_unpack (_value2))
Tercio@11 252 end
Tercio@11 253 else
Tercio@11 254 _object.texture:SetTexture (_value)
Tercio@11 255 _object.background:SetTexture (_value)
Tercio@11 256 end
Tercio@11 257 return
Tercio@11 258 end
Tercio@11 259 --> font face
Tercio@11 260 local smember_textfont = function (_object, _value)
Tercio@11 261 DF:SetFontFace (_object.textleft, _value)
Tercio@11 262 return DF:SetFontFace (_object.textright, _value)
Tercio@11 263 end
Tercio@11 264 --> font size
Tercio@11 265 local smember_textsize = function (_object, _value)
Tercio@11 266 DF:SetFontSize (_object.textleft, _value)
Tercio@11 267 return DF:SetFontSize (_object.textright, _value)
Tercio@11 268 end
Tercio@11 269 --> font color
Tercio@11 270 local smember_textcolor = function (_object, _value)
Tercio@11 271 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value)
Tercio@11 272 _object.textleft:SetTextColor (_value1, _value2, _value3, _value4)
Tercio@11 273 return _object.textright:SetTextColor (_value1, _value2, _value3, _value4)
Tercio@11 274 end
Tercio@11 275
Tercio@11 276 local set_members_function_index = {
Tercio@11 277 ["tooltip"] = smember_tooltip,
Tercio@11 278 ["shown"] = smember_shown,
Tercio@11 279 ["width"] = smember_width,
Tercio@11 280 ["height"] = smember_height,
Tercio@11 281 ["value"] = smember_value,
Tercio@11 282 ["righttext"] = smember_rtext,
Tercio@11 283 ["lefttext"] = smember_ltext,
Tercio@11 284 ["rightcolor"] = smember_rcolor,
Tercio@11 285 ["leftcolor"] = smember_lcolor,
Tercio@11 286 ["righticon"] = smember_ricon,
Tercio@11 287 ["lefticon"] = smember_licon,
Tercio@11 288 ["texture"] = smember_texture,
Tercio@11 289 ["fontsize"] = smember_textsize,
Tercio@11 290 ["fontface"] = smember_textfont,
Tercio@11 291 ["fontcolor"] = smember_textcolor,
Tercio@11 292 ["textsize"] = smember_textsize, --alias
Tercio@11 293 ["textfont"] = smember_textfont, --alias
Tercio@11 294 ["textcolor"] = smember_textcolor --alias
Tercio@11 295 }
Tercio@11 296
Tercio@11 297 SplitBarMetaFunctions.__newindex = function (_table, _key, _value)
Tercio@11 298 local func = set_members_function_index [_key]
Tercio@11 299 if (func) then
Tercio@11 300 return func (_table, _value)
Tercio@11 301 else
Tercio@11 302 return _rawset (_table, _key, _value)
Tercio@11 303 end
Tercio@11 304 end
Tercio@11 305
Tercio@11 306 ------------------------------------------------------------------------------------------------------------
Tercio@11 307 --> methods
Tercio@11 308
Tercio@11 309 --> show & hide
Tercio@11 310 function SplitBarMetaFunctions:Show()
Tercio@11 311 return self.statusbar:Show()
Tercio@11 312 end
Tercio@11 313 function SplitBarMetaFunctions:Hide()
Tercio@11 314 return self.statusbar:Hide()
Tercio@11 315 end
Tercio@11 316
Tercio@11 317 -- set split
Tercio@11 318 function SplitBarMetaFunctions:SetSplit (value)
Tercio@11 319 if (not value) then
Tercio@11 320 value = self.statusbar:GetValue()
Tercio@11 321 elseif (value < 0 or value > 100) then
Tercio@11 322 return
Tercio@11 323 end
Tercio@11 324 self.statusbar:SetValue (value)
Tercio@11 325 self.div:SetPoint ("left", self.statusbar, "left", value * (self.statusbar:GetWidth()/100) - 18, 0)
Tercio@11 326 end
Tercio@11 327
Tercio@11 328 -- setpoint
Tercio@11 329 function SplitBarMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 330 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
Tercio@11 331 if (not v1) then
Tercio@11 332 print ("Invalid parameter for SetPoint")
Tercio@11 333 return
Tercio@11 334 end
Tercio@11 335 return self.widget:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 336 end
Tercio@11 337
Tercio@11 338 -- sizes
Tercio@11 339 function SplitBarMetaFunctions:SetSize (w, h)
Tercio@11 340 if (w) then
Tercio@11 341 self.statusbar:SetWidth (w)
Tercio@11 342 end
Tercio@11 343 if (h) then
Tercio@11 344 self.statusbar:SetHeight (h)
Tercio@11 345 end
Tercio@11 346 end
Tercio@11 347
Tercio@11 348 -- texture
Tercio@11 349 function SplitBarMetaFunctions:SetTexture (texture)
Tercio@11 350 self.background:SetTexture (texture)
Tercio@11 351 self.texture:SetTexture (texture)
Tercio@11 352 end
Tercio@11 353
Tercio@11 354 -- texts
Tercio@11 355 function SplitBarMetaFunctions:SetLeftText (text)
Tercio@11 356 self.textleft:SetText (text)
Tercio@11 357 end
Tercio@11 358 function SplitBarMetaFunctions:SetRightText (text)
Tercio@11 359 self.textright:SetText (text)
Tercio@11 360 end
Tercio@11 361
Tercio@11 362 -- colors
Tercio@11 363 function SplitBarMetaFunctions:SetLeftColor (r, g, b, a)
Tercio@11 364 r, g, b, a = DF:ParseColors (r, g, b, a)
Tercio@11 365 self.texture:SetVertexColor (r, g, b, a)
Tercio@11 366 self.texture.original_colors = {r, g, b, a}
Tercio@11 367 end
Tercio@11 368 function SplitBarMetaFunctions:SetRightColor (r, g, b, a)
Tercio@11 369 r, g, b, a = DF:ParseColors (r, g, b, a)
Tercio@11 370 self.background:SetVertexColor (r, g, b, a)
Tercio@11 371 self.background.original_colors = {r, g, b, a}
Tercio@11 372 end
Tercio@11 373
Tercio@11 374 -- icons
Tercio@11 375 function SplitBarMetaFunctions:SetLeftIcon (texture, ...)
Tercio@11 376 self.iconleft:SetTexture (texture)
Tercio@11 377 if (...) then
Tercio@11 378 local L, R, U, D = unpack (...)
Tercio@11 379 self.iconleft:SetTexCoord (L, R, U, D)
Tercio@11 380 end
Tercio@11 381 end
Tercio@11 382 function SplitBarMetaFunctions:SetRightIcon (texture, ...)
Tercio@11 383 self.iconright:SetTexture (texture)
Tercio@11 384 if (...) then
Tercio@11 385 local L, R, U, D = unpack (...)
Tercio@11 386 self.iconright:SetTexCoord (L, R, U, D)
Tercio@11 387 end
Tercio@11 388 end
Tercio@11 389
Tercio@11 390 -- tooltip
Tercio@11 391 function SplitBarMetaFunctions:SetTooltip (tooltip)
Tercio@11 392 if (tooltip) then
Tercio@11 393 return _rawset (self, "have_tooltip", tooltip)
Tercio@11 394 else
Tercio@11 395 return _rawset (self, "have_tooltip", nil)
Tercio@11 396 end
Tercio@11 397 end
Tercio@11 398 function SplitBarMetaFunctions:GetTooltip()
Tercio@11 399 return _rawget (self, "have_tooltip")
Tercio@11 400 end
Tercio@11 401
Tercio@11 402 -- frame levels
Tercio@11 403 function SplitBarMetaFunctions:GetFrameLevel()
Tercio@11 404 return self.statusbar:GetFrameLevel()
Tercio@11 405 end
Tercio@11 406 function SplitBarMetaFunctions:SetFrameLevel (level, frame)
Tercio@11 407 if (not frame) then
Tercio@11 408 return self.statusbar:SetFrameLevel (level)
Tercio@11 409 else
Tercio@11 410 local framelevel = frame:GetFrameLevel (frame) + level
Tercio@11 411 return self.statusbar:SetFrameLevel (framelevel)
Tercio@11 412 end
Tercio@11 413 end
Tercio@11 414
Tercio@11 415 -- frame stratas
Tercio@11 416 function SplitBarMetaFunctions:SetFrameStrata()
Tercio@11 417 return self.statusbar:GetFrameStrata()
Tercio@11 418 end
Tercio@11 419 function SplitBarMetaFunctions:SetFrameStrata (strata)
Tercio@11 420 if (_type (strata) == "table") then
Tercio@11 421 self.statusbar:SetFrameStrata (strata:GetFrameStrata())
Tercio@11 422 else
Tercio@11 423 self.statusbar:SetFrameStrata (strata)
Tercio@11 424 end
Tercio@11 425 end
Tercio@11 426
Tercio@11 427 --> hooks
Tercio@11 428 function SplitBarMetaFunctions:SetHook (hookType, func)
Tercio@11 429 if (func) then
Tercio@11 430 _rawset (self, hookType.."Hook", func)
Tercio@11 431 else
Tercio@11 432 _rawset (self, hookType.."Hook", nil)
Tercio@11 433 end
Tercio@11 434 end
Tercio@11 435
Tercio@11 436 ------------------------------------------------------------------------------------------------------------
Tercio@11 437 --> scripts
Tercio@11 438 local OnEnter = function (frame)
Tercio@11 439 if (frame.MyObject.OnEnterHook) then
Tercio@11 440 local interrupt = frame.MyObject.OnEnterHook (frame)
Tercio@11 441 if (interrupt) then
Tercio@11 442 return
Tercio@11 443 end
Tercio@11 444 end
Tercio@11 445
Tercio@11 446 local oc = frame.MyObject.texture.original_colors --original colors
Tercio@11 447 DF:GradientEffect ( frame.MyObject.texture, "texture", oc[1], oc[2], oc[3], oc[4], oc[1]+0.2, oc[2]+0.2, oc[3]+0.2, oc[4], .2)
Tercio@11 448 frame.MyObject.div:SetPoint ("left", frame, "left", frame:GetValue() * (frame:GetWidth()/100) - 18, 0)
Tercio@11 449
Tercio@11 450 if (frame.MyObject.have_tooltip) then
Tercio@11 451 GameCooltip2:Reset()
Tercio@11 452 GameCooltip2:AddLine (frame.MyObject.have_tooltip)
Tercio@11 453 GameCooltip2:ShowCooltip (frame, "tooltip")
Tercio@11 454 end
Tercio@11 455
Tercio@11 456 local parent = frame:GetParent().MyObject
Tercio@11 457 if (parent and parent.type == "panel") then
Tercio@11 458 if (parent.GradientEnabled) then
Tercio@11 459 parent:RunGradient()
Tercio@11 460 end
Tercio@11 461 end
Tercio@11 462 end
Tercio@11 463
Tercio@11 464 local OnLeave = function (frame)
Tercio@11 465 if (frame.MyObject.OnLeaveHook) then
Tercio@11 466 local interrupt = frame.MyObject.OnLeaveHook (frame)
Tercio@11 467 if (interrupt) then
Tercio@11 468 return
Tercio@11 469 end
Tercio@11 470 end
Tercio@11 471
Tercio@11 472 local oc = frame.MyObject.texture.original_colors --original colors
Tercio@11 473 local r, g, b, a = frame.MyObject.texture:GetVertexColor()
Tercio@11 474 DF:GradientEffect ( frame.MyObject.texture, "texture", r, g, b, a, oc[1], oc[2], oc[3], oc[4], .2)
Tercio@11 475
Tercio@11 476 if (frame.MyObject.have_tooltip) then
Tercio@11 477 DF.popup:ShowMe (false)
Tercio@11 478 end
Tercio@11 479
Tercio@11 480 local parent = frame:GetParent().MyObject
Tercio@11 481 if (parent and parent.type == "panel") then
Tercio@11 482 if (parent.GradientEnabled) then
Tercio@11 483 parent:RunGradient (false)
Tercio@11 484 end
Tercio@11 485 end
Tercio@11 486 end
Tercio@11 487
Tercio@11 488 local OnHide = function (frame)
Tercio@11 489 if (frame.MyObject.OnHideHook) then
Tercio@11 490 local interrupt = frame.MyObject.OnHideHook (frame)
Tercio@11 491 if (interrupt) then
Tercio@11 492 return
Tercio@11 493 end
Tercio@11 494 end
Tercio@11 495 end
Tercio@11 496
Tercio@11 497 local OnShow = function (frame)
Tercio@11 498 if (frame.MyObject.OnShowHook) then
Tercio@11 499 local interrupt = frame.MyObject.OnShowHook (frame)
Tercio@11 500 if (interrupt) then
Tercio@11 501 return
Tercio@11 502 end
Tercio@11 503 end
Tercio@11 504 end
Tercio@11 505
Tercio@11 506 local OnMouseDown = function (frame, button)
Tercio@11 507 if (frame.MyObject.OnMouseDownHook) then
Tercio@11 508 local interrupt = frame.MyObject.OnMouseDownHook (frame, button)
Tercio@11 509 if (interrupt) then
Tercio@11 510 return
Tercio@11 511 end
Tercio@11 512 end
Tercio@11 513
Tercio@11 514 if (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then
Tercio@11 515 if (not frame.isLocked and frame:IsMovable()) then
Tercio@11 516 frame.MyObject.container.isMoving = true
Tercio@11 517 frame.MyObject.container:StartMoving()
Tercio@11 518 end
Tercio@11 519 end
Tercio@11 520 end
Tercio@11 521
Tercio@11 522 local OnMouseUp = function (frame, button)
Tercio@11 523 if (frame.MyObject.OnMouseUpHook) then
Tercio@11 524 local interrupt = frame.MyObject.OnMouseUpHook (frame, button)
Tercio@11 525 if (interrupt) then
Tercio@11 526 return
Tercio@11 527 end
Tercio@11 528 end
Tercio@11 529
Tercio@11 530 if (frame.MyObject.container.isMoving) then
Tercio@11 531 frame.MyObject.container:StopMovingOrSizing()
Tercio@11 532 frame.MyObject.container.isMoving = false
Tercio@11 533 end
Tercio@11 534 end
Tercio@11 535
Tercio@11 536 local OnSizeChanged = function (statusbar)
Tercio@11 537 statusbar.MyObject.div:SetPoint ("left", statusbar, "left", statusbar:GetValue() * (statusbar:GetWidth()/100) - 18, 0)
Tercio@11 538 end
Tercio@11 539
Tercio@11 540 ------------------------------------------------------------------------------------------------------------
Tercio@11 541 --> object constructor
Tercio@11 542
Tercio@11 543 function DetailsFrameworkSplitlBar_OnCreate (self)
Tercio@11 544 self.texture.original_colors = {1, 1, 1, 1}
Tercio@11 545 self.background.original_colors = {.5, .5, .5, 1}
Tercio@11 546 self.spark:SetPoint ("left", self, "left", self:GetValue() * (self:GetWidth()/100) - 18, 0)
Tercio@11 547 return true
Tercio@11 548 end
Tercio@11 549
Tercio@11 550 function DF:CreateSplitBar (parent, parent, w, h, member, name)
Tercio@11 551 return DF:NewSplitBar (parent, container, name, member, w, h)
Tercio@11 552 end
Tercio@11 553
Tercio@11 554 function DF:NewSplitBar (parent, container, name, member, w, h)
Tercio@11 555
Tercio@11 556 if (not name) then
Tercio@11 557 name = "DetailsFrameworkSplitbar" .. DF.SplitBarCounter
Tercio@11 558 DF.SplitBarCounter = DF.SplitBarCounter + 1
Tercio@11 559 end
Tercio@11 560 if (not parent) then
Tercio@11 561 return nil
Tercio@11 562 end
Tercio@11 563 if (not container) then
Tercio@11 564 container = parent
Tercio@11 565 end
Tercio@11 566
Tercio@11 567 if (name:find ("$parent")) then
Tercio@11 568 name = name:gsub ("$parent", parent:GetName())
Tercio@11 569 end
Tercio@11 570
Tercio@11 571 local SplitBarObject = {type = "barsplit", dframework = true}
Tercio@11 572
Tercio@11 573 if (member) then
Tercio@11 574 parent [member] = SplitBarObject
Tercio@11 575 end
Tercio@11 576
Tercio@11 577 if (parent.dframework) then
Tercio@11 578 parent = parent.widget
Tercio@11 579 end
Tercio@11 580 if (container.dframework) then
Tercio@11 581 container = container.widget
Tercio@11 582 end
Tercio@11 583
Tercio@11 584 --> default members:
Tercio@11 585 --> hooks
Tercio@11 586 SplitBarObject.OnEnterHook = nil
Tercio@11 587 SplitBarObject.OnLeaveHook = nil
Tercio@11 588 SplitBarObject.OnHideHook = nil
Tercio@11 589 SplitBarObject.OnShowHook = nil
Tercio@11 590 SplitBarObject.OnMouseDownHook = nil
Tercio@11 591 SplitBarObject.OnMouseUpHook = nil
Tercio@11 592 --> misc
Tercio@11 593 SplitBarObject.tooltip = nil
Tercio@11 594 SplitBarObject.locked = false
Tercio@11 595 SplitBarObject.have_tooltip = nil
Tercio@11 596 SplitBarObject.container = container
Tercio@11 597
Tercio@11 598 --> create widgets
Tercio@11 599 SplitBarObject.statusbar = CreateFrame ("statusbar", name, parent, "DetailsFrameworkSplitBarTemplate")
Tercio@11 600 SplitBarObject.widget = SplitBarObject.statusbar
Tercio@11 601
Tercio@11 602 if (not APISplitBarFunctions) then
Tercio@11 603 APISplitBarFunctions = true
Tercio@11 604 local idx = getmetatable (SplitBarObject.statusbar).__index
Tercio@11 605 for funcName, funcAddress in pairs (idx) do
Tercio@11 606 if (not SplitBarMetaFunctions [funcName]) then
Tercio@11 607 SplitBarMetaFunctions [funcName] = function (object, ...)
Tercio@11 608 local x = loadstring ( "return _G."..object.statusbar:GetName()..":"..funcName.."(...)")
Tercio@11 609 return x (...)
Tercio@11 610 end
Tercio@11 611 end
Tercio@11 612 end
Tercio@11 613 end
Tercio@11 614
Tercio@11 615 SplitBarObject.statusbar:SetHeight (h or 200)
Tercio@11 616 SplitBarObject.statusbar:SetWidth (w or 14)
Tercio@11 617
Tercio@11 618 SplitBarObject.statusbar.MyObject = SplitBarObject
Tercio@11 619
Tercio@11 620 SplitBarObject.textleft = _G [name .. "_TextLeft"]
Tercio@11 621 SplitBarObject.textright = _G [name .. "_TextRight"]
Tercio@11 622
Tercio@11 623 SplitBarObject.iconleft = _G [name .. "_IconLeft"]
Tercio@11 624 SplitBarObject.iconright = _G [name .. "_IconRight"]
Tercio@11 625
Tercio@11 626 SplitBarObject.background = _G [name .. "_StatusBarBackground"]
Tercio@11 627 SplitBarObject.texture = _G [name .. "_StatusBarTexture"]
Tercio@11 628
Tercio@11 629 SplitBarObject.div = _G [name .. "_Spark"]
Tercio@11 630
Tercio@11 631
Tercio@11 632 --> hooks
Tercio@11 633 SplitBarObject.statusbar:SetScript ("OnEnter", OnEnter)
Tercio@11 634 SplitBarObject.statusbar:SetScript ("OnLeave", OnLeave)
Tercio@11 635 SplitBarObject.statusbar:SetScript ("OnHide", OnHide)
Tercio@11 636 SplitBarObject.statusbar:SetScript ("OnShow", OnShow)
Tercio@11 637 SplitBarObject.statusbar:SetScript ("OnMouseDown", OnMouseDown)
Tercio@11 638 SplitBarObject.statusbar:SetScript ("OnMouseUp", OnMouseUp)
Tercio@11 639 SplitBarObject.statusbar:SetScript ("OnSizeChanged", OnSizeChanged)
Tercio@11 640
Tercio@11 641 _setmetatable (SplitBarObject, SplitBarMetaFunctions)
Tercio@11 642
Tercio@11 643 return SplitBarObject
Tercio@11 644 end