Eeschema: Update line syle colorbox

Line style colorbox is updated to follow Kicad colorbox
convention.  The alpha channel is also forced to opaque.
This commit is contained in:
Seth Hillbrand 2017-11-14 15:19:03 -08:00 committed by jean-pierre charras
parent 13ef1a911f
commit 634fc80916
6 changed files with 138 additions and 65 deletions

View File

@ -23,19 +23,24 @@
*/
#include <cassert>
#include <widgets/color4Dpickerdlg.h>
#include <dialog_edit_line_style.h>
const int BUTT_SIZE_X = 32;
const int BUTT_SIZE_Y = 16;
DIALOG_EDIT_LINE_STYLE::DIALOG_EDIT_LINE_STYLE( wxWindow* parent ) :
DIALOG_EDIT_LINE_STYLE_BASE( parent )
{
m_sdbSizer1Apply->SetLabel( _( "Default" ) );
m_lineStyle->SetSelection( 0 );
m_lineWidth->SetFocus();
defaultStyle = 0;
defaultWidth = "";
wxBitmap bitmap( BUTT_SIZE_X, BUTT_SIZE_Y );
m_colorButton->SetBitmap( bitmap );
m_sdbSizer1OK->SetDefault();
// Now all widgets have the size fixed, call FinishDialogSettings
@ -47,24 +52,74 @@ DIALOG_EDIT_LINE_STYLE::DIALOG_EDIT_LINE_STYLE( wxWindow* parent ) :
Raise();
}
void DIALOG_EDIT_LINE_STYLE::onColorButtonClicked( wxCommandEvent& event )
{
COLOR4D newColor = COLOR4D::UNSPECIFIED;
COLOR4D_PICKER_DLG dialog( this, selectedColor, false );
if( dialog.ShowModal() == wxID_OK )
newColor = dialog.GetColor();
if( newColor == COLOR4D::UNSPECIFIED || selectedColor == newColor )
return;
SetColor( newColor, true );
}
void DIALOG_EDIT_LINE_STYLE::updateColorButton( COLOR4D& aColor )
{
wxMemoryDC iconDC;
wxBitmap bitmap = m_colorButton->GetBitmapLabel();
iconDC.SelectObject( bitmap );
iconDC.SetPen( *wxBLACK_PEN );
wxBrush brush;
brush.SetColour( aColor.ToColour() );
brush.SetStyle( wxBRUSHSTYLE_SOLID );
iconDC.SetBrush( brush );
iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
m_colorButton->SetBitmapLabel( bitmap );
m_colorButton->Refresh();
Refresh( false );
}
void DIALOG_EDIT_LINE_STYLE::resetDefaults( wxCommandEvent& event )
{
SetStyle( defaultStyle );
SetWidth( defaultWidth );
SetColor( defaultColor );
SetColor( defaultColor, true );
Refresh();
}
void DIALOG_EDIT_LINE_STYLE::SetColor( const COLOR4D& aColor )
void DIALOG_EDIT_LINE_STYLE::SetColor( const COLOR4D& aColor, bool aRefresh )
{
assert( aColor.r >= 0.0 && aColor.r <= 1.0 );
assert( aColor.g >= 0.0 && aColor.g <= 1.0 );
assert( aColor.b >= 0.0 && aColor.b <= 1.0 );
assert( aColor.a >= 0.0 && aColor.a <= 1.0 );
m_colorPicker->SetColour( aColor.ToColour() );
selectedColor = aColor;
if( aRefresh )
updateColorButton( selectedColor );
}
void DIALOG_EDIT_LINE_STYLE::SetDefaultColor( const COLOR4D& aColor )
{
assert( aColor.r >= 0.0 && aColor.r <= 1.0 );
assert( aColor.g >= 0.0 && aColor.g <= 1.0 );
assert( aColor.b >= 0.0 && aColor.b <= 1.0 );
assert( aColor.a >= 0.0 && aColor.a <= 1.0 );
defaultColor = aColor;
}

