From 03a2723b6706f73d7e753e5ac42b707fa8a03278 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 16 Dec 2021 18:04:59 +0000 Subject: [PATCH] Improve GUI of lib item colors. --- common/widgets/color_swatch.cpp | 2 +- .../dialogs/dialog_lib_shape_properties.cpp | 92 +++- .../dialogs/dialog_lib_shape_properties.h | 4 + .../dialog_lib_shape_properties_base.cpp | 44 +- .../dialog_lib_shape_properties_base.fbp | 401 +++++++++++++----- .../dialog_lib_shape_properties_base.h | 34 +- eeschema/sch_painter.cpp | 5 +- 7 files changed, 451 insertions(+), 131 deletions(-) diff --git a/common/widgets/color_swatch.cpp b/common/widgets/color_swatch.cpp index 11e230b594..bab2c2b628 100644 --- a/common/widgets/color_swatch.cpp +++ b/common/widgets/color_swatch.cpp @@ -222,7 +222,7 @@ void COLOR_SWATCH::rePostEvent( wxEvent& aEvent ) static void sendSwatchChangeEvent( COLOR_SWATCH& aSender ) { - wxCommandEvent changeEvt( COLOR_SWATCH_CHANGED ); + wxCommandEvent changeEvt( COLOR_SWATCH_CHANGED, aSender.GetId() ); // use this class as the object (alternative might be to // set a custom event class but that's more work) diff --git a/eeschema/dialogs/dialog_lib_shape_properties.cpp b/eeschema/dialogs/dialog_lib_shape_properties.cpp index 0c21649060..efc2ae9858 100644 --- a/eeschema/dialogs/dialog_lib_shape_properties.cpp +++ b/eeschema/dialogs/dialog_lib_shape_properties.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include DIALOG_LIB_SHAPE_PROPERTIES::DIALOG_LIB_SHAPE_PROPERTIES( SYMBOL_EDIT_FRAME* aParent, LIB_ITEM* aItem ) : @@ -37,6 +39,8 @@ DIALOG_LIB_SHAPE_PROPERTIES::DIALOG_LIB_SHAPE_PROPERTIES( SYMBOL_EDIT_FRAME* aPa SetTitle( aItem->GetTypeName() + wxT( " " ) + GetTitle() ); m_helpLabel->SetFont( KIUI::GetInfoFont( this ).Italic() ); + m_colorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED ); + SetInitialFocus( m_widthCtrl ); // Required under wxGTK if we want to dismiss the dialog with the ESC key @@ -51,11 +55,7 @@ DIALOG_LIB_SHAPE_PROPERTIES::DIALOG_LIB_SHAPE_PROPERTIES( SYMBOL_EDIT_FRAME* aPa m_sdbSizerOK->Enable( false ); } - m_fillCtrl->Bind( wxEVT_RADIOBOX, - [this]( wxEvent& ) - { - m_fillColorSizer->Show( m_fillCtrl->GetSelection() == 3 ); - } ); + m_colorSwatch->Bind( COLOR_SWATCH_CHANGED, &DIALOG_LIB_SHAPE_PROPERTIES::onSwatch, this ); // Now all widgets have the size fixed, call FinishDialogSettings finishDialogSettings(); @@ -88,19 +88,76 @@ bool DIALOG_LIB_SHAPE_PROPERTIES::TransferDataToWindow() m_checkApplyToAllConversions->Enable( enblConvOptStyle ); - if( shape ) + m_rbFillNone->Enable( shape != nullptr ); + m_rbFillOutline->Enable( shape != nullptr ); + m_rbFillBackground->Enable( shape != nullptr ); + m_rbFillCustom->Enable( shape != nullptr ); + m_colorSwatch->Enable( shape != nullptr ); + + if( shape && shape->GetFillMode() == FILL_T::FILLED_SHAPE ) { - m_fillCtrl->SetSelection( static_cast( shape->GetFillMode() ) - 1 ); - m_fillColorPicker->SetColour( shape->GetFillColor().ToColour() ); - m_fillColorSizer->Show( shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR ); + m_rbFillOutline->SetValue( true ); + + COLOR4D color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE ); + m_colorSwatch->SetSwatchColor( color, false ); + } + else if( shape && shape->GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR ) + { + m_rbFillBackground->SetValue( true ); + + COLOR4D color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE_BACKGROUND ); + m_colorSwatch->SetSwatchColor( color, false ); + } + else if( shape && shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR ) + { + m_rbFillCustom->SetValue( true ); + m_colorSwatch->SetSwatchColor( shape->GetFillColor(), false ); + } + else + { + m_rbFillNone->SetValue( true ); + m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false ); } - m_fillCtrl->Enable( shape != nullptr ); - return true; } +void DIALOG_LIB_SHAPE_PROPERTIES::onFill( wxCommandEvent& event ) +{ + if( event.GetId() == NO_FILL ) + { + m_rbFillNone->SetValue( true ); + m_colorSwatch->SetSwatchColor( COLOR4D::UNSPECIFIED, false ); + } + else if( event.GetId() == FILLED_SHAPE ) + { + m_rbFillOutline->SetValue( true ); + + COLOR4D color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE ); + m_colorSwatch->SetSwatchColor( color, false ); + } + else if( event.GetId() == FILLED_WITH_BG_BODYCOLOR ) + { + m_rbFillBackground->SetValue( true ); + + COLOR4D color = m_frame->GetRenderSettings()->GetLayerColor( LAYER_DEVICE_BACKGROUND ); + m_colorSwatch->SetSwatchColor( color, false ); + } + else if( event.GetId() == FILLED_WITH_COLOR ) + { + m_rbFillCustom->SetValue( true ); + m_colorSwatch->GetNewSwatchColor(); + } +} + + +void DIALOG_LIB_SHAPE_PROPERTIES::onSwatch( wxCommandEvent& aEvent ) +{ + m_rbFillCustom->SetValue( true ); +} + + bool DIALOG_LIB_SHAPE_PROPERTIES::TransferDataFromWindow() { if( !wxDialog::TransferDataFromWindow() ) @@ -110,9 +167,16 @@ bool DIALOG_LIB_SHAPE_PROPERTIES::TransferDataFromWindow() if( shape ) { - FILL_T fill = static_cast( std::max( m_fillCtrl->GetSelection() + 1, 1 ) ); - shape->SetFillMode( fill ); - shape->SetFillColor( static_cast(m_fillColorPicker->GetColour() ) ); + if( m_rbFillOutline->GetValue() ) + shape->SetFillMode( FILL_T::FILLED_SHAPE ); + else if( m_rbFillBackground->GetValue() ) + shape->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR ); + else if( m_rbFillCustom->GetValue() ) + shape->SetFillMode( FILL_T::FILLED_WITH_COLOR ); + else + shape->SetFillMode( FILL_T::NO_FILL ); + + shape->SetFillColor( m_colorSwatch->GetSwatchColor() ); STROKE_PARAMS stroke = shape->GetStroke(); stroke.SetWidth( m_lineWidth.GetValue() ); diff --git a/eeschema/dialogs/dialog_lib_shape_properties.h b/eeschema/dialogs/dialog_lib_shape_properties.h index 40df9d96bd..7b793df58a 100644 --- a/eeschema/dialogs/dialog_lib_shape_properties.h +++ b/eeschema/dialogs/dialog_lib_shape_properties.h @@ -48,6 +48,10 @@ public: bool GetApplyToAllConversions(); bool GetApplyToAllUnits(); +private: + void onFill(wxCommandEvent &event) override; + void onSwatch( wxCommandEvent& aEvent ); + private: SYMBOL_EDIT_FRAME* m_frame; LIB_ITEM* m_item; diff --git a/eeschema/dialogs/dialog_lib_shape_properties_base.cpp b/eeschema/dialogs/dialog_lib_shape_properties_base.cpp index 8c5f6dfbd5..910d71416b 100644 --- a/eeschema/dialogs/dialog_lib_shape_properties_base.cpp +++ b/eeschema/dialogs/dialog_lib_shape_properties_base.cpp @@ -1,14 +1,23 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// +#include "widgets/color_swatch.h" + #include "dialog_lib_shape_properties_base.h" /////////////////////////////////////////////////////////////////////////// +BEGIN_EVENT_TABLE( DIALOG_LIB_SHAPE_PROPERTIES_BASE, DIALOG_SHIM ) + EVT_RADIOBUTTON( NO_FILL, DIALOG_LIB_SHAPE_PROPERTIES_BASE::_wxFB_onFill ) + EVT_RADIOBUTTON( FILLED_SHAPE, DIALOG_LIB_SHAPE_PROPERTIES_BASE::_wxFB_onFill ) + EVT_RADIOBUTTON( FILLED_WITH_BG_BODYCOLOR, DIALOG_LIB_SHAPE_PROPERTIES_BASE::_wxFB_onFill ) + EVT_RADIOBUTTON( FILLED_WITH_COLOR, DIALOG_LIB_SHAPE_PROPERTIES_BASE::_wxFB_onFill ) +END_EVENT_TABLE() + DIALOG_LIB_SHAPE_PROPERTIES_BASE::DIALOG_LIB_SHAPE_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); @@ -40,25 +49,34 @@ DIALOG_LIB_SHAPE_PROPERTIES_BASE::DIALOG_LIB_SHAPE_PROPERTIES_BASE( wxWindow* pa m_helpLabel->Wrap( 333 ); dlgBorderSizer->Add( m_helpLabel, 0, wxALL, 5 ); - wxBoxSizer* bSizer4; - bSizer4 = new wxBoxSizer( wxHORIZONTAL ); + wxStaticBoxSizer* bSizerFill; + bSizerFill = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Fill Style") ), wxVERTICAL ); - wxString m_fillCtrlChoices[] = { _("Do not fill"), _("Fill with body outline color"), _("Fill with body background color"), _("Fill with custom color") }; - int m_fillCtrlNChoices = sizeof( m_fillCtrlChoices ) / sizeof( wxString ); - m_fillCtrl = new wxRadioBox( this, wxID_ANY, _("Fill Style"), wxDefaultPosition, wxDefaultSize, m_fillCtrlNChoices, m_fillCtrlChoices, 1, wxRA_SPECIFY_COLS ); - m_fillCtrl->SetSelection( 0 ); - bSizer4->Add( m_fillCtrl, 0, wxEXPAND|wxTOP|wxBOTTOM, 10 ); + wxGridBagSizer* gbSizer1; + gbSizer1 = new wxGridBagSizer( 3, 0 ); + gbSizer1->SetFlexibleDirection( wxBOTH ); + gbSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - m_fillColorSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Fill Color") ), wxVERTICAL ); + m_rbFillNone = new wxRadioButton( bSizerFill->GetStaticBox(), NO_FILL, _("Do not fill"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP ); + gbSizer1->Add( m_rbFillNone, wxGBPosition( 0, 0 ), wxGBSpan( 1, 2 ), wxALIGN_CENTER_VERTICAL, 5 ); - m_fillColorPicker = new wxColourPickerCtrl( m_fillColorSizer->GetStaticBox(), wxID_ANY, *wxBLACK, wxDefaultPosition, wxDefaultSize, wxCLRP_DEFAULT_STYLE ); - m_fillColorSizer->Add( m_fillColorPicker, 0, wxALL|wxEXPAND, 5 ); + m_rbFillOutline = new wxRadioButton( bSizerFill->GetStaticBox(), FILLED_SHAPE, _("Fill with body outline color"), wxDefaultPosition, wxDefaultSize, 0 ); + gbSizer1->Add( m_rbFillOutline, wxGBPosition( 1, 0 ), wxGBSpan( 1, 2 ), wxALIGN_CENTER_VERTICAL, 5 ); + + m_rbFillBackground = new wxRadioButton( bSizerFill->GetStaticBox(), FILLED_WITH_BG_BODYCOLOR, _("Fill with body background color"), wxDefaultPosition, wxDefaultSize, 0 ); + gbSizer1->Add( m_rbFillBackground, wxGBPosition( 2, 0 ), wxGBSpan( 1, 2 ), wxALIGN_CENTER_VERTICAL, 5 ); + + m_rbFillCustom = new wxRadioButton( bSizerFill->GetStaticBox(), FILLED_WITH_COLOR, _("Fill with:"), wxDefaultPosition, wxDefaultSize, 0 ); + gbSizer1->Add( m_rbFillCustom, wxGBPosition( 3, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); + + m_colorSwatch = new COLOR_SWATCH( bSizerFill->GetStaticBox(), FILLED_WITH_COLOR, wxDefaultPosition, wxDefaultSize, 0 ); + gbSizer1->Add( m_colorSwatch, wxGBPosition( 3, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); - bSizer4->Add( m_fillColorSizer, 1, wxBOTTOM|wxEXPAND|wxLEFT|wxTOP, 10 ); + bSizerFill->Add( gbSizer1, 1, wxEXPAND|wxBOTTOM, 5 ); - dlgBorderSizer->Add( bSizer4, 1, wxEXPAND, 5 ); + dlgBorderSizer->Add( bSizerFill, 0, wxEXPAND|wxTOP|wxBOTTOM, 5 ); m_checkApplyToAllUnits = new wxCheckBox( this, wxID_ANY, _("Common to all &units in symbol"), wxDefaultPosition, wxDefaultSize, 0 ); dlgBorderSizer->Add( m_checkApplyToAllUnits, 0, wxALL, 3 ); diff --git a/eeschema/dialogs/dialog_lib_shape_properties_base.fbp b/eeschema/dialogs/dialog_lib_shape_properties_base.fbp index 0d710c9f7c..de65eeb1f5 100644 --- a/eeschema/dialogs/dialog_lib_shape_properties_base.fbp +++ b/eeschema/dialogs/dialog_lib_shape_properties_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,7 +14,6 @@ dialog_lib_shape_properties_base 1000 none - 1 dialog_lib_shape_properties @@ -26,7 +25,6 @@ 1 1 UI - 0 1 0 @@ -52,20 +50,19 @@ DIALOG_SHIM; dialog_shim.h Drawing Properties - 0 - + mainSizer wxVERTICAL none - + 10 wxALL|wxEXPAND 1 - + dlgBorderSizer wxVERTICAL @@ -330,96 +327,39 @@ 5 - wxEXPAND - 1 - + wxEXPAND|wxTOP|wxBOTTOM + 0 + + wxID_ANY + Fill Style - bSizer4 - wxHORIZONTAL + bSizerFill + wxVERTICAL + 1 none - - 10 - wxEXPAND|wxTOP|wxBOTTOM - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - "Do not fill" "Fill with body outline color" "Fill with body background color" "Fill with custom color" - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Fill Style - 1 - - 0 - - - 0 - - 1 - m_fillCtrl - 1 - - - protected - 1 - - Resizable - 0 - 1 - - wxRA_SPECIFY_COLS - ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - 10 - wxBOTTOM|wxEXPAND|wxLEFT|wxTOP + 5 + wxEXPAND|wxBOTTOM 1 - - wxID_ANY - Fill Color + + + wxBOTH + + + 0 - m_fillColorSizer - wxVERTICAL - 1 - protected - + gbSizer1 + wxFLEX_GROWMODE_SPECIFIED + none + 3 + 5 - wxALL|wxEXPAND - 0 - + 2 + 0 + wxALIGN_CENTER_VERTICAL + 0 + 1 + 1 1 1 @@ -434,7 +374,6 @@ 1 0 1 - 1 0 @@ -447,7 +386,8 @@ 0 0 - wxID_ANY + NO_FILL + Do not fill 0 @@ -455,7 +395,7 @@ 0 1 - m_fillColorPicker + m_rbFillNone 1 @@ -465,7 +405,7 @@ Resizable 1 - wxCLRP_DEFAULT_STYLE + wxRB_GROUP ; ; forward_declare 0 @@ -473,6 +413,277 @@ wxFILTER_NONE wxDefaultValidator + 0 + + + + onFill + + + + 5 + 2 + 0 + wxALIGN_CENTER_VERTICAL + 1 + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + FILLED_SHAPE + Fill with body outline color + + 0 + + + 0 + + 1 + m_rbFillOutline + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + onFill + + + + 5 + 2 + 0 + wxALIGN_CENTER_VERTICAL + 2 + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + FILLED_WITH_BG_BODYCOLOR + Fill with body background color + + 0 + + + 0 + + 1 + m_rbFillBackground + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + onFill + + + + 5 + 1 + 0 + wxALIGN_CENTER_VERTICAL + 3 + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + FILLED_WITH_COLOR + Fill with: + + 0 + + + 0 + + 1 + m_rbFillCustom + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + onFill + + + + 5 + 1 + 1 + wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT + 3 + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + COLOR_SWATCH + 1 + + + 1 + + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + FILLED_WITH_COLOR + + + 0 + + + 0 + + 1 + m_colorSwatch + 1 + + + protected + 1 + + Resizable + + 1 + + COLOR_SWATCH; widgets/color_swatch.h; forward_declare + 0 + diff --git a/eeschema/dialogs/dialog_lib_shape_properties_base.h b/eeschema/dialogs/dialog_lib_shape_properties_base.h index f88054e7d7..04feed965b 100644 --- a/eeschema/dialogs/dialog_lib_shape_properties_base.h +++ b/eeschema/dialogs/dialog_lib_shape_properties_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -10,6 +10,8 @@ #include #include #include +class COLOR_SWATCH; + #include "dialog_shim.h" #include #include @@ -19,8 +21,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -34,16 +36,31 @@ /////////////////////////////////////////////////////////////////////////////// class DIALOG_LIB_SHAPE_PROPERTIES_BASE : public DIALOG_SHIM { + DECLARE_EVENT_TABLE() private: + // Private event handlers + void _wxFB_onFill( wxCommandEvent& event ){ onFill( event ); } + + protected: + enum + { + NO_FILL = 1000, + FILLED_SHAPE, + FILLED_WITH_BG_BODYCOLOR, + FILLED_WITH_COLOR + }; + wxStaticText* m_widthLabel; wxTextCtrl* m_widthCtrl; wxStaticText* m_widthUnits; wxStaticText* m_helpLabel; - wxRadioBox* m_fillCtrl; - wxStaticBoxSizer* m_fillColorSizer; - wxColourPickerCtrl* m_fillColorPicker; + wxRadioButton* m_rbFillNone; + wxRadioButton* m_rbFillOutline; + wxRadioButton* m_rbFillBackground; + wxRadioButton* m_rbFillCustom; + COLOR_SWATCH* m_colorSwatch; wxCheckBox* m_checkApplyToAllUnits; wxCheckBox* m_checkApplyToAllConversions; wxStaticLine* m_staticline; @@ -51,10 +68,13 @@ class DIALOG_LIB_SHAPE_PROPERTIES_BASE : public DIALOG_SHIM wxButton* m_sdbSizerOK; wxButton* m_sdbSizerCancel; + // Virtual event handlers, overide them in your derived class + virtual void onFill( wxCommandEvent& event ) { event.Skip(); } + + public: DIALOG_LIB_SHAPE_PROPERTIES_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Drawing Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); - ~DIALOG_LIB_SHAPE_PROPERTIES_BASE(); }; diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 665a3bccee..3bb8524138 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -528,7 +528,10 @@ bool SCH_PAINTER::setDeviceColors( const LIB_ITEM* aItem, int aLayer ) if( shape ) { COLOR4D fillColor; - if( shape->GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR ) + + if( shape->GetFillMode() == FILL_T::FILLED_SHAPE ) + fillColor = getRenderColor( aItem, LAYER_DEVICE, false ); + else if( shape->GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR ) fillColor = getRenderColor( aItem, LAYER_DEVICE_BACKGROUND, false ); else if( shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR ) fillColor = shape->GetFillColor();