annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-ColorPicker.lua @ 20:d200c55c85fb v7.3.2.020

- Added demonhunter class detection. - ToC Bump.
author Tercio
date Sat, 09 Dec 2017 11:04:43 -0200
parents a0dcdcaec1ea
children
rev   line source
tercio@0 1 --[[-----------------------------------------------------------------------------
tercio@0 2 ColorPicker Widget
tercio@0 3 -------------------------------------------------------------------------------]]
Tercio@18 4 local Type, Version = "ColorPicker", 23
tercio@0 5 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
tercio@0 6 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
tercio@0 7
tercio@0 8 -- Lua APIs
tercio@0 9 local pairs = pairs
tercio@0 10
tercio@0 11 -- WoW APIs
tercio@0 12 local CreateFrame, UIParent = CreateFrame, UIParent
tercio@0 13
tercio@0 14 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
tercio@0 15 -- List them here for Mikk's FindGlobals script
tercio@0 16 -- GLOBALS: ShowUIPanel, HideUIPanel, ColorPickerFrame, OpacitySliderFrame
tercio@0 17
tercio@0 18 --[[-----------------------------------------------------------------------------
tercio@0 19 Support functions
tercio@0 20 -------------------------------------------------------------------------------]]
tercio@0 21 local function ColorCallback(self, r, g, b, a, isAlpha)
tercio@0 22 if not self.HasAlpha then
tercio@0 23 a = 1
tercio@0 24 end
tercio@0 25 self:SetColor(r, g, b, a)
tercio@0 26 if ColorPickerFrame:IsVisible() then
tercio@0 27 --colorpicker is still open
tercio@0 28 self:Fire("OnValueChanged", r, g, b, a)
tercio@0 29 else
tercio@0 30 --colorpicker is closed, color callback is first, ignore it,
tercio@0 31 --alpha callback is the final call after it closes so confirm now
tercio@0 32 if isAlpha then
tercio@0 33 self:Fire("OnValueConfirmed", r, g, b, a)
tercio@0 34 end
tercio@0 35 end
tercio@0 36 end
tercio@0 37
tercio@0 38 --[[-----------------------------------------------------------------------------
tercio@0 39 Scripts
tercio@0 40 -------------------------------------------------------------------------------]]
tercio@0 41 local function Control_OnEnter(frame)
tercio@0 42 frame.obj:Fire("OnEnter")
tercio@0 43 end
tercio@0 44
tercio@0 45 local function Control_OnLeave(frame)
tercio@0 46 frame.obj:Fire("OnLeave")
tercio@0 47 end
tercio@0 48
tercio@0 49 local function ColorSwatch_OnClick(frame)
tercio@0 50 HideUIPanel(ColorPickerFrame)
tercio@0 51 local self = frame.obj
tercio@0 52 if not self.disabled then
tercio@0 53 ColorPickerFrame:SetFrameStrata("FULLSCREEN_DIALOG")
Tercio@18 54 ColorPickerFrame:SetFrameLevel(frame:GetFrameLevel() + 10)
tercio@0 55 ColorPickerFrame:SetClampedToScreen(true)
tercio@0 56
tercio@0 57 ColorPickerFrame.func = function()
tercio@0 58 local r, g, b = ColorPickerFrame:GetColorRGB()
tercio@0 59 local a = 1 - OpacitySliderFrame:GetValue()
tercio@0 60 ColorCallback(self, r, g, b, a)
tercio@0 61 end
tercio@0 62
tercio@0 63 ColorPickerFrame.hasOpacity = self.HasAlpha
tercio@0 64 ColorPickerFrame.opacityFunc = function()
tercio@0 65 local r, g, b = ColorPickerFrame:GetColorRGB()
tercio@0 66 local a = 1 - OpacitySliderFrame:GetValue()
tercio@0 67 ColorCallback(self, r, g, b, a, true)
tercio@0 68 end
tercio@0 69
tercio@0 70 local r, g, b, a = self.r, self.g, self.b, self.a
tercio@0 71 if self.HasAlpha then
tercio@0 72 ColorPickerFrame.opacity = 1 - (a or 0)
tercio@0 73 end
tercio@0 74 ColorPickerFrame:SetColorRGB(r, g, b)
tercio@0 75
tercio@0 76 ColorPickerFrame.cancelFunc = function()
tercio@0 77 ColorCallback(self, r, g, b, a, true)
tercio@0 78 end
tercio@0 79
tercio@0 80 ShowUIPanel(ColorPickerFrame)
tercio@0 81 end
tercio@0 82 AceGUI:ClearFocus()
tercio@0 83 end
tercio@0 84
tercio@0 85 --[[-----------------------------------------------------------------------------
tercio@0 86 Methods
tercio@0 87 -------------------------------------------------------------------------------]]
tercio@0 88 local methods = {
tercio@0 89 ["OnAcquire"] = function(self)
tercio@0 90 self:SetHeight(24)
tercio@0 91 self:SetWidth(200)
tercio@0 92 self:SetHasAlpha(false)
tercio@0 93 self:SetColor(0, 0, 0, 1)
tercio@0 94 self:SetDisabled(nil)
tercio@0 95 self:SetLabel(nil)
tercio@0 96 end,
tercio@0 97
tercio@0 98 -- ["OnRelease"] = nil,
tercio@0 99
tercio@0 100 ["SetLabel"] = function(self, text)
tercio@0 101 self.text:SetText(text)
tercio@0 102 end,
tercio@0 103
tercio@0 104 ["SetColor"] = function(self, r, g, b, a)
tercio@0 105 self.r = r
tercio@0 106 self.g = g
tercio@0 107 self.b = b
tercio@0 108 self.a = a or 1
tercio@0 109 self.colorSwatch:SetVertexColor(r, g, b, a)
tercio@0 110 end,
tercio@0 111
tercio@0 112 ["SetHasAlpha"] = function(self, HasAlpha)
tercio@0 113 self.HasAlpha = HasAlpha
tercio@0 114 end,
tercio@0 115
tercio@0 116 ["SetDisabled"] = function(self, disabled)
tercio@0 117 self.disabled = disabled
tercio@0 118 if self.disabled then
tercio@0 119 self.frame:Disable()
tercio@0 120 self.text:SetTextColor(0.5, 0.5, 0.5)
tercio@0 121 else
tercio@0 122 self.frame:Enable()
tercio@0 123 self.text:SetTextColor(1, 1, 1)
tercio@0 124 end
tercio@0 125 end
tercio@0 126 }
tercio@0 127
tercio@0 128 --[[-----------------------------------------------------------------------------
tercio@0 129 Constructor
tercio@0 130 -------------------------------------------------------------------------------]]
tercio@0 131 local function Constructor()
tercio@0 132 local frame = CreateFrame("Button", nil, UIParent)
tercio@0 133 frame:Hide()
tercio@0 134
tercio@0 135 frame:EnableMouse(true)
tercio@0 136 frame:SetScript("OnEnter", Control_OnEnter)
tercio@0 137 frame:SetScript("OnLeave", Control_OnLeave)
tercio@0 138 frame:SetScript("OnClick", ColorSwatch_OnClick)
tercio@0 139
tercio@0 140 local colorSwatch = frame:CreateTexture(nil, "OVERLAY")
tercio@0 141 colorSwatch:SetWidth(19)
tercio@0 142 colorSwatch:SetHeight(19)
tercio@0 143 colorSwatch:SetTexture("Interface\\ChatFrame\\ChatFrameColorSwatch")
tercio@0 144 colorSwatch:SetPoint("LEFT")
tercio@0 145
tercio@0 146 local texture = frame:CreateTexture(nil, "BACKGROUND")
tercio@0 147 texture:SetWidth(16)
tercio@0 148 texture:SetHeight(16)
Tercio@18 149 texture:SetColorTexture(1, 1, 1)
tercio@0 150 texture:SetPoint("CENTER", colorSwatch)
tercio@0 151 texture:Show()
tercio@0 152
tercio@0 153 local checkers = frame:CreateTexture(nil, "BACKGROUND")
tercio@0 154 checkers:SetWidth(14)
tercio@0 155 checkers:SetHeight(14)
tercio@0 156 checkers:SetTexture("Tileset\\Generic\\Checkers")
tercio@0 157 checkers:SetTexCoord(.25, 0, 0.5, .25)
tercio@0 158 checkers:SetDesaturated(true)
tercio@0 159 checkers:SetVertexColor(1, 1, 1, 0.75)
tercio@0 160 checkers:SetPoint("CENTER", colorSwatch)
tercio@0 161 checkers:Show()
tercio@0 162
tercio@0 163 local text = frame:CreateFontString(nil,"OVERLAY","GameFontHighlight")
tercio@0 164 text:SetHeight(24)
tercio@0 165 text:SetJustifyH("LEFT")
tercio@0 166 text:SetTextColor(1, 1, 1)
tercio@0 167 text:SetPoint("LEFT", colorSwatch, "RIGHT", 2, 0)
tercio@0 168 text:SetPoint("RIGHT")
tercio@0 169
tercio@0 170 --local highlight = frame:CreateTexture(nil, "HIGHLIGHT")
tercio@0 171 --highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
tercio@0 172 --highlight:SetBlendMode("ADD")
tercio@0 173 --highlight:SetAllPoints(frame)
tercio@0 174
tercio@0 175 local widget = {
tercio@0 176 colorSwatch = colorSwatch,
tercio@0 177 text = text,
tercio@0 178 frame = frame,
tercio@0 179 type = Type
tercio@0 180 }
tercio@0 181 for method, func in pairs(methods) do
tercio@0 182 widget[method] = func
tercio@0 183 end
tercio@0 184
tercio@0 185 return AceGUI:RegisterAsWidget(widget)
tercio@0 186 end
tercio@0 187
tercio@0 188 AceGUI:RegisterWidgetType(Type, Constructor, Version)