annotate Libs/DF/button.lua @ 55:307f5af3ad02

- Framework update.
author Tercio
date Sat, 09 Dec 2017 11:49:01 -0200
parents 7d5934415ad0
children 0682d738499b
rev   line source
Tercio@11 1
Tercio@11 2 local DF = _G ["DetailsFramework"]
Tercio@11 3
Tercio@20 4 if (not DF or not DetailsFrameworkCanLoad) then
Tercio@20 5 return
Tercio@20 6 end
Tercio@20 7
Tercio@11 8 local _
Tercio@11 9 local _rawset = rawset --> lua local
Tercio@11 10 local _rawget = rawget --> lua local
Tercio@11 11 local _setmetatable = setmetatable --> lua local
Tercio@11 12 local _unpack = unpack --> lua local
Tercio@11 13 local _type = type --> lua local
Tercio@11 14 local _math_floor = math.floor --> lua local
Tercio@11 15 local loadstring = loadstring --> lua local
Tercio@11 16
Tercio@11 17 local cleanfunction = function() end
Tercio@11 18 local APIButtonFunctions = false
Tercio@39 19
Tercio@39 20 do
Tercio@39 21 local metaPrototype = {
Tercio@39 22 WidgetType = "button",
Tercio@39 23 SetHook = DF.SetHook,
Tercio@39 24 RunHooksForWidget = DF.RunHooksForWidget,
Tercio@39 25 }
Tercio@39 26
Tercio@39 27 _G [DF.GlobalWidgetControlNames ["button"]] = _G [DF.GlobalWidgetControlNames ["button"]] or metaPrototype
Tercio@39 28 end
Tercio@39 29
Tercio@39 30 local ButtonMetaFunctions = _G [DF.GlobalWidgetControlNames ["button"]]
Tercio@11 31
Tercio@11 32 ------------------------------------------------------------------------------------------------------------
Tercio@11 33 --> metatables
Tercio@11 34
Tercio@11 35 ButtonMetaFunctions.__call = function (_table, value, ...)
Tercio@11 36 return self.func (_table.param1, _table.param2, value, ...)
Tercio@11 37 end
Tercio@11 38
Tercio@11 39 ------------------------------------------------------------------------------------------------------------
Tercio@11 40 --> members
Tercio@11 41
Tercio@11 42 --> tooltip
Tercio@11 43 local gmember_tooltip = function (_object)
Tercio@11 44 return _object:GetTooltip()
Tercio@11 45 end
Tercio@11 46 --> shown
Tercio@11 47 local gmember_shown = function (_object)
Tercio@11 48 return _object:IsShown()
Tercio@11 49 end
Tercio@11 50 --> frame width
Tercio@11 51 local gmember_width = function (_object)
Tercio@11 52 return _object.button:GetWidth()
Tercio@11 53 end
Tercio@11 54 --> frame height
Tercio@11 55 local gmember_height = function (_object)
Tercio@11 56 return _object.button:GetHeight()
Tercio@11 57 end
Tercio@11 58 --> text
Tercio@11 59 local gmember_text = function (_object)
Tercio@11 60 return _object.button.text:GetText()
Tercio@11 61 end
Tercio@11 62 --> function
Tercio@11 63 local gmember_function = function (_object)
Tercio@11 64 return _rawget (_object, "func")
Tercio@11 65 end
Tercio@11 66 --> text color
Tercio@11 67 local gmember_textcolor = function (_object)
Tercio@11 68 return _object.button.text:GetTextColor()
Tercio@11 69 end
Tercio@11 70 --> text font
Tercio@11 71 local gmember_textfont = function (_object)
Tercio@11 72 local fontface = _object.button.text:GetFont()
Tercio@11 73 return fontface
Tercio@11 74 end
Tercio@11 75 --> text size
Tercio@11 76 local gmember_textsize = function (_object)
Tercio@11 77 local _, fontsize = _object.button.text:GetFont()
Tercio@11 78 return fontsize
Tercio@11 79 end
Tercio@11 80 --> texture
Tercio@11 81 local gmember_texture = function (_object)
Tercio@11 82 return {_object.button:GetNormalTexture(), _object.button:GetHighlightTexture(), _object.button:GetPushedTexture(), _object.button:GetDisabledTexture()}
Tercio@11 83 end
Tercio@11 84 --> locked
Tercio@11 85 local gmember_locked = function (_object)
Tercio@11 86 return _rawget (_object, "is_locked")
Tercio@11 87 end
Tercio@11 88
Tercio@39 89 ButtonMetaFunctions.GetMembers = ButtonMetaFunctions.GetMembers or {}
Tercio@39 90 ButtonMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip
Tercio@39 91 ButtonMetaFunctions.GetMembers ["shown"] = gmember_shown
Tercio@39 92 ButtonMetaFunctions.GetMembers ["width"] = gmember_width
Tercio@39 93 ButtonMetaFunctions.GetMembers ["height"] = gmember_height
Tercio@39 94 ButtonMetaFunctions.GetMembers ["text"] = gmember_text
Tercio@39 95 ButtonMetaFunctions.GetMembers ["clickfunction"] = gmember_function
Tercio@39 96 ButtonMetaFunctions.GetMembers ["texture"] = gmember_texture
Tercio@39 97 ButtonMetaFunctions.GetMembers ["locked"] = gmember_locked
Tercio@39 98 ButtonMetaFunctions.GetMembers ["fontcolor"] = gmember_textcolor
Tercio@39 99 ButtonMetaFunctions.GetMembers ["fontface"] = gmember_textfont
Tercio@39 100 ButtonMetaFunctions.GetMembers ["fontsize"] = gmember_textsize
Tercio@39 101 ButtonMetaFunctions.GetMembers ["textcolor"] = gmember_textcolor --alias
Tercio@39 102 ButtonMetaFunctions.GetMembers ["textfont"] = gmember_textfont --alias
Tercio@39 103 ButtonMetaFunctions.GetMembers ["textsize"] = gmember_textsize --alias
Tercio@11 104
Tercio@11 105 ButtonMetaFunctions.__index = function (_table, _member_requested)
Tercio@11 106
Tercio@39 107 local func = ButtonMetaFunctions.GetMembers [_member_requested]
Tercio@11 108 if (func) then
Tercio@11 109 return func (_table, _member_requested)
Tercio@11 110 end
Tercio@11 111
Tercio@11 112 local fromMe = _rawget (_table, _member_requested)
Tercio@11 113 if (fromMe) then
Tercio@11 114 return fromMe
Tercio@11 115 end
Tercio@11 116
Tercio@11 117 return ButtonMetaFunctions [_member_requested]
Tercio@11 118 end
Tercio@11 119
Tercio@11 120 -------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tercio@11 121
Tercio@11 122 --> tooltip
Tercio@11 123 local smember_tooltip = function (_object, _value)
Tercio@11 124 return _object:SetTooltip (_value)
Tercio@11 125 end
Tercio@11 126 --> show
Tercio@11 127 local smember_show = function (_object, _value)
Tercio@11 128 if (_value) then
Tercio@11 129 return _object:Show()
Tercio@11 130 else
Tercio@11 131 return _object:Hide()
Tercio@11 132 end
Tercio@11 133 end
Tercio@11 134 --> hide
Tercio@11 135 local smember_hide = function (_object, _value)
Tercio@11 136 if (not _value) then
Tercio@11 137 return _object:Show()
Tercio@11 138 else
Tercio@11 139 return _object:Hide()
Tercio@11 140 end
Tercio@11 141 end
Tercio@11 142 --> frame width
Tercio@11 143 local smember_width = function (_object, _value)
Tercio@11 144 return _object.button:SetWidth (_value)
Tercio@11 145 end
Tercio@11 146 --> frame height
Tercio@11 147 local smember_height = function (_object, _value)
Tercio@11 148 return _object.button:SetHeight (_value)
Tercio@11 149 end
Tercio@11 150 --> text
Tercio@11 151 local smember_text = function (_object, _value)
Tercio@11 152 return _object.button.text:SetText (_value)
Tercio@11 153 end
Tercio@11 154 --> function
Tercio@11 155 local smember_function = function (_object, _value)
Tercio@11 156 return _rawset (_object, "func", _value)
Tercio@11 157 end
Tercio@55 158 --> param1
Tercio@55 159 local smember_param1 = function (_object, _value)
Tercio@55 160 return _rawset (_object, "param1", _value)
Tercio@55 161 end
Tercio@55 162 --> param2
Tercio@55 163 local smember_param2 = function (_object, _value)
Tercio@55 164 return _rawset (_object, "param2", _value)
Tercio@55 165 end
Tercio@11 166 --> text color
Tercio@11 167 local smember_textcolor = function (_object, _value)
Tercio@11 168 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value)
Tercio@11 169 return _object.button.text:SetTextColor (_value1, _value2, _value3, _value4)
Tercio@11 170 end
Tercio@11 171 --> text font
Tercio@11 172 local smember_textfont = function (_object, _value)
Tercio@11 173 return DF:SetFontFace (_object.button.text, _value)
Tercio@11 174 end
Tercio@11 175 --> text size
Tercio@11 176 local smember_textsize = function (_object, _value)
Tercio@11 177 return DF:SetFontSize (_object.button.text, _value)
Tercio@11 178 end
Tercio@11 179 --> texture
Tercio@11 180 local smember_texture = function (_object, _value)
Tercio@11 181 if (_type (_value) == "table") then
Tercio@11 182 local _value1, _value2, _value3, _value4 = unpack (_value)
Tercio@11 183 if (_value1) then
Tercio@11 184 _object.button:SetNormalTexture (_value1)
Tercio@11 185 end
Tercio@11 186 if (_value2) then
Tercio@11 187 _object.button:SetHighlightTexture (_value2, "ADD")
Tercio@11 188 end
Tercio@11 189 if (_value3) then
Tercio@11 190 _object.button:SetPushedTexture (_value3)
Tercio@11 191 end
Tercio@11 192 if (_value4) then
Tercio@11 193 _object.button:SetDisabledTexture (_value4)
Tercio@11 194 end
Tercio@11 195 else
Tercio@11 196 _object.button:SetNormalTexture (_value)
Tercio@11 197 _object.button:SetHighlightTexture (_value, "ADD")
Tercio@11 198 _object.button:SetPushedTexture (_value)
Tercio@11 199 _object.button:SetDisabledTexture (_value)
Tercio@11 200 end
Tercio@11 201 return
Tercio@11 202 end
Tercio@11 203 --> locked
Tercio@11 204 local smember_locked = function (_object, _value)
Tercio@11 205 if (_value) then
Tercio@11 206 _object.button:SetMovable (false)
Tercio@11 207 return _rawset (_object, "is_locked", true)
Tercio@11 208 else
Tercio@11 209 _object.button:SetMovable (true)
Tercio@11 210 _rawset (_object, "is_locked", false)
Tercio@11 211 return
Tercio@11 212 end
Tercio@11 213 end
Tercio@11 214 --> text align
Tercio@11 215 local smember_textalign = function (_object, _value)
Tercio@11 216 if (_value == "left" or _value == "<") then
Tercio@11 217 _object.button.text:SetPoint ("left", _object.button, "left", 2, 0)
Tercio@11 218 _object.capsule_textalign = "left"
Tercio@11 219 elseif (_value == "center" or _value == "|") then
Tercio@11 220 _object.button.text:SetPoint ("center", _object.button, "center", 0, 0)
Tercio@11 221 _object.capsule_textalign = "center"
Tercio@11 222 elseif (_value == "right" or _value == ">") then
Tercio@11 223 _object.button.text:SetPoint ("right", _object.button, "right", -2, 0)
Tercio@11 224 _object.capsule_textalign = "right"
Tercio@11 225 end
Tercio@11 226 end
Tercio@39 227
Tercio@39 228 ButtonMetaFunctions.SetMembers = ButtonMetaFunctions.SetMembers or {}
Tercio@39 229 ButtonMetaFunctions.SetMembers ["tooltip"] = smember_tooltip
Tercio@39 230 ButtonMetaFunctions.SetMembers ["show"] = smember_show
Tercio@39 231 ButtonMetaFunctions.SetMembers ["hide"] = smember_hide
Tercio@39 232 ButtonMetaFunctions.SetMembers ["width"] = smember_width
Tercio@39 233 ButtonMetaFunctions.SetMembers ["height"] = smember_height
Tercio@39 234 ButtonMetaFunctions.SetMembers ["text"] = smember_text
Tercio@39 235 ButtonMetaFunctions.SetMembers ["clickfunction"] = smember_function
Tercio@55 236 ButtonMetaFunctions.SetMembers ["param1"] = smember_param1
Tercio@55 237 ButtonMetaFunctions.SetMembers ["param2"] = smember_param2
Tercio@39 238 ButtonMetaFunctions.SetMembers ["textcolor"] = smember_textcolor
Tercio@39 239 ButtonMetaFunctions.SetMembers ["textfont"] = smember_textfont
Tercio@39 240 ButtonMetaFunctions.SetMembers ["textsize"] = smember_textsize
Tercio@39 241 ButtonMetaFunctions.SetMembers ["texture"] = smember_texture
Tercio@39 242 ButtonMetaFunctions.SetMembers ["locked"] = smember_locked
Tercio@39 243 ButtonMetaFunctions.SetMembers ["textalign"] = smember_textalign
Tercio@11 244
Tercio@11 245 ButtonMetaFunctions.__newindex = function (_table, _key, _value)
Tercio@39 246 local func = ButtonMetaFunctions.SetMembers [_key]
Tercio@11 247 if (func) then
Tercio@11 248 return func (_table, _value)
Tercio@11 249 else
Tercio@11 250 return _rawset (_table, _key, _value)
Tercio@11 251 end
Tercio@11 252 end
Tercio@11 253
Tercio@11 254 ------------------------------------------------------------------------------------------------------------
Tercio@11 255 --> methods
Tercio@11 256
Tercio@11 257 --> show & hide
Tercio@11 258 function ButtonMetaFunctions:IsShown()
Tercio@11 259 return self.button:IsShown()
Tercio@11 260 end
Tercio@11 261 function ButtonMetaFunctions:Show()
Tercio@11 262 return self.button:Show()
Tercio@11 263 end
Tercio@11 264 function ButtonMetaFunctions:Hide()
Tercio@11 265 return self.button:Hide()
Tercio@11 266 end
Tercio@11 267
Tercio@11 268 -- setpoint
Tercio@11 269 function ButtonMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 270 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
Tercio@11 271 if (not v1) then
Tercio@11 272 error ("SetPoint: Invalid parameter.")
Tercio@11 273 return
Tercio@11 274 end
Tercio@11 275 return self.widget:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 276 end
Tercio@11 277
Tercio@11 278 -- sizes
Tercio@11 279 function ButtonMetaFunctions:SetSize (w, h)
Tercio@11 280 if (w) then
Tercio@11 281 self.button:SetWidth (w)
Tercio@11 282 end
Tercio@11 283 if (h) then
Tercio@11 284 return self.button:SetHeight (h)
Tercio@11 285 end
Tercio@11 286 end
Tercio@11 287
Tercio@11 288 -- tooltip
Tercio@11 289 function ButtonMetaFunctions:SetTooltip (tooltip)
Tercio@11 290 if (tooltip) then
Tercio@11 291 return _rawset (self, "have_tooltip", tooltip)
Tercio@11 292 else
Tercio@11 293 return _rawset (self, "have_tooltip", nil)
Tercio@11 294 end
Tercio@11 295 end
Tercio@11 296 function ButtonMetaFunctions:GetTooltip()
Tercio@11 297 return _rawget (self, "have_tooltip")
Tercio@11 298 end
Tercio@11 299
Tercio@11 300 -- functions
Tercio@11 301 function ButtonMetaFunctions:SetClickFunction (func, param1, param2, clicktype)
Tercio@11 302 if (not clicktype or string.find (string.lower (clicktype), "left")) then
Tercio@11 303 if (func) then
Tercio@11 304 _rawset (self, "func", func)
Tercio@11 305 else
Tercio@11 306 _rawset (self, "func", cleanfunction)
Tercio@11 307 end
Tercio@11 308
Tercio@11 309 if (param1 ~= nil) then
Tercio@11 310 _rawset (self, "param1", param1)
Tercio@11 311 end
Tercio@11 312 if (param2 ~= nil) then
Tercio@11 313 _rawset (self, "param2", param2)
Tercio@11 314 end
Tercio@11 315
Tercio@11 316 elseif (clicktype or string.find (string.lower (clicktype), "right")) then
Tercio@11 317 if (func) then
Tercio@11 318 _rawset (self, "funcright", func)
Tercio@11 319 else
Tercio@11 320 _rawset (self, "funcright", cleanfunction)
Tercio@11 321 end
Tercio@11 322 end
Tercio@11 323 end
Tercio@11 324
Tercio@11 325 -- text
Tercio@11 326 function ButtonMetaFunctions:SetText (text)
Tercio@11 327 if (text) then
Tercio@11 328 self.button.text:SetText (text)
Tercio@11 329 else
Tercio@11 330 self.button.text:SetText (nil)
Tercio@11 331 end
Tercio@11 332 end
Tercio@11 333
Tercio@11 334 -- textcolor
Tercio@11 335 function ButtonMetaFunctions:SetTextColor (color, arg2, arg3, arg4)
Tercio@11 336 if (arg2) then
Tercio@11 337 return self.button.text:SetTextColor (color, arg2, arg3, arg4 or 1)
Tercio@11 338 end
Tercio@11 339 local _value1, _value2, _value3, _value4 = DF:ParseColors (color)
Tercio@11 340 return self.button.text:SetTextColor (_value1, _value2, _value3, _value4)
Tercio@11 341 end
Tercio@11 342
Tercio@11 343 -- textsize
Tercio@11 344 function ButtonMetaFunctions:SetTextSize (size)
Tercio@11 345 return DF:SetFontSize (self.button.text, _value)
Tercio@11 346 end
Tercio@11 347
Tercio@11 348 -- textfont
Tercio@11 349 function ButtonMetaFunctions:SetTextFont (font)
Tercio@11 350 return DF:SetFontFace (_object.button.text, _value)
Tercio@11 351 end
Tercio@11 352
Tercio@11 353 -- textures
Tercio@11 354 function ButtonMetaFunctions:SetTexture (normal, highlight, pressed, disabled)
Tercio@11 355 if (normal) then
Tercio@11 356 self.button:SetNormalTexture (normal)
Tercio@11 357 elseif (_type (normal) ~= "boolean") then
Tercio@11 358 self.button:SetNormalTexture (nil)
Tercio@11 359 end
Tercio@11 360
Tercio@11 361 if (_type (highlight) == "boolean") then
Tercio@11 362 if (highlight and normal and _type (normal) ~= "boolean") then
Tercio@11 363 self.button:SetHighlightTexture (normal, "ADD")
Tercio@11 364 end
Tercio@11 365 elseif (highlight == nil) then
Tercio@11 366 self.button:SetHighlightTexture (nil)
Tercio@11 367 else
Tercio@11 368 self.button:SetHighlightTexture (highlight, "ADD")
Tercio@11 369 end
Tercio@11 370
Tercio@11 371 if (_type (pressed) == "boolean") then
Tercio@11 372 if (pressed and normal and _type (normal) ~= "boolean") then
Tercio@11 373 self.button:SetPushedTexture (normal)
Tercio@11 374 end
Tercio@11 375 elseif (pressed == nil) then
Tercio@11 376 self.button:SetPushedTexture (nil)
Tercio@11 377 else
Tercio@11 378 self.button:SetPushedTexture (pressed, "ADD")
Tercio@11 379 end
Tercio@11 380
Tercio@11 381 if (_type (disabled) == "boolean") then
Tercio@11 382 if (disabled and normal and _type (normal) ~= "boolean") then
Tercio@11 383 self.button:SetDisabledTexture (normal)
Tercio@11 384 end
Tercio@11 385 elseif (disabled == nil) then
Tercio@11 386 self.button:SetDisabledTexture (nil)
Tercio@11 387 else
Tercio@11 388 self.button:SetDisabledTexture (disabled, "ADD")
Tercio@11 389 end
Tercio@11 390
Tercio@11 391 end
Tercio@11 392
Tercio@11 393 -- frame levels
Tercio@11 394 function ButtonMetaFunctions:GetFrameLevel()
Tercio@11 395 return self.button:GetFrameLevel()
Tercio@11 396 end
Tercio@11 397 function ButtonMetaFunctions:SetFrameLevel (level, frame)
Tercio@11 398 if (not frame) then
Tercio@11 399 return self.button:SetFrameLevel (level)
Tercio@11 400 else
Tercio@11 401 local framelevel = frame:GetFrameLevel (frame) + level
Tercio@11 402 return self.button:SetFrameLevel (framelevel)
Tercio@11 403 end
Tercio@11 404 end
Tercio@11 405
Tercio@11 406 -- icon
Tercio@49 407 function ButtonMetaFunctions:SetIcon (texture, width, height, layout, texcoord, overlay, textdistance, leftpadding, textheight, short_method)
Tercio@11 408 if (not self.icon) then
Tercio@11 409 self.icon = self:CreateTexture (nil, "artwork")
Tercio@11 410 self.icon:SetSize (self.height*0.8, self.height*0.8)
Tercio@11 411 self.icon:SetPoint ("left", self.widget, "left", 4 + (leftpadding or 0), 0)
Tercio@11 412 self.icon.leftpadding = leftpadding or 0
Tercio@11 413 self.widget.text:ClearAllPoints()
Tercioo@29 414 self.widget.text:SetPoint ("left", self.icon, "right", textdistance or 2, 0 + (textheight or 0))
Tercio@11 415 end
Tercio@11 416
Tercio@11 417 self.icon:SetTexture (texture)
Tercio@11 418 self.icon:SetSize (width or self.height*0.8, height or self.height*0.8)
Tercio@11 419 self.icon:SetDrawLayer (layout or "artwork")
Tercio@11 420 if (texcoord) then
Tercio@11 421 self.icon:SetTexCoord (unpack (texcoord))
Tercio@11 422 else
Tercio@11 423 self.icon:SetTexCoord (0, 1, 0, 1)
Tercio@11 424 end
Tercio@11 425 if (overlay) then
Tercio@11 426 if (type (overlay) == "string") then
Tercio@11 427 local r, g, b, a = DF:ParseColors (overlay)
Tercio@11 428 self.icon:SetVertexColor (r, g, b, a)
Tercio@11 429 else
Tercio@11 430 self.icon:SetVertexColor (unpack (overlay))
Tercio@11 431 end
Tercio@11 432 else
Tercio@11 433 self.icon:SetVertexColor (1, 1, 1, 1)
Tercio@11 434 end
Tercio@11 435
Tercio@11 436 local w = self.button:GetWidth()
Tercio@11 437 local iconw = self.icon:GetWidth()
Tercio@11 438 local text_width = self.button.text:GetStringWidth()
Tercio@11 439 if (text_width > w-15-iconw) then
Tercio@49 440
Tercio@49 441 if (short_method == false) then
Tercio@49 442
Tercio@49 443 elseif (not short_method) then
Tercio@11 444 local new_width = text_width+15+iconw
Tercio@11 445 self.button:SetWidth (new_width)
Tercio@49 446
Tercio@11 447 elseif (short_method == 1) then
Tercio@11 448 local loop = true
Tercio@11 449 local textsize = 11
Tercio@11 450 while (loop) do
Tercio@11 451 if (text_width+15+iconw < w or textsize < 8) then
Tercio@11 452 loop = false
Tercio@11 453 break
Tercio@11 454 else
Tercio@11 455 DF:SetFontSize (self.button.text, textsize)
Tercio@11 456 text_width = self.button.text:GetStringWidth()
Tercio@11 457 textsize = textsize - 1
Tercio@11 458 end
Tercio@11 459 end
Tercio@49 460
Tercio@11 461 end
Tercio@11 462 end
Tercio@11 463
Tercio@11 464 end
Tercio@11 465
Tercio@11 466 -- frame stratas
Tercio@11 467 function ButtonMetaFunctions:SetFrameStrata()
Tercio@11 468 return self.button:GetFrameStrata()
Tercio@11 469 end
Tercio@11 470 function ButtonMetaFunctions:SetFrameStrata (strata)
Tercio@11 471 if (_type (strata) == "table") then
Tercio@11 472 self.button:SetFrameStrata (strata:GetFrameStrata())
Tercio@11 473 else
Tercio@11 474 self.button:SetFrameStrata (strata)
Tercio@11 475 end
Tercio@11 476 end
Tercio@11 477
Tercio@11 478 -- enabled
Tercio@11 479 function ButtonMetaFunctions:IsEnabled()
Tercio@11 480 return self.button:IsEnabled()
Tercio@11 481 end
Tercio@11 482 function ButtonMetaFunctions:Enable()
Tercio@11 483 return self.button:Enable()
Tercio@11 484 end
Tercio@11 485 function ButtonMetaFunctions:Disable()
Tercio@11 486 return self.button:Disable()
Tercio@11 487 end
Tercio@11 488
Tercio@11 489 -- exec
Tercio@11 490 function ButtonMetaFunctions:Exec()
Tercio@11 491 return self.func (self.param1, self.param2)
Tercio@11 492 end
Tercio@11 493 function ButtonMetaFunctions:Click()
Tercio@11 494 return self.func (self.param1, self.param2)
Tercio@11 495 end
Tercio@11 496 function ButtonMetaFunctions:RightClick()
Tercio@11 497 return self.funcright()
Tercio@11 498 end
Tercio@11 499
Tercio@11 500 --> custom textures
Tercio@11 501 function ButtonMetaFunctions:InstallCustomTexture (texture, rect, coords, use_split, side_textures, side_textures2)
Tercio@11 502
Tercio@11 503 self.button:SetNormalTexture (nil)
Tercio@11 504 self.button:SetPushedTexture (nil)
Tercio@11 505 self.button:SetDisabledTexture (nil)
Tercio@11 506 self.button:SetHighlightTexture (nil)
Tercio@11 507
Tercio@11 508 local button = self.button
Tercio@11 509
Tercio@11 510 if (use_split) then
Tercio@11 511
Tercio@11 512 --> 4 corners
Tercio@11 513 button.textureTopLeft = button:CreateTexture (nil, "artwork"); button.textureTopLeft:SetSize (8, 8); button.textureTopLeft:SetPoint ("topleft", button)
Tercio@11 514 button.textureTopRight = button:CreateTexture (nil, "artwork"); button.textureTopRight:SetSize (8, 8); button.textureTopRight:SetPoint ("topright", button)
Tercio@11 515 button.textureBottomLeft = button:CreateTexture (nil, "artwork"); button.textureBottomLeft:SetSize (8, 8); button.textureBottomLeft:SetPoint ("bottomleft", button)
Tercio@11 516 button.textureBottomRight = button:CreateTexture (nil, "artwork"); button.textureBottomRight:SetSize (8, 8); button.textureBottomRight:SetPoint ("bottomright", button)
Tercio@11 517
Tercio@11 518 button.textureLeft = button:CreateTexture (nil, "artwork"); button.textureLeft:SetWidth (4); button.textureLeft:SetPoint ("topleft", button.textureTopLeft, "bottomleft"); button.textureLeft:SetPoint ("bottomleft", button.textureBottomLeft, "topleft")
Tercio@11 519 button.textureRight = button:CreateTexture (nil, "artwork"); button.textureRight:SetWidth (4); button.textureRight:SetPoint ("topright", button.textureTopRight, "bottomright"); button.textureRight:SetPoint ("bottomright", button.textureBottomRight, "topright")
Tercio@11 520 button.textureTop = button:CreateTexture (nil, "artwork"); button.textureTop:SetHeight (4); button.textureTop:SetPoint ("topleft", button.textureTopLeft, "topright"); button.textureTop:SetPoint ("topright", button.textureTopRight, "topleft");
Tercio@11 521 button.textureBottom = button:CreateTexture (nil, "artwork"); button.textureBottom:SetHeight (4); button.textureBottom:SetPoint ("bottomleft", button.textureBottomLeft, "bottomright"); button.textureBottom:SetPoint ("bottomright", button.textureBottomRight, "bottomleft");
Tercio@11 522
Tercio@11 523 button.textureLeft:SetTexCoord (0, 4/128, 9/128, 24/128)
Tercio@11 524 button.textureRight:SetTexCoord (124/128, 1, 9/128, 24/128)
Tercio@11 525 button.textureTop:SetTexCoord (9/128, 120/128, 0, 4/128)
Tercio@11 526 button.textureBottom:SetTexCoord (9/128, 119/128, 28/128, 32/128)
Tercio@11 527
Tercio@11 528 button.textureTopLeft:SetTexCoord (0, 8/128, 0, 8/128)
Tercio@11 529 button.textureTopRight:SetTexCoord (121/128, 1, 0, 8/128)
Tercio@11 530 button.textureBottomLeft:SetTexCoord (0, 8/128, 24/128, 32/128)
Tercio@11 531 button.textureBottomRight:SetTexCoord (120/128, 1, 24/128, 32/128)
Tercio@11 532
Tercio@11 533 button.textureTopLeft:SetTexture ([[Interface\AddOns\Details\images\default_button]])
Tercio@11 534 button.textureTopRight:SetTexture ([[Interface\AddOns\Details\images\default_button]])
Tercio@11 535 button.textureBottomLeft:SetTexture ([[Interface\AddOns\Details\images\default_button]])
Tercio@11 536 button.textureBottomRight:SetTexture ([[Interface\AddOns\Details\images\default_button]])
Tercio@11 537 button.textureLeft:SetTexture ([[Interface\AddOns\Details\images\default_button]])
Tercio@11 538 button.textureRight:SetTexture ([[Interface\AddOns\Details\images\default_button]])
Tercio@11 539 button.textureTop:SetTexture ([[Interface\AddOns\Details\images\default_button]])
Tercio@11 540 button.textureBottom:SetTexture ([[Interface\AddOns\Details\images\default_button]])
Tercio@11 541
Tercio@11 542 else
Tercio@11 543 texture = texture or "Interface\\AddOns\\Details\\images\\default_button"
Tercio@11 544 self.button.texture = self.button:CreateTexture (nil, "artwork")
Tercio@11 545
Tercio@11 546 if (not rect) then
Tercio@11 547 self.button.texture:SetAllPoints (self.button)
Tercio@11 548 else
Tercio@11 549 self.button.texture:SetPoint ("topleft", self.button, "topleft", rect.x1, rect.y1)
Tercio@11 550 self.button.texture:SetPoint ("bottomright", self.button, "bottomright", rect.x2, rect.y2)
Tercio@11 551 end
Tercio@11 552
Tercio@11 553 if (coords) then
Tercio@11 554 self.button.texture.coords = coords
Tercio@11 555 self.button.texture:SetTexCoord (_unpack (coords.Normal))
Tercio@11 556 else
Tercio@11 557 self.button.texture:SetTexCoord (0, 1, 0, 0.24609375)
Tercio@11 558 end
Tercio@11 559
Tercio@11 560 self.button.texture:SetTexture (texture)
Tercio@11 561 end
Tercio@11 562
Tercio@11 563 if (side_textures) then
Tercio@11 564 local left = self.button:CreateTexture (nil, "overlay")
Tercio@11 565 left:SetTexture ([[Interface\TALENTFRAME\talent-main]])
Tercio@11 566 left:SetTexCoord (0.13671875, 0.25, 0.486328125, 0.576171875)
Tercio@11 567 left:SetPoint ("left", self.button, 0, 0)
Tercio@11 568 left:SetWidth (10)
Tercio@11 569 left:SetHeight (self.button:GetHeight()+2)
Tercio@11 570 self.button.left_border = left
Tercio@11 571
Tercio@11 572 local right = self.button:CreateTexture (nil, "overlay")
Tercio@11 573 right:SetTexture ([[Interface\TALENTFRAME\talent-main]])
Tercio@11 574 right:SetTexCoord (0.01953125, 0.13671875, 0.486328125, 0.576171875)
Tercio@11 575 right:SetPoint ("right", self.button, 0, 0)
Tercio@11 576 right:SetWidth (10)
Tercio@11 577 right:SetHeight (self.button:GetHeight()+2)
Tercio@11 578 self.button.right_border = right
Tercio@11 579
Tercio@11 580 elseif (side_textures2) then
Tercio@11 581
Tercio@11 582 local left = self.button:CreateTexture (nil, "overlay")
Tercio@11 583 left:SetTexture ([[Interface\AddOns\Details\images\icons]])
Tercio@11 584 left:SetTexCoord (94/512, 123/512, 42/512, 87/512)
Tercio@11 585 left:SetPoint ("left", self.button, 0, 0)
Tercio@11 586 left:SetWidth (10)
Tercio@11 587 left:SetHeight (self.button:GetHeight()+2)
Tercio@11 588 self.button.left_border = left
Tercio@11 589
Tercio@11 590 local right = self.button:CreateTexture (nil, "overlay")
Tercio@11 591 right:SetTexture ([[Interface\AddOns\Details\images\icons]])
Tercio@11 592 right:SetTexCoord (65/512, 94/512, 42/512, 87/512)
Tercio@11 593 right:SetPoint ("right", self.button, 0, 0)
Tercio@11 594 right:SetWidth (10)
Tercio@11 595 right:SetHeight (self.button:GetHeight()+2)
Tercio@11 596 self.button.right_border = right
Tercio@11 597 end
Tercio@11 598 end
Tercio@11 599
Tercio@11 600 ------------------------------------------------------------------------------------------------------------
Tercio@11 601 --> scripts
Tercio@11 602
Tercio@11 603 local OnEnter = function (button)
Tercio@11 604
Tercio@39 605 local capsule = button.MyObject
Tercio@39 606
Tercio@11 607 if (button.textureTopLeft) then
Tercio@11 608 button.textureLeft:SetTexCoord (0, 4/128, 40/128, 56/128)
Tercio@11 609 button.textureRight:SetTexCoord (124/128, 1, 40/128, 56/128)
Tercio@11 610 button.textureTop:SetTexCoord (9/128, 120/128, 33/128, 37/128)
Tercio@11 611 button.textureBottom:SetTexCoord (9/128, 119/128, 60/128, 64/128)
Tercio@11 612
Tercio@11 613 button.textureTopLeft:SetTexCoord (0, 8/128, 33/128, 40/128)
Tercio@11 614 button.textureTopRight:SetTexCoord (121/128, 1, 33/128, 40/128)
Tercio@11 615 button.textureBottomLeft:SetTexCoord (0, 8/128, 56/128, 64/128)
Tercio@11 616 button.textureBottomRight:SetTexCoord (120/128, 1, 56/128, 64/128)
Tercio@11 617 end
Tercio@39 618
Tercio@39 619 local kill = capsule:RunHooksForWidget ("OnEnter", button, capsule)
Tercio@39 620 if (kill) then
Tercio@39 621 return
Tercio@11 622 end
Tercio@11 623
Tercio@11 624 button.MyObject.is_mouse_over = true
Tercio@11 625
Tercio@11 626 if (button.texture) then
Tercio@11 627 if (button.texture.coords) then
Tercio@11 628 button.texture:SetTexCoord (_unpack (button.texture.coords.Highlight))
Tercio@11 629 else
Tercio@11 630 button.texture:SetTexCoord (0, 1, 0.24609375, 0.49609375)
Tercio@11 631 end
Tercio@11 632 end
Tercio@11 633
Tercio@22 634 if (button.MyObject.onenter_backdrop_border_color) then
Tercio@22 635 button:SetBackdropBorderColor (unpack (button.MyObject.onenter_backdrop_border_color))
Tercio@22 636 end
Tercio@22 637
Tercio@22 638 if (button.MyObject.onenter_backdrop) then
Tercio@22 639 button:SetBackdropColor (unpack (button.MyObject.onenter_backdrop))
Tercio@22 640 end
Tercio@22 641
Tercio@11 642 if (button.MyObject.have_tooltip) then
Tercio@11 643 GameCooltip2:Preset (2)
Tercio@11 644 if (type (button.MyObject.have_tooltip) == "function") then
Tercio@11 645 GameCooltip2:AddLine (button.MyObject.have_tooltip() or "")
Tercio@11 646 else
Tercio@11 647 GameCooltip2:AddLine (button.MyObject.have_tooltip)
Tercio@11 648 end
Tercio@11 649 GameCooltip2:ShowCooltip (button, "tooltip")
Tercio@11 650 end
Tercio@11 651 end
Tercio@11 652
Tercio@11 653 local OnLeave = function (button)
Tercio@11 654
Tercio@39 655 local capsule = button.MyObject
Tercio@39 656
Tercio@11 657 if (button.textureLeft and not button.MyObject.is_mouse_down) then
Tercio@11 658 button.textureLeft:SetTexCoord (0, 4/128, 9/128, 24/128)
Tercio@11 659 button.textureRight:SetTexCoord (124/128, 1, 9/128, 24/128)
Tercio@11 660 button.textureTop:SetTexCoord (9/128, 120/128, 0, 4/128)
Tercio@11 661 button.textureBottom:SetTexCoord (9/128, 119/128, 28/128, 32/128)
Tercio@11 662
Tercio@11 663 button.textureTopLeft:SetTexCoord (0, 8/128, 0, 8/128)
Tercio@11 664 button.textureTopRight:SetTexCoord (121/128, 1, 0, 8/128)
Tercio@11 665 button.textureBottomLeft:SetTexCoord (0, 8/128, 24/128, 32/128)
Tercio@11 666 button.textureBottomRight:SetTexCoord (120/128, 1, 24/128, 32/128)
Tercio@11 667 end
Tercio@39 668
Tercio@39 669 local kill = capsule:RunHooksForWidget ("OnLeave", button, capsule)
Tercio@39 670 if (kill) then
Tercio@39 671 return
Tercio@11 672 end
Tercio@11 673
Tercio@11 674 button.MyObject.is_mouse_over = false
Tercio@11 675
Tercio@11 676 if (button.texture and not button.MyObject.is_mouse_down) then
Tercio@11 677 if (button.texture.coords) then
Tercio@11 678 button.texture:SetTexCoord (_unpack (button.texture.coords.Normal))
Tercio@11 679 else
Tercio@11 680 button.texture:SetTexCoord (0, 1, 0, 0.24609375)
Tercio@11 681 end
Tercio@11 682 end
Tercio@11 683
Tercio@22 684 if (button.MyObject.onleave_backdrop_border_color) then
Tercio@22 685 button:SetBackdropBorderColor (unpack (button.MyObject.onleave_backdrop_border_color))
Tercio@22 686 end
Tercio@22 687
Tercio@22 688 if (button.MyObject.onleave_backdrop) then
Tercio@22 689 button:SetBackdropColor (unpack (button.MyObject.onleave_backdrop))
Tercio@22 690 end
Tercio@22 691
Tercio@11 692 if (button.MyObject.have_tooltip) then
Tercio@11 693 if (GameCooltip2:GetText (1) == button.MyObject.have_tooltip or type (button.MyObject.have_tooltip) == "function") then
Tercio@11 694 GameCooltip2:Hide()
Tercio@11 695 end
Tercio@11 696 end
Tercio@11 697 end
Tercio@11 698
Tercio@11 699 local OnHide = function (button)
Tercio@39 700 local capsule = button.MyObject
Tercio@39 701 local kill = capsule:RunHooksForWidget ("OnHide", button, capsule)
Tercio@39 702 if (kill) then
Tercio@39 703 return
Tercio@11 704 end
Tercio@11 705 end
Tercio@11 706
Tercio@11 707 local OnShow = function (button)
Tercio@39 708 local capsule = button.MyObject
Tercio@39 709 local kill = capsule:RunHooksForWidget ("OnShow", button, capsule)
Tercio@39 710 if (kill) then
Tercio@39 711 return
Tercio@11 712 end
Tercio@11 713 end
Tercio@11 714
Tercio@11 715 local OnMouseDown = function (button, buttontype)
Tercio@39 716 local capsule = button.MyObject
Tercio@39 717
Tercio@11 718 if (not button:IsEnabled()) then
Tercio@11 719 return
Tercio@39 720 end
Tercio@11 721
Tercio@11 722 if (button.textureTopLeft) then
Tercio@11 723 button.textureLeft:SetTexCoord (0, 4/128, 72/128, 88/128)
Tercio@11 724 button.textureRight:SetTexCoord (124/128, 1, 72/128, 88/128)
Tercio@11 725 button.textureTop:SetTexCoord (9/128, 120/128, 65/128, 68/128)
Tercio@11 726 button.textureBottom:SetTexCoord (9/128, 119/128, 92/128, 96/128)
Tercio@11 727
Tercio@11 728 button.textureTopLeft:SetTexCoord (0, 8/128, 65/128, 71/128)
Tercio@11 729 button.textureTopRight:SetTexCoord (121/128, 1, 65/128, 71/128)
Tercio@11 730 button.textureBottomLeft:SetTexCoord (0, 8/128, 88/128, 96/128)
Tercio@11 731 button.textureBottomRight:SetTexCoord (120/128, 1, 88/128, 96/128)
Tercio@11 732 end
Tercio@39 733
Tercio@39 734 local kill = capsule:RunHooksForWidget ("OnMouseDown", button, capsule)
Tercio@39 735 if (kill) then
Tercio@39 736 return
Tercio@11 737 end
Tercio@11 738
Tercio@11 739 button.MyObject.is_mouse_down = true
Tercio@11 740
Tercio@11 741 if (button.texture) then
Tercio@11 742 if (button.texture.coords) then
Tercio@11 743 button.texture:SetTexCoord (_unpack (button.texture.coords.Pushed))
Tercio@11 744 else
Tercio@11 745 button.texture:SetTexCoord (0, 1, 0.5078125, 0.75)
Tercio@11 746 end
Tercio@11 747 end
Tercio@11 748
Tercio@11 749 if (button.MyObject.capsule_textalign) then
Tercio@11 750 if (button.MyObject.icon) then
Tercio@11 751 button.MyObject.icon:SetPoint ("left", button, "left", 5 + (button.MyObject.icon.leftpadding or 0), -1)
Tercio@11 752 elseif (button.MyObject.capsule_textalign == "left") then
Tercio@11 753 button.text:SetPoint ("left", button, "left", 3, -1)
Tercio@11 754 elseif (button.MyObject.capsule_textalign == "center") then
Tercio@11 755 button.text:SetPoint ("center", button, "center", 1, -1)
Tercio@11 756 elseif (button.MyObject.capsule_textalign == "right") then
Tercio@11 757 button.text:SetPoint ("right", button, "right", -1, -1)
Tercio@11 758 end
Tercio@11 759 else
Tercio@11 760 if (button.MyObject.icon) then
Tercio@11 761 button.MyObject.icon:SetPoint ("left", button, "left", 7 + (button.MyObject.icon.leftpadding or 0), -2)
Tercio@11 762 else
Tercio@11 763 button.text:SetPoint ("center", button,"center", 1, -1)
Tercio@11 764 end
Tercio@11 765 end
Tercio@11 766
Tercio@11 767 button.mouse_down = GetTime()
Tercio@11 768 local x, y = GetCursorPosition()
Tercio@11 769 button.x = _math_floor (x)
Tercio@11 770 button.y = _math_floor (y)
Tercio@11 771
Tercio@11 772 if (not button.MyObject.container.isLocked and button.MyObject.container:IsMovable()) then
Tercio@11 773 if (not button.isLocked and button:IsMovable()) then
Tercio@11 774 button.MyObject.container.isMoving = true
Tercio@11 775 button.MyObject.container:StartMoving()
Tercio@11 776 end
Tercio@11 777 end
Tercio@11 778
Tercio@11 779 if (button.MyObject.options.OnGrab) then
Tercio@11 780 if (_type (button.MyObject.options.OnGrab) == "string" and button.MyObject.options.OnGrab == "PassClick") then
Tercio@11 781 if (buttontype == "LeftButton") then
Tercio@11 782 button.MyObject.func (button.MyObject.param1, button.MyObject.param2)
Tercio@11 783 else
Tercio@11 784 button.MyObject.funcright (button.MyObject.param1, button.MyObject.param2)
Tercio@11 785 end
Tercio@11 786 end
Tercio@11 787 end
Tercio@11 788 end
Tercio@11 789
Tercio@11 790 local OnMouseUp = function (button, buttontype)
Tercio@11 791 if (not button:IsEnabled()) then
Tercio@11 792 return
Tercio@11 793 end
Tercio@11 794
Tercio@11 795 if (button.textureLeft) then
Tercio@11 796 if (button.MyObject.is_mouse_over) then
Tercio@11 797 button.textureLeft:SetTexCoord (0, 4/128, 40/128, 56/128)
Tercio@11 798 button.textureRight:SetTexCoord (124/128, 1, 40/128, 56/128)
Tercio@11 799 button.textureTop:SetTexCoord (9/128, 120/128, 33/128, 37/128)
Tercio@11 800 button.textureBottom:SetTexCoord (9/128, 119/128, 60/128, 64/128)
Tercio@11 801
Tercio@11 802 button.textureTopLeft:SetTexCoord (0, 8/128, 33/128, 40/128)
Tercio@11 803 button.textureTopRight:SetTexCoord (121/128, 1, 33/128, 40/128)
Tercio@11 804 button.textureBottomLeft:SetTexCoord (0, 8/128, 56/128, 64/128)
Tercio@11 805 button.textureBottomRight:SetTexCoord (120/128, 1, 56/128, 64/128)
Tercio@11 806 else
Tercio@11 807 button.textureLeft:SetTexCoord (0, 4/128, 9/128, 24/128)
Tercio@11 808 button.textureRight:SetTexCoord (124/128, 1, 9/128, 24/128)
Tercio@11 809 button.textureTop:SetTexCoord (9/128, 120/128, 0, 4/128)
Tercio@11 810 button.textureBottom:SetTexCoord (9/128, 119/128, 28/128, 32/128)
Tercio@11 811
Tercio@11 812 button.textureTopLeft:SetTexCoord (0, 8/128, 0, 8/128)
Tercio@11 813 button.textureTopRight:SetTexCoord (121/128, 1, 0, 8/128)
Tercio@11 814 button.textureBottomLeft:SetTexCoord (0, 8/128, 24/128, 32/128)
Tercio@11 815 button.textureBottomRight:SetTexCoord (120/128, 1, 24/128, 32/128)
Tercio@11 816 end
Tercio@11 817 end
Tercio@11 818
Tercio@39 819 local capsule = button.MyObject
Tercio@39 820 local kill = capsule:RunHooksForWidget ("OnMouseUp", button, capsule)
Tercio@39 821 if (kill) then
Tercio@39 822 return
Tercio@11 823 end
Tercio@11 824
Tercio@11 825 button.MyObject.is_mouse_down = false
Tercio@11 826
Tercio@11 827 if (button.texture) then
Tercio@11 828 if (button.texture.coords) then
Tercio@11 829 if (button.MyObject.is_mouse_over) then
Tercio@11 830 button.texture:SetTexCoord (_unpack (button.texture.coords.Highlight))
Tercio@11 831 else
Tercio@11 832 button.texture:SetTexCoord (_unpack (coords.Normal))
Tercio@11 833 end
Tercio@11 834 else
Tercio@11 835 if (button.MyObject.is_mouse_over) then
Tercio@11 836 button.texture:SetTexCoord (0, 1, 0.24609375, 0.49609375)
Tercio@11 837 else
Tercio@11 838 button.texture:SetTexCoord (0, 1, 0, 0.24609375)
Tercio@11 839 end
Tercio@11 840 end
Tercio@11 841 end
Tercio@11 842
Tercio@11 843 if (button.MyObject.capsule_textalign) then
Tercio@11 844 if (button.MyObject.icon) then
Tercio@11 845 button.MyObject.icon:SetPoint ("left", button, "left", 4 + (button.MyObject.icon.leftpadding or 0), 0)
Tercio@11 846 elseif (button.MyObject.capsule_textalign == "left") then
Tercio@11 847 button.text:SetPoint ("left", button, "left", 2, 0)
Tercio@11 848 elseif (button.MyObject.capsule_textalign == "center") then
Tercio@11 849 button.text:SetPoint ("center", button, "center", 0, 0)
Tercio@11 850 elseif (button.MyObject.capsule_textalign == "right") then
Tercio@11 851 button.text:SetPoint ("right", button, "right", -2, 0)
Tercio@11 852 end
Tercio@11 853 else
Tercio@11 854 if (button.MyObject.icon) then
Tercio@11 855 button.MyObject.icon:SetPoint ("left", button, "left", 4 + (button.MyObject.icon.leftpadding or 0), 0)
Tercio@11 856 else
Tercio@11 857 button.text:SetPoint ("center", button,"center", 0, 0)
Tercio@11 858 end
Tercio@11 859 end
Tercio@11 860
Tercio@11 861 if (button.MyObject.container.isMoving) then
Tercio@11 862 button.MyObject.container:StopMovingOrSizing()
Tercio@11 863 button.MyObject.container.isMoving = false
Tercio@11 864 end
Tercio@11 865
Tercio@11 866 local x, y = GetCursorPosition()
Tercio@11 867 x = _math_floor (x)
Tercio@11 868 y = _math_floor (y)
Tercioo@28 869 if (
Tercioo@28 870 (x == button.x and y == button.y) or
Tercioo@28 871 (button.mouse_down+0.5 > GetTime() and button:IsMouseOver())
Tercioo@28 872 ) then
Tercio@11 873 if (buttontype == "LeftButton") then
Tercio@55 874
Tercio@55 875 local success, errorText = pcall (button.MyObject.func, button, buttontype, button.MyObject.param1, button.MyObject.param2)
Tercio@55 876 if (not success) then
Tercio@55 877 error ("Details! Framework: button " .. button:GetName() .. " error: " .. errorText)
Tercio@55 878 end
Tercio@55 879
Tercio@55 880 --button.MyObject.func (button, buttontype, button.MyObject.param1, button.MyObject.param2)
Tercio@11 881 else
Tercio@55 882
Tercio@55 883 local success, errorText = pcall (button.MyObject.funcright, button, buttontype, button.MyObject.param1, button.MyObject.param2)
Tercio@55 884 if (not success) then
Tercio@55 885 error ("Details! Framework: button " .. button:GetName() .. " error: " .. errorText)
Tercio@55 886 end
Tercio@55 887
Tercio@55 888 --button.MyObject.funcright (button, buttontype, button.MyObject.param1, button.MyObject.param2)
Tercio@11 889 end
Tercio@11 890 end
Tercio@11 891 end
Tercio@11 892
Tercio@11 893 ------------------------------------------------------------------------------------------------------------
Tercio@22 894
Tercio@22 895 function ButtonMetaFunctions:SetTemplate (template)
Tercio@22 896
Tercio@22 897 if (template.width) then
Tercio@22 898 self:SetWidth (template.width)
Tercio@22 899 end
Tercio@22 900 if (template.height) then
Tercio@22 901 self:SetHeight (template.height)
Tercio@22 902 end
Tercio@22 903
Tercio@22 904 if (template.backdrop) then
Tercio@22 905 self:SetBackdrop (template.backdrop)
Tercio@22 906 end
Tercio@22 907 if (template.backdropcolor) then
Tercio@22 908 local r, g, b, a = DF:ParseColors (template.backdropcolor)
Tercio@22 909 self:SetBackdropColor (r, g, b, a)
Tercio@22 910 self.onleave_backdrop = {r, g, b, a}
Tercio@22 911 end
Tercio@22 912 if (template.backdropbordercolor) then
Tercio@22 913 local r, g, b, a = DF:ParseColors (template.backdropbordercolor)
Tercio@22 914 self:SetBackdropBorderColor (r, g, b, a)
Tercio@22 915 self.onleave_backdrop_border_color = {r, g, b, a}
Tercio@22 916 end
Tercio@22 917
Tercio@22 918 if (template.onentercolor) then
Tercio@22 919 local r, g, b, a = DF:ParseColors (template.onentercolor)
Tercio@22 920 self.onenter_backdrop = {r, g, b, a}
Tercio@22 921 end
Tercio@22 922
Tercio@22 923 if (template.onleavecolor) then
Tercio@22 924 local r, g, b, a = DF:ParseColors (template.onleavecolor)
Tercio@22 925 self.onleave_backdrop = {r, g, b, a}
Tercio@22 926 end
Tercio@22 927
Tercio@22 928 if (template.onenterbordercolor) then
Tercio@22 929 local r, g, b, a = DF:ParseColors (template.onenterbordercolor)
Tercio@22 930 self.onenter_backdrop_border_color = {r, g, b, a}
Tercio@22 931 end
Tercio@22 932
Tercio@22 933 if (template.onleavebordercolor) then
Tercio@22 934 local r, g, b, a = DF:ParseColors (template.onleavebordercolor)
Tercio@22 935 self.onleave_backdrop_border_color = {r, g, b, a}
Tercio@22 936 end
Tercio@22 937
Tercio@22 938 if (template.icon) then
Tercio@22 939 local i = template.icon
Tercio@22 940 self:SetIcon (i.texture, i.width, i.height, i.layout, i.texcoord, i.color, i.textdistance, i.leftpadding)
Tercio@22 941 end
Tercio@22 942
Tercio@55 943 if (template.textsize) then
Tercio@55 944 self.textsize = template.textsize
Tercio@55 945 end
Tercio@55 946
Tercio@55 947 if (template.textfont) then
Tercio@55 948 self.textfont = template.textfont
Tercio@55 949 end
Tercio@55 950
Tercio@55 951 if (template.textcolor) then
Tercio@55 952 self.textcolor = template.textcolor
Tercio@55 953 end
Tercio@55 954
Tercio@55 955 if (template.textalign) then
Tercio@55 956 self.textalign = template.textalign
Tercio@55 957 end
Tercio@22 958 end
Tercio@22 959
Tercio@22 960 ------------------------------------------------------------------------------------------------------------
Tercio@11 961 --> object constructor
Tercio@11 962
Tercio@22 963 function DF:CreateButton (parent, func, w, h, text, param1, param2, texture, member, name, short_method, button_template, text_template)
Tercio@22 964 return DF:NewButton (parent, parent, name, member, w, h, func, param1, param2, texture, text, short_method, button_template, text_template)
Tercio@11 965 end
Tercio@11 966
Tercio@22 967 function DF:NewButton (parent, container, name, member, w, h, func, param1, param2, texture, text, short_method, button_template, text_template)
Tercio@11 968
Tercio@11 969 if (not name) then
Tercio@11 970 name = "DetailsFrameworkButtonNumber" .. DF.ButtonCounter
Tercio@11 971 DF.ButtonCounter = DF.ButtonCounter + 1
Tercio@11 972
Tercio@11 973 elseif (not parent) then
Tercioo@29 974 return error ("Details! FrameWork: parent not found.", 2)
Tercio@11 975 end
Tercio@11 976 if (not container) then
Tercio@11 977 container = parent
Tercio@11 978 end
Tercio@11 979
Tercio@11 980 if (name:find ("$parent")) then
Tercioo@28 981 local parentName = DF.GetParentName (parent)
Tercioo@28 982 name = name:gsub ("$parent", parentName)
Tercio@11 983 end
Tercio@22 984
Tercio@11 985 local ButtonObject = {type = "button", dframework = true}
Tercio@11 986
Tercio@11 987 if (member) then
Tercio@11 988 parent [member] = ButtonObject
Tercio@11 989 end
Tercio@11 990
Tercio@11 991 if (parent.dframework) then
Tercio@11 992 parent = parent.widget
Tercio@11 993 end
Tercio@11 994 if (container.dframework) then
Tercio@11 995 container = container.widget
Tercio@11 996 end
Tercio@11 997
Tercio@11 998 --> default members:
Tercio@11 999 ButtonObject.is_locked = true
Tercio@11 1000 ButtonObject.container = container
Tercio@11 1001 ButtonObject.options = {OnGrab = false}
Tercio@11 1002
Tercio@11 1003 ButtonObject.button = CreateFrame ("button", name, parent, "DetailsFrameworkButtonTemplate")
Tercio@11 1004 ButtonObject.widget = ButtonObject.button
Tercio@11 1005
Tercio@22 1006 --ButtonObject.button:SetBackdrop ({bgFile = DF.folder .. "background", tileSize = 64, edgeFile = DF.folder .. "border_2", edgeSize = 10, insets = {left = 1, right = 1, top = 1, bottom = 1}})
Tercio@11 1007 ButtonObject.button:SetBackdropColor (0, 0, 0, 0.4)
Tercio@11 1008 ButtonObject.button:SetBackdropBorderColor (1, 1, 1, 1)
Tercio@11 1009
Tercio@11 1010 if (not APIButtonFunctions) then
Tercio@11 1011 APIButtonFunctions = true
Tercio@11 1012 local idx = getmetatable (ButtonObject.button).__index
Tercio@11 1013 for funcName, funcAddress in pairs (idx) do
Tercio@11 1014 if (not ButtonMetaFunctions [funcName]) then
Tercio@11 1015 ButtonMetaFunctions [funcName] = function (object, ...)
Tercio@20 1016 local x = loadstring ( "return _G['"..object.button:GetName().."']:"..funcName.."(...)")
Tercio@11 1017 return x (...)
Tercio@11 1018 end
Tercio@11 1019 end
Tercio@11 1020 end
Tercio@11 1021 end
Tercio@11 1022
Tercio@22 1023
Tercio@11 1024 ButtonObject.button:SetWidth (w or 100)
Tercio@11 1025 ButtonObject.button:SetHeight (h or 20)
Tercio@11 1026 ButtonObject.button.MyObject = ButtonObject
Tercio@11 1027
Tercio@11 1028 ButtonObject.text_overlay = _G [name .. "_Text"]
Tercio@11 1029 ButtonObject.disabled_overlay = _G [name .. "_TextureDisabled"]
Tercio@11 1030
Tercio@11 1031 ButtonObject.button:SetNormalTexture (texture)
Tercio@11 1032 ButtonObject.button:SetPushedTexture (texture)
Tercio@11 1033 ButtonObject.button:SetDisabledTexture (texture)
Tercio@11 1034 ButtonObject.button:SetHighlightTexture (texture, "ADD")
Tercio@11 1035
Tercio@11 1036 ButtonObject.button.text:SetText (text)
Tercio@11 1037 ButtonObject.button.text:SetPoint ("center", ButtonObject.button, "center")
Tercio@39 1038
Tercio@11 1039 local text_width = ButtonObject.button.text:GetStringWidth()
Tercio@11 1040 if (text_width > w-15 and ButtonObject.button.text:GetText() ~= "") then
Tercio@39 1041 if (short_method == false) then --> if is false, do not use auto resize
Tercio@39 1042 --do nothing
Tercio@39 1043 elseif (not short_method) then --> if the value is omitted, use the default resize
Tercio@11 1044 local new_width = text_width+15
Tercio@11 1045 ButtonObject.button:SetWidth (new_width)
Tercio@39 1046
Tercio@11 1047 elseif (short_method == 1) then
Tercio@11 1048 local loop = true
Tercio@11 1049 local textsize = 11
Tercio@11 1050 while (loop) do
Tercio@11 1051 if (text_width+15 < w or textsize < 8) then
Tercio@11 1052 loop = false
Tercio@11 1053 break
Tercio@11 1054 else
Tercio@11 1055 DF:SetFontSize (ButtonObject.button.text, textsize)
Tercio@11 1056 text_width = ButtonObject.button.text:GetStringWidth()
Tercio@11 1057 textsize = textsize - 1
Tercio@11 1058 end
Tercio@11 1059 end
Tercio@49 1060
Tercio@49 1061 elseif (short_method == 2) then
Tercio@49 1062
Tercio@11 1063 end
Tercio@11 1064 end
Tercio@11 1065
Tercio@11 1066 ButtonObject.func = func or cleanfunction
Tercio@11 1067 ButtonObject.funcright = cleanfunction
Tercio@11 1068 ButtonObject.param1 = param1
Tercio@11 1069 ButtonObject.param2 = param2
Tercio@11 1070
Tercio@11 1071 ButtonObject.short_method = short_method
Tercio@11 1072
Tercio@22 1073 if (text_template) then
Tercio@22 1074 if (text_template.size) then
Tercio@22 1075 DF:SetFontSize (ButtonObject.button.text, text_template.size)
Tercio@20 1076 end
Tercio@22 1077 if (text_template.color) then
Tercio@22 1078 local r, g, b, a = DF:ParseColors (text_template.color)
Tercio@20 1079 ButtonObject.button.text:SetTextColor (r, g, b, a)
Tercio@20 1080 end
Tercio@22 1081 if (text_template.font) then
Tercio@20 1082 local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0")
Tercio@22 1083 local font = SharedMedia:Fetch ("font", text_template.font)
Tercio@20 1084 DF:SetFontFace (ButtonObject.button.text, font)
Tercio@20 1085 end
Tercio@20 1086 end
Tercio@20 1087
Tercio@11 1088 --> hooks
Tercio@39 1089 ButtonObject.HookList = {
Tercio@39 1090 OnEnter = {},
Tercio@39 1091 OnLeave = {},
Tercio@39 1092 OnHide = {},
Tercio@39 1093 OnShow = {},
Tercio@39 1094 OnMouseDown = {},
Tercio@39 1095 OnMouseUp = {},
Tercio@39 1096 }
Tercio@39 1097
Tercio@11 1098 ButtonObject.button:SetScript ("OnEnter", OnEnter)
Tercio@11 1099 ButtonObject.button:SetScript ("OnLeave", OnLeave)
Tercio@11 1100 ButtonObject.button:SetScript ("OnHide", OnHide)
Tercio@11 1101 ButtonObject.button:SetScript ("OnShow", OnShow)
Tercio@11 1102 ButtonObject.button:SetScript ("OnMouseDown", OnMouseDown)
Tercio@11 1103 ButtonObject.button:SetScript ("OnMouseUp", OnMouseUp)
Tercio@11 1104
Tercio@11 1105 _setmetatable (ButtonObject, ButtonMetaFunctions)
Tercio@11 1106
Tercio@22 1107 if (button_template) then
Tercio@22 1108 ButtonObject:SetTemplate (button_template)
Tercio@22 1109 end
Tercio@22 1110
Tercio@11 1111 return ButtonObject
Tercio@11 1112
Tercio@11 1113 end
Tercio@11 1114
Tercio@11 1115 local pickcolor_callback = function (self, r, g, b, a, button)
Tercio@19 1116 a = abs (a-1)
Tercio@11 1117 button.MyObject.color_texture:SetVertexColor (r, g, b, a)
Tercio@11 1118 button.MyObject:color_callback (r, g, b, a)
Tercio@11 1119 end
Tercio@19 1120 local pickcolor = function (self, alpha, param2)
Tercio@11 1121 local r, g, b, a = self.MyObject.color_texture:GetVertexColor()
Tercio@19 1122 a = abs (a-1)
Tercio@11 1123 DF:ColorPick (self, r, g, b, a, pickcolor_callback)
Tercio@11 1124 end
Tercio@11 1125
Tercio@11 1126 local color_button_height = 16
Tercio@11 1127 local color_button_width = 16
Tercio@11 1128
Tercio@11 1129 local set_colorpick_color = function (button, r, g, b, a)
Tercio@19 1130 a = a or 1
Tercio@11 1131 button.color_texture:SetVertexColor (r, g, b, a)
Tercio@11 1132 end
Tercio@11 1133
Tercio@11 1134 local colorpick_cancel = function (self)
Tercio@11 1135 ColorPickerFrame:Hide()
Tercio@11 1136 end
Tercio@11 1137
Tercio@22 1138 function DF:CreateColorPickButton (parent, name, member, callback, alpha, button_template)
Tercio@22 1139 return DF:NewColorPickButton (parent, name, member, callback, alpha, button_template)
Tercio@11 1140 end
Tercio@11 1141
Tercio@22 1142 function DF:NewColorPickButton (parent, name, member, callback, alpha, button_template)
Tercio@11 1143
Tercio@11 1144 --button
Tercio@22 1145 local button = DF:NewButton (parent, _, name, member, color_button_width, color_button_height, pickcolor, alpha, "param2", nil, nil, nil, button_template)
Tercio@11 1146 button.color_callback = callback
Tercio@11 1147 button.Cancel = colorpick_cancel
Tercio@11 1148 button.SetColor = set_colorpick_color
Tercio@11 1149
Tercio@22 1150 if (not button_template) then
Tercio@22 1151 button:InstallCustomTexture()
Tercio@22 1152 button:SetBackdrop ({edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 6,
Tercio@22 1153 bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], insets = {left = 0, right = 0, top = 0, bottom = 0}})
Tercio@22 1154 end
Tercio@11 1155
Tercio@11 1156 --textura do fundo
Tercio@11 1157 local background = DF:NewImage (button, nil, color_button_width, color_button_height, nil, nil, nil, "$parentBck")
Tercio@11 1158 --background:SetTexture ([[Interface\AddOns\Details\images\icons]])
Tercio@11 1159 background:SetPoint ("topleft", button.widget, "topleft", 1, -2)
Tercio@11 1160 background:SetPoint ("bottomright", button.widget, "bottomright", -1, 1)
Tercio@11 1161 background:SetTexCoord (0.337890625, 0.390625, 0.625, 0.658203125)
Tercio@11 1162 background:SetDrawLayer ("background", 1)
Tercio@11 1163
Tercio@11 1164 --textura da cor
Tercio@11 1165 local img = DF:NewImage (button, nil, color_button_width, color_button_height, nil, nil, "color_texture", "$parentTex")
Tercio@39 1166 img:SetColorTexture (1, 1, 1)
Tercio@11 1167 img:SetPoint ("topleft", button.widget, "topleft", 1, -2)
Tercio@11 1168 img:SetPoint ("bottomright", button.widget, "bottomright", -1, 1)
Tercio@11 1169 img:SetDrawLayer ("background", 2)
Tercio@11 1170
Tercio@11 1171 return button
Tercio@11 1172
Tercio@11 1173 end