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