annotate ui/AmrUiCheckBox.lua @ 112:57c6cac5143c v52

7.3 update, preparation for reading crucible.
author yellowfive
date Mon, 28 Aug 2017 19:33:14 -0700
parents 01b63b8ed811
children e31b02b24488
rev   line source
yellowfive@57 1 --[[-----------------------------------------------------------------------------
yellowfive@57 2 CheckBox Widget
yellowfive@57 3 -------------------------------------------------------------------------------]]
yellowfive@57 4 local Type, Version = "AmrUiCheckBox", 1
yellowfive@57 5 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
yellowfive@57 6 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
yellowfive@57 7
yellowfive@57 8 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
yellowfive@57 9
yellowfive@57 10 -- Lua APIs
yellowfive@57 11 local pairs = pairs
yellowfive@57 12
yellowfive@57 13 -- WoW APIs
yellowfive@57 14 local _G = _G
yellowfive@57 15 local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent
yellowfive@57 16
yellowfive@57 17
yellowfive@57 18 --[[-----------------------------------------------------------------------------
yellowfive@57 19 Scripts
yellowfive@57 20 -------------------------------------------------------------------------------]]
yellowfive@57 21 local function buttonOnClick(frame, ...)
yellowfive@57 22 AceGUI:ClearFocus()
yellowfive@112 23 --PlaySound("igMainMenuOption")
yellowfive@57 24 frame.obj:Fire("OnClick", ...)
yellowfive@57 25 end
yellowfive@57 26
yellowfive@57 27 --[[-----------------------------------------------------------------------------
yellowfive@57 28 Methods
yellowfive@57 29 -------------------------------------------------------------------------------]]
yellowfive@57 30 local methods = {
yellowfive@57 31 ["OnAcquire"] = function(self)
yellowfive@57 32 -- restore default values
yellowfive@57 33 self:SetDisabled(false)
yellowfive@57 34 self:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
yellowfive@57 35 self:SetText()
yellowfive@57 36 self:SetChecked(false)
yellowfive@57 37 self.frame:ClearAllPoints()
yellowfive@57 38 end,
yellowfive@57 39
yellowfive@57 40 ["SetText"] = function(self, text)
yellowfive@57 41 self.label:SetText(text)
yellowfive@57 42 self.frame:SetWidth(16 + 6 + self.label:GetStringWidth())
yellowfive@57 43 end,
yellowfive@57 44
yellowfive@57 45 ["SetFont"] = function(self, font)
yellowfive@57 46 self.label:SetFontObject(font)
yellowfive@57 47 end,
yellowfive@57 48
yellowfive@57 49 ["SetChecked"] = function(self, checked)
yellowfive@57 50 -- not sure if WoW expects boolean type or not, too lazy to find out so just cast it
yellowfive@57 51 self.frame:SetChecked(not not checked)
yellowfive@57 52 end,
yellowfive@57 53
yellowfive@57 54 ["GetChecked"] = function(self)
yellowfive@57 55 return self.frame:GetChecked()
yellowfive@57 56 end,
yellowfive@57 57
yellowfive@57 58 ["GetWidth"] = function(self)
yellowfive@57 59 return self.frame:GetWidth()
yellowfive@57 60 end,
yellowfive@57 61
yellowfive@57 62 ["SetDisabled"] = function(self, disabled)
yellowfive@57 63 self.disabled = disabled
yellowfive@57 64 if disabled then
yellowfive@57 65 self.frame:Disable()
yellowfive@57 66 else
yellowfive@57 67 self.frame:Enable()
yellowfive@57 68 end
yellowfive@57 69 end,
yellowfive@57 70
yellowfive@57 71 ["SetVisible"] = function(self, visible)
yellowfive@57 72 if visible then
yellowfive@57 73 self.frame:Show()
yellowfive@57 74 else
yellowfive@57 75 self.frame:Hide()
yellowfive@57 76 end
yellowfive@57 77 end
yellowfive@57 78 }
yellowfive@57 79
yellowfive@57 80 --[[-----------------------------------------------------------------------------
yellowfive@57 81 Constructor
yellowfive@57 82 -------------------------------------------------------------------------------]]
yellowfive@57 83 local function Constructor()
yellowfive@57 84 local name = "AmrUiCheckBox" .. AceGUI:GetNextWidgetNum(Type)
yellowfive@57 85 local frame = CreateFrame("CheckButton", name, UIParent)
yellowfive@57 86 frame:SetHeight(16)
yellowfive@57 87 frame:SetPushedTextOffset(0, 0)
yellowfive@57 88 frame:Hide()
yellowfive@57 89
yellowfive@57 90 frame:EnableMouse(true)
yellowfive@57 91 frame:SetScript("OnClick", buttonOnClick)
yellowfive@57 92
yellowfive@57 93 -- unchecked texture
yellowfive@57 94 local texNormal = frame:CreateTexture(nil, "BACKGROUND")
yellowfive@57 95 texNormal:SetWidth(16)
yellowfive@57 96 texNormal:SetHeight(16)
yellowfive@57 97 texNormal:SetTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\check-off")
yellowfive@57 98 texNormal:SetPoint("LEFT", frame, "LEFT")
yellowfive@57 99 frame:SetNormalTexture(texNormal)
yellowfive@57 100
yellowfive@57 101 -- checked texture
yellowfive@57 102 local texCheck = frame:CreateTexture(nil, "BORDER")
yellowfive@57 103 texCheck:SetTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\check-on")
yellowfive@57 104 texCheck:SetPoint("LEFT", frame, "LEFT")
yellowfive@57 105 frame:SetCheckedTexture(texCheck)
yellowfive@57 106
yellowfive@57 107 -- label
yellowfive@57 108 local lbl = frame:CreateFontString(nil, "ARTWORK")
yellowfive@57 109 lbl:SetJustifyV("MIDDLE")
yellowfive@57 110 lbl:SetPoint("LEFT", texNormal, "RIGHT", 8, 0)
yellowfive@57 111 frame:SetFontString(lbl)
yellowfive@57 112
yellowfive@57 113 local widget = {
yellowfive@57 114 texNormal = texNormal,
yellowfive@57 115 label = lbl,
yellowfive@57 116 frame = frame,
yellowfive@57 117 type = Type
yellowfive@57 118 }
yellowfive@57 119 for method, func in pairs(methods) do
yellowfive@57 120 widget[method] = func
yellowfive@57 121 end
yellowfive@57 122
yellowfive@57 123 return AceGUI:RegisterAsWidget(widget)
yellowfive@57 124 end
yellowfive@57 125
yellowfive@57 126 AceGUI:RegisterWidgetType(Type, Constructor, Version)