Skip to content

Commit

Permalink
AceGUI-3.0: ColorPicker: Fix alpha handling on Classic Era
Browse files Browse the repository at this point in the history
Fixes WoWHead Ticket #655
Closes GitHub #11
  • Loading branch information
Nevcairiel committed Feb 22, 2024
1 parent 7345a02 commit 1384284
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ read_globals = {
"OpacitySliderFrame",
"SELECTED_CHAT_FRAME",
"UIParent",
"WOW_PROJECT_ID",
"WOW_PROJECT_MAINLINE",

-- Custom Globals
"GAME_LOCALE",
Expand Down
24 changes: 17 additions & 7 deletions AceGUI-3.0/widgets/AceGUIWidget-ColorPicker.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--[[-----------------------------------------------------------------------------
ColorPicker Widget
-------------------------------------------------------------------------------]]
local Type, Version = "ColorPicker", 27
local Type, Version = "ColorPicker", 28
local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end

Expand All @@ -11,10 +11,17 @@ local pairs = pairs
-- WoW APIs
local CreateFrame, UIParent = CreateFrame, UIParent

-- Unfortunately we have no way to realistically detect if a client uses inverted alpha
-- as no API will tell you. Wrath uses the old colorpicker, era uses the new one, both are inverted
local INVERTED_ALPHA = (WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE)

--[[-----------------------------------------------------------------------------
Support functions
-------------------------------------------------------------------------------]]
local function ColorCallback(self, r, g, b, a, isAlpha)
if INVERTED_ALPHA then
a = 1 - a
end
if not self.HasAlpha then
a = 1
end
Expand Down Expand Up @@ -56,7 +63,10 @@ local function ColorSwatch_OnClick(frame)
ColorPickerFrame:EnableMouse(true) -- Make sure the background isn't click-through

if ColorPickerFrame.SetupColorPickerAndShow then -- 10.2.5 color picker overhaul
local r2, g2, b2, a2 = self.r, self.g, self.b, self.a
local r2, g2, b2, a2 = self.r, self.g, self.b, (self.a or 1)
if INVERTED_ALPHA then
a2 = 1 - a2
end

local info = {
swatchFunc = function()
Expand All @@ -71,7 +81,7 @@ local function ColorSwatch_OnClick(frame)
local a = ColorPickerFrame:GetColorAlpha()
ColorCallback(self, r, g, b, a, true)
end,
opacity = (a2 or 1),
opacity = a2,

cancelFunc = function()
ColorCallback(self, r2, g2, b2, a2, true)
Expand All @@ -86,20 +96,20 @@ local function ColorSwatch_OnClick(frame)
else
ColorPickerFrame.func = function()
local r, g, b = ColorPickerFrame:GetColorRGB()
local a = 1 - OpacitySliderFrame:GetValue()
local a = OpacitySliderFrame:GetValue()
ColorCallback(self, r, g, b, a)
end

ColorPickerFrame.hasOpacity = self.HasAlpha
ColorPickerFrame.opacityFunc = function()
local r, g, b = ColorPickerFrame:GetColorRGB()
local a = 1 - OpacitySliderFrame:GetValue()
local a = OpacitySliderFrame:GetValue()
ColorCallback(self, r, g, b, a, true)
end

local r, g, b, a = self.r, self.g, self.b, self.a
local r, g, b, a = self.r, self.g, self.b, 1 - (self.a or 1)
if self.HasAlpha then
ColorPickerFrame.opacity = 1 - (a or 0)
ColorPickerFrame.opacity = a
end
ColorPickerFrame:SetColorRGB(r, g, b)

Expand Down

0 comments on commit 1384284

Please sign in to comment.