Add text field for color definitions.

You can enter HTML notation, CSS 3-value notation (rgb), or CSS
4-value notation (rgba).  It will always print rgba.

Fixes https://gitlab.com/kicad/code/kicad/issues/4016
This commit is contained in:
Jeff Young 2020-05-15 00:17:05 +01:00
parent c7f0f0b844
commit 37adf7d3d5
5 changed files with 122 additions and 7 deletions

View File

@ -530,7 +530,7 @@ void DIALOG_COLOR_PICKER::SetEditVals( CHANGED_COLOR aChanged, bool aCheckTransp
if( aCheckTransparency )
{
// If they've changed the color, they probably don't want it to remain 100% transparent,
// and it looks like a bug when it changing the color has no effect.
// and it looks like a bug when changing the color has no effect.
if( m_newColor4D.a == 0.0 )
m_newColor4D.a = 1.0;
}
@ -556,9 +556,10 @@ void DIALOG_COLOR_PICKER::SetEditVals( CHANGED_COLOR aChanged, bool aCheckTransp
m_spinCtrlSaturation->SetValue( m_sat * 255 );
if( aChanged != VAL_CHANGED )
{
m_sliderBrightness->SetValue(normalizeToInt( m_val ) );
}
if( aChanged != HEX_CHANGED )
m_colorValue->SetValue( m_newColor4D.ToWxString( wxC2S_CSS_SYNTAX ) );
}
@ -714,6 +715,16 @@ void DIALOG_COLOR_PICKER::onHSVMouseDrag( wxMouseEvent& event )
}
void DIALOG_COLOR_PICKER::OnColorValueText( wxCommandEvent& event )
{
m_newColor4D.SetFromWxString( m_colorValue->GetValue() );
m_newColor4D.ToHSV( m_hue, m_sat, m_val, true );
SetEditVals( HEX_CHANGED, true );
drawAll();
}
bool DIALOG_COLOR_PICKER::setHSvaluesFromCursor( wxPoint aMouseCursor )
{
wxPoint mousePos = aMouseCursor;

View File

@ -62,6 +62,7 @@ enum CHANGED_COLOR
HUE_CHANGED,
SAT_CHANGED,
VAL_CHANGED,
HEX_CHANGED
};
class DIALOG_COLOR_PICKER : public DIALOG_COLOR_PICKER_BASE
@ -148,6 +149,8 @@ private:
void onHSVMouseClick( wxMouseEvent& event ) override;
void onHSVMouseDrag( wxMouseEvent& event ) override;
void OnColorValueText( wxCommandEvent& event ) override;
///< Event handler for the reset button press
void OnResetButton( wxCommandEvent& aEvent ) override;

View File

