kicad/pcbnew/layer_widget.cpp

998 lines
28 KiB
C++
Raw Normal View History

2010-01-07 02:18:25 +00:00
/*
* This program source code file is part of KiCad, a free EDA CAD application.
2010-01-07 02:18:25 +00:00
*
* Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2010 KiCad Developers, see change_log.txt for contributors.
2010-01-07 02:18:25 +00:00
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* This source module implements the layer visibility and selection widget
2010-01-24 02:05:07 +00:00
@todo make the bitmapbutton a staticbitmap, and make dependent on the point size.
2010-01-07 02:18:25 +00:00
*/
2010-01-21 07:41:30 +00:00
//#define STAND_ALONE 1 // define to enable test program for LAYER_WIDGET
2010-01-07 02:18:25 +00:00
2010-01-24 02:05:07 +00:00
#include "layer_widget.h"
2010-01-21 07:41:30 +00:00
#include "macros.h"
#include "common.h"
#include "colors.h"
#include <wx/colour.h>
2010-01-16 06:22:24 +00:00
#define BUTT_SIZE_X 20
#define BUTT_SIZE_Y 18
#define BUTT_VOID 4
2010-01-21 07:41:30 +00:00
/* XPM
* This bitmap is used for not selected layers
*/
2010-01-07 16:33:41 +00:00
static const char * clear_xpm[] = {
"10 14 1 1",
2010-01-07 16:33:41 +00:00
" c None",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};
2010-01-07 16:33:41 +00:00
/* XPM
* This bitmap can be used to show a not selected layer
* with special property (mainly not selected layers not in use in GerbView)
*/
static const char * clear_alternate_xpm[] = {
"10 14 4 1",
" c None",
"X c #008080",
"o c GREEN",
"O c #00B080",
" ",
" ",
" ",
" ",
" X ",
" XXX ",
" XXXXX ",
" OOOOOOO ",
" ooooo ",
" ooo ",
" o ",
" ",
" ",
" "};
/* XPM
* This bitmap is used for a normale selected layer
*/
2010-01-07 16:33:41 +00:00
static const char * rightarrow_xpm[] = {
"10 14 4 1",
" c None",
"X c #8080ff",
"o c BLUE",
"O c gray56",
" X ",
" XX ",
" XXX ",
" XXXX ",
" XXXXX ",
" XXXXXX ",
" XXXXXXX ",
" oooooooO",
" ooooooO ",
" oooooO ",
" ooooO ",
" oooO ",
" ooO ",
" oO "};
2010-01-07 16:33:41 +00:00
/* XPM
* This bitmap can be used to show the selected layer
* with special property (mainly a layer in use in GerbView)
*/
static const char * rightarrow_alternate_xpm[] = {
"10 14 5 1",
" c None",
". c #00B000",
"X c #8080ff",
"o c BLUE",
"O c gray56",
"..X ",
"..XX ",
"..XXX ",
"..XXXX ",
"..XXXXX ",
"..XXXXXX ",
"..XXXXXXX ",
"..oooooooO",
"..ooooooO ",
"..oooooO ",
"..ooooO ",
"..oooO ",
"..ooO ",
"..oO "};
2010-01-11 16:49:11 +00:00
/**
* Function makeColorTxt
* returns a string containing the numeric value of the color.
* in a form like 0x00000000. (Color is currently an index, not RGB).
*/
static wxString makeColorTxt( int aColor )
{
2010-01-21 07:41:30 +00:00
wxString txt;
txt.Printf( wxT("0x%08x"), aColor );
return txt;
2010-01-11 16:49:11 +00:00
}
2010-01-07 02:18:25 +00:00
/**
* Function shrinkFont
* reduces the size of the wxFont associated with \a aControl
*/
2010-01-24 02:05:07 +00:00
static void shrinkFont( wxWindow* aControl, int aPointSize )
{
wxFont font = aControl->GetFont();
2010-01-24 02:05:07 +00:00
font.SetPointSize( aPointSize );
aControl->SetFont( font ); // need this?
}
int LAYER_WIDGET::encodeId( int aColumn, int aId )
{
int id = aId * LYR_COLUMN_COUNT + aColumn;
return id;
}
int LAYER_WIDGET::getDecodedId( int aControlId )
{
int id = aControlId / LYR_COLUMN_COUNT; // rounding is OK.
return id;
}
2010-01-24 02:05:07 +00:00
2010-01-18 15:55:18 +00:00
wxBitmap LAYER_WIDGET::makeBitmap( int aColor )
2010-01-07 02:18:25 +00:00
{
2010-01-18 15:55:18 +00:00
// 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;
2010-01-10 05:44:29 +00:00
2010-01-18 15:55:18 +00:00
iconDC.SelectObject( bitmap );
2010-01-16 06:22:24 +00:00
2010-01-18 15:55:18 +00:00
brush.SetColour( MakeColour( aColor ) );
brush.SetStyle( wxSOLID );
iconDC.SetBrush( brush );
2010-01-16 06:22:24 +00:00
2010-01-18 15:55:18 +00:00
iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X - 2 * BUTT_VOID, BUTT_SIZE_Y - 2 * BUTT_VOID );
2010-01-16 06:22:24 +00:00
2010-01-18 15:55:18 +00:00
return bitmap;
}
2010-01-07 02:18:25 +00:00
2010-01-18 15:55:18 +00:00
wxBitmapButton* LAYER_WIDGET::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 );
2010-01-07 02:18:25 +00:00
#ifndef __WXMAC__
2010-01-18 15:55:18 +00:00
wxBitmapButton* ret = new wxBitmapButton( aParent, aID, bitmap,
wxDefaultPosition, wxSize(BUTT_SIZE_X, BUTT_SIZE_Y), wxBORDER_RAISED );
#else
wxBitmapButton* ret = new wxBitmapButton( aParent, aID, bitmap,
wxDefaultPosition, wxSize(BUTT_SIZE_X, BUTT_SIZE_Y));
#endif
2010-01-18 15:55:18 +00:00
// save the color value in the name, no where else to put it.
ret->SetName( makeColorTxt( aColor ) );
return ret;
}
2010-01-07 02:18:25 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::OnLeftDownLayers( wxMouseEvent& event )
{
int row;
2010-01-24 02:05:07 +00:00
int layer;
2010-01-10 07:56:07 +00:00
2010-01-18 15:55:18 +00:00
wxWindow* eventSource = (wxWindow*) event.GetEventObject();
2010-01-10 07:56:07 +00:00
2010-01-18 15:55:18 +00:00
// if mouse event is coming from the m_LayerScrolledWindow and not one
// of its children, we have to find the row manually based on y coord.
if( eventSource == m_LayerScrolledWindow )
2010-01-10 07:56:07 +00:00
{
2010-01-18 15:55:18 +00:00
int y = event.GetY();
2010-01-10 07:56:07 +00:00
2010-01-18 15:55:18 +00:00
wxArrayInt heights = m_LayersFlexGridSizer->GetRowHeights();
2010-01-09 15:51:09 +00:00
2010-01-18 15:55:18 +00:00
int height = 0;
2010-01-08 01:17:59 +00:00
2010-01-18 15:55:18 +00:00
int rowCount = GetLayerRowCount();
for( row = 0; row<rowCount; ++row )
2010-01-08 01:17:59 +00:00
{
2010-01-18 15:55:18 +00:00
if( y < height + heights[row] )
break;
2010-01-08 01:17:59 +00:00
2010-01-18 15:55:18 +00:00
height += heights[row];
2010-01-09 15:51:09 +00:00
}
2010-01-08 01:17:59 +00:00
2010-01-18 15:55:18 +00:00
if( row >= rowCount )
row = rowCount - 1;
2010-01-24 02:05:07 +00:00
2010-01-30 17:42:22 +00:00
layer = getDecodedId( getLayerComp( row, 0 )->GetId() );
2010-01-07 02:18:25 +00:00
}
2010-01-08 01:17:59 +00:00
2010-01-18 15:55:18 +00:00
else
2010-01-07 02:18:25 +00:00
{
2010-01-18 15:55:18 +00:00
// all nested controls on a given row will have their ID encoded with
// encodeId(), and the corresponding decoding is getDecodedId()
2010-01-24 02:05:07 +00:00
int id = eventSource->GetId();
layer = getDecodedId( id );
row = findLayerRow( layer );
2010-01-18 15:55:18 +00:00
}
2010-01-10 07:56:07 +00:00
2010-01-24 02:05:07 +00:00
if( OnLayerSelect( layer ) ) // if client allows this change.
2010-01-18 15:55:18 +00:00
SelectLayerRow( row );
2010-01-21 20:53:01 +00:00
passOnFocus();
2010-01-18 15:55:18 +00:00
}
2010-01-10 07:56:07 +00:00
2010-01-21 07:41:30 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::OnMiddleDownLayerColor( wxMouseEvent& event )
{
wxBitmapButton* eventSource = (wxBitmapButton*) event.GetEventObject();
2010-01-10 07:56:07 +00:00
2010-01-18 15:55:18 +00:00
wxString colorTxt = eventSource->GetName();
2010-01-10 07:56:07 +00:00
int oldColor = strtoul( TO_UTF8(colorTxt), NULL, 0 );
2010-01-18 15:55:18 +00:00
int newColor = DisplayColorFrame( this, oldColor );
2010-01-11 16:49:11 +00:00
2010-01-18 15:55:18 +00:00
if( newColor >= 0 )
{
eventSource->SetName( makeColorTxt( newColor ) );
2010-01-11 16:49:11 +00:00
2010-01-18 15:55:18 +00:00
wxBitmap bm = makeBitmap( newColor );
eventSource->SetBitmapLabel( bm );
int layer = getDecodedId( eventSource->GetId() );
// tell the client code.
OnLayerColorChange( layer, newColor );
2010-01-07 02:18:25 +00:00
}
2010-01-21 20:53:01 +00:00
passOnFocus();
2010-01-18 15:55:18 +00:00
}
2010-01-08 01:17:59 +00:00
2010-01-11 16:49:11 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::OnLayerCheckBox( wxCommandEvent& event )
{
wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject();
int layer = getDecodedId( eventSource->GetId() );
OnLayerVisible( layer, eventSource->IsChecked() );
2010-01-21 20:53:01 +00:00
passOnFocus();
2010-01-18 15:55:18 +00:00
}
2010-01-16 06:22:24 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::OnMiddleDownRenderColor( wxMouseEvent& event )
{
wxBitmapButton* eventSource = (wxBitmapButton*) event.GetEventObject();
2010-01-16 06:22:24 +00:00
2010-01-18 15:55:18 +00:00
wxString colorTxt = eventSource->GetName();
2010-01-16 06:22:24 +00:00
int oldColor = strtoul( TO_UTF8(colorTxt), NULL, 0 );
2010-01-18 15:55:18 +00:00
int newColor = DisplayColorFrame( this, oldColor );
2010-01-16 06:22:24 +00:00
2010-01-18 15:55:18 +00:00
if( newColor >= 0 )
{
eventSource->SetName( makeColorTxt( newColor ) );
2010-01-16 06:22:24 +00:00
2010-01-18 15:55:18 +00:00
wxBitmap bm = makeBitmap( newColor );
eventSource->SetBitmapLabel( bm );
2010-01-16 06:22:24 +00:00
int id = getDecodedId( eventSource->GetId() );
2010-01-11 16:49:11 +00:00
2010-01-18 15:55:18 +00:00
// tell the client code.
OnRenderColorChange( id, newColor );
2010-01-07 16:33:41 +00:00
}
2010-01-21 20:53:01 +00:00
passOnFocus();
2010-01-18 15:55:18 +00:00
}
2010-01-07 02:18:25 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::OnRenderCheckBox( wxCommandEvent& event )
{
wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject();
int id = getDecodedId( eventSource->GetId() );
OnRenderEnable( id, eventSource->IsChecked() );
2010-01-21 20:53:01 +00:00
passOnFocus();
2010-01-18 15:55:18 +00:00
}
2010-01-08 01:17:59 +00:00
void LAYER_WIDGET::OnTabChange( wxNotebookEvent& event )
{
// wxFocusEvent event( wxEVT_SET_FOCUS );
// m_FocusOwner->AddPendingEvent( event );
passOnFocus(); // does not work in this context, probably because we have receive control here too early.
}
2010-01-30 17:42:22 +00:00
wxWindow* LAYER_WIDGET::getLayerComp( int aRow, int aColumn )
2010-01-18 15:55:18 +00:00
{
2010-01-30 17:42:22 +00:00
int ndx = aRow * LYR_COLUMN_COUNT + aColumn;
if( (unsigned) ndx < m_LayersFlexGridSizer->GetChildren().GetCount() )
return m_LayersFlexGridSizer->GetChildren()[ndx]->GetWindow();
2010-01-18 15:55:18 +00:00
return NULL;
}
2010-01-16 06:22:24 +00:00
2010-01-21 07:41:30 +00:00
2010-01-18 15:55:18 +00:00
int LAYER_WIDGET::findLayerRow( int aLayer )
{
int count = GetLayerRowCount();
for( int row=0; row<count; ++row )
2010-01-16 06:22:24 +00:00
{
2010-01-18 15:55:18 +00:00
// column 0 in the layer scroll window has a wxStaticBitmap, get its ID.
2010-01-30 17:42:22 +00:00
wxWindow* w = getLayerComp( row, 0 );
wxASSERT( w );
2010-01-16 06:22:24 +00:00
if( aLayer == getDecodedId( w->GetId() ))
return row;
}
return -1;
}
2010-01-30 17:42:22 +00:00
wxWindow* LAYER_WIDGET::getRenderComp( int aRow, int aColumn )
{
2010-01-30 17:42:22 +00:00
int ndx = aRow * RND_COLUMN_COUNT + aColumn;
if( (unsigned) ndx < m_RenderFlexGridSizer->GetChildren().GetCount() )
return m_RenderFlexGridSizer->GetChildren()[ndx]->GetWindow();
return NULL;
}
int LAYER_WIDGET::findRenderRow( int aId )
{
int count = GetRenderRowCount();
for( int row=0; row<count; ++row )
{
// column 0 in the layer scroll window has a wxStaticBitmap, get its ID.
2010-01-30 17:42:22 +00:00
wxWindow* w = getRenderComp( row, 0 );
wxASSERT( w );
if( aId == getDecodedId( w->GetId() ))
2010-01-18 15:55:18 +00:00
return row;
}
return -1;
}
2010-01-16 06:22:24 +00:00
2010-01-21 07:41:30 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::insertLayerRow( int aRow, const ROW& aSpec )
{
wxASSERT( aRow >= 0 && aRow < MAX_LAYER_ROWS );
int col;
int index = aRow * LYR_COLUMN_COUNT;
const int flags = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT;
// column 0
col = 0;
wxStaticBitmap* sbm = new wxStaticBitmap( m_LayerScrolledWindow, encodeId( col, aSpec.id ),
useAlternateBitmap(aRow) ? *m_BlankAlternateBitmap : *m_BlankBitmap,
wxDefaultPosition, m_BitmapSize );
2010-01-18 15:55:18 +00:00
sbm->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this );
m_LayersFlexGridSizer->wxSizer::Insert( index+col, sbm, 0, flags );
2010-01-18 15:55:18 +00:00
// column 1
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->SetToolTip( _("Left click to select, middle click for color change, right click for menu" ) );
m_LayersFlexGridSizer->wxSizer::Insert( index+col, bmb, 0, flags );
2010-01-18 15:55:18 +00:00
// column 2
col = 2;
wxStaticText* st = new wxStaticText( m_LayerScrolledWindow, encodeId( col, aSpec.id ), aSpec.rowName );
2010-01-24 02:05:07 +00:00
shrinkFont( st, m_PointSize );
2010-01-18 15:55:18 +00:00
st->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this );
st->SetToolTip( aSpec.tooltip );
m_LayersFlexGridSizer->wxSizer::Insert( index+col, st, 0, flags );
2010-01-18 15:55:18 +00:00
// column 3
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->wxSizer::Insert( index+col, cb, 0, flags );
2010-01-18 15:55:18 +00:00
}
2010-01-16 06:22:24 +00:00
2010-01-21 07:41:30 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::insertRenderRow( int aRow, const ROW& aSpec )
{
wxASSERT( aRow >= 0 && aRow < MAX_LAYER_ROWS );
2010-01-16 06:22:24 +00:00
2010-01-18 15:55:18 +00:00
int col;
int index = aRow * RND_COLUMN_COUNT;
const int flags = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT;
2010-01-16 06:22:24 +00:00
2010-01-18 15:55:18 +00:00
// column 0
col = 0;
if( aSpec.color != -1 )
{
2010-01-16 06:22:24 +00:00
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->wxSizer::Insert( index+col, bmb, 0, flags );
2010-01-18 15:55:18 +00:00
// could add a left click handler on the color button that toggles checkbox.
}
2010-01-21 07:41:30 +00:00
else // == -1, no color selection wanted
2010-01-18 15:55:18 +00:00
{
// need a place holder within the sizer to keep grid full.
wxPanel* invisible = new wxPanel( m_RenderScrolledWindow );
m_RenderFlexGridSizer->wxSizer::Insert( index+col, invisible, 0, flags );
2010-01-07 16:33:41 +00:00
}
2010-01-18 15:55:18 +00:00
// column 1
col = 1;
wxCheckBox* cb = new wxCheckBox( m_RenderScrolledWindow, encodeId( col, aSpec.id ),
aSpec.rowName, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );
2010-01-24 02:05:07 +00:00
shrinkFont( cb, m_PointSize );
2010-01-21 20:53:01 +00:00
cb->SetValue( aSpec.state );
2010-01-18 15:55:18 +00:00
cb->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler( LAYER_WIDGET::OnRenderCheckBox ), NULL, this );
cb->SetToolTip( aSpec.tooltip );
m_RenderFlexGridSizer->wxSizer::Insert( index+col, cb, 0, flags );
2010-01-18 15:55:18 +00:00
}
2010-01-11 16:49:11 +00:00
2010-01-07 16:33:41 +00:00
2010-01-21 20:53:01 +00:00
void LAYER_WIDGET::passOnFocus()
{
m_FocusOwner->SetFocus();
2010-01-21 20:53:01 +00:00
}
2010-01-18 15:55:18 +00:00
//-----<public>-------------------------------------------------------
2010-01-07 16:33:41 +00:00
2010-01-24 02:05:07 +00:00
LAYER_WIDGET::LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner, int aPointSize,
wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) :
wxPanel( aParent, id, pos, size, style )
2010-01-18 15:55:18 +00:00
{
wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
2010-01-24 02:05:07 +00:00
m_notebook = new wxAuiNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_TOP );
wxFont font = m_notebook->GetFont();
if( aPointSize == -1 )
{
m_PointSize = font.GetPointSize();
}
else
{
m_PointSize = aPointSize;
// change the font size on the notebook's tabs to match aPointSize
font.SetPointSize( aPointSize );
m_notebook->SetFont( font );
m_notebook->SetNormalFont( font );
m_notebook->SetSelectedFont( font );
m_notebook->SetMeasuringFont( font );
}
2010-01-24 02:05:07 +00:00
m_LayerPanel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* bSizer3;
bSizer3 = new wxBoxSizer( wxVERTICAL );
m_LayerScrolledWindow = new wxScrolledWindow( m_LayerPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER );
m_LayerScrolledWindow->SetScrollRate( 5, 5 );
m_LayersFlexGridSizer = new wxFlexGridSizer( 0, 4, 0, 1 );
m_LayersFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL );
m_LayersFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_LayerScrolledWindow->SetSizer( m_LayersFlexGridSizer );
m_LayerScrolledWindow->Layout();
m_LayersFlexGridSizer->Fit( m_LayerScrolledWindow );
bSizer3->Add( m_LayerScrolledWindow, 1, wxBOTTOM|wxEXPAND|wxLEFT|wxTOP, 2 );
m_LayerPanel->SetSizer( bSizer3 );
m_LayerPanel->Layout();
bSizer3->Fit( m_LayerPanel );
m_notebook->AddPage( m_LayerPanel, _("Layer"), true );
m_RenderingPanel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* bSizer4;
bSizer4 = new wxBoxSizer( wxVERTICAL );
m_RenderScrolledWindow = new wxScrolledWindow( m_RenderingPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER );
m_RenderScrolledWindow->SetScrollRate( 5, 5 );
m_RenderFlexGridSizer = new wxFlexGridSizer( 0, 2, 0, 1 );
m_RenderFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL );
m_RenderFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE );
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, _("Render"), false );
boxSizer->Add( m_notebook, 1, wxEXPAND | wxALL, 5 );
SetSizer( boxSizer );
m_FocusOwner = aFocusOwner;
2010-01-21 20:53:01 +00:00
2010-01-24 02:05:07 +00:00
m_CurrentRow = -1; // hide the arrow initially
2010-01-07 02:18:25 +00:00
2010-01-18 15:55:18 +00:00
m_RightArrowBitmap = new wxBitmap( rightarrow_xpm );
m_RightArrowAlternateBitmap = new wxBitmap( rightarrow_alternate_xpm );
2010-01-07 16:33:41 +00:00
2010-01-18 15:55:18 +00:00
m_BlankBitmap = new wxBitmap( clear_xpm ); // translucent
m_BlankAlternateBitmap = new wxBitmap( clear_alternate_xpm );
2010-01-18 15:55:18 +00:00
m_BitmapSize = wxSize(m_BlankBitmap->GetWidth(), m_BlankBitmap->GetHeight());
2010-01-07 16:33:41 +00:00
// trap the tab changes so that we can call passOnFocus().
m_notebook->Connect( -1, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
wxNotebookEventHandler( LAYER_WIDGET::OnTabChange ), NULL, this );
2010-01-24 02:05:07 +00:00
Layout();
2010-01-18 15:55:18 +00:00
}
2010-01-11 16:49:11 +00:00
2010-01-18 15:55:18 +00:00
wxSize LAYER_WIDGET::GetBestSize() const
{
#if 0
wxSize layerz = m_LayersFlexGridSizer->GetMinSize();
wxSize renderz = m_RenderFlexGridSizer->GetMinSize();
2010-01-24 02:05:07 +00:00
wxSize clientz( MAX(renderz.x,layerz.x), MAX(renderz.y,layerz.y) );
return ClientToWindowSize( clientz );
#else
2010-01-18 15:55:18 +00:00
// size of m_LayerScrolledWindow --------------
wxArrayInt widths = m_LayersFlexGridSizer->GetColWidths();
int totWidth = 0;
if( widths.GetCount() )
2010-01-11 16:49:11 +00:00
{
2010-01-18 15:55:18 +00:00
for( int i=0; i<LYR_COLUMN_COUNT; ++i )
2010-01-11 16:49:11 +00:00
{
totWidth += widths[i] + m_LayersFlexGridSizer->GetHGap();
2010-01-16 06:22:24 +00:00
// printf("widths[%d]:%d\n", i, widths[i] );
2010-01-11 16:49:11 +00:00
}
2010-01-18 15:55:18 +00:00
}
// Account for the parent's frame:
totWidth += 10;
2010-01-11 16:49:11 +00:00
2010-01-18 15:55:18 +00:00
wxArrayInt heights = m_LayersFlexGridSizer->GetRowHeights();
int totHeight = 0;
if( heights.GetCount() )
{
2010-01-11 16:49:11 +00:00
int rowCount = GetLayerRowCount();
2010-01-18 15:55:18 +00:00
for( int i=0; i<rowCount; ++i )
2010-01-11 16:49:11 +00:00
{
totHeight += heights[i] + m_LayersFlexGridSizer->GetVGap();
2010-01-16 06:22:24 +00:00
// printf("heights[%d]:%d\n", i, heights[i] );
2010-01-11 16:49:11 +00:00
}
2010-01-18 15:55:18 +00:00
totHeight += 2 * heights[0]; // use 2 row heights to approximate tab height
}
else
totHeight += 20; // not used except before adding rows.
2010-01-11 16:49:11 +00:00
2010-01-18 15:55:18 +00:00
wxSize layerz( totWidth, totHeight );
2010-01-10 05:44:29 +00:00
layerz += m_LayerPanel->GetWindowBorderSize();
2010-01-16 06:22:24 +00:00
2010-01-18 15:55:18 +00:00
// size of m_RenderScrolledWindow --------------
widths = m_RenderFlexGridSizer->GetColWidths();
totWidth = 0;
if( widths.GetCount() )
{
for( int i=0; i<RND_COLUMN_COUNT; ++i )
2010-01-16 07:50:01 +00:00
{
totWidth += widths[i] + m_RenderFlexGridSizer->GetHGap();
// printf("widths[%d]:%d\n", i, widths[i] );
}
2010-01-18 15:55:18 +00:00
}
// account for the parent's frame, this one has void space of 10 PLUS a border:
totWidth += 20;
2010-01-16 07:50:01 +00:00
2010-01-18 15:55:18 +00:00
heights = m_RenderFlexGridSizer->GetRowHeights();
totHeight = 0;
if( heights.GetCount() )
{
int rowCount = GetRenderRowCount();
2010-01-16 07:50:01 +00:00
for( int i=0; i<rowCount && i<(int)heights.GetCount(); ++i )
{
totHeight += heights[i] + m_RenderFlexGridSizer->GetVGap();
// printf("heights[%d]:%d\n", i, heights[i] );
}
2010-01-18 15:55:18 +00:00
totHeight += 2 * heights[0]; // use 2 row heights to approximate tab height
}
else
totHeight += 20; // not used except before adding rows
2010-01-16 07:50:01 +00:00
2010-01-18 15:55:18 +00:00
wxSize renderz( totWidth, totHeight );
2010-01-16 07:50:01 +00:00
renderz += m_RenderingPanel->GetWindowBorderSize();
2010-01-24 02:05:07 +00:00
wxSize clientz( MAX(renderz.x,layerz.x), MAX(renderz.y,layerz.y) );
// wxSize diffz( GetSize() - GetClientSize() );
// clientz += diffz;
return clientz;
#endif
2010-01-18 15:55:18 +00:00
}
2010-01-16 07:50:01 +00:00
2010-01-18 15:55:18 +00:00
int LAYER_WIDGET::GetLayerRowCount() const
{
int controlCount = m_LayersFlexGridSizer->GetChildren().GetCount();
return controlCount / LYR_COLUMN_COUNT;
}
2010-01-07 02:18:25 +00:00
2010-01-07 16:33:41 +00:00
2010-01-18 15:55:18 +00:00
int LAYER_WIDGET::GetRenderRowCount() const
{
int controlCount = m_RenderFlexGridSizer->GetChildren().GetCount();
return controlCount / RND_COLUMN_COUNT;
}
2010-01-16 06:22:24 +00:00
2010-01-09 15:51:09 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::AppendLayerRow( const ROW& aRow )
{
int nextRow = GetLayerRowCount();
insertLayerRow( nextRow, aRow );
2010-01-21 07:41:30 +00:00
UpdateLayouts();
2010-01-18 15:55:18 +00:00
}
2010-01-09 15:51:09 +00:00
2010-01-11 16:49:11 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::ClearLayerRows()
{
2010-01-21 07:41:30 +00:00
m_LayersFlexGridSizer->Clear( true );
2010-01-18 15:55:18 +00:00
}
2010-01-16 06:22:24 +00:00
2010-01-09 15:51:09 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::AppendRenderRow( const ROW& aRow )
{
int nextRow = GetRenderRowCount();
insertRenderRow( nextRow, aRow );
2010-01-21 07:41:30 +00:00
UpdateLayouts();
2010-01-18 15:55:18 +00:00
}
2010-01-11 16:49:11 +00:00
2010-01-09 15:51:09 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::ClearRenderRows()
{
2010-01-21 07:41:30 +00:00
m_RenderFlexGridSizer->Clear( true );
2010-01-18 15:55:18 +00:00
}
2010-01-09 15:51:09 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::SelectLayerRow( int aRow )
{
// enable the layer tab at index 0
m_notebook->SetSelection( 0 );
2010-01-09 15:51:09 +00:00
2010-01-30 17:42:22 +00:00
wxStaticBitmap* oldbm = (wxStaticBitmap*) getLayerComp( m_CurrentRow, 0 );
2010-01-18 15:55:18 +00:00
if( oldbm )
oldbm->SetBitmap( useAlternateBitmap(m_CurrentRow) ? *m_BlankAlternateBitmap : *m_BlankBitmap );
2010-01-18 15:55:18 +00:00
2010-01-30 17:42:22 +00:00
wxStaticBitmap* newbm = (wxStaticBitmap*) getLayerComp( aRow, 0 );
2010-01-18 15:55:18 +00:00
if( newbm )
2010-01-09 15:51:09 +00:00
{
newbm->SetBitmap( useAlternateBitmap(aRow) ? *m_RightArrowAlternateBitmap : *m_RightArrowBitmap );
2010-01-18 15:55:18 +00:00
// Make sure the desired layer row is visible.
2010-01-21 20:53:01 +00:00
// It seems that as of 2.8.2, setting the focus does this.
// I don't expect the scrolling to be needed at all because
// the minimum window size may end up being established so that the
// scroll bars will not be visible.
2010-01-30 17:42:22 +00:00
getLayerComp( aRow, 1 )->SetFocus();
2010-01-09 15:51:09 +00:00
}
2010-01-21 20:53:01 +00:00
2010-01-30 17:42:22 +00:00
m_CurrentRow = aRow;
2010-01-21 20:53:01 +00:00
// give the focus back to the app.
passOnFocus();
2010-01-18 15:55:18 +00:00
}
2010-01-09 15:51:09 +00:00
2010-01-11 16:49:11 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::SelectLayer( int aLayer )
{
int row = findLayerRow( aLayer );
SelectLayerRow( row );
}
int LAYER_WIDGET::GetSelectedLayer()
{
2010-01-30 17:42:22 +00:00
wxWindow* w = getLayerComp( m_CurrentRow, 0 );
if( w )
return getDecodedId( w->GetId() );
2010-01-18 15:55:18 +00:00
return -1;
}
2010-01-16 06:22:24 +00:00
2010-01-18 15:55:18 +00:00
void LAYER_WIDGET::SetLayerVisible( int aLayer, bool isVisible )
{
int row = findLayerRow( aLayer );
if( row >= 0 )
2010-01-16 06:22:24 +00:00
{
2010-01-30 17:42:22 +00:00
wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, 3 );
2010-01-18 15:55:18 +00:00
wxASSERT( cb );
cb->SetValue( isVisible ); // does not fire an event
2010-01-16 06:22:24 +00:00
}
2010-01-18 15:55:18 +00:00
}
2010-01-07 02:18:25 +00:00
bool LAYER_WIDGET::IsLayerVisible( int aLayer )
{
int row = findLayerRow( aLayer );
if( row >= 0 )
{
2010-01-30 17:42:22 +00:00
wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, 3 );
wxASSERT( cb );
return cb->GetValue();
}
return false;
}
void LAYER_WIDGET::SetLayerColor( int aLayer, int aColor )
{
int row = findLayerRow( aLayer );
if( row >= 0 )
{
int col = 1; // bitmap button is column 1
2010-01-30 17:42:22 +00:00
wxBitmapButton* bmb = (wxBitmapButton*) getLayerComp( row, col );
wxASSERT( bmb );
wxBitmap bm = makeBitmap( aColor );
bmb->SetBitmapLabel( bm );
bmb->SetName( makeColorTxt( aColor ) ); // save color value in name as string
}
}
int LAYER_WIDGET::GetLayerColor( int aLayer )
{
int row = findLayerRow( aLayer );
if( row >= 0 )
{
int col = 1; // bitmap button is column 1
2010-01-30 17:42:22 +00:00
wxBitmapButton* bmb = (wxBitmapButton*) getLayerComp( row, col );
wxASSERT( bmb );
wxString colorTxt = bmb->GetName();
int color = strtoul( TO_UTF8(colorTxt), NULL, 0 );
return color;
}
return 0; // it's caller fault, gave me a bad layer
}
void LAYER_WIDGET::SetRenderState( int aId, bool isSet )
{
int row = findRenderRow( aId );
if( row >= 0 )
{
int col = 1; // checkbox is column 1
2010-01-30 17:42:22 +00:00
wxCheckBox* cb = (wxCheckBox*) getRenderComp( row, col );
wxASSERT( cb );
cb->SetValue( isSet ); // does not fire an event
}
}
bool LAYER_WIDGET::GetRenderState( int aId )
{
int row = findRenderRow( aId );
if( row >= 0 )
{
int col = 1; // checkbox is column 1
2010-01-30 17:42:22 +00:00
wxCheckBox* cb = (wxCheckBox*) getRenderComp( row, col );
wxASSERT( cb );
return cb->GetValue();
}
return false; // the value of a non-existent row
}
2010-01-21 07:41:30 +00:00
void LAYER_WIDGET::UpdateLayouts()
{
m_LayersFlexGridSizer->Layout();
m_RenderFlexGridSizer->Layout();
2010-01-21 20:53:01 +00:00
FitInside();
2010-01-21 07:41:30 +00:00
}
2010-01-07 02:18:25 +00:00
#if defined(STAND_ALONE)
2010-01-21 07:41:30 +00:00
#include <wx/aui/aui.h>
2010-01-07 02:18:25 +00:00
/**
* Class MYFRAME
* is a test class here to exercise the LAYER_WIDGET and explore use cases.
* @see http://www.kirix.com/labs/wxaui/screenshots.html
* for ideas.
*/
2010-01-09 15:51:09 +00:00
class MYFRAME : public wxFrame
{
2010-01-10 05:44:29 +00:00
// example of how to derive from LAYER_WIDGET in order to provide the
// abstract methods.
2010-01-09 15:51:09 +00:00
class MYLAYERS : public LAYER_WIDGET
{
public:
2010-01-10 06:40:22 +00:00
// your constructor could take a BOARD argument. here I leave it
// out because this source module wants to know nothing of BOARDs
// to maximize re-use.
MYLAYERS( wxWindow* aParent ) :
LAYER_WIDGET( aParent, aParent )
2010-01-09 15:51:09 +00:00
{
}
2010-01-16 06:22:24 +00:00
void OnLayerColorChange( int aLayer, int aColor )
2010-01-09 15:51:09 +00:00
{
2010-01-16 06:22:24 +00:00
printf( "OnLayerColorChange( aLayer:%d, aColor:%d )\n", aLayer, aColor );
2010-01-11 16:49:11 +00:00
2010-01-16 06:22:24 +00:00
/* a test trigger only
2010-01-11 16:49:11 +00:00
if( aLayer == 2 )
{
ClearLayerRows();
printf(" GetLayerRowCount(): %d\n", GetLayerRowCount() );
}
2010-01-16 06:22:24 +00:00
*/
2010-01-09 15:51:09 +00:00
}
2010-01-11 16:49:11 +00:00
bool OnLayerSelect( int aLayer )
2010-01-09 15:51:09 +00:00
{
2010-01-11 16:49:11 +00:00
printf( "OnLayerSelect( aLayer:%d )\n", aLayer );
2010-01-09 15:51:09 +00:00
return true;
}
2010-01-11 16:49:11 +00:00
2010-01-21 07:41:30 +00:00
void OnLayerVisible( int aLayer, bool isVisible, bool isFinal )
2010-01-11 16:49:11 +00:00
{
2010-01-21 07:41:30 +00:00
printf( "OnLayerVisible( aLayer:%d, isVisible:%d isFinal:%d)\n", aLayer, isVisible, isFinal );
2010-01-11 16:49:11 +00:00
}
2010-01-16 06:22:24 +00:00
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 );
}
2010-01-09 15:51:09 +00:00
};
2010-01-07 02:18:25 +00:00
public:
2010-01-10 06:40:22 +00:00
MYFRAME( wxWindow * parent ) :
wxFrame( parent, -1, wxT( "wxAUI Test" ), wxDefaultPosition,
2010-01-10 06:40:22 +00:00
wxSize( 800, 600 ), wxDEFAULT_FRAME_STYLE )
2010-01-07 02:18:25 +00:00
{
// notify wxAUI which frame to use
m_mgr.SetManagedWindow( this );
MYLAYERS* lw = new MYLAYERS( this );
2010-01-07 02:18:25 +00:00
2010-01-18 15:55:18 +00:00
// add some layer rows
2010-01-21 07:41:30 +00:00
static const LAYER_WIDGET::ROW layerRows[] = {
LAYER_WIDGET::ROW( wxT("layer 1"), 0, RED, wxT("RED"), false ),
LAYER_WIDGET::ROW( wxT("layer 2"), 1, GREEN, wxT("GREEN"), true ),
LAYER_WIDGET::ROW( wxT("brown_layer"), 2, BROWN, wxT("BROWN"), true ),
LAYER_WIDGET::ROW( wxT("layer_4_you"), 3, BLUE, wxT("BLUE"), false ),
2010-01-21 07:41:30 +00:00
};
lw->AppendLayerRows( layerRows, DIM(layerRows) );
2010-01-07 02:18:25 +00:00
2010-01-18 15:55:18 +00:00
// add some render rows
2010-01-21 07:41:30 +00:00
static const LAYER_WIDGET::ROW renderRows[] = {
LAYER_WIDGET::ROW( wxT("With Very Large Ears"), 0, -1, wxT("Spock here") ),
2010-01-21 07:41:30 +00:00
LAYER_WIDGET::ROW( wxT("With Legs"), 1, YELLOW ),
LAYER_WIDGET::ROW( wxT("With Oval Eyes"), 1, BROWN, wxT("My eyes are upon you") ),
2010-01-21 07:41:30 +00:00
};
lw->AppendRenderRows( renderRows, DIM(renderRows) );
2010-01-16 06:22:24 +00:00
lw->SelectLayerRow( 1 );
2010-01-07 02:18:25 +00:00
2010-01-10 06:40:22 +00:00
wxAuiPaneInfo li;
2010-01-16 07:50:01 +00:00
li.MinSize( lw->GetBestSize() );
li.BestSize( lw->GetBestSize() );
2010-01-10 06:40:22 +00:00
li.Left();
2010-01-16 06:22:24 +00:00
// li.MaximizeButton( true );
// li.MinimizeButton( true );
2010-01-10 06:40:22 +00:00
li.CloseButton( false );
li.Caption( wxT( "Layers" ) );
2010-01-16 06:22:24 +00:00
m_mgr.AddPane( lw, li );
2010-01-10 06:40:22 +00:00
wxTextCtrl* text2 = new wxTextCtrl( this, -1, wxT( "Pane 2 - sample text" ),
2010-01-16 06:22:24 +00:00
wxDefaultPosition, wxSize( 200, 150 ),
wxNO_BORDER | wxTE_MULTILINE );
2010-01-07 02:18:25 +00:00
m_mgr.AddPane( text2, wxBOTTOM, wxT( "Pane Number Two" ) );
2010-01-16 06:22:24 +00:00
wxTextCtrl* text3 = new wxTextCtrl( this, -1, wxT( "Main content window" ),
2010-01-16 06:22:24 +00:00
wxDefaultPosition, wxSize( 200, 150 ),
wxNO_BORDER | wxTE_MULTILINE );
2010-01-07 02:18:25 +00:00
m_mgr.AddPane( text3, wxCENTER );
// tell the manager to "commit" all the changes just made
m_mgr.Update();
}
~MYFRAME()
{
// deinitialize the frame manager
m_mgr.UnInit();
}
private:
wxAuiManager m_mgr;
};
// our normal wxApp-derived class, as usual
2010-01-10 07:56:07 +00:00
class MyApp : public wxApp
{
2010-01-07 02:18:25 +00:00
public:
bool OnInit()
{
wxFrame* frame = new MYFRAME( NULL );
SetTopWindow( frame );
frame->Show();
return true;
}
};
DECLARE_APP( MyApp );
IMPLEMENT_APP( MyApp );
2010-01-11 16:49:11 +00:00
#endif // STAND_ALONE