From 9a054104700c972a64140d73486502070a709090 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 30 Oct 2018 20:53:35 +0100 Subject: [PATCH] Adding IsSolid to wxColour Under macOS colors can be patterns, then accessors for RGB values are useless, IsSolid returns true if the color can be expressed in RGB values at all. --- include/wx/colour.h | 3 +++ include/wx/osx/core/colour.h | 7 ++++++- interface/wx/colour.h | 5 +++++ src/osx/cocoa/colour.mm | 7 +++++++ src/osx/core/colour.cpp | 7 +++++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/wx/colour.h b/include/wx/colour.h index aa50b349ec..7565f09162 100644 --- a/include/wx/colour.h +++ b/include/wx/colour.h @@ -118,6 +118,9 @@ public: virtual ChannelType Blue() const = 0; virtual ChannelType Alpha() const { return wxALPHA_OPAQUE ; } + + virtual bool IsSolid() const + { return true; } // implemented in colourcmn.cpp virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const; diff --git a/include/wx/osx/core/colour.h b/include/wx/osx/core/colour.h index b862332173..d3b6ec4eb6 100644 --- a/include/wx/osx/core/colour.h +++ b/include/wx/osx/core/colour.h @@ -34,6 +34,8 @@ public: virtual ChannelType Blue() const wxOVERRIDE; virtual ChannelType Alpha() const wxOVERRIDE; + virtual bool IsSolid() const wxOVERRIDE; + wxColour& operator=(const wxColour& col); // comparison @@ -90,7 +92,10 @@ public: virtual CGFloat Green() const = 0; virtual CGFloat Blue() const = 0; virtual CGFloat Alpha() const = 0; - + + virtual bool IsSolid() const + { return true; } + virtual CGColorRef GetCGColor() const = 0; virtual wxColourRefData* Clone() const = 0; diff --git a/interface/wx/colour.h b/interface/wx/colour.h index 09c1c242a6..cd217d853a 100644 --- a/interface/wx/colour.h +++ b/interface/wx/colour.h @@ -182,6 +182,11 @@ public: */ virtual unsigned char Red() const; + /** + Returns @true if the color can be described using RGB values, ie is solid, + @false if it is a pattern (currently only possible on macOS) + */ + virtual bool IsSolid() const; //@{ /** Sets the RGB intensity values using the given values (first overload), diff --git a/src/osx/cocoa/colour.mm b/src/osx/cocoa/colour.mm index d7fc6ec81d..32d6ae8c8c 100644 --- a/src/osx/cocoa/colour.mm +++ b/src/osx/cocoa/colour.mm @@ -27,6 +27,8 @@ public: virtual CGFloat Blue() const wxOVERRIDE; virtual CGFloat Alpha() const wxOVERRIDE; + virtual bool IsSolid() const wxOVERRIDE; + CGColorRef GetCGColor() const wxOVERRIDE; virtual wxColourRefData* Clone() const wxOVERRIDE { return new wxNSColorRefData(*this); } @@ -94,6 +96,11 @@ CGFloat wxNSColorRefData::Alpha() const return 0.0; } +bool wxNSColorRefData::IsSolid() const +{ + return [m_nsColour colorUsingColorSpaceName:NSCalibratedRGBColorSpace] != nil; +} + CGColorRef wxNSColorRefData::GetCGColor() const { #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 diff --git a/src/osx/core/colour.cpp b/src/osx/core/colour.cpp index 8edb7f0669..3f15e6edeb 100644 --- a/src/osx/core/colour.cpp +++ b/src/osx/core/colour.cpp @@ -189,6 +189,13 @@ wxColour::ChannelType wxColour::Alpha() const return wxRound(M_COLDATA->Alpha() * 255.0); } +bool wxColour::IsSolid() const +{ + wxCHECK_MSG( IsOk(), false, "invalid colour" ); + + return M_COLDATA->IsSolid(); +} + #if wxOSX_USE_COCOA_OR_CARBON void wxColour::GetRGBColor(RGBColor* col) const {