Blame 37a4bf86937e4e18c5cce70913b6b90e39df20cc.patch

Scott Talbert a378d6
From 37a4bf86937e4e18c5cce70913b6b90e39df20cc Mon Sep 17 00:00:00 2001
Scott Talbert a378d6
From: Vadim Zeitlin <vadim@wxwidgets.org>
Scott Talbert a378d6
Date: Thu, 27 Jan 2022 15:46:42 +0100
Scott Talbert a378d6
Subject: [PATCH] Add wxColour::Get{Red,Green,Blue,Alpha}() to avoid gcc 12
Scott Talbert a378d6
 warnings
Scott Talbert a378d6
Scott Talbert a378d6
These functions return the colour components as unsigned int and so
Scott Talbert a378d6
promote to this type in arithmetic expressions, unlike unsigned char
Scott Talbert a378d6
returned by the existing accessors without the "Get" prefix, which
Scott Talbert a378d6
promotes to (signed) int and results in gcc 12 -Warith-conversion
Scott Talbert a378d6
warnings when the result is then converted to unsigned, as it happened
Scott Talbert a378d6
in our own wxColour::GetRGB() and GetRGBA() functions and would probably
Scott Talbert a378d6
happen in a lot of code outside wx, which could also be updated to use
Scott Talbert a378d6
the new functions instead of inserting casts.
Scott Talbert a378d6
---
Scott Talbert a378d6
 include/wx/colour.h   | 11 ++++++++--
Scott Talbert a378d6
 interface/wx/colour.h | 51 +++++++++++++++++++++++++++++++++++++++++++
Scott Talbert a378d6
 2 files changed, 60 insertions(+), 2 deletions(-)
Scott Talbert a378d6
Scott Talbert a378d6
diff --git a/include/wx/colour.h b/include/wx/colour.h
Scott Talbert a378d6
index 4e9e0a185407..22a145ab22d1 100644
Scott Talbert a378d6
--- a/include/wx/colour.h
Scott Talbert a378d6
+++ b/include/wx/colour.h
Scott Talbert a378d6
@@ -125,6 +125,13 @@ class WXDLLIMPEXP_CORE wxColourBase : public
Scott Talbert a378d6
     virtual ChannelType Alpha() const
Scott Talbert a378d6
         { return wxALPHA_OPAQUE ; }
Scott Talbert a378d6
 
Scott Talbert a378d6
+    // These getters return the values as unsigned int, which avoids promoting
Scott Talbert a378d6
+    // them to (signed) int in arithmetic expressions, unlike the ones above.
Scott Talbert a378d6
+    unsigned int GetRed() const { return Red(); }
Scott Talbert a378d6
+    unsigned int GetGreen() const { return Green(); }
Scott Talbert a378d6
+    unsigned int GetBlue() const { return Blue(); }
Scott Talbert a378d6
+    unsigned int GetAlpha() const { return Alpha(); }
Scott Talbert a378d6
+
Scott Talbert a378d6
     virtual bool IsSolid() const
Scott Talbert a378d6
         { return true; }
Scott Talbert a378d6
 
Scott Talbert a378d6
@@ -147,10 +154,10 @@ class WXDLLIMPEXP_CORE wxColourBase : public
Scott Talbert a378d6
     }
Scott Talbert a378d6
 
Scott Talbert a378d6
     wxUint32 GetRGB() const
Scott Talbert a378d6
-        { return Red() | (Green() << 8) | (Blue() << 16); }
Scott Talbert a378d6
+        { return GetRed() | (GetGreen() << 8) | (GetBlue() << 16); }
Scott Talbert a378d6
 
Scott Talbert a378d6
     wxUint32 GetRGBA() const
Scott Talbert a378d6
-        { return Red() | (Green() << 8) | (Blue() << 16) | (Alpha() << 24); }
Scott Talbert a378d6
+        { return GetRed() | (GetGreen() << 8) | (GetBlue() << 16) | (GetAlpha() << 24); }
Scott Talbert a378d6
 
Scott Talbert a378d6
 #if !wxCOLOUR_IS_GDIOBJECT
Scott Talbert a378d6
     virtual bool IsOk() const= 0;
Scott Talbert a378d6
diff --git a/interface/wx/colour.h b/interface/wx/colour.h
Scott Talbert a378d6
index 32424f1123c7..9cc0ac7c9dec 100644
Scott Talbert a378d6
--- a/interface/wx/colour.h
Scott Talbert a378d6
+++ b/interface/wx/colour.h
Scott Talbert a378d6
@@ -34,6 +34,20 @@ const unsigned char wxALPHA_OPAQUE = 0xff;
Scott Talbert a378d6
 
Scott Talbert a378d6
     You can retrieve the current system colour settings with wxSystemSettings.
Scott Talbert a378d6
 
