Commit e7a49c83 authored by dickelbeck's avatar dickelbeck

more layer_widget work

parent 8789ca5f
......@@ -36,16 +36,27 @@ LAYER_PANEL_BASE::LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id, const wxPoi
m_LayerPanel->Layout();
bSizer3->Fit( m_LayerPanel );
m_notebook->AddPage( m_LayerPanel, _("Layers"), true );
m_Page1Panel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
m_Page1Panel->SetToolTip( _("Part depiction and visibility") );
m_RenderingPanel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
m_RenderingPanel->SetToolTip( _("Part depiction and visibility") );
wxBoxSizer* bSizer4;
bSizer4 = new wxBoxSizer( wxVERTICAL );
m_Page1Panel->SetSizer( bSizer4 );
m_Page1Panel->Layout();
bSizer4->Fit( m_Page1Panel );
m_notebook->AddPage( m_Page1Panel, _("Rendering"), false );
m_RenderScrolledWindow = new wxScrolledWindow( m_RenderingPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL );
m_RenderScrolledWindow->SetScrollRate( 5, 5 );
m_RenderFlexGridSizer = new wxFlexGridSizer( 0, 2, 1, 3 );
m_RenderFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL );
m_RenderFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_RenderScrolledWindow->SetSizer( m_RenderFlexGridSizer );
m_RenderScrolledWindow->Layout();
m_RenderFlexGridSizer->Fit( m_RenderScrolledWindow );
bSizer4->Add( m_RenderScrolledWindow, 1, wxALL|wxEXPAND, 5 );
m_RenderingPanel->SetSizer( bSizer4 );
m_RenderingPanel->Layout();
bSizer4->Fit( m_RenderingPanel );
m_notebook->AddPage( m_RenderingPanel, _("Rendering"), false );
boxSizer->Add( m_notebook, 1, wxEXPAND | wxALL, 5 );
......@@ -53,7 +64,6 @@ LAYER_PANEL_BASE::LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id, const wxPoi
this->Layout();
// Connect Events
m_LayerScrolledWindow->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( LAYER_PANEL_BASE::OnLeftDblClickLayers ), NULL, this );
m_LayerScrolledWindow->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_PANEL_BASE::OnLeftDownLayers ), NULL, this );
m_LayerScrolledWindow->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_PANEL_BASE::OnRightDownLayers ), NULL, this );
}
......@@ -61,7 +71,6 @@ LAYER_PANEL_BASE::LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id, const wxPoi
LAYER_PANEL_BASE::~LAYER_PANEL_BASE()
{
// Disconnect Events
m_LayerScrolledWindow->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( LAYER_PANEL_BASE::OnLeftDblClickLayers ), NULL, this );
m_LayerScrolledWindow->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_PANEL_BASE::OnLeftDownLayers ), NULL, this );
m_LayerScrolledWindow->Disconnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_PANEL_BASE::OnRightDownLayers ), NULL, this );
}
......@@ -38,10 +38,11 @@ class LAYER_PANEL_BASE : public wxPanel
wxPanel* m_LayerPanel;
wxScrolledWindow* m_LayerScrolledWindow;
wxFlexGridSizer* m_LayersFlexGridSizer;
wxPanel* m_Page1Panel;
wxPanel* m_RenderingPanel;
wxScrolledWindow* m_RenderScrolledWindow;
wxFlexGridSizer* m_RenderFlexGridSizer;
// Virtual event handlers, overide them in your derived class
virtual void OnLeftDblClickLayers( wxMouseEvent& event ){ event.Skip(); }
virtual void OnLeftDownLayers( wxMouseEvent& event ){ event.Skip(); }
virtual void OnRightDownLayers( wxMouseEvent& event ){ event.Skip(); }
......
......@@ -43,13 +43,19 @@
#include "layer_panel_base.h"
#include "colors.h"
#include "pcbstruct.h" // IsValidCopperLayerIndex()
/* no external data knowledge needed or wanted
#include "pcbnew.h"
#include "wxPcbStruct.h"
*/
#define LAYER_COLUMN_COUNT 4
#define LYR_COLUMN_COUNT 4 ///< Layer tab column count
#define RND_COLUMN_COUNT 2 ///< Rendering tab column count
#define ID_SHOW_ALL_COPPERS wxID_HIGHEST
#define ID_SHOW_NO_COPPERS (wxID_HIGHEST+1)
/* XPM */
......@@ -96,27 +102,27 @@ static const char * rightarrow_xpm[] = {
/**
* Function layerId
* Function encodeId
* is here to allow saving a layer index within a control as its wxControl id,
* but to do so in a way that all child wxControl ids within a wxWindow are unique,
* since this is required by Windows.
* @see getLayerId()
* @see getDecodedId()
*/
static int layerId( int aColumn, int aLayer )
static int encodeId( int aColumn, int aId )
{
int id = aLayer * LAYER_COLUMN_COUNT + aColumn;
int id = aId * LYR_COLUMN_COUNT + aColumn;
return id;
}
/**
* Function getLayerId
* decodes \a aControlId to return a layer.
* Function getDecodedId
* decodes \a aControlId to original un-encoded value.
*/
static int getLayerId( int aControlId )
static int getDecodedId( int aControlId )
{
int layer = aControlId / LAYER_COLUMN_COUNT; // rounding is OK.
return layer;
int id = aControlId / LYR_COLUMN_COUNT; // rounding is OK.
return id;
}
......@@ -133,25 +139,6 @@ static wxString makeColorTxt( int aColor )
}
/**
* Struct LAYER_SPEC
* provides all the data needed to add a layer row to a LAYER_WIDGET
*/
struct LAYER_SPEC
{
wxString layerName;
int layer;
int color;
LAYER_SPEC( const wxString& aLayerName, int aLayer, int aColor = 0 )
{
layerName = aLayerName;
layer = aLayer;
color = aColor;
}
};
/**
* Class LAYER_WIDGET
* is abstract and is derived from a wxFormBuilder maintained class called
......@@ -162,22 +149,46 @@ struct LAYER_SPEC
* 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 OnColorChange( int aLayer, int aColor );
* <p>
* bool OnLayerSelect( int aLayer );
* <p>
* void OnLayerVisible( int aLayer, bool isVisible );
* <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
protected:
wxBitmap* m_BlankBitmap;
wxBitmap* m_RightArrowBitmap;
wxSize m_BitmapSize;
......@@ -185,8 +196,8 @@ protected:
static wxBitmap makeBitmap( int aColor )
{
// the bitmap will be 8 pixels smaller than the button, leaving a
// border of 4 pixels on each side.
// the bitmap will be BUTT_VOID*2 pixels smaller than the button, leaving a
// border of BUTT_VOID pixels on each side.
wxBitmap bitmap( BUTT_SIZE_X - 2 * BUTT_VOID, BUTT_SIZE_Y - 2 * BUTT_VOID );
wxBrush brush;
wxMemoryDC iconDC;
......@@ -207,13 +218,13 @@ protected:
* Function makeColorButton
* creates a wxBitmapButton and assigns it a solid color and a control ID
*/
wxBitmapButton* makeColorButton( int aColor, int aID )
wxBitmapButton* makeColorButton( wxWindow* aParent, int aColor, int aID )
{
// dynamically make a wxBitMap and brush it with the appropriate color,
// then create a wxBitmapButton from it.
wxBitmap bitmap = makeBitmap( aColor );
wxBitmapButton* ret = new wxBitmapButton( m_LayerScrolledWindow, aID, bitmap,
wxBitmapButton* ret = new wxBitmapButton( aParent, aID, bitmap,
wxDefaultPosition, wxSize(BUTT_SIZE_X, BUTT_SIZE_Y), wxBORDER_RAISED );
// save the color value in the name, no where else to put it.
......@@ -221,7 +232,6 @@ protected:
return ret;
}
void OnLeftDownLayers( wxMouseEvent& event )
{
int row;
......@@ -254,8 +264,8 @@ protected:
else
{
// all nested controls on a given row will have their ID encoded with
// makeLayerId(), and the corresponding decoding is getLayerId()
int layer = getLayerId( eventSource ->GetId() );
// encodeId(), and the corresponding decoding is getDecodedId()
int layer = getDecodedId( eventSource ->GetId() );
row = findLayerRow( layer );
}
......@@ -283,10 +293,10 @@ protected:
wxBitmap bm = makeBitmap( newColor );
eventSource->SetBitmapLabel( bm );
int layer = getLayerId( eventSource->GetId() );
int layer = getDecodedId( eventSource->GetId() );
// tell the client code.
OnColorChange( layer, newColor );
OnLayerColorChange( layer, newColor );
}
}
......@@ -297,8 +307,48 @@ protected:
*/
void OnRightDownLayers( wxMouseEvent& event )
{
// popup menu
printf( "OnRightDownLayers\n" );
wxMenu menu;
// menu text is capitalized:
// 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,
_("Show All Copper Layers") ) );
menu.Append( new wxMenuItem( &menu, ID_SHOW_NO_COPPERS,
_( "Show No Copper Layers" ) ) );
PopupMenu( &menu );
}
void OnPopupSelection( wxCommandEvent& event )
{
int rowCount;
int menuId = event.GetId();
bool visible;
switch( menuId )
{
case ID_SHOW_ALL_COPPERS:
visible = true;
goto L_change_coppers;
case ID_SHOW_NO_COPPERS:
visible = false;
L_change_coppers:
rowCount = GetLayerRowCount();
for( int row=0; row<rowCount; ++row )
{
wxCheckBox* cb = (wxCheckBox*) getLayerComp( row*LYR_COLUMN_COUNT + 3 );
int layer = getDecodedId( cb->GetId() );
if( IsValidCopperLayerIndex( layer ) )
{
cb->SetValue( visible );
OnLayerVisible( layer, visible );
}
}
break;
}
}
......@@ -310,23 +360,55 @@ protected:
void OnLayerCheckBox( wxCommandEvent& event )
{
wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject();
int layer = getDecodedId( eventSource->GetId() );
OnLayerVisible( layer, eventSource->IsChecked() );
}
int layer = getLayerId( eventSource->GetId() );
OnLayerVisible( layer, eventSource->IsChecked() );
void OnMiddleDownRenderColor( wxMouseEvent& event )
{
wxBitmapButton* eventSource = (wxBitmapButton*) event.GetEventObject();
wxString colorTxt = eventSource->GetName();
int oldColor = strtoul( CONV_TO_UTF8(colorTxt), NULL, 0 );
int newColor = DisplayColorFrame( this, oldColor );
if( newColor >= 0 )
{
eventSource->SetName( makeColorTxt( newColor ) );
wxBitmap bm = makeBitmap( newColor );
eventSource->SetBitmapLabel( bm );
int id = getDecodedId( eventSource->GetId() );
// tell the client code.
OnRenderColorChange( id, newColor );
}
}
void OnRenderCheckBox( wxCommandEvent& event )
{
wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject();
int id = getDecodedId( eventSource->GetId() );
OnRenderEnable( id, eventSource->IsChecked() );
}
/**
* Function getLayerComp
* returns the component within the m_LayersFlexGridSizer at aSizerNdx.
* returns the component within the m_LayersFlexGridSizer at aSizerNdx or
* NULL if \a aSizerNdx is out of range.
*
* @param aSizerNdx is the 0 based index into all the wxWindows which have
* been added to the m_LayersFlexGridSizer.
*/
wxWindow* getLayerComp( int aSizerNdx )
{
return m_LayersFlexGridSizer->GetChildren()[aSizerNdx]->GetWindow();
if( (unsigned) aSizerNdx < m_LayersFlexGridSizer->GetChildren().GetCount() )
return m_LayersFlexGridSizer->GetChildren()[aSizerNdx]->GetWindow();
return NULL;
}
/**
......@@ -336,15 +418,14 @@ protected:
int findLayerRow( int aLayer )
{
int count = GetLayerRowCount();
for( int row=0; row<count; ++row )
for( int row=0; row<count; ++row )
{
// column 0 in the layer scroll window has a wxStaticBitmap, get its ID.
wxStaticBitmap* bm = (wxStaticBitmap*) getLayerComp( row * LAYER_COLUMN_COUNT + 0 );
wxStaticBitmap* bm = (wxStaticBitmap*) getLayerComp( row * LYR_COLUMN_COUNT );
if( aLayer == getLayerId( bm->GetId() ))
if( aLayer == getDecodedId( bm->GetId() ))
return row;
}
return -1;
}
......@@ -352,46 +433,94 @@ protected:
* Function insertLayerRow
* appends or inserts a new row in the layer portion of the widget.
*/
void insertLayerRow( int aRow, const LAYER_SPEC& aSpec )
void insertLayerRow( int aRow, const ROW& aSpec )
{
int col;
wxASSERT( aRow >= 0 && aRow < MAX_LAYER_ROWS );
size_t index = aRow * LAYER_COLUMN_COUNT;
size_t index = aRow * LYR_COLUMN_COUNT;
wxSizerFlags flags;
flags.Align(wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
// column 0
wxStaticBitmap* sbm = new wxStaticBitmap( m_LayerScrolledWindow, layerId( 0, aSpec.layer ),
col = 0;
wxStaticBitmap* sbm = new wxStaticBitmap( m_LayerScrolledWindow, encodeId( col, aSpec.id ),
*m_BlankBitmap, wxDefaultPosition, m_BitmapSize );
sbm->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this );
sbm->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this );
m_LayersFlexGridSizer->Insert( index+0,
m_LayersFlexGridSizer->Insert( index+col,
new wxSizerItem( sbm, wxSizerFlags().Align( wxALIGN_CENTER_VERTICAL ) ) );
// column 1
wxBitmapButton* bmb = makeColorButton( aSpec.color, layerId( 1, aSpec.layer ) );
col = 1;
wxBitmapButton* bmb = makeColorButton( m_LayerScrolledWindow, aSpec.color, encodeId( col, aSpec.id ) );
bmb->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), 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->SetToolTip( _("Right click to change layer color, left click to select layer" ) );
m_LayersFlexGridSizer->Insert( index+1,
new wxSizerItem( bmb, flags ) );
bmb->SetToolTip( _("Left click to select, middle click for color change, right click for menu" ) );
m_LayersFlexGridSizer->Insert( index+col, new wxSizerItem( bmb, flags ) );
// column 2
wxStaticText* st = new wxStaticText( m_LayerScrolledWindow, layerId( 2, aSpec.layer ), aSpec.layerName );
col = 2;
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_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this );
st->SetToolTip( _( "Click here to select this layer" ) );
m_LayersFlexGridSizer->Insert( index+2,
m_LayersFlexGridSizer->Insert( index+col,
new wxSizerItem( st, wxSizerFlags().Align( wxALIGN_CENTER_VERTICAL )) );
// column 3
wxCheckBox* cb = new wxCheckBox( m_LayerScrolledWindow, layerId( 3, aSpec.layer ), wxEmptyString );
col = 3;
wxCheckBox* cb = new wxCheckBox( m_LayerScrolledWindow, encodeId( col, aSpec.id ), wxEmptyString );
cb->SetValue( aSpec.state );
cb->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( LAYER_WIDGET::OnLayerCheckBox ), NULL, this );
cb->SetToolTip( _( "Enable this for visibility" ) );
m_LayersFlexGridSizer->Insert( index+3, new wxSizerItem( cb, flags ) );
m_LayersFlexGridSizer->Insert( index+col, new wxSizerItem( cb, flags ) );
}
void insertRenderRow( int aRow, const ROW& aSpec )
{
int col;
wxASSERT( aRow >= 0 && aRow < MAX_LAYER_ROWS );
size_t index = aRow * RND_COLUMN_COUNT;
wxSizerFlags flags;
flags.Align(wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
// column 0
col = 0;
wxBitmapButton* bmb = makeColorButton( m_RenderScrolledWindow, aSpec.color, encodeId( col, aSpec.id ) );
bmb->Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnMiddleDownRenderColor ), NULL, this );
bmb->SetToolTip( _("Middle click for color change" ) );
m_RenderFlexGridSizer->Insert( index+col, new wxSizerItem( bmb, flags ) );
#if 1
// column 1
col = 1;
wxCheckBox* cb = new wxCheckBox( m_RenderScrolledWindow, encodeId( col, aSpec.id ), aSpec.rowName );
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
col = 1;
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 )) );
// column 2
col = 2;
wxCheckBox* cb = new wxCheckBox( m_RenderScrolledWindow, encodeId( col, aSpec.id ), wxEmptyString );
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 ) );
#endif
}
......@@ -401,24 +530,22 @@ public:
LAYER_WIDGET( wxWindow* parent ) :
LAYER_PANEL_BASE( parent )
{
m_CurrentRow = 0;
m_CurrentRow = -1;
m_RightArrowBitmap = new wxBitmap( rightarrow_xpm );
m_BlankBitmap = new wxBitmap( clear_xpm ); // translucent
m_BlankBitmap = new wxBitmap( clear_xpm ); // translucent
m_BitmapSize = wxSize(m_BlankBitmap->GetWidth(), m_BlankBitmap->GetHeight());
m_LayerScrolledWindow->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this );
AppendLayerRow( LAYER_SPEC( wxT("layer 1"), 0, RED ) );
AppendLayerRow( LAYER_SPEC( wxT("layer 2"), 1, GREEN ) );
AppendLayerRow( LAYER_SPEC( wxT("brown_layer"), 2, BROWN ) );
AppendLayerRow( LAYER_SPEC( wxT("layer_4_you"), 3, BLUE ) );
// handle the popup menu over the layer window
m_LayerScrolledWindow->Connect( wxEVT_RIGHT_DOWN,
wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this );
SelectLayerRow( 1 );
SetMinSize( GetPreferredSize() );
// since Popupmenu() call this->ProcessEvent() we must call this->Connect()
// and not m_LayerScrolledWindow->Connect()
Connect( ID_SHOW_ALL_COPPERS, ID_SHOW_NO_COPPERS,
wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler( LAYER_WIDGET::OnPopupSelection ), NULL, this );
}
......@@ -429,30 +556,38 @@ public:
*/
wxSize GetPreferredSize()
{
m_LayersFlexGridSizer->Layout();
FitInside();
// size of m_LayerScrolledWindow --------------
wxArrayInt widths = m_LayersFlexGridSizer->GetColWidths();
int totWidth = 0;
for( int i=0; i<LAYER_COLUMN_COUNT; ++i )
for( int i=0; i<LYR_COLUMN_COUNT; ++i )
{
totWidth += widths[i] + m_LayersFlexGridSizer->GetHGap();
printf("widths[%d]:%d\n", i, widths[i] );
// printf("widths[%d]:%d\n", i, widths[i] );
}
wxArrayInt heights = m_LayersFlexGridSizer->GetRowHeights();
int totHeight = 0;
int totHeight = 2 * heights[0]; // use 2 row heights to approximate tab height
int rowCount = GetLayerRowCount();
for( int i=0; i<rowCount; ++i )
{
totHeight += heights[i] + m_LayersFlexGridSizer->GetVGap();
printf("heights[%d]:%d\n", i, heights[i] );
// printf("heights[%d]:%d\n", i, heights[i] );
}
wxSize layerPanelSize( totWidth, totHeight );
// on linux: trial and error min until horizontal scroll bar goes away.
// I think this is to account for the top most window's frame:
totWidth += 10;
// this aint done yet, just a place holder for more work.
wxSize layerWindowSize( totWidth, totHeight );
return layerPanelSize;
return layerWindowSize;
}
void SetPreferredSize()
{
SetMinSize( GetPreferredSize() );
}
......@@ -463,17 +598,28 @@ public:
int GetLayerRowCount() const
{
int controlCount = m_LayersFlexGridSizer->GetChildren().GetCount();
return controlCount / LAYER_COLUMN_COUNT;
return controlCount / LYR_COLUMN_COUNT;
}
/**
* Function GetRenderRowCount
* returns the number of rows in the render tab.
*/
int GetRenderRowCount() const
{
int controlCount = m_RenderFlexGridSizer->GetChildren().GetCount();
return controlCount / RND_COLUMN_COUNT;
}
/**
* Function AppendLayerRow
* appends a new row in the layer portion of the widget.
* 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 LAYER_SPEC& aSpec )
void AppendLayerRow( const ROW& aRow )
{
int nextRow = GetLayerRowCount();
insertLayerRow( nextRow, aSpec );
insertLayerRow( nextRow, aRow );
}
/**
......@@ -485,28 +631,48 @@ public:
m_LayerScrolledWindow->DestroyChildren();
}
/**
* Function AppendRenderRow
* 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();
insertRenderRow( nextRow, aRow );
}
/**
* Function ClearRenderRows
* empties out the render rows.
*/
void ClearRenderRows()
{
m_RenderScrolledWindow->DestroyChildren();
}
/**
* Function SelectLayerRow
* changes the row selection in the layer list to the given row.
*/
bool SelectLayerRow( int aRow )
void SelectLayerRow( int aRow )
{
// enable the layer tab at index 0
m_notebook->ChangeSelection( 0 );
if( (unsigned) aRow < (unsigned) GetLayerRowCount() )
{
int newNdx = LAYER_COLUMN_COUNT * aRow;
int oldNdx = LAYER_COLUMN_COUNT * m_CurrentRow;
int oldNdx = LYR_COLUMN_COUNT * m_CurrentRow;
int newNdx = LYR_COLUMN_COUNT * aRow;
wxStaticBitmap* oldbm = (wxStaticBitmap*) getLayerComp( oldNdx );
wxStaticBitmap* newbm = (wxStaticBitmap*) getLayerComp( newNdx );
m_CurrentRow = aRow;
wxStaticBitmap* oldbm = (wxStaticBitmap*) getLayerComp( oldNdx );
if( oldbm )
oldbm->SetBitmap( *m_BlankBitmap );
newbm->SetBitmap( *m_RightArrowBitmap );
m_CurrentRow = aRow;
wxStaticBitmap* newbm = (wxStaticBitmap*) getLayerComp( newNdx );
if( newbm )
{
newbm->SetBitmap( *m_RightArrowBitmap );
// Change the focus to the wxBitmapButton in column 1 for this row.
// We really do not need or want the focus, but because we get focus
......@@ -519,31 +685,58 @@ public:
// It seems that as of 2.8.2, setting the focus
// does this and generally I don't expect the scrolling to be needed at all because
// the minimum window size may end up being established by the number of layers.
return true;
}
return false;
}
/**
* Function SelectLayer
* changes the row selection in the layer list to \a aLayer provided.
*/
bool SelectLayer( int aLayer )
void SelectLayer( int aLayer )
{
int row = findLayerRow( aLayer );
return SelectLayerRow( row );
SelectLayerRow( row );
}
/**
* 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.
wxStaticBitmap* bm = (wxStaticBitmap*) getLayerComp( m_CurrentRow * LYR_COLUMN_COUNT );
if( bm )
return getDecodedId( bm->GetId() );
return -1;
}
/**
* Function SetLayerVisible
* sets \a aLayer visible or not. This does not invoke OnLayerVisible().
*/
void SetLayerVisible( int aLayer, bool isVisible )
{
int row = findLayerRow( aLayer );
if( row >= 0 )
{
wxCheckBox* cb = (wxCheckBox*) getLayerComp( row * LYR_COLUMN_COUNT + 3 );
wxASSERT( cb );
cb->SetValue( isVisible ); // does not fire an event
}
}
//-----<abstract functions>-------------------------------------------
/**
* Function OnColorChange
* Function OnLayerColorChange
* is called to notify client code about a layer color change. Derived
* classes will handle this accordingly.
*/
virtual void OnColorChange( int aLayer, int aColor ) = 0;
virtual void OnLayerColorChange( int aLayer, int aColor ) = 0;
/**
* Function OnLayerSelect
......@@ -559,8 +752,26 @@ public:
*/
virtual void OnLayerVisible( int aLayer, bool isVisible ) = 0;
//-----</abstract functions>------------------------------------------
/**
* 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>------------------------------------------
};
......@@ -590,16 +801,17 @@ class MYFRAME : public wxFrame
{
}
void OnColorChange( int aLayer, int aColor )
void OnLayerColorChange( int aLayer, int aColor )
{
printf( "OnColorChange( aLayer:%d, aColor:%d )\n", aLayer, aColor );
printf( "OnLayerColorChange( aLayer:%d, aColor:%d )\n", aLayer, aColor );
// a test trigger only
/* a test trigger only
if( aLayer == 2 )
{
ClearLayerRows();
printf(" GetLayerRowCount(): %d\n", GetLayerRowCount() );
}
*/
}
bool OnLayerSelect( int aLayer )
......@@ -612,6 +824,16 @@ class MYFRAME : public wxFrame
{
printf( "OnLayerVisible( aLayer:%d, isVisible:%d )\n", aLayer, isVisible );
}
void OnRenderColorChange( int aId, int aColor )
{
printf( "OnRenderColorChange( aId:%d, aColor:%d )\n", aId, aColor );
}
void OnRenderEnable( int aId, bool isEnabled )
{
printf( "OnRenderEnable( aId:%d, isEnabled:%d )\n", aId, isEnabled );
}
};
......@@ -623,28 +845,39 @@ public:
// notify wxAUI which frame to use
m_mgr.SetManagedWindow( this );
MYLAYERS* layerWidget = new MYLAYERS( this, this );
MYLAYERS* lw = new MYLAYERS( this, this );
wxTextCtrl* text2 = new wxTextCtrl( this, -1, _( "Pane 2 - sample text" ),
wxDefaultPosition, wxSize( 200, 150 ),
wxNO_BORDER | wxTE_MULTILINE );
lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer 1"), 0, RED, false ) );
lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer 2"), 1, GREEN ) );
lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("brown_layer"), 2, BROWN ) );
lw->AppendLayerRow( LAYER_WIDGET::ROW( wxT("layer_4_you"), 3, BLUE, false ) );
wxTextCtrl* text3 = new wxTextCtrl( this, -1, _( "Main content window" ),
wxDefaultPosition, wxSize( 200, 150 ),
wxNO_BORDER | wxTE_MULTILINE );
lw->AppendRenderRow( LAYER_WIDGET::ROW( wxT("With Ears"), 0, GREEN ) );
lw->AppendRenderRow( LAYER_WIDGET::ROW( wxT("With Legs"), 1, YELLOW ) );
lw->SetPreferredSize();
lw->SelectLayerRow( 1 );
// add the panes to the manager
wxAuiPaneInfo li;
li.MinSize( layerWidget->GetPreferredSize() ); // ignored on linux
li.BestSize( layerWidget->GetPreferredSize() );
li.MinSize( lw->GetPreferredSize() );
li.BestSize( lw->GetPreferredSize() );
li.Left();
li.MaximizeButton( true );
li.MinimizeButton( true );
// li.MaximizeButton( true );
// li.MinimizeButton( true );
li.CloseButton( false );
li.Caption( wxT( "Layers" ) );
m_mgr.AddPane( layerWidget, li );
m_mgr.AddPane( lw, li );
wxTextCtrl* text2 = new wxTextCtrl( this, -1, _( "Pane 2 - sample text" ),
wxDefaultPosition, wxSize( 200, 150 ),
wxNO_BORDER | wxTE_MULTILINE );
m_mgr.AddPane( text2, wxBOTTOM, wxT( "Pane Number Two" ) );
wxTextCtrl* text3 = new wxTextCtrl( this, -1, _( "Main content window" ),
wxDefaultPosition, wxSize( 200, 150 ),
wxNO_BORDER | wxTE_MULTILINE );
m_mgr.AddPane( text3, wxCENTER );
// tell the manager to "commit" all the changes just made
......
......@@ -198,7 +198,7 @@
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick">OnLeftDblClickLayers</event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown">OnLeftDownLayers</event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
......@@ -246,7 +246,7 @@
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">m_Page1Panel</property>
<property name="name">m_RenderingPanel</property>
<property name="permission">protected</property>
<property name="pos"></property>
<property name="size"></property>
......@@ -283,6 +283,69 @@
<property name="name">bSizer4</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxScrolledWindow" expanded="1">
<property name="bg"></property>
<property name="context_help"></property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="font"></property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">m_RenderScrolledWindow</property>
<property name="permission">protected</property>
<property name="pos"></property>
<property name="scroll_rate_x">5</property>
<property name="scroll_rate_y">5</property>
<property name="size"></property>
<property name="subclass"></property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style">wxVSCROLL</property>
<event name="OnChar"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
<event name="OnKeyUp"></event>
<event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event>
<event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event>
<event name="OnLeftUp"></event>
<event name="OnMiddleDClick"></event>
<event name="OnMiddleDown"></event>
<event name="OnMiddleUp"></event>
<event name="OnMotion"></event>
<event name="OnMouseEvents"></event>
<event name="OnMouseWheel"></event>
<event name="OnPaint"></event>
<event name="OnRightDClick"></event>
<event name="OnRightDown"></event>
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
<object class="wxFlexGridSizer" expanded="1">
<property name="cols">2</property>
<property name="flexible_direction">wxHORIZONTAL</property>
<property name="growablecols"></property>
<property name="growablerows"></property>
<property name="hgap">3</property>
<property name="minimum_size"></property>
<property name="name">m_RenderFlexGridSizer</property>
<property name="non_flexible_grow_mode">wxFLEX_GROWMODE_SPECIFIED</property>
<property name="permission">protected</property>
<property name="rows">0</property>
<property name="vgap">1</property>
</object>
</object>
</object>
</object>
</object>
</object>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment