annotate Libs/DF/help.lua @ 53:36b4d9559b69 v7.3.0.053

- framework update.
author Tercio
date Sat, 14 Oct 2017 17:09:17 -0300
parents dc1c77254f80
children 0682d738499b
rev   line source
Tercio@11 1
Tercio@11 2
Tercio@11 3 local DF = _G ["DetailsFramework"]
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
Tercio@11 12 local APIHelpFunctions = false
Tercio@11 13 local HelpMetaFunctions = {}
Tercio@11 14
Tercio@11 15 local get_members_function_index = {}
Tercio@11 16
Tercio@11 17 HelpMetaFunctions.__index = function (_table, _member_requested)
Tercio@11 18
Tercio@11 19 local func = get_members_function_index [_member_requested]
Tercio@11 20 if (func) then
Tercio@11 21 return func (_table, _member_requested)
Tercio@11 22 end
Tercio@11 23
Tercio@11 24 local fromMe = _rawget (_table, _member_requested)
Tercio@11 25 if (fromMe) then
Tercio@11 26 return fromMe
Tercio@11 27 end
Tercio@11 28
Tercio@11 29 return HelpMetaFunctions [_member_requested]
Tercio@11 30 end
Tercio@11 31
Tercio@11 32 local set_members_function_index = {}
Tercio@11 33
Tercio@11 34 HelpMetaFunctions.__newindex = function (_table, _key, _value)
Tercio@11 35 local func = set_members_function_index [_key]
Tercio@11 36 if (func) then
Tercio@11 37 return func (_table, _value)
Tercio@11 38 else
Tercio@11 39 return _rawset (_table, _key, _value)
Tercio@11 40 end
Tercio@11 41 end
Tercio@11 42
Tercio@11 43 function HelpMetaFunctions:AddHelp (width, height, x, y, buttonX, buttonY, text, anchor)
Tercio@11 44 self.helpTable [#self.helpTable + 1] = {
Tercio@11 45 HighLightBox = {x = x, y = y, width = width, height = height},
Tercio@11 46 ButtonPos = { x = buttonX, y = buttonY},
Tercio@11 47 ToolTipDir = anchor or "RIGHT",
Tercio@11 48 ToolTipText = text
Tercio@11 49 }
Tercio@11 50 end
Tercio@11 51
Tercio@11 52 function HelpMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 53 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
Tercio@11 54 if (not v1) then
Tercio@11 55 print ("Invalid parameter for SetPoint")
Tercio@11 56 return
Tercio@11 57 end
Tercio@11 58 return self.widget:SetPoint (v1, v2, v3, v4, v5)
Tercio@11 59 end
Tercio@11 60
Tercio@11 61 function HelpMetaFunctions:ShowHelp()
Tercio@11 62 if (not HelpPlate_IsShowing (self.helpTable)) then
Tercio@11 63 HelpPlate_Show (self.helpTable, self.frame, self.button, true)
Tercio@11 64 else
Tercio@11 65 HelpPlate_Hide (true)
Tercio@11 66 end
Tercio@11 67 end
Tercio@11 68
Tercio@11 69 local nameCounter = 1
Tercio@11 70 function DF:NewHelp (parent, width, height, x, y, buttonWidth, buttonHeight, name)
Tercio@11 71
Tercio@11 72 local help = {}
Tercio@11 73
Tercio@11 74 if (parent.dframework) then
Tercio@11 75 parent = parent.widget
Tercio@11 76 end
Tercio@11 77
Tercio@11 78 local helpButton = CreateFrame ("button", name or "DetailsFrameworkHelpButton"..nameCounter, parent, "MainHelpPlateButton")
Tercio@11 79 nameCounter = nameCounter + 1
Tercio@11 80
Tercio@11 81 if (not APIHelpFunctions) then
Tercio@11 82 APIHelpFunctions = true
Tercio@11 83 local idx = getmetatable (helpButton).__index
Tercio@11 84 for funcName, funcAddress in pairs (idx) do
Tercio@11 85 if (not HelpMetaFunctions [funcName]) then
Tercio@11 86 HelpMetaFunctions [funcName] = function (object, ...)
Tercio@11 87 local x = loadstring ( "return _G."..object.button:GetName()..":"..funcName.."(...)")
Tercio@11 88 return x (...)
Tercio@11 89 end
Tercio@11 90 end
Tercio@11 91 end
Tercio@11 92 end
Tercio@11 93
Tercio@11 94 if (buttonWidth and buttonHeight) then
Tercio@11 95 helpButton:SetWidth (buttonWidth)
Tercio@11 96 helpButton:SetHeight (buttonHeight)
Tercio@11 97 helpButton.I:SetWidth (buttonWidth*0.8)
Tercio@11 98 helpButton.I:SetHeight (buttonHeight*0.8)
Tercio@11 99 helpButton.Ring:SetWidth (buttonWidth)
Tercio@11 100 helpButton.Ring:SetHeight (buttonHeight)
Tercio@11 101 helpButton.Ring:SetPoint ("center", buttonWidth*.2, -buttonWidth*.2)
Tercio@11 102 end
Tercio@11 103
Tercio@11 104 help.helpTable = {
Tercio@11 105 FramePos = {x = x, y = y},
Tercio@11 106 FrameSize = {width = width, height = height}
Tercio@11 107 }
Tercio@11 108
Tercio@11 109 help.frame = parent
Tercio@11 110 help.button = helpButton
Tercio@11 111 help.widget = helpButton
Tercio@11 112 help.I = helpButton.I
Tercio@11 113 help.Ring = helpButton.Ring
Tercio@11 114
Tercio@11 115 helpButton:SetScript ("OnClick", function()
Tercio@11 116 help:ShowHelp()
Tercio@11 117 end)
Tercio@11 118
Tercio@11 119 setmetatable (help, HelpMetaFunctions)
Tercio@11 120
Tercio@11 121 return help
Tercio@11 122
Tercio@11 123 end