Scott Talbert a378d6
+
Scott Talbert a378d6
+    @section colour_accessors Channel Accessor Functions
Scott Talbert a378d6
+
Scott Talbert a378d6
+    Note that this class provides pairs of functions for each of the colour
Scott Talbert a378d6
+    channels, i.e. red, green, blue and alpha values. The one word functions
Scott Talbert a378d6
+    Red(), Green(), Blue() and Alpha() return the values of type @c unsigned @c
Scott Talbert a378d6
+    char, while GetRed(), GetGreen(), GetBlue() and GetAlpha() returns the same
Scott Talbert a378d6
+    value as @c unsigned @c int. According to the C++ integer promotion rules,
Scott Talbert a378d6
+    the result of any arithmetic expression involving the former will be
Scott Talbert a378d6
+    (signed) @c int, while that of the latter will be @c unsigned, which is
Scott Talbert a378d6
+    what would be commonly expected, so the latter family of functions should
Scott Talbert a378d6
+    be typically preferred (but they are only available since wxWidgets 3.1.6).
Scott Talbert a378d6
+
Scott Talbert a378d6
+
Scott Talbert a378d6
     @library{wxcore}
Scott Talbert a378d6
     @category{gdi}
Scott Talbert a378d6
 
Scott Talbert a378d6
@@ -94,14 +108,47 @@ class wxColour : public wxObject
Scott Talbert a378d6
     /**
Scott Talbert a378d6
         Returns the alpha value, on platforms where alpha is not yet supported, this
Scott Talbert a378d6
         always returns wxALPHA_OPAQUE.
Scott Talbert a378d6
+
Scott Talbert a378d6
+        @see GetAlpha()
Scott Talbert a378d6
     */
Scott Talbert a378d6
     virtual unsigned char Alpha() const;
Scott Talbert a378d6
 
Scott Talbert a378d6
     /**
Scott Talbert a378d6
         Returns the blue intensity.
Scott Talbert a378d6
+
Scott Talbert a378d6
+        @see GetBlue()
Scott Talbert a378d6
     */
Scott Talbert a378d6
     virtual unsigned char Blue() const;
Scott Talbert a378d6
 
Scott Talbert a378d6
+    /**
Scott Talbert a378d6
+        Returns the alpha value, on platforms where alpha is not yet supported, this
Scott Talbert a378d6
+        always returns wxALPHA_OPAQUE.
Scott Talbert a378d6
+
Scott Talbert a378d6
+        @since 3.1.6
Scott Talbert a378d6
+     */
Scott Talbert a378d6
+    unsigned int GetAlpha() const;
Scott Talbert a378d6
+
Scott Talbert a378d6
+    /**
Scott Talbert a378d6
+        Returns the blue intensity as unsigned int.
Scott Talbert a378d6
+
Scott Talbert a378d6
+        @since 3.1.6
Scott Talbert a378d6
+     */
Scott Talbert a378d6
+    unsigned int GetBlue() const;
Scott Talbert a378d6
+
Scott Talbert a378d6
+    /**
Scott Talbert a378d6
+        Returns the green intensity as unsigned int.
Scott Talbert a378d6
+
Scott Talbert a378d6
+        @since 3.1.6
Scott Talbert a378d6
+     */
Scott Talbert a378d6
+    unsigned int GetGreen() const;
Scott Talbert a378d6
+
Scott Talbert a378d6
+    /**
Scott Talbert a378d6
+        Returns the red intensity as unsigned int.
Scott Talbert a378d6
+
Scott Talbert a378d6
+        @since 3.1.6
Scott Talbert a378d6
+     */
Scott Talbert a378d6
+    unsigned int GetRed() const;
Scott Talbert a378d6
+
Scott Talbert a378d6
     /**
Scott Talbert a378d6
         Converts this colour to a wxString using the given flags.
Scott Talbert a378d6
 
Scott Talbert a378d6
@@ -184,6 +231,8 @@ class wxColour : public wxObject
Scott Talbert a378d6
 
Scott Talbert a378d6
     /**
Scott Talbert a378d6
         Returns the green intensity.
Scott Talbert a378d6
+
Scott Talbert a378d6
+        @see GetGreen()
Scott Talbert a378d6
     */
Scott Talbert a378d6
     virtual unsigned char Green() const;
Scott Talbert a378d6
 
Scott Talbert a378d6
@@ -195,6 +244,8 @@ class wxColour : public wxObject
Scott Talbert a378d6
 
Scott Talbert a378d6
     /**
Scott Talbert a378d6
         Returns the red intensity.
Scott Talbert a378d6
+
Scott Talbert a378d6
+        @see GetRed()
Scott Talbert a378d6
     */
Scott Talbert a378d6
     virtual unsigned char Red() const;
Scott Talbert a378d6