yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: CheckBox Widget yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local Type, Version = "AmrUiCheckBox", 1 yellowfive@57: local AceGUI = LibStub and LibStub("AceGUI-3.0", true) yellowfive@57: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end yellowfive@57: yellowfive@57: local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot") yellowfive@57: yellowfive@57: -- Lua APIs yellowfive@57: local pairs = pairs yellowfive@57: yellowfive@57: -- WoW APIs yellowfive@57: local _G = _G yellowfive@57: local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent yellowfive@57: yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Scripts yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function buttonOnClick(frame, ...) yellowfive@57: AceGUI:ClearFocus() yellowfive@57: PlaySound("igMainMenuOption") yellowfive@57: frame.obj:Fire("OnClick", ...) yellowfive@57: end yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Methods yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local methods = { yellowfive@57: ["OnAcquire"] = function(self) yellowfive@57: -- restore default values yellowfive@57: self:SetDisabled(false) yellowfive@57: self:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text)) yellowfive@57: self:SetText() yellowfive@57: self:SetChecked(false) yellowfive@57: self.frame:ClearAllPoints() yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetText"] = function(self, text) yellowfive@57: self.label:SetText(text) yellowfive@57: self.frame:SetWidth(16 + 6 + self.label:GetStringWidth()) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetFont"] = function(self, font) yellowfive@57: self.label:SetFontObject(font) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetChecked"] = function(self, checked) yellowfive@57: -- not sure if WoW expects boolean type or not, too lazy to find out so just cast it yellowfive@57: self.frame:SetChecked(not not checked) yellowfive@57: end, yellowfive@57: yellowfive@57: ["GetChecked"] = function(self) yellowfive@57: return self.frame:GetChecked() yellowfive@57: end, yellowfive@57: yellowfive@57: ["GetWidth"] = function(self) yellowfive@57: return self.frame:GetWidth() yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetDisabled"] = function(self, disabled) yellowfive@57: self.disabled = disabled yellowfive@57: if disabled then yellowfive@57: self.frame:Disable() yellowfive@57: else yellowfive@57: self.frame:Enable() yellowfive@57: end yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetVisible"] = function(self, visible) yellowfive@57: if visible then yellowfive@57: self.frame:Show() yellowfive@57: else yellowfive@57: self.frame:Hide() yellowfive@57: end yellowfive@57: end yellowfive@57: } yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Constructor yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function Constructor() yellowfive@57: local name = "AmrUiCheckBox" .. AceGUI:GetNextWidgetNum(Type) yellowfive@57: local frame = CreateFrame("CheckButton", name, UIParent) yellowfive@57: frame:SetHeight(16) yellowfive@57: frame:SetPushedTextOffset(0, 0) yellowfive@57: frame:Hide() yellowfive@57: yellowfive@57: frame:EnableMouse(true) yellowfive@57: frame:SetScript("OnClick", buttonOnClick) yellowfive@57: yellowfive@57: -- unchecked texture yellowfive@57: local texNormal = frame:CreateTexture(nil, "BACKGROUND") yellowfive@57: texNormal:SetWidth(16) yellowfive@57: texNormal:SetHeight(16) yellowfive@57: texNormal:SetTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\check-off") yellowfive@57: texNormal:SetPoint("LEFT", frame, "LEFT") yellowfive@57: frame:SetNormalTexture(texNormal) yellowfive@57: yellowfive@57: -- checked texture yellowfive@57: local texCheck = frame:CreateTexture(nil, "BORDER") yellowfive@57: texCheck:SetTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\check-on") yellowfive@57: texCheck:SetPoint("LEFT", frame, "LEFT") yellowfive@57: frame:SetCheckedTexture(texCheck) yellowfive@57: yellowfive@57: -- label yellowfive@57: local lbl = frame:CreateFontString(nil, "ARTWORK") yellowfive@57: lbl:SetJustifyV("MIDDLE") yellowfive@57: lbl:SetPoint("LEFT", texNormal, "RIGHT", 8, 0) yellowfive@57: frame:SetFontString(lbl) yellowfive@57: yellowfive@57: local widget = { yellowfive@57: texNormal = texNormal, yellowfive@57: label = lbl, yellowfive@57: frame = frame, yellowfive@57: type = Type yellowfive@57: } yellowfive@57: for method, func in pairs(methods) do yellowfive@57: widget[method] = func yellowfive@57: end yellowfive@57: yellowfive@57: return AceGUI:RegisterAsWidget(widget) yellowfive@57: end yellowfive@57: yellowfive@57: AceGUI:RegisterWidgetType(Type, Constructor, Version)