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