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
This commit is contained in:
Jeff Young 2021-08-31 18:55:26 +01:00
parent 45c7ef7e76
commit e58671e2da
3 changed files with 36 additions and 2 deletions

View File

@ -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 );

View File

@ -27,6 +27,8 @@
#include <nlohmann/json.hpp>
#include <gal/color4d.h>
#include <i18n_utility.h>
#include <wx/crt.h>
#include <math/util.h>
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;

View File

@ -155,6 +155,9 @@ public:
wxString ToWxString( long flags ) const;
bool SetFromHexString( const wxString& aColorString );
wxString ToHexString() const;
wxColour ToColour() const;
/**