View File

@ -34,6 +34,7 @@
#include <dialog_edit_line_style_base.h>
#include <sch_line.h>
class WIDGET_EESCHEMA_COLOR_CONFIG;
class DIALOG_EDIT_LINE_STYLE : public DIALOG_EDIT_LINE_STYLE_BASE
{
@ -44,9 +45,9 @@ public:
void SetDefaultWidth( const wxString& aWidth ) { defaultWidth = aWidth; }
wxString GetWidth() const { return m_lineWidth->GetValue(); }
COLOR4D GetColor() const { return COLOR4D( m_colorPicker->GetColour() ); }
void SetColor( const COLOR4D& aColor );
void SetDefaultColor( const COLOR4D& aColor ) { defaultColor = aColor; }
COLOR4D GetColor() const { return selectedColor; }
void SetColor( const COLOR4D& aColor, bool aRefresh );
void SetDefaultColor( const COLOR4D& aColor );
void SetStyle( const int aStyle );
void SetDefaultStyle( const int aStyle ) { defaultStyle = aStyle; }
@ -56,12 +57,16 @@ public:
{
m_staticWidthUnits->SetLabel( aUnits );
}
private:
int defaultStyle;
wxString defaultWidth;
COLOR4D defaultColor;
COLOR4D selectedColor;
void resetDefaults( wxCommandEvent& event ) override;
void onColorButtonClicked( wxCommandEvent& aEvent ) override;
void updateColorButton( COLOR4D& aColor );
};
#endif // __dialog_edit_line_style__

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Nov 9 2017)
// C++ code generated with wxFormBuilder (version Oct 30 2017)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -10,6 +10,7 @@
///////////////////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE( DIALOG_EDIT_LINE_STYLE_BASE, DIALOG_SHIM )
EVT_BUTTON( idColorBtn, DIALOG_EDIT_LINE_STYLE_BASE::_wxFB_onColorButtonClicked )
EVT_BUTTON( wxID_APPLY, DIALOG_EDIT_LINE_STYLE_BASE::_wxFB_resetDefaults )
END_EVENT_TABLE()
@ -36,51 +37,43 @@ DIALOG_EDIT_LINE_STYLE_BASE::DIALOG_EDIT_LINE_STYLE_BASE( wxWindow* parent, wxWi
m_staticWidth1->Wrap( -1 );
bSizer31->Add( m_staticWidth1, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_lineWidth = new wxTextCtrl( sbSizer1->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
#ifdef __WXGTK__
if ( !m_lineWidth->HasFlag( wxTE_MULTILINE ) )
{
m_lineWidth->SetMaxLength( 6 );
}
#else
m_lineWidth->SetMaxLength( 6 );
#endif
bSizer31->Add( m_lineWidth, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_lineWidth = new wxTextCtrl( sbSizer1->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 2,-1 ), 0 );
bSizer31->Add( m_lineWidth, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
m_staticWidthUnits = new wxStaticText( sbSizer1->GetStaticBox(), wxID_ANY, _("millimeter"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticWidthUnits->Wrap( -1 );
bSizer31->Add( m_staticWidthUnits, 1, wxALIGN_CENTER_VERTICAL|wxALL, 3 );
bSizer31->Add( m_staticWidthUnits, 1, wxALIGN_CENTER_VERTICAL|wxALL, 1 );
sbSizer1->Add( bSizer31, 0, wxALL|wxEXPAND, 1 );
sbSizer1->Add( bSizer31, 4, wxALL|wxEXPAND, 1 );
wxBoxSizer* bSizer5;
bSizer5 = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* bColorSizer;
bColorSizer = new wxBoxSizer( wxHORIZONTAL );
m_staticText5 = new wxStaticText( sbSizer1->GetStaticBox(), wxID_ANY, _("C&olor:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText5->Wrap( -1 );
bSizer5->Add( m_staticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
bColorSizer->Add( m_staticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_colorPicker = new wxColourPickerCtrl( sbSizer1->GetStaticBox(), wxID_ANY, wxColour( 0, 0, 0 ), wxDefaultPosition, wxDefaultSize, wxCLRP_DEFAULT_STYLE );
bSizer5->Add( m_colorPicker, 0, wxALL, 5 );
m_colorButton = new wxBitmapButton( sbSizer1->GetStaticBox(), idColorBtn, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
bColorSizer->Add( m_colorButton, 1, wxALL, 5 );
bSizer5->Add( 0, 0, 1, wxEXPAND, 5 );
bColorSizer->Add( 0, 0, 1, 0, 1 );
sbSizer1->Add( bSizer5, 0, wxEXPAND|wxALL, 1 );
sbSizer1->Add( bColorSizer, 3, wxEXPAND|wxALL, 1 );
bSizer7->Add( sbSizer1, 3, wxALL|wxEXPAND, 5 );
bSizer7->Add( sbSizer1, 2, wxALL, 5 );
wxString m_lineStyleChoices[] = { _("Solid"), _("Dashed"), _("Dotted"), _("Dash-Dot") };
int m_lineStyleNChoices = sizeof( m_lineStyleChoices ) / sizeof( wxString );
m_lineStyle = new wxRadioBox( this, wxID_ANY, _("&Pen Style"), wxDefaultPosition, wxDefaultSize, m_lineStyleNChoices, m_lineStyleChoices, 4, wxRA_SPECIFY_ROWS );
m_lineStyle->SetSelection( 1 );
bSizer7->Add( m_lineStyle, 2, wxALL|wxEXPAND, 5 );
m_lineStyle->SetSelection( 0 );
bSizer7->Add( m_lineStyle, 1, wxALL, 5 );
dlgBorderSizer->Add( bSizer7, 1, wxEXPAND, 5 );
dlgBorderSizer->Add( bSizer7, 0, wxEXPAND, 5 );
dlgBorderSizer->Add( 0, 0, 0, wxALL|wxEXPAND, 1 );

View File

@ -44,7 +44,7 @@
<property name="minimum_size"></property>
<property name="name">DIALOG_EDIT_LINE_STYLE_BASE</property>
<property name="pos"></property>
<property name="size">399,230</property>
<property name="size">410,230</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">Line Style</property>
@ -105,7 +105,7 @@
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer7</property>
@ -113,8 +113,8 @@
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">3</property>
<property name="flag">wxALL</property>
<property name="proportion">2</property>
<object class="wxStaticBoxSizer" expanded="1">
<property name="id">wxID_ANY</property>
<property name="label">General</property>
@ -124,11 +124,11 @@
<property name="parent">1</property>
<property name="permission">none</property>
<event name="OnUpdateUI"></event>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">1</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="0">
<property name="proportion">4</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer31</property>
<property name="orient">wxHORIZONTAL</property>
@ -219,7 +219,7 @@
<object class="sizeritem" expanded="0">
<property name="border">3</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL</property>
<property name="proportion">0</property>
<property name="proportion">1</property>
<object class="wxTextCtrl" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
@ -251,7 +251,7 @@
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="maxlength">6</property>
<property name="maxlength">0</property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
@ -265,7 +265,7 @@
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="size">2,-1</property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
@ -308,7 +308,7 @@
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">3</property>
<property name="border">1</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL</property>
<property name="proportion">1</property>
<object class="wxStaticText" expanded="0">
@ -395,10 +395,10 @@
<object class="sizeritem" expanded="1">
<property name="border">1</property>
<property name="flag">wxEXPAND|wxALL</property>
<property name="proportion">0</property>
<property name="proportion">3</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizer5</property>
<property name="name">bColorSizer</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="0">
@ -484,11 +484,11 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxColourPickerCtrl" expanded="0">
<property name="proportion">1</property>
<object class="wxBitmapButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -499,24 +499,29 @@
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap">Load From File; </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="colour">0,0,0</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></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="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="hover"></property>
<property name="id">idColorBtn</property>
<property name="label">MyButton</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
@ -524,7 +529,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_colorPicker</property>
<property name="name">m_colorButton</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -532,9 +537,10 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="selected"></property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxCLRP_DEFAULT_STYLE</property>
<property name="style">wxBU_AUTODRAW</property>
<property name="subclass">; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
@ -545,8 +551,8 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">onColorButtonClicked</event>
<event name="OnChar"></event>
<event name="OnColourChanged"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
@ -572,8 +578,8 @@
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="border">1</property>
<property name="flag"></property>
<property name="proportion">1</property>
<object class="spacer" expanded="0">
<property name="height">0</property>
@ -587,8 +593,8 @@
</object>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">2</property>
<property name="flag">wxALL</property>
<property name="proportion">1</property>
<object class="wxRadioBox" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
@ -635,7 +641,7 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="selection">1</property>
<property name="selection">0</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxRA_SPECIFY_ROWS</property>

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Nov 9 2017)
// C++ code generated with wxFormBuilder (version Oct 30 2017)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -20,10 +20,13 @@
#include <wx/settings.h>
#include <wx/textctrl.h>
#include <wx/sizer.h>
#include <wx/clrpicker.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/bmpbuttn.h>
#include <wx/button.h>
#include <wx/statbox.h>
#include <wx/radiobox.h>
#include <wx/button.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
@ -37,15 +40,21 @@ class DIALOG_EDIT_LINE_STYLE_BASE : public DIALOG_SHIM
private:
// Private event handlers
void _wxFB_onColorButtonClicked( wxCommandEvent& event ){ onColorButtonClicked( event ); }
void _wxFB_resetDefaults( wxCommandEvent& event ){ resetDefaults( event ); }
protected:
enum
{
idColorBtn = 1000
};
wxStaticText* m_staticWidth1;
wxTextCtrl* m_lineWidth;
wxStaticText* m_staticWidthUnits;
wxStaticText* m_staticText5;
wxColourPickerCtrl* m_colorPicker;
wxBitmapButton* m_colorButton;
wxRadioBox* m_lineStyle;
wxStdDialogButtonSizer* m_sdbSizer1;
wxButton* m_sdbSizer1OK;
@ -53,13 +62,14 @@ class DIALOG_EDIT_LINE_STYLE_BASE : public DIALOG_SHIM
wxButton* m_sdbSizer1Cancel;
// Virtual event handlers, overide them in your derived class
virtual void onColorButtonClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void resetDefaults( wxCommandEvent& event ) { event.Skip(); }
public:
bool m_isValid;
DIALOG_EDIT_LINE_STYLE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Line Style"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 399,230 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
DIALOG_EDIT_LINE_STYLE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Line Style"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 410,230 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_EDIT_LINE_STYLE_BASE();
};

View File

@ -237,10 +237,14 @@ void SCH_LINE::SetLineColor( const double r, const double g, const double b, con
{
COLOR4D newColor(r, g, b, a);
if( newColor == GetDefaultColor() )
if( newColor == GetDefaultColor() || newColor == COLOR4D::UNSPECIFIED )
m_color = COLOR4D::UNSPECIFIED;
else
{
// Eeschema does not allow alpha channel in colors
newColor.a = 1.0;
m_color = newColor;
}
}
@ -742,7 +746,7 @@ int SCH_EDIT_FRAME::EditLine( SCH_LINE* aLine, bool aRedraw )
dlg.SetWidth( StringFromValue( g_UserUnit, old_width, false ) );
dlg.SetStyle( old_style );
dlg.SetLineWidthUnits( units );
dlg.SetColor( old_color );
dlg.SetColor( old_color, true );
dlg.Layout();
dlg.Fit();