@ -182,7 +182,7 @@ DIALOG_COLOR_PICKER_BASE::DIALOG_COLOR_PICKER_BASE( wxWindow* parent, wxWindowID
wxBoxSizer* bButtonsSizer;
bButtonsSizer = new wxBoxSizer( wxHORIZONTAL );
m_staticTextOldColor = new wxStaticText( this, wxID_ANY, _("Preview (old / new):"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextOldColor = new wxStaticText( this, wxID_ANY, _("Preview (old/new):"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextOldColor->Wrap( -1 );
bButtonsSizer->Add( m_staticTextOldColor, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
@ -196,8 +196,19 @@ DIALOG_COLOR_PICKER_BASE::DIALOG_COLOR_PICKER_BASE( wxWindow* parent, wxWindowID
bButtonsSizer->Add( m_NewColorRect, 0, wxALIGN_CENTER_VERTICAL, 5 );
bButtonsSizer->Add( 10, 0, 0, wxEXPAND, 5 );
m_colorValue = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_colorValue->SetMinSize( wxSize( 176,-1 ) );
bButtonsSizer->Add( m_colorValue, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
bButtonsSizer->Add( 20, 0, 0, wxEXPAND, 5 );
m_resetToDefault = new wxButton( this, wxID_ANY, _("Reset to Default"), wxDefaultPosition, wxDefaultSize, 0 );
bButtonsSizer->Add( m_resetToDefault, 0, wxALL, 5 );
bButtonsSizer->Add( m_resetToDefault, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_sdbSizer = new wxStdDialogButtonSizer();
m_sdbSizerOK = new wxButton( this, wxID_OK );
@ -246,6 +257,7 @@ DIALOG_COLOR_PICKER_BASE::DIALOG_COLOR_PICKER_BASE( wxWindow* parent, wxWindowID
m_sliderTransparency->Connect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( DIALOG_COLOR_PICKER_BASE::OnChangeAlpha ), NULL, this );
m_sliderTransparency->Connect( wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler( DIALOG_COLOR_PICKER_BASE::OnChangeAlpha ), NULL, this );
m_sliderTransparency->Connect( wxEVT_SCROLL_CHANGED, wxScrollEventHandler( DIALOG_COLOR_PICKER_BASE::OnChangeAlpha ), NULL, this );
m_colorValue->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_COLOR_PICKER_BASE::OnColorValueText ), NULL, this );
m_resetToDefault->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COLOR_PICKER_BASE::OnResetButton ), NULL, this );
}
@ -279,6 +291,7 @@ DIALOG_COLOR_PICKER_BASE::~DIALOG_COLOR_PICKER_BASE()
m_sliderTransparency->Disconnect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( DIALOG_COLOR_PICKER_BASE::OnChangeAlpha ), NULL, this );
m_sliderTransparency->Disconnect( wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler( DIALOG_COLOR_PICKER_BASE::OnChangeAlpha ), NULL, this );
m_sliderTransparency->Disconnect( wxEVT_SCROLL_CHANGED, wxScrollEventHandler( DIALOG_COLOR_PICKER_BASE::OnChangeAlpha ), NULL, this );
m_colorValue->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_COLOR_PICKER_BASE::OnColorValueText ), NULL, this );
m_resetToDefault->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COLOR_PICKER_BASE::OnResetButton ), NULL, this );
}

View File

@ -1493,7 +1493,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Preview (old / new):</property>
<property name="label">Preview (old/new):</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
@ -1640,7 +1640,92 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="spacer" expanded="1">
<property name="height">0</property>
<property name="permission">protected</property>
<property name="width">10</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxTextCtrl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="maxlength"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size">176,-1</property>
<property name="moveable">1</property>
<property name="name">m_colorValue</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnText">OnColorValueText</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="spacer" expanded="1">
<property name="height">0</property>
<property name="permission">protected</property>
<property name="width">20</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxALIGN_CENTER_VERTICAL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>

View File

@ -28,6 +28,7 @@
#include <wx/panel.h>
#include <wx/notebook.h>
#include <wx/statline.h>
#include <wx/textctrl.h>
#include <wx/button.h>
#include <wx/dialog.h>
@ -68,6 +69,7 @@ class DIALOG_COLOR_PICKER_BASE : public DIALOG_SHIM
wxStaticText* m_staticTextOldColor;
wxStaticBitmap* m_OldColorRect;
wxStaticBitmap* m_NewColorRect;
wxTextCtrl* m_colorValue;
wxButton* m_resetToDefault;
wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK;
@ -85,6 +87,7 @@ class DIALOG_COLOR_PICKER_BASE : public DIALOG_SHIM
virtual void OnChangeEditSat( wxSpinEvent& event ) { event.Skip(); }
virtual void OnChangeBrightness( wxScrollEvent& event ) { event.Skip(); }
virtual void OnChangeAlpha( wxScrollEvent& event ) { event.Skip(); }
virtual void OnColorValueText( wxCommandEvent& event ) { event.Skip(); }
virtual void OnResetButton( wxCommandEvent& event ) { event.Skip(); }