From 138428446ed76332e199b5da836a0d097f0218c5 Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Thu, 22 Feb 2024 01:20:54 +0100 Subject: [PATCH] AceGUI-3.0: ColorPicker: Fix alpha handling on Classic Era Fixes WoWHead Ticket #655 Closes GitHub #11 --- .luacheckrc | 2 ++ .../widgets/AceGUIWidget-ColorPicker.lua | 24 +++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index bd684ac..77d453c 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -94,6 +94,8 @@ read_globals = { "OpacitySliderFrame", "SELECTED_CHAT_FRAME", "UIParent", + "WOW_PROJECT_ID", + "WOW_PROJECT_MAINLINE", -- Custom Globals "GAME_LOCALE", diff --git a/AceGUI-3.0/widgets/AceGUIWidget-ColorPicker.lua b/AceGUI-3.0/widgets/AceGUIWidget-ColorPicker.lua index 2d12ab7..671caea 100644 --- a/AceGUI-3.0/widgets/AceGUIWidget-ColorPicker.lua +++ b/AceGUI-3.0/widgets/AceGUIWidget-ColorPicker.lua @@ -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 @@ -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 @@ -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() @@ -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) @@ -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)