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