Fix wxColour::GetAsString called for non-solid colour
Don't return RGB values if colour is not solid and hence cannot be represented with these values. Non-solid colour should be reported as an unknown RGB value, e.g. '??????'. Closes #18596.
This commit is contained in:
@@ -118,6 +118,9 @@ public:
|
||||
@c wxC2S_CSS_SYNTAX (which is the only one supporting alpha) is not
|
||||
specified in flags.
|
||||
|
||||
@note For non-solid (i.e. non-RGB) colour this function returns
|
||||
"rgb(??, ?? ??)" or "#??????".
|
||||
|
||||
@since 2.7.0
|
||||
*/
|
||||
virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const;
|
||||
|
@@ -220,6 +220,8 @@ wxString wxColourBase::GetAsString(long flags) const
|
||||
{
|
||||
wxString colName;
|
||||
|
||||
if ( IsSolid() )
|
||||
{
|
||||
const int alpha = Alpha();
|
||||
const bool isOpaque = alpha == wxALPHA_OPAQUE;
|
||||
|
||||
@@ -260,6 +262,18 @@ wxString wxColourBase::GetAsString(long flags) const
|
||||
colName.Printf(wxT("#%02X%02X%02X%02X"), red, green, blue, alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( flags & wxC2S_CSS_SYNTAX )
|
||||
{
|
||||
colName = wxS("rgb(??, ??, \?\?)"); // \? form to avoid ??) trigraph
|
||||
}
|
||||
else if ( flags & wxC2S_HTML_SYNTAX )
|
||||
{
|
||||
colName = wxS("#??????");
|
||||
}
|
||||
}
|
||||
|
||||
// this function should alway returns a non-empty string
|
||||
wxASSERT_MSG(!colName.empty(),
|
||||
|
Reference in New Issue
Block a user