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@133: local CreateFrame, UIParent = CreateFrame, UIParent yellowfive@57: yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Scripts yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function buttonOnClick(frame, ...) yellowfive@57: AceGUI:ClearFocus() yellowfive@124: frame.obj:SetChecked(not frame.obj.isChecked) yellowfive@124: yellowfive@112: --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@124: --["OnRelease"] = function(self) yellowfive@124: -- print(self.name .. " released") yellowfive@124: --end, yellowfive@124: 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@124: self.isChecked = not not checked yellowfive@124: if checked then yellowfive@124: self.texNormal:Hide() yellowfive@124: self.texCheck:Show() yellowfive@124: else yellowfive@124: self.texCheck:Hide() yellowfive@124: self.texNormal:Show() yellowfive@124: end yellowfive@57: end, yellowfive@57: yellowfive@124: ["GetChecked"] = function(self) yellowfive@124: return self.isChecked 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@124: local frame = CreateFrame("Button", nil, 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@124: texNormal.name = name 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: yellowfive@57: -- checked texture yellowfive@124: local texCheck = frame:CreateTexture(nil, "BACKGROUND") yellowfive@124: texCheck.name = name yellowfive@124: texCheck:SetWidth(16) yellowfive@124: texCheck:SetHeight(16) yellowfive@57: texCheck:SetTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\check-on") yellowfive@57: texCheck:SetPoint("LEFT", frame, "LEFT") yellowfive@124: texCheck:Hide() yellowfive@57: yellowfive@57: -- label yellowfive@124: local lbl = frame:CreateFontString(nil, "BACKGROUND") yellowfive@57: lbl:SetJustifyV("MIDDLE") yellowfive@57: lbl:SetPoint("LEFT", texNormal, "RIGHT", 8, 0) yellowfive@57: yellowfive@57: local widget = { yellowfive@57: texNormal = texNormal, yellowfive@124: texCheck = texCheck, yellowfive@57: label = lbl, yellowfive@57: frame = frame, yellowfive@124: type = Type, yellowfive@124: isChecked = false, yellowfive@124: name = name 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)