From e58671e2dacc0879503b39061326ad504c7a2484 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 31 Aug 2021 18:55:26 +0100 Subject: [PATCH] Move color picker from CSS to HTML format for colors. This is an attempt to remove the decimal separator from the equation, which appears to be causing trouble on MSW. Fixes https://gitlab.com/kicad/code/kicad/issues/9043 --- common/dialogs/dialog_color_picker.cpp | 4 ++-- common/gal/color4d.cpp | 31 ++++++++++++++++++++++++++ include/gal/color4d.h | 3 +++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/common/dialogs/dialog_color_picker.cpp b/common/dialogs/dialog_color_picker.cpp index 19e32b753d..a84306c631 100644 --- a/common/dialogs/dialog_color_picker.cpp +++ b/common/dialogs/dialog_color_picker.cpp @@ -512,7 +512,7 @@ void DIALOG_COLOR_PICKER::SetEditVals( CHANGED_COLOR aChanged, bool aCheckTransp m_sliderBrightness->SetValue(normalizeToInt( m_val ) ); if( aChanged != HEX_CHANGED ) - m_colorValue->ChangeValue( m_newColor4D.ToWxString( wxC2S_CSS_SYNTAX ) ); + m_colorValue->ChangeValue( m_newColor4D.ToHexString() ); } @@ -676,7 +676,7 @@ void DIALOG_COLOR_PICKER::onHSVMouseDrag( wxMouseEvent& event ) void DIALOG_COLOR_PICKER::OnColorValueText( wxCommandEvent& event ) { - m_newColor4D.SetFromWxString( m_colorValue->GetValue() ); + m_newColor4D.SetFromHexString( m_colorValue->GetValue() ); m_newColor4D.ToHSV( m_hue, m_sat, m_val, true ); SetEditVals( HEX_CHANGED, true ); diff --git a/common/gal/color4d.cpp b/common/gal/color4d.cpp index be50762333..ebed7b3d99 100644 --- a/common/gal/color4d.cpp +++ b/common/gal/color4d.cpp @@ -27,6 +27,8 @@ #include #include #include +#include +#include using namespace KIGFX; @@ -142,6 +144,35 @@ wxString COLOR4D::ToWxString( long flags ) const } +bool COLOR4D::SetFromHexString( const wxString& aColorString ) +{ + if( aColorString.length() != 9 || aColorString.GetChar( 0 ) != '#' ) + return false; + + unsigned long tmp; + + if( wxSscanf( aColorString.wx_str() + 1, wxT( "%lx" ), &tmp ) != 1 ) + return false; + + r = ( (tmp >> 24) & 0xFF ) / 255.0; + g = ( (tmp >> 16) & 0xFF ) / 255.0; + b = ( (tmp >> 8) & 0xFF ) / 255.0; + a = ( tmp & 0xFF ) / 255.0; + + return true; +} + + +wxString COLOR4D::ToHexString() const +{ + return wxString::Format( wxT("#%02X%02X%02X%02X" ), + KiROUND( r * 255.0 ), + KiROUND( g * 255.0 ), + KiROUND( b * 255.0 ), + KiROUND( a * 255.0 ) ); +} + + wxColour COLOR4D::ToColour() const { using CHAN_T = wxColourBase::ChannelType; diff --git a/include/gal/color4d.h b/include/gal/color4d.h index 4fbcf4d6df..6d733b463b 100644 --- a/include/gal/color4d.h +++ b/include/gal/color4d.h @@ -155,6 +155,9 @@ public: wxString ToWxString( long flags ) const; + bool SetFromHexString( const wxString& aColorString ); + wxString ToHexString() const; + wxColour ToColour() const; /**