Loading pcbnew/layer_panel_base.cpp +1 −3 Original line number Original line Diff line number Diff line Loading @@ -11,8 +11,6 @@ LAYER_PANEL_BASE::LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style ) LAYER_PANEL_BASE::LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style ) { { this->SetMinSize( wxSize( 100,100 ) ); wxBoxSizer* boxSizer; wxBoxSizer* boxSizer; boxSizer = new wxBoxSizer( wxVERTICAL ); boxSizer = new wxBoxSizer( wxVERTICAL ); Loading Loading @@ -42,7 +40,7 @@ LAYER_PANEL_BASE::LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id, const wxPoi m_RenderScrolledWindow = new wxScrolledWindow( m_RenderingPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxVSCROLL ); m_RenderScrolledWindow = new wxScrolledWindow( m_RenderingPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxVSCROLL ); m_RenderScrolledWindow->SetScrollRate( 5, 5 ); m_RenderScrolledWindow->SetScrollRate( 5, 5 ); m_RenderFlexGridSizer = new wxFlexGridSizer( 0, 3, 1, 3 ); m_RenderFlexGridSizer = new wxFlexGridSizer( 0, 2, 1, 3 ); m_RenderFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL ); m_RenderFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL ); m_RenderFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE ); m_RenderFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE ); Loading pcbnew/layer_panel_base.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -48,7 +48,7 @@ class LAYER_PANEL_BASE : public wxPanel public: public: LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 183,184 ), long style = wxTAB_TRAVERSAL ); LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 200,200 ), long style = wxTAB_TRAVERSAL ); ~LAYER_PANEL_BASE(); ~LAYER_PANEL_BASE(); }; }; Loading pcbnew/layer_widget.cpp +397 −555 Original line number Original line Diff line number Diff line Loading @@ -33,26 +33,13 @@ // also enable KICAD_AUIMANAGER and KICAD_AUITOOLBAR in ccmake to // also enable KICAD_AUIMANAGER and KICAD_AUITOOLBAR in ccmake to // build this test program // build this test program #include <wx/wx.h> #include "layer_widget.h" #include <wx/statbmp.h> #include <wx/aui/aui.h> #include "macros.h" #include "common.h" #include "layer_panel_base.h" #include "colors.h" #include "pcbstruct.h" // IsValidCopperLayerIndex() #include "pcbstruct.h" // IsValidCopperLayerIndex() /* no external data knowledge needed or wanted #include "pcbnew.h" #include "wxPcbStruct.h" */ #define LYR_COLUMN_COUNT 4 ///< Layer tab column count #define LYR_COLUMN_COUNT 4 ///< Layer tab column count #define RND_COLUMN_COUNT 3 ///< Rendering tab column count #define RND_COLUMN_COUNT 2 ///< Rendering tab column count #define ID_SHOW_ALL_COPPERS wxID_HIGHEST #define ID_SHOW_ALL_COPPERS wxID_HIGHEST #define ID_SHOW_NO_COPPERS (wxID_HIGHEST+1) #define ID_SHOW_NO_COPPERS (wxID_HIGHEST+1) Loading Loading @@ -139,62 +126,7 @@ static wxString makeColorTxt( int aColor ) } } /** wxBitmap LAYER_WIDGET::makeBitmap( int aColor ) * Class LAYER_WIDGET * is abstract and is derived from a wxFormBuilder maintained class called * LAYER_PANEL_BASE. It is used to manage a list of layers, with the notion of * a "current" layer, and layer specific visibility control. You must derive from * it to use it so you can implement the abstract functions which recieve the * events. Each layer is given its own color, and that color can be changed * within the UI provided here. This widget knows nothing of the client code, meaning * it has no knowledge of a BOARD or anything. To use it you must derive from * this class and implement the abstract functions: * <p> void OnLayerColorChange( int aLayer, int aColor ); * <p> bool OnLayerSelect( int aLayer ); * <p> void OnLayerVisible( int aLayer, bool isVisible ); * <p> void OnRenderColorChange( int id, int aColor ); * <p> void OnRenderEnable( int id, bool isEnabled ); */ class LAYER_WIDGET : public LAYER_PANEL_BASE { public: /** * Struct ROW * provides all the data needed to add a row to a LAYER_WIDGET. This is * part of the public API for a LAYER_WIDGET. */ struct ROW { wxString rowName; int id; // either a layer or int color; // -1 if none. bool state; // initial wxCheckBox state ROW( const wxString& aRowName, int aId, int aColor = 0, bool aState = true ) { rowName = aRowName; id = aId; color = aColor; state = aState; } }; protected: #define MAX_LAYER_ROWS 64 #define BUTT_SIZE_X 32 #define BUTT_SIZE_Y 22 #define BUTT_VOID 6 wxBitmap* m_BlankBitmap; wxBitmap* m_RightArrowBitmap; wxSize m_BitmapSize; int m_CurrentRow; ///< selected row of layer list static wxBitmap makeBitmap( int aColor ) { { // the bitmap will be BUTT_VOID*2 pixels smaller than the button, leaving a // the bitmap will be BUTT_VOID*2 pixels smaller than the button, leaving a // border of BUTT_VOID pixels on each side. // border of BUTT_VOID pixels on each side. Loading @@ -213,12 +145,7 @@ protected: return bitmap; return bitmap; } } wxBitmapButton* LAYER_WIDGET::makeColorButton( wxWindow* aParent, int aColor, int aID ) /** * Function makeColorButton * creates a wxBitmapButton and assigns it a solid color and a control ID */ wxBitmapButton* makeColorButton( wxWindow* aParent, int aColor, int aID ) { { // dynamically make a wxBitMap and brush it with the appropriate color, // dynamically make a wxBitMap and brush it with the appropriate color, // then create a wxBitmapButton from it. // then create a wxBitmapButton from it. Loading @@ -232,7 +159,7 @@ protected: return ret; return ret; } } void OnLeftDownLayers( wxMouseEvent& event ) void LAYER_WIDGET::OnLeftDownLayers( wxMouseEvent& event ) { { int row; int row; Loading Loading @@ -277,7 +204,7 @@ protected: * Function OnMiddleDownLayerColor * Function OnMiddleDownLayerColor * is called only from a color button when user right clicks. * is called only from a color button when user right clicks. */ */ void OnMiddleDownLayerColor( wxMouseEvent& event ) void LAYER_WIDGET::OnMiddleDownLayerColor( wxMouseEvent& event ) { { wxBitmapButton* eventSource = (wxBitmapButton*) event.GetEventObject(); wxBitmapButton* eventSource = (wxBitmapButton*) event.GetEventObject(); Loading Loading @@ -305,22 +232,22 @@ protected: * Function OnRightDownLayers * Function OnRightDownLayers * puts up a popup menu for the layer panel. * puts up a popup menu for the layer panel. */ */ void OnRightDownLayers( wxMouseEvent& event ) void LAYER_WIDGET::OnRightDownLayers( wxMouseEvent& event ) { { wxMenu menu; wxMenu menu; // menu text is capitalized: // menu text is capitalized: // http://library.gnome.org/devel/hig-book/2.20/design-text-labels.html.en#layout-capitalization // http://library.gnome.org/devel/hig-book/2.20/design-text-labels.html.en#layout-capitalization menu.Append( new wxMenuItem( &menu, ID_SHOW_ALL_COPPERS, menu.Append( new wxMenuItem( &menu, ID_SHOW_ALL_COPPERS, _("Show All Copper Layers") ) ); _("Show All Cu") ) ); menu.Append( new wxMenuItem( &menu, ID_SHOW_NO_COPPERS, menu.Append( new wxMenuItem( &menu, ID_SHOW_NO_COPPERS, _( "Show No Copper Layers" ) ) ); _( "Hide All Cu" ) ) ); PopupMenu( &menu ); PopupMenu( &menu ); } } void OnPopupSelection( wxCommandEvent& event ) void LAYER_WIDGET::OnPopupSelection( wxCommandEvent& event ) { { int rowCount; int rowCount; int menuId = event.GetId(); int menuId = event.GetId(); Loading Loading @@ -357,7 +284,7 @@ protected: * handles the "is layer visible" checkbox and propogates the * handles the "is layer visible" checkbox and propogates the * event to the client's notification function. * event to the client's notification function. */ */ void OnLayerCheckBox( wxCommandEvent& event ) void LAYER_WIDGET::OnLayerCheckBox( wxCommandEvent& event ) { { wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject(); wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject(); int layer = getDecodedId( eventSource->GetId() ); int layer = getDecodedId( eventSource->GetId() ); Loading @@ -365,7 +292,7 @@ protected: } } void OnMiddleDownRenderColor( wxMouseEvent& event ) void LAYER_WIDGET::OnMiddleDownRenderColor( wxMouseEvent& event ) { { wxBitmapButton* eventSource = (wxBitmapButton*) event.GetEventObject(); wxBitmapButton* eventSource = (wxBitmapButton*) event.GetEventObject(); Loading @@ -388,7 +315,7 @@ protected: } } } } void OnRenderCheckBox( wxCommandEvent& event ) void LAYER_WIDGET::OnRenderCheckBox( wxCommandEvent& event ) { { wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject(); wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject(); int id = getDecodedId( eventSource->GetId() ); int id = getDecodedId( eventSource->GetId() ); Loading @@ -404,7 +331,7 @@ protected: * @param aSizerNdx is the 0 based index into all the wxWindows which have * @param aSizerNdx is the 0 based index into all the wxWindows which have * been added to the m_LayersFlexGridSizer. * been added to the m_LayersFlexGridSizer. */ */ wxWindow* getLayerComp( int aSizerNdx ) wxWindow* LAYER_WIDGET::getLayerComp( int aSizerNdx ) { { if( (unsigned) aSizerNdx < m_LayersFlexGridSizer->GetChildren().GetCount() ) if( (unsigned) aSizerNdx < m_LayersFlexGridSizer->GetChildren().GetCount() ) return m_LayersFlexGridSizer->GetChildren()[aSizerNdx]->GetWindow(); return m_LayersFlexGridSizer->GetChildren()[aSizerNdx]->GetWindow(); Loading @@ -415,7 +342,7 @@ protected: * Function findLayerRow * Function findLayerRow * returns the row index that \a aLayer resides in, or -1 if not found. * returns the row index that \a aLayer resides in, or -1 if not found. */ */ int findLayerRow( int aLayer ) int LAYER_WIDGET::findLayerRow( int aLayer ) { { int count = GetLayerRowCount(); int count = GetLayerRowCount(); for( int row=0; row<count; ++row ) for( int row=0; row<count; ++row ) Loading @@ -433,17 +360,13 @@ protected: * Function insertLayerRow * Function insertLayerRow * appends or inserts a new row in the layer portion of the widget. * appends or inserts a new row in the layer portion of the widget. */ */ void insertLayerRow( int aRow, const ROW& aSpec ) void LAYER_WIDGET::insertLayerRow( int aRow, const ROW& aSpec ) { { int col; wxASSERT( aRow >= 0 && aRow < MAX_LAYER_ROWS ); wxASSERT( aRow >= 0 && aRow < MAX_LAYER_ROWS ); size_t index = aRow * LYR_COLUMN_COUNT; int col; int index = aRow * LYR_COLUMN_COUNT; wxSizerFlags flags; const int flags = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT; flags.Align(wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL); // column 0 // column 0 col = 0; col = 0; Loading @@ -451,8 +374,7 @@ protected: *m_BlankBitmap, wxDefaultPosition, m_BitmapSize ); *m_BlankBitmap, wxDefaultPosition, m_BitmapSize ); sbm->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this ); sbm->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this ); sbm->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this ); sbm->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this ); m_LayersFlexGridSizer->Insert( index+col, m_LayersFlexGridSizer->Insert( index+col, sbm, 0, flags ); new wxSizerItem( sbm, wxSizerFlags().Align( wxALIGN_CENTER_VERTICAL ) ) ); // column 1 // column 1 col = 1; col = 1; Loading @@ -461,16 +383,15 @@ protected: bmb->Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnMiddleDownLayerColor ), NULL, this ); bmb->Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnMiddleDownLayerColor ), NULL, this ); bmb->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this ); bmb->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this ); bmb->SetToolTip( _("Left click to select, middle click for color change, right click for menu" ) ); bmb->SetToolTip( _("Left click to select, middle click for color change, right click for menu" ) ); m_LayersFlexGridSizer->Insert( index+col, new wxSizerItem( bmb, flags ) ); m_LayersFlexGridSizer->Insert( index+col, bmb, 0, flags ); // column 2 // column 2 col = 2; col = 2; wxStaticText* st = new wxStaticText( m_LayerScrolledWindow, encodeId( col, aSpec.id ), aSpec.rowName ); wxStaticText* st = new wxStaticText( m_LayerScrolledWindow, encodeId( col, aSpec.id ), aSpec.rowName ); st->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this ); st->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this ); st->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this ); st->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this ); st->SetToolTip( _( "Click here to select this layer" ) ); st->SetToolTip( aSpec.tooltip ); m_LayersFlexGridSizer->Insert( index+col, m_LayersFlexGridSizer->Insert( index+col, st, 0, flags ); new wxSizerItem( st, wxSizerFlags().Align( wxALIGN_CENTER_VERTICAL )) ); // column 3 // column 3 col = 3; col = 3; Loading @@ -478,57 +399,50 @@ protected: cb->SetValue( aSpec.state ); cb->SetValue( aSpec.state ); cb->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( LAYER_WIDGET::OnLayerCheckBox ), NULL, this ); cb->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( LAYER_WIDGET::OnLayerCheckBox ), NULL, this ); cb->SetToolTip( _( "Enable this for visibility" ) ); cb->SetToolTip( _( "Enable this for visibility" ) ); m_LayersFlexGridSizer->Insert( index+col, new wxSizerItem( cb, flags ) ); m_LayersFlexGridSizer->Insert( index+col, cb, 0, flags ); } } void insertRenderRow( int aRow, const ROW& aSpec ) void LAYER_WIDGET::insertRenderRow( int aRow, const ROW& aSpec ) { { int col; wxASSERT( aRow >= 0 && aRow < MAX_LAYER_ROWS ); wxASSERT( aRow >= 0 && aRow < MAX_LAYER_ROWS ); size_t index = aRow * RND_COLUMN_COUNT; int col; int index = aRow * RND_COLUMN_COUNT; wxSizerFlags flags; const int flags = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT; flags.Align(wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL); // column 0 // column 0 col = 0; col = 0; if( aSpec.color != -1 ) { wxBitmapButton* bmb = makeColorButton( m_RenderScrolledWindow, aSpec.color, encodeId( col, aSpec.id ) ); wxBitmapButton* bmb = makeColorButton( m_RenderScrolledWindow, aSpec.color, encodeId( col, aSpec.id ) ); bmb->Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnMiddleDownRenderColor ), NULL, this ); bmb->Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnMiddleDownRenderColor ), NULL, this ); bmb->SetToolTip( _("Middle click for color change" ) ); bmb->SetToolTip( _("Middle click for color change" ) ); m_RenderFlexGridSizer->Insert( index+col, new wxSizerItem( bmb, flags ) ); m_RenderFlexGridSizer->Insert( index+col, bmb, 0, flags ); // could add a left click handler on the color button that toggles checkbox. } else // no color selection wanted { // need a place holder within the sizer to keep grid full. wxPanel* invisible = new wxPanel( m_RenderScrolledWindow ); m_RenderFlexGridSizer->Insert( index+col, invisible, 0, flags ); } #if 0 // column 1 col = 1; wxCheckBox* cb = new wxCheckBox( m_RenderScrolledWindow, encodeId( col, aSpec.id ), aSpec.rowName, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT ); cb->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( LAYER_WIDGET::OnRenderCheckBox ), NULL, this ); // cb->SetToolTip( _( "Enable this for visibility" ) ); m_RenderFlexGridSizer->Insert( index+col, new wxSizerItem( cb, flags ) ); #else // column 1 // column 1 col = 1; col = 1; wxCheckBox* cb = new wxCheckBox( m_RenderScrolledWindow, encodeId( col, aSpec.id ), wxEmptyString ); wxCheckBox* cb = new wxCheckBox( m_RenderScrolledWindow, encodeId( col, aSpec.id ), cb->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( LAYER_WIDGET::OnRenderCheckBox ), NULL, this ); aSpec.rowName, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT ); // cb->SetToolTip( _( "Enable this for visibility" ) ); cb->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, m_RenderFlexGridSizer->Insert( index+col, new wxSizerItem( cb, flags ) ); wxCommandEventHandler( LAYER_WIDGET::OnRenderCheckBox ), NULL, this ); cb->SetToolTip( aSpec.tooltip ); // column 2 m_RenderFlexGridSizer->Insert( index+col, cb, 0, flags ); col = 2; wxStaticText* st = new wxStaticText( m_RenderScrolledWindow, encodeId( col, aSpec.id ), aSpec.rowName ); m_RenderFlexGridSizer->Insert( index+col, new wxSizerItem( st, wxSizerFlags().Align( wxALIGN_CENTER_VERTICAL )) ); #endif } } public: //-----<public>------------------------------------------------------- /** Constructor */ /** Constructor */ LAYER_WIDGET( wxWindow* parent ) : LAYER_WIDGET::LAYER_WIDGET( wxWindow* parent ) : LAYER_PANEL_BASE( parent ) LAYER_PANEL_BASE( parent ) { { m_CurrentRow = -1; m_CurrentRow = -1; Loading @@ -550,64 +464,69 @@ public: } } /** wxSize LAYER_WIDGET::GetBestSize() const * Function GetBestSize * returns the preferred minimum size, taking into consideration the * dynamic content. Nothing in wxWidgets was reliable enough. */ wxSize GetBestSize() const { { // size of m_LayerScrolledWindow -------------- // size of m_LayerScrolledWindow -------------- wxArrayInt widths = m_LayersFlexGridSizer->GetColWidths(); wxArrayInt widths = m_LayersFlexGridSizer->GetColWidths(); int totWidth = 0; int totWidth = 0; for( int i=0; i<LYR_COLUMN_COUNT && i<(int)widths.GetCount(); ++i ) if( widths.GetCount() ) { for( int i=0; i<LYR_COLUMN_COUNT; ++i ) { { totWidth += widths[i] + m_LayersFlexGridSizer->GetHGap(); totWidth += widths[i] + m_LayersFlexGridSizer->GetHGap(); // printf("widths[%d]:%d\n", i, widths[i] ); // printf("widths[%d]:%d\n", i, widths[i] ); } } } // Account for the parent's frame: totWidth += 10; wxArrayInt heights = m_LayersFlexGridSizer->GetRowHeights(); wxArrayInt heights = m_LayersFlexGridSizer->GetRowHeights(); int totHeight = 0; int totHeight = 0; if( heights.GetCount() ) { int rowCount = GetLayerRowCount(); int rowCount = GetLayerRowCount(); for( int i=0; i<rowCount && i<(int)heights.GetCount(); ++i ) for( int i=0; i<rowCount; ++i ) { { totHeight += heights[i] + m_LayersFlexGridSizer->GetVGap(); totHeight += heights[i] + m_LayersFlexGridSizer->GetVGap(); // printf("heights[%d]:%d\n", i, heights[i] ); // printf("heights[%d]:%d\n", i, heights[i] ); } } // Account for the parent's frame: totWidth += 10; if( heights.GetCount() ) totHeight += 2 * heights[0]; // use 2 row heights to approximate tab height totHeight += 2 * heights[0]; // use 2 row heights to approximate tab height } else else totHeight += 20; // not used except before adding rows. totHeight += 20; // not used except before adding rows. wxSize layerz( totWidth, totHeight ); wxSize layerz( totWidth, totHeight ); // size of m_RenderScrolledWindow -------------- // size of m_RenderScrolledWindow -------------- widths = m_RenderFlexGridSizer->GetColWidths(); widths = m_RenderFlexGridSizer->GetColWidths(); totWidth = 0; totWidth = 0; for( int i=0; i<RND_COLUMN_COUNT && i<(int)widths.GetCount(); ++i ) if( widths.GetCount() ) { for( int i=0; i<RND_COLUMN_COUNT; ++i ) { { totWidth += widths[i] + m_RenderFlexGridSizer->GetHGap(); totWidth += widths[i] + m_RenderFlexGridSizer->GetHGap(); // printf("widths[%d]:%d\n", i, widths[i] ); // printf("widths[%d]:%d\n", i, widths[i] ); } } } // account for the parent's frame, this one has void space of 10 PLUS a border: totWidth += 20; heights = m_RenderFlexGridSizer->GetRowHeights(); heights = m_RenderFlexGridSizer->GetRowHeights(); totHeight = 0; totHeight = 0; rowCount = GetRenderRowCount(); if( heights.GetCount() ) { int rowCount = GetRenderRowCount(); for( int i=0; i<rowCount && i<(int)heights.GetCount(); ++i ) for( int i=0; i<rowCount && i<(int)heights.GetCount(); ++i ) { { totHeight += heights[i] + m_RenderFlexGridSizer->GetVGap(); totHeight += heights[i] + m_RenderFlexGridSizer->GetVGap(); // printf("heights[%d]:%d\n", i, heights[i] ); // printf("heights[%d]:%d\n", i, heights[i] ); } } // account for the parent's frame, this one void space of 10 PLUS a border: totWidth += 20; if( heights.GetCount() ) totHeight += 2 * heights[0]; // use 2 row heights to approximate tab height totHeight += 2 * heights[0]; // use 2 row heights to approximate tab height } else else totHeight += 20; // not used except before adding rows totHeight += 20; // not used except before adding rows Loading @@ -617,73 +536,49 @@ public: } } /** int LAYER_WIDGET::GetLayerRowCount() const * Function GetLayerRowCount * returns the number of rows in the layer tab. */ int GetLayerRowCount() const { { int controlCount = m_LayersFlexGridSizer->GetChildren().GetCount(); int controlCount = m_LayersFlexGridSizer->GetChildren().GetCount(); return controlCount / LYR_COLUMN_COUNT; return controlCount / LYR_COLUMN_COUNT; } } /** * Function GetRenderRowCount int LAYER_WIDGET::GetRenderRowCount() const * returns the number of rows in the render tab. */ int GetRenderRowCount() const { { int controlCount = m_RenderFlexGridSizer->GetChildren().GetCount(); int controlCount = m_RenderFlexGridSizer->GetChildren().GetCount(); return controlCount / RND_COLUMN_COUNT; return controlCount / RND_COLUMN_COUNT; } } /** * Function AppendLayerRow void LAYER_WIDGET::AppendLayerRow( const ROW& aRow ) * appends a new row in the layer portion of the widget. The user must * ensure that ROW::id is unique for all existing rows on Windows. */ void AppendLayerRow( const ROW& aRow ) { { int nextRow = GetLayerRowCount(); int nextRow = GetLayerRowCount(); insertLayerRow( nextRow, aRow ); insertLayerRow( nextRow, aRow ); FitInside(); FitInside(); } } /** * Function ClearLayerRows void LAYER_WIDGET::ClearLayerRows() * empties out the layer rows. */ void ClearLayerRows() { { m_LayerScrolledWindow->DestroyChildren(); m_LayerScrolledWindow->DestroyChildren(); } } /** * Function AppendRenderRow void LAYER_WIDGET::AppendRenderRow( const ROW& aRow ) * appends a new row in the render portion of the widget. The user must * ensure that ROW::id is unique for all existing rows on Windows. */ void AppendRenderRow( const ROW& aRow ) { { int nextRow = GetRenderRowCount(); int nextRow = GetRenderRowCount(); insertRenderRow( nextRow, aRow ); insertRenderRow( nextRow, aRow ); FitInside(); FitInside(); } } /** * Function ClearRenderRows void LAYER_WIDGET::ClearRenderRows() * empties out the render rows. */ void ClearRenderRows() { { m_RenderScrolledWindow->DestroyChildren(); m_RenderScrolledWindow->DestroyChildren(); } } /** * Function SelectLayerRow void LAYER_WIDGET::SelectLayerRow( int aRow ) * changes the row selection in the layer list to the given row. */ void SelectLayerRow( int aRow ) { { // enable the layer tab at index 0 // enable the layer tab at index 0 m_notebook->ChangeSelection( 0 ); m_notebook->ChangeSelection( 0 ); Loading Loading @@ -717,22 +612,14 @@ public: } } /** void LAYER_WIDGET::SelectLayer( int aLayer ) * Function SelectLayer * changes the row selection in the layer list to \a aLayer provided. */ void SelectLayer( int aLayer ) { { int row = findLayerRow( aLayer ); int row = findLayerRow( aLayer ); SelectLayerRow( row ); SelectLayerRow( row ); } } /** int LAYER_WIDGET::GetSelectedLayer() * Function GetSelectedLayer * returns the selected layer or -1 if none. */ int GetSelectedLayer() { { // column 0 in the layer scroll window has a wxStaticBitmap, get its ID. // column 0 in the layer scroll window has a wxStaticBitmap, get its ID. wxStaticBitmap* bm = (wxStaticBitmap*) getLayerComp( m_CurrentRow * LYR_COLUMN_COUNT ); wxStaticBitmap* bm = (wxStaticBitmap*) getLayerComp( m_CurrentRow * LYR_COLUMN_COUNT ); Loading @@ -742,11 +629,8 @@ public: return -1; return -1; } } /** * Function SetLayerVisible void LAYER_WIDGET::SetLayerVisible( int aLayer, bool isVisible ) * sets \a aLayer visible or not. This does not invoke OnLayerVisible(). */ void SetLayerVisible( int aLayer, bool isVisible ) { { int row = findLayerRow( aLayer ); int row = findLayerRow( aLayer ); if( row >= 0 ) if( row >= 0 ) Loading @@ -757,51 +641,6 @@ public: } } } } //-----<abstract functions>------------------------------------------- /** * Function OnLayerColorChange * is called to notify client code about a layer color change. Derived * classes will handle this accordingly. */ virtual void OnLayerColorChange( int aLayer, int aColor ) = 0; /** * Function OnLayerSelect * is called to notify client code whenever the user selects a different * layer. Derived classes will handle this accordingly, and can deny * the change by returning false. */ virtual bool OnLayerSelect( int aLayer ) = 0; /** * Function OnLayerVisible * is called to notify client code about a layer visibility change. */ virtual void OnLayerVisible( int aLayer, bool isVisible ) = 0; /** * Function OnRenderColorChange * is called to notify client code whenever the user changes a rendering * color. * @param aId is the same id that was established in a Rendering row * via the AddRenderRow() function. */ virtual void OnRenderColorChange( int aId, int aColor ) = 0; /** * Function OnRenderEnable * is called to notify client code whenever the user changes an rendering * enable in one of the rendering checkboxes. * @param aId is the same id that was established in a Rendering row * via the AddRenderRow() function. * @param isEnabled is the state of the checkbox, true if checked. */ virtual void OnRenderEnable( int aId, bool isEnabled ) = 0; //-----</abstract functions>------------------------------------------ }; #if defined(STAND_ALONE) #if defined(STAND_ALONE) Loading Loading @@ -875,13 +714,16 @@ public: MYLAYERS* lw = new MYLAYERS( this, this ); MYLAYERS* lw = new MYLAYERS( this, this ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer 1"), 0, RED, false ) ); // add some layer rows lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer 2"), 1, GREEN ) ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer 1"), 0, RED, _("RED"), false ) ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("brown_layer"), 2, BROWN ) ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer 2"), 1, GREEN, _("GREEN"), true ) ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer_4_you"), 3, BLUE, false ) ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("brown_layer"), 2, BROWN, _("BROWN"), true ) ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer_4_you"), 3, BLUE, _("BLUE"), false ) ); lw->AppendRenderRow( LAYER_WIDGET::ROW( wxT("With Very Large Ears"), 0, GREEN ) ); // add some render rows lw->AppendRenderRow( LAYER_WIDGET::ROW( wxT("With Very Large Ears"), 0, -1, _("Spock here") ) ); lw->AppendRenderRow( LAYER_WIDGET::ROW( wxT("With Legs"), 1, YELLOW ) ); lw->AppendRenderRow( LAYER_WIDGET::ROW( wxT("With Legs"), 1, YELLOW ) ); lw->AppendRenderRow( LAYER_WIDGET::ROW( wxT("With Oval Eyes"), 1, BROWN, _("My eyes are upon you") ) ); lw->SelectLayerRow( 1 ); lw->SelectLayerRow( 1 ); Loading Loading
pcbnew/layer_panel_base.cpp +1 −3 Original line number Original line Diff line number Diff line Loading @@ -11,8 +11,6 @@ LAYER_PANEL_BASE::LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style ) LAYER_PANEL_BASE::LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style ) { { this->SetMinSize( wxSize( 100,100 ) ); wxBoxSizer* boxSizer; wxBoxSizer* boxSizer; boxSizer = new wxBoxSizer( wxVERTICAL ); boxSizer = new wxBoxSizer( wxVERTICAL ); Loading Loading @@ -42,7 +40,7 @@ LAYER_PANEL_BASE::LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id, const wxPoi m_RenderScrolledWindow = new wxScrolledWindow( m_RenderingPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxVSCROLL ); m_RenderScrolledWindow = new wxScrolledWindow( m_RenderingPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxVSCROLL ); m_RenderScrolledWindow->SetScrollRate( 5, 5 ); m_RenderScrolledWindow->SetScrollRate( 5, 5 ); m_RenderFlexGridSizer = new wxFlexGridSizer( 0, 3, 1, 3 ); m_RenderFlexGridSizer = new wxFlexGridSizer( 0, 2, 1, 3 ); m_RenderFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL ); m_RenderFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL ); m_RenderFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE ); m_RenderFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE ); Loading
pcbnew/layer_panel_base.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -48,7 +48,7 @@ class LAYER_PANEL_BASE : public wxPanel public: public: LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 183,184 ), long style = wxTAB_TRAVERSAL ); LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 200,200 ), long style = wxTAB_TRAVERSAL ); ~LAYER_PANEL_BASE(); ~LAYER_PANEL_BASE(); }; }; Loading
pcbnew/layer_widget.cpp +397 −555 Original line number Original line Diff line number Diff line Loading @@ -33,26 +33,13 @@ // also enable KICAD_AUIMANAGER and KICAD_AUITOOLBAR in ccmake to // also enable KICAD_AUIMANAGER and KICAD_AUITOOLBAR in ccmake to // build this test program // build this test program #include <wx/wx.h> #include "layer_widget.h" #include <wx/statbmp.h> #include <wx/aui/aui.h> #include "macros.h" #include "common.h" #include "layer_panel_base.h" #include "colors.h" #include "pcbstruct.h" // IsValidCopperLayerIndex() #include "pcbstruct.h" // IsValidCopperLayerIndex() /* no external data knowledge needed or wanted #include "pcbnew.h" #include "wxPcbStruct.h" */ #define LYR_COLUMN_COUNT 4 ///< Layer tab column count #define LYR_COLUMN_COUNT 4 ///< Layer tab column count #define RND_COLUMN_COUNT 3 ///< Rendering tab column count #define RND_COLUMN_COUNT 2 ///< Rendering tab column count #define ID_SHOW_ALL_COPPERS wxID_HIGHEST #define ID_SHOW_ALL_COPPERS wxID_HIGHEST #define ID_SHOW_NO_COPPERS (wxID_HIGHEST+1) #define ID_SHOW_NO_COPPERS (wxID_HIGHEST+1) Loading Loading @@ -139,62 +126,7 @@ static wxString makeColorTxt( int aColor ) } } /** wxBitmap LAYER_WIDGET::makeBitmap( int aColor ) * Class LAYER_WIDGET * is abstract and is derived from a wxFormBuilder maintained class called * LAYER_PANEL_BASE. It is used to manage a list of layers, with the notion of * a "current" layer, and layer specific visibility control. You must derive from * it to use it so you can implement the abstract functions which recieve the * events. Each layer is given its own color, and that color can be changed * within the UI provided here. This widget knows nothing of the client code, meaning * it has no knowledge of a BOARD or anything. To use it you must derive from * this class and implement the abstract functions: * <p> void OnLayerColorChange( int aLayer, int aColor ); * <p> bool OnLayerSelect( int aLayer ); * <p> void OnLayerVisible( int aLayer, bool isVisible ); * <p> void OnRenderColorChange( int id, int aColor ); * <p> void OnRenderEnable( int id, bool isEnabled ); */ class LAYER_WIDGET : public LAYER_PANEL_BASE { public: /** * Struct ROW * provides all the data needed to add a row to a LAYER_WIDGET. This is * part of the public API for a LAYER_WIDGET. */ struct ROW { wxString rowName; int id; // either a layer or int color; // -1 if none. bool state; // initial wxCheckBox state ROW( const wxString& aRowName, int aId, int aColor = 0, bool aState = true ) { rowName = aRowName; id = aId; color = aColor; state = aState; } }; protected: #define MAX_LAYER_ROWS 64 #define BUTT_SIZE_X 32 #define BUTT_SIZE_Y 22 #define BUTT_VOID 6 wxBitmap* m_BlankBitmap; wxBitmap* m_RightArrowBitmap; wxSize m_BitmapSize; int m_CurrentRow; ///< selected row of layer list static wxBitmap makeBitmap( int aColor ) { { // the bitmap will be BUTT_VOID*2 pixels smaller than the button, leaving a // the bitmap will be BUTT_VOID*2 pixels smaller than the button, leaving a // border of BUTT_VOID pixels on each side. // border of BUTT_VOID pixels on each side. Loading @@ -213,12 +145,7 @@ protected: return bitmap; return bitmap; } } wxBitmapButton* LAYER_WIDGET::makeColorButton( wxWindow* aParent, int aColor, int aID ) /** * Function makeColorButton * creates a wxBitmapButton and assigns it a solid color and a control ID */ wxBitmapButton* makeColorButton( wxWindow* aParent, int aColor, int aID ) { { // dynamically make a wxBitMap and brush it with the appropriate color, // dynamically make a wxBitMap and brush it with the appropriate color, // then create a wxBitmapButton from it. // then create a wxBitmapButton from it. Loading @@ -232,7 +159,7 @@ protected: return ret; return ret; } } void OnLeftDownLayers( wxMouseEvent& event ) void LAYER_WIDGET::OnLeftDownLayers( wxMouseEvent& event ) { { int row; int row; Loading Loading @@ -277,7 +204,7 @@ protected: * Function OnMiddleDownLayerColor * Function OnMiddleDownLayerColor * is called only from a color button when user right clicks. * is called only from a color button when user right clicks. */ */ void OnMiddleDownLayerColor( wxMouseEvent& event ) void LAYER_WIDGET::OnMiddleDownLayerColor( wxMouseEvent& event ) { { wxBitmapButton* eventSource = (wxBitmapButton*) event.GetEventObject(); wxBitmapButton* eventSource = (wxBitmapButton*) event.GetEventObject(); Loading Loading @@ -305,22 +232,22 @@ protected: * Function OnRightDownLayers * Function OnRightDownLayers * puts up a popup menu for the layer panel. * puts up a popup menu for the layer panel. */ */ void OnRightDownLayers( wxMouseEvent& event ) void LAYER_WIDGET::OnRightDownLayers( wxMouseEvent& event ) { { wxMenu menu; wxMenu menu; // menu text is capitalized: // menu text is capitalized: // http://library.gnome.org/devel/hig-book/2.20/design-text-labels.html.en#layout-capitalization // http://library.gnome.org/devel/hig-book/2.20/design-text-labels.html.en#layout-capitalization menu.Append( new wxMenuItem( &menu, ID_SHOW_ALL_COPPERS, menu.Append( new wxMenuItem( &menu, ID_SHOW_ALL_COPPERS, _("Show All Copper Layers") ) ); _("Show All Cu") ) ); menu.Append( new wxMenuItem( &menu, ID_SHOW_NO_COPPERS, menu.Append( new wxMenuItem( &menu, ID_SHOW_NO_COPPERS, _( "Show No Copper Layers" ) ) ); _( "Hide All Cu" ) ) ); PopupMenu( &menu ); PopupMenu( &menu ); } } void OnPopupSelection( wxCommandEvent& event ) void LAYER_WIDGET::OnPopupSelection( wxCommandEvent& event ) { { int rowCount; int rowCount; int menuId = event.GetId(); int menuId = event.GetId(); Loading Loading @@ -357,7 +284,7 @@ protected: * handles the "is layer visible" checkbox and propogates the * handles the "is layer visible" checkbox and propogates the * event to the client's notification function. * event to the client's notification function. */ */ void OnLayerCheckBox( wxCommandEvent& event ) void LAYER_WIDGET::OnLayerCheckBox( wxCommandEvent& event ) { { wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject(); wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject(); int layer = getDecodedId( eventSource->GetId() ); int layer = getDecodedId( eventSource->GetId() ); Loading @@ -365,7 +292,7 @@ protected: } } void OnMiddleDownRenderColor( wxMouseEvent& event ) void LAYER_WIDGET::OnMiddleDownRenderColor( wxMouseEvent& event ) { { wxBitmapButton* eventSource = (wxBitmapButton*) event.GetEventObject(); wxBitmapButton* eventSource = (wxBitmapButton*) event.GetEventObject(); Loading @@ -388,7 +315,7 @@ protected: } } } } void OnRenderCheckBox( wxCommandEvent& event ) void LAYER_WIDGET::OnRenderCheckBox( wxCommandEvent& event ) { { wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject(); wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject(); int id = getDecodedId( eventSource->GetId() ); int id = getDecodedId( eventSource->GetId() ); Loading @@ -404,7 +331,7 @@ protected: * @param aSizerNdx is the 0 based index into all the wxWindows which have * @param aSizerNdx is the 0 based index into all the wxWindows which have * been added to the m_LayersFlexGridSizer. * been added to the m_LayersFlexGridSizer. */ */ wxWindow* getLayerComp( int aSizerNdx ) wxWindow* LAYER_WIDGET::getLayerComp( int aSizerNdx ) { { if( (unsigned) aSizerNdx < m_LayersFlexGridSizer->GetChildren().GetCount() ) if( (unsigned) aSizerNdx < m_LayersFlexGridSizer->GetChildren().GetCount() ) return m_LayersFlexGridSizer->GetChildren()[aSizerNdx]->GetWindow(); return m_LayersFlexGridSizer->GetChildren()[aSizerNdx]->GetWindow(); Loading @@ -415,7 +342,7 @@ protected: * Function findLayerRow * Function findLayerRow * returns the row index that \a aLayer resides in, or -1 if not found. * returns the row index that \a aLayer resides in, or -1 if not found. */ */ int findLayerRow( int aLayer ) int LAYER_WIDGET::findLayerRow( int aLayer ) { { int count = GetLayerRowCount(); int count = GetLayerRowCount(); for( int row=0; row<count; ++row ) for( int row=0; row<count; ++row ) Loading @@ -433,17 +360,13 @@ protected: * Function insertLayerRow * Function insertLayerRow * appends or inserts a new row in the layer portion of the widget. * appends or inserts a new row in the layer portion of the widget. */ */ void insertLayerRow( int aRow, const ROW& aSpec ) void LAYER_WIDGET::insertLayerRow( int aRow, const ROW& aSpec ) { { int col; wxASSERT( aRow >= 0 && aRow < MAX_LAYER_ROWS ); wxASSERT( aRow >= 0 && aRow < MAX_LAYER_ROWS ); size_t index = aRow * LYR_COLUMN_COUNT; int col; int index = aRow * LYR_COLUMN_COUNT; wxSizerFlags flags; const int flags = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT; flags.Align(wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL); // column 0 // column 0 col = 0; col = 0; Loading @@ -451,8 +374,7 @@ protected: *m_BlankBitmap, wxDefaultPosition, m_BitmapSize ); *m_BlankBitmap, wxDefaultPosition, m_BitmapSize ); sbm->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this ); sbm->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this ); sbm->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this ); sbm->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this ); m_LayersFlexGridSizer->Insert( index+col, m_LayersFlexGridSizer->Insert( index+col, sbm, 0, flags ); new wxSizerItem( sbm, wxSizerFlags().Align( wxALIGN_CENTER_VERTICAL ) ) ); // column 1 // column 1 col = 1; col = 1; Loading @@ -461,16 +383,15 @@ protected: bmb->Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnMiddleDownLayerColor ), NULL, this ); bmb->Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnMiddleDownLayerColor ), NULL, this ); bmb->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this ); bmb->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this ); bmb->SetToolTip( _("Left click to select, middle click for color change, right click for menu" ) ); bmb->SetToolTip( _("Left click to select, middle click for color change, right click for menu" ) ); m_LayersFlexGridSizer->Insert( index+col, new wxSizerItem( bmb, flags ) ); m_LayersFlexGridSizer->Insert( index+col, bmb, 0, flags ); // column 2 // column 2 col = 2; col = 2; wxStaticText* st = new wxStaticText( m_LayerScrolledWindow, encodeId( col, aSpec.id ), aSpec.rowName ); wxStaticText* st = new wxStaticText( m_LayerScrolledWindow, encodeId( col, aSpec.id ), aSpec.rowName ); st->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this ); st->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this ); st->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this ); st->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this ); st->SetToolTip( _( "Click here to select this layer" ) ); st->SetToolTip( aSpec.tooltip ); m_LayersFlexGridSizer->Insert( index+col, m_LayersFlexGridSizer->Insert( index+col, st, 0, flags ); new wxSizerItem( st, wxSizerFlags().Align( wxALIGN_CENTER_VERTICAL )) ); // column 3 // column 3 col = 3; col = 3; Loading @@ -478,57 +399,50 @@ protected: cb->SetValue( aSpec.state ); cb->SetValue( aSpec.state ); cb->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( LAYER_WIDGET::OnLayerCheckBox ), NULL, this ); cb->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( LAYER_WIDGET::OnLayerCheckBox ), NULL, this ); cb->SetToolTip( _( "Enable this for visibility" ) ); cb->SetToolTip( _( "Enable this for visibility" ) ); m_LayersFlexGridSizer->Insert( index+col, new wxSizerItem( cb, flags ) ); m_LayersFlexGridSizer->Insert( index+col, cb, 0, flags ); } } void insertRenderRow( int aRow, const ROW& aSpec ) void LAYER_WIDGET::insertRenderRow( int aRow, const ROW& aSpec ) { { int col; wxASSERT( aRow >= 0 && aRow < MAX_LAYER_ROWS ); wxASSERT( aRow >= 0 && aRow < MAX_LAYER_ROWS ); size_t index = aRow * RND_COLUMN_COUNT; int col; int index = aRow * RND_COLUMN_COUNT; wxSizerFlags flags; const int flags = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT; flags.Align(wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL); // column 0 // column 0 col = 0; col = 0; if( aSpec.color != -1 ) { wxBitmapButton* bmb = makeColorButton( m_RenderScrolledWindow, aSpec.color, encodeId( col, aSpec.id ) ); wxBitmapButton* bmb = makeColorButton( m_RenderScrolledWindow, aSpec.color, encodeId( col, aSpec.id ) ); bmb->Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnMiddleDownRenderColor ), NULL, this ); bmb->Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnMiddleDownRenderColor ), NULL, this ); bmb->SetToolTip( _("Middle click for color change" ) ); bmb->SetToolTip( _("Middle click for color change" ) ); m_RenderFlexGridSizer->Insert( index+col, new wxSizerItem( bmb, flags ) ); m_RenderFlexGridSizer->Insert( index+col, bmb, 0, flags ); // could add a left click handler on the color button that toggles checkbox. } else // no color selection wanted { // need a place holder within the sizer to keep grid full. wxPanel* invisible = new wxPanel( m_RenderScrolledWindow ); m_RenderFlexGridSizer->Insert( index+col, invisible, 0, flags ); } #if 0 // column 1 col = 1; wxCheckBox* cb = new wxCheckBox( m_RenderScrolledWindow, encodeId( col, aSpec.id ), aSpec.rowName, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT ); cb->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( LAYER_WIDGET::OnRenderCheckBox ), NULL, this ); // cb->SetToolTip( _( "Enable this for visibility" ) ); m_RenderFlexGridSizer->Insert( index+col, new wxSizerItem( cb, flags ) ); #else // column 1 // column 1 col = 1; col = 1; wxCheckBox* cb = new wxCheckBox( m_RenderScrolledWindow, encodeId( col, aSpec.id ), wxEmptyString ); wxCheckBox* cb = new wxCheckBox( m_RenderScrolledWindow, encodeId( col, aSpec.id ), cb->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( LAYER_WIDGET::OnRenderCheckBox ), NULL, this ); aSpec.rowName, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT ); // cb->SetToolTip( _( "Enable this for visibility" ) ); cb->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, m_RenderFlexGridSizer->Insert( index+col, new wxSizerItem( cb, flags ) ); wxCommandEventHandler( LAYER_WIDGET::OnRenderCheckBox ), NULL, this ); cb->SetToolTip( aSpec.tooltip ); // column 2 m_RenderFlexGridSizer->Insert( index+col, cb, 0, flags ); col = 2; wxStaticText* st = new wxStaticText( m_RenderScrolledWindow, encodeId( col, aSpec.id ), aSpec.rowName ); m_RenderFlexGridSizer->Insert( index+col, new wxSizerItem( st, wxSizerFlags().Align( wxALIGN_CENTER_VERTICAL )) ); #endif } } public: //-----<public>------------------------------------------------------- /** Constructor */ /** Constructor */ LAYER_WIDGET( wxWindow* parent ) : LAYER_WIDGET::LAYER_WIDGET( wxWindow* parent ) : LAYER_PANEL_BASE( parent ) LAYER_PANEL_BASE( parent ) { { m_CurrentRow = -1; m_CurrentRow = -1; Loading @@ -550,64 +464,69 @@ public: } } /** wxSize LAYER_WIDGET::GetBestSize() const * Function GetBestSize * returns the preferred minimum size, taking into consideration the * dynamic content. Nothing in wxWidgets was reliable enough. */ wxSize GetBestSize() const { { // size of m_LayerScrolledWindow -------------- // size of m_LayerScrolledWindow -------------- wxArrayInt widths = m_LayersFlexGridSizer->GetColWidths(); wxArrayInt widths = m_LayersFlexGridSizer->GetColWidths(); int totWidth = 0; int totWidth = 0; for( int i=0; i<LYR_COLUMN_COUNT && i<(int)widths.GetCount(); ++i ) if( widths.GetCount() ) { for( int i=0; i<LYR_COLUMN_COUNT; ++i ) { { totWidth += widths[i] + m_LayersFlexGridSizer->GetHGap(); totWidth += widths[i] + m_LayersFlexGridSizer->GetHGap(); // printf("widths[%d]:%d\n", i, widths[i] ); // printf("widths[%d]:%d\n", i, widths[i] ); } } } // Account for the parent's frame: totWidth += 10; wxArrayInt heights = m_LayersFlexGridSizer->GetRowHeights(); wxArrayInt heights = m_LayersFlexGridSizer->GetRowHeights(); int totHeight = 0; int totHeight = 0; if( heights.GetCount() ) { int rowCount = GetLayerRowCount(); int rowCount = GetLayerRowCount(); for( int i=0; i<rowCount && i<(int)heights.GetCount(); ++i ) for( int i=0; i<rowCount; ++i ) { { totHeight += heights[i] + m_LayersFlexGridSizer->GetVGap(); totHeight += heights[i] + m_LayersFlexGridSizer->GetVGap(); // printf("heights[%d]:%d\n", i, heights[i] ); // printf("heights[%d]:%d\n", i, heights[i] ); } } // Account for the parent's frame: totWidth += 10; if( heights.GetCount() ) totHeight += 2 * heights[0]; // use 2 row heights to approximate tab height totHeight += 2 * heights[0]; // use 2 row heights to approximate tab height } else else totHeight += 20; // not used except before adding rows. totHeight += 20; // not used except before adding rows. wxSize layerz( totWidth, totHeight ); wxSize layerz( totWidth, totHeight ); // size of m_RenderScrolledWindow -------------- // size of m_RenderScrolledWindow -------------- widths = m_RenderFlexGridSizer->GetColWidths(); widths = m_RenderFlexGridSizer->GetColWidths(); totWidth = 0; totWidth = 0; for( int i=0; i<RND_COLUMN_COUNT && i<(int)widths.GetCount(); ++i ) if( widths.GetCount() ) { for( int i=0; i<RND_COLUMN_COUNT; ++i ) { { totWidth += widths[i] + m_RenderFlexGridSizer->GetHGap(); totWidth += widths[i] + m_RenderFlexGridSizer->GetHGap(); // printf("widths[%d]:%d\n", i, widths[i] ); // printf("widths[%d]:%d\n", i, widths[i] ); } } } // account for the parent's frame, this one has void space of 10 PLUS a border: totWidth += 20; heights = m_RenderFlexGridSizer->GetRowHeights(); heights = m_RenderFlexGridSizer->GetRowHeights(); totHeight = 0; totHeight = 0; rowCount = GetRenderRowCount(); if( heights.GetCount() ) { int rowCount = GetRenderRowCount(); for( int i=0; i<rowCount && i<(int)heights.GetCount(); ++i ) for( int i=0; i<rowCount && i<(int)heights.GetCount(); ++i ) { { totHeight += heights[i] + m_RenderFlexGridSizer->GetVGap(); totHeight += heights[i] + m_RenderFlexGridSizer->GetVGap(); // printf("heights[%d]:%d\n", i, heights[i] ); // printf("heights[%d]:%d\n", i, heights[i] ); } } // account for the parent's frame, this one void space of 10 PLUS a border: totWidth += 20; if( heights.GetCount() ) totHeight += 2 * heights[0]; // use 2 row heights to approximate tab height totHeight += 2 * heights[0]; // use 2 row heights to approximate tab height } else else totHeight += 20; // not used except before adding rows totHeight += 20; // not used except before adding rows Loading @@ -617,73 +536,49 @@ public: } } /** int LAYER_WIDGET::GetLayerRowCount() const * Function GetLayerRowCount * returns the number of rows in the layer tab. */ int GetLayerRowCount() const { { int controlCount = m_LayersFlexGridSizer->GetChildren().GetCount(); int controlCount = m_LayersFlexGridSizer->GetChildren().GetCount(); return controlCount / LYR_COLUMN_COUNT; return controlCount / LYR_COLUMN_COUNT; } } /** * Function GetRenderRowCount int LAYER_WIDGET::GetRenderRowCount() const * returns the number of rows in the render tab. */ int GetRenderRowCount() const { { int controlCount = m_RenderFlexGridSizer->GetChildren().GetCount(); int controlCount = m_RenderFlexGridSizer->GetChildren().GetCount(); return controlCount / RND_COLUMN_COUNT; return controlCount / RND_COLUMN_COUNT; } } /** * Function AppendLayerRow void LAYER_WIDGET::AppendLayerRow( const ROW& aRow ) * appends a new row in the layer portion of the widget. The user must * ensure that ROW::id is unique for all existing rows on Windows. */ void AppendLayerRow( const ROW& aRow ) { { int nextRow = GetLayerRowCount(); int nextRow = GetLayerRowCount(); insertLayerRow( nextRow, aRow ); insertLayerRow( nextRow, aRow ); FitInside(); FitInside(); } } /** * Function ClearLayerRows void LAYER_WIDGET::ClearLayerRows() * empties out the layer rows. */ void ClearLayerRows() { { m_LayerScrolledWindow->DestroyChildren(); m_LayerScrolledWindow->DestroyChildren(); } } /** * Function AppendRenderRow void LAYER_WIDGET::AppendRenderRow( const ROW& aRow ) * appends a new row in the render portion of the widget. The user must * ensure that ROW::id is unique for all existing rows on Windows. */ void AppendRenderRow( const ROW& aRow ) { { int nextRow = GetRenderRowCount(); int nextRow = GetRenderRowCount(); insertRenderRow( nextRow, aRow ); insertRenderRow( nextRow, aRow ); FitInside(); FitInside(); } } /** * Function ClearRenderRows void LAYER_WIDGET::ClearRenderRows() * empties out the render rows. */ void ClearRenderRows() { { m_RenderScrolledWindow->DestroyChildren(); m_RenderScrolledWindow->DestroyChildren(); } } /** * Function SelectLayerRow void LAYER_WIDGET::SelectLayerRow( int aRow ) * changes the row selection in the layer list to the given row. */ void SelectLayerRow( int aRow ) { { // enable the layer tab at index 0 // enable the layer tab at index 0 m_notebook->ChangeSelection( 0 ); m_notebook->ChangeSelection( 0 ); Loading Loading @@ -717,22 +612,14 @@ public: } } /** void LAYER_WIDGET::SelectLayer( int aLayer ) * Function SelectLayer * changes the row selection in the layer list to \a aLayer provided. */ void SelectLayer( int aLayer ) { { int row = findLayerRow( aLayer ); int row = findLayerRow( aLayer ); SelectLayerRow( row ); SelectLayerRow( row ); } } /** int LAYER_WIDGET::GetSelectedLayer() * Function GetSelectedLayer * returns the selected layer or -1 if none. */ int GetSelectedLayer() { { // column 0 in the layer scroll window has a wxStaticBitmap, get its ID. // column 0 in the layer scroll window has a wxStaticBitmap, get its ID. wxStaticBitmap* bm = (wxStaticBitmap*) getLayerComp( m_CurrentRow * LYR_COLUMN_COUNT ); wxStaticBitmap* bm = (wxStaticBitmap*) getLayerComp( m_CurrentRow * LYR_COLUMN_COUNT ); Loading @@ -742,11 +629,8 @@ public: return -1; return -1; } } /** * Function SetLayerVisible void LAYER_WIDGET::SetLayerVisible( int aLayer, bool isVisible ) * sets \a aLayer visible or not. This does not invoke OnLayerVisible(). */ void SetLayerVisible( int aLayer, bool isVisible ) { { int row = findLayerRow( aLayer ); int row = findLayerRow( aLayer ); if( row >= 0 ) if( row >= 0 ) Loading @@ -757,51 +641,6 @@ public: } } } } //-----<abstract functions>------------------------------------------- /** * Function OnLayerColorChange * is called to notify client code about a layer color change. Derived * classes will handle this accordingly. */ virtual void OnLayerColorChange( int aLayer, int aColor ) = 0; /** * Function OnLayerSelect * is called to notify client code whenever the user selects a different * layer. Derived classes will handle this accordingly, and can deny * the change by returning false. */ virtual bool OnLayerSelect( int aLayer ) = 0; /** * Function OnLayerVisible * is called to notify client code about a layer visibility change. */ virtual void OnLayerVisible( int aLayer, bool isVisible ) = 0; /** * Function OnRenderColorChange * is called to notify client code whenever the user changes a rendering * color. * @param aId is the same id that was established in a Rendering row * via the AddRenderRow() function. */ virtual void OnRenderColorChange( int aId, int aColor ) = 0; /** * Function OnRenderEnable * is called to notify client code whenever the user changes an rendering * enable in one of the rendering checkboxes. * @param aId is the same id that was established in a Rendering row * via the AddRenderRow() function. * @param isEnabled is the state of the checkbox, true if checked. */ virtual void OnRenderEnable( int aId, bool isEnabled ) = 0; //-----</abstract functions>------------------------------------------ }; #if defined(STAND_ALONE) #if defined(STAND_ALONE) Loading Loading @@ -875,13 +714,16 @@ public: MYLAYERS* lw = new MYLAYERS( this, this ); MYLAYERS* lw = new MYLAYERS( this, this ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer 1"), 0, RED, false ) ); // add some layer rows lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer 2"), 1, GREEN ) ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer 1"), 0, RED, _("RED"), false ) ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("brown_layer"), 2, BROWN ) ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer 2"), 1, GREEN, _("GREEN"), true ) ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer_4_you"), 3, BLUE, false ) ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("brown_layer"), 2, BROWN, _("BROWN"), true ) ); lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer_4_you"), 3, BLUE, _("BLUE"), false ) ); lw->AppendRenderRow( LAYER_WIDGET::ROW( wxT("With Very Large Ears"), 0, GREEN ) ); // add some render rows lw->AppendRenderRow( LAYER_WIDGET::ROW( wxT("With Very Large Ears"), 0, -1, _("Spock here") ) ); lw->AppendRenderRow( LAYER_WIDGET::ROW( wxT("With Legs"), 1, YELLOW ) ); lw->AppendRenderRow( LAYER_WIDGET::ROW( wxT("With Legs"), 1, YELLOW ) ); lw->AppendRenderRow( LAYER_WIDGET::ROW( wxT("With Oval Eyes"), 1, BROWN, _("My eyes are upon you") ) ); lw->SelectLayerRow( 1 ); lw->SelectLayerRow( 1 ); Loading