2010-01-07 02:18:25 +00:00
|
|
|
|
|
|
|
/*
|
2011-09-30 18:15:37 +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>
|
2011-09-30 18:15:37 +00:00
|
|
|
* 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
|
2017-02-21 11:09:10 +00:00
|
|
|
@todo make bitmap size 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
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <layer_widget.h>
|
2010-01-21 07:41:30 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <macros.h>
|
|
|
|
#include <common.h>
|
2016-05-28 16:46:29 +00:00
|
|
|
|
2017-02-22 12:34:23 +00:00
|
|
|
#include <widgets/indicator_icon.h>
|
2016-05-28 16:46:29 +00:00
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
#include <algorithm>
|
2010-01-21 07:41:30 +00:00
|
|
|
|
2017-09-21 16:09:17 +00:00
|
|
|
#include <menus_helpers.h>
|
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
|
2014-07-09 09:59:23 +00:00
|
|
|
const wxEventType LAYER_WIDGET::EVT_LAYER_COLOR_CHANGE = wxNewEventType();
|
|
|
|
|
2010-01-11 16:49:11 +00:00
|
|
|
|
2017-02-21 11:09:10 +00:00
|
|
|
/**
|
|
|
|
* Function shrinkFont
|
|
|
|
* reduces the size of the wxFont associated with \a aControl
|
|
|
|
*/
|
|
|
|
static void shrinkFont( wxWindow* aControl, int aPointSize )
|
|
|
|
{
|
|
|
|
wxFont font = aControl->GetFont();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LAYER_NUM LAYER_WIDGET::getDecodedId( int aControlId )
|
|
|
|
{
|
|
|
|
int id = aControlId / LYR_COLUMN_COUNT; // rounding is OK.
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-18 15:55:18 +00:00
|
|
|
void LAYER_WIDGET::OnLeftDownLayers( wxMouseEvent& event )
|
|
|
|
{
|
|
|
|
int row;
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM 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
|
|
|
|
2017-09-21 16:09:17 +00:00
|
|
|
void LAYER_WIDGET::OnRightDownLayer( wxMouseEvent& aEvent, COLOR_SWATCH* aColorSwatch, const wxString& aLayerName )
|
|
|
|
{
|
|
|
|
wxMenu menu;
|
|
|
|
|
|
|
|
AddMenuItem( &menu, ID_CHANGE_LAYER_COLOR,
|
|
|
|
_( "Change Layer Color for " ) + aLayerName,
|
|
|
|
KiBitmap( setcolor_copper_xpm ) );
|
|
|
|
menu.AppendSeparator();
|
|
|
|
|
|
|
|
OnLayerRightClick( menu );
|
|
|
|
|
2018-04-19 12:42:53 +00:00
|
|
|
menu.Bind( wxEVT_COMMAND_MENU_SELECTED, [aColorSwatch]( wxCommandEvent& event ) {
|
2017-09-21 16:09:17 +00:00
|
|
|
if ( event.GetId() == ID_CHANGE_LAYER_COLOR ) {
|
|
|
|
aColorSwatch->GetNewSwatchColor();
|
|
|
|
} else {
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
PopupMenu( &menu );
|
|
|
|
passOnFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
void LAYER_WIDGET::OnLayerSwatchChanged( wxCommandEvent& aEvent )
|
2010-01-18 15:55:18 +00:00
|
|
|
{
|
2017-02-21 12:31:19 +00:00
|
|
|
auto eventSource = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
|
2010-01-10 07:56:07 +00:00
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
COLOR4D newColor = eventSource->GetSwatchColor();
|
2017-02-20 16:57:41 +00:00
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
LAYER_NUM layer = getDecodedId( eventSource->GetId() );
|
2010-01-18 15:55:18 +00:00
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
// tell the client code.
|
|
|
|
OnLayerColorChange( layer, newColor );
|
2014-07-09 09:59:23 +00:00
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
// notify others
|
|
|
|
wxCommandEvent event( EVT_LAYER_COLOR_CHANGE );
|
|
|
|
wxPostEvent( this, event );
|
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();
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM layer = getDecodedId( eventSource->GetId() );
|
2010-01-18 15:55:18 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2017-09-21 16:09:17 +00:00
|
|
|
void LAYER_WIDGET::OnRightDownRender( wxMouseEvent& aEvent, COLOR_SWATCH* aColorSwatch, const wxString& aRenderName )
|
|
|
|
{
|
|
|
|
wxMenu menu;
|
|
|
|
|
|
|
|
AddMenuItem( &menu, ID_CHANGE_RENDER_COLOR,
|
|
|
|
_( "Change Render Color for " ) + aRenderName,
|
|
|
|
KiBitmap( setcolor_board_body_xpm ) );
|
|
|
|
|
2018-04-19 12:42:53 +00:00
|
|
|
menu.Bind( wxEVT_COMMAND_MENU_SELECTED, [aColorSwatch]( wxCommandEvent& event ) {
|
2017-09-21 16:09:17 +00:00
|
|
|
if ( event.GetId() == ID_CHANGE_RENDER_COLOR ) {
|
|
|
|
aColorSwatch->GetNewSwatchColor();
|
|
|
|
} else {
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
PopupMenu( &menu );
|
|
|
|
passOnFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
void LAYER_WIDGET::OnRenderSwatchChanged( wxCommandEvent& aEvent )
|
2010-01-18 15:55:18 +00:00
|
|
|
{
|
2017-02-21 12:31:19 +00:00
|
|
|
auto eventSource = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
|
2010-01-16 06:22:24 +00:00
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
COLOR4D newColor = eventSource->GetSwatchColor();
|
2017-02-20 16:57:41 +00:00
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
LAYER_NUM id = getDecodedId( eventSource->GetId() );
|
2010-01-16 06:22:24 +00:00
|
|
|
|
2018-01-03 22:38:25 +00:00
|
|
|
if( id == LAYER_PCB_BACKGROUND )
|
|
|
|
{
|
|
|
|
// Update all swatch backgrounds
|
|
|
|
int count = GetLayerRowCount();
|
|
|
|
int row;
|
|
|
|
int col = 1; // bitmap button is column 1 in layers tab
|
|
|
|
for( row = 0; row < count; ++row )
|
|
|
|
{
|
|
|
|
COLOR_SWATCH* swatch = dynamic_cast<COLOR_SWATCH*>( getLayerComp( row, col ) );
|
|
|
|
if( swatch )
|
|
|
|
swatch->SetSwatchBackground( newColor );
|
|
|
|
}
|
|
|
|
|
|
|
|
count = GetRenderRowCount();
|
|
|
|
col = 0; // bitmap button is column 0 in render tab
|
|
|
|
for( row = 0; row < count; ++row )
|
|
|
|
{
|
|
|
|
COLOR_SWATCH* swatch = dynamic_cast<COLOR_SWATCH*>( getRenderComp( row, col ) );
|
|
|
|
if( swatch )
|
|
|
|
swatch->SetSwatchBackground( newColor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
// tell the client code.
|
|
|
|
OnRenderColorChange( id, newColor );
|
2010-01-11 16:49:11 +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
|
|
|
|
2012-03-12 00:40:48 +00:00
|
|
|
|
2010-01-18 15:55:18 +00:00
|
|
|
void LAYER_WIDGET::OnRenderCheckBox( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject();
|
2013-04-06 16:46:03 +00:00
|
|
|
LAYER_NUM id = getDecodedId( eventSource->GetId() );
|
2010-01-18 15:55:18 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2010-01-22 19:59:27 +00:00
|
|
|
void LAYER_WIDGET::OnTabChange( wxNotebookEvent& event )
|
|
|
|
{
|
2010-01-23 07:00:21 +00:00
|
|
|
// 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-22 19:59:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
wxWindow* LAYER_WIDGET::getLayerComp( int aRow, int aColumn ) const
|
2010-01-18 15:55:18 +00:00
|
|
|
{
|
2013-03-31 13:27:46 +00:00
|
|
|
unsigned ndx = aRow * LYR_COLUMN_COUNT + aColumn;
|
2017-03-01 08:50:36 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
if( ndx < m_LayersFlexGridSizer->GetChildren().GetCount() )
|
2010-01-30 17:42:22 +00:00
|
|
|
return m_LayersFlexGridSizer->GetChildren()[ndx]->GetWindow();
|
2017-03-01 08:50:36 +00:00
|
|
|
|
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
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
int LAYER_WIDGET::findLayerRow( LAYER_NUM aLayer ) const
|
2010-01-18 15:55:18 +00:00
|
|
|
{
|
|
|
|
int count = GetLayerRowCount();
|
2017-03-01 08:50:36 +00:00
|
|
|
|
|
|
|
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 );
|
2010-01-30 17:12:43 +00:00
|
|
|
wxASSERT( w );
|
2010-01-16 06:22:24 +00:00
|
|
|
|
2010-01-30 17:12:43 +00:00
|
|
|
if( aLayer == getDecodedId( w->GetId() ))
|
|
|
|
return row;
|
|
|
|
}
|
2017-03-01 08:50:36 +00:00
|
|
|
|
2010-01-30 17:12:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
wxWindow* LAYER_WIDGET::getRenderComp( int aRow, int aColumn ) const
|
2010-01-30 17:12:43 +00:00
|
|
|
{
|
2010-01-30 17:42:22 +00:00
|
|
|
int ndx = aRow * RND_COLUMN_COUNT + aColumn;
|
2017-03-01 08:50:36 +00:00
|
|
|
|
2010-01-30 17:42:22 +00:00
|
|
|
if( (unsigned) ndx < m_RenderFlexGridSizer->GetChildren().GetCount() )
|
|
|
|
return m_RenderFlexGridSizer->GetChildren()[ndx]->GetWindow();
|
2017-03-01 08:50:36 +00:00
|
|
|
|
2010-01-30 17:12:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
int LAYER_WIDGET::findRenderRow( int aId ) const
|
2010-01-30 17:12:43 +00:00
|
|
|
{
|
|
|
|
int count = GetRenderRowCount();
|
2017-03-01 08:50:36 +00:00
|
|
|
|
|
|
|
for( int row = 0; row < count; ++row )
|
2010-01-30 17:12:43 +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 = getRenderComp( row, 0 );
|
2010-01-30 17:12:43 +00:00
|
|
|
wxASSERT( w );
|
|
|
|
|
|
|
|
if( aId == getDecodedId( w->GetId() ))
|
2010-01-18 15:55:18 +00:00
|
|
|
return row;
|
|
|
|
}
|
2017-03-01 08:50:36 +00:00
|
|
|
|
2010-01-18 15:55:18 +00:00
|
|
|
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 )
|
|
|
|
{
|
2013-04-06 16:46:03 +00:00
|
|
|
wxASSERT( aRow >= 0 );
|
2010-01-18 15:55:18 +00:00
|
|
|
|
|
|
|
int col;
|
|
|
|
int index = aRow * LYR_COLUMN_COUNT;
|
|
|
|
const int flags = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT;
|
|
|
|
|
|
|
|
// column 0
|
2017-02-22 12:34:23 +00:00
|
|
|
col = COLUMN_ICON_ACTIVE;
|
2018-02-21 16:29:24 +00:00
|
|
|
auto sbm = new INDICATOR_ICON( m_LayerScrolledWindow, *m_IconProvider,
|
|
|
|
ROW_ICON_PROVIDER::STATE::OFF, encodeId( col, aSpec.id ) );
|
2017-02-21 12:43:02 +00:00
|
|
|
sbm->Bind( wxEVT_LEFT_DOWN, &LAYER_WIDGET::OnLeftDownLayers, this );
|
2010-01-21 14:51:08 +00:00
|
|
|
m_LayersFlexGridSizer->wxSizer::Insert( index+col, sbm, 0, flags );
|
2010-01-18 15:55:18 +00:00
|
|
|
|
2014-07-04 13:53:41 +00:00
|
|
|
// column 1 (COLUMN_COLORBM)
|
|
|
|
col = COLUMN_COLORBM;
|
2017-02-20 16:57:41 +00:00
|
|
|
|
2017-02-21 12:31:19 +00:00
|
|
|
auto bmb = new COLOR_SWATCH( m_LayerScrolledWindow, aSpec.color, encodeId( col, aSpec.id ),
|
2018-01-03 22:38:25 +00:00
|
|
|
AreArbitraryColorsAllowed(), getBackgroundLayerColor() );
|
2017-02-21 12:31:19 +00:00
|
|
|
bmb->Bind( wxEVT_LEFT_DOWN, &LAYER_WIDGET::OnLeftDownLayers, this );
|
|
|
|
bmb->Bind( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnLayerSwatchChanged, this );
|
2016-01-28 08:02:25 +00:00
|
|
|
bmb->SetToolTip( _("Left double click or middle click for color change, right click for menu" ) );
|
2017-02-21 12:31:19 +00:00
|
|
|
m_LayersFlexGridSizer->wxSizer::Insert( index+col, bmb, 0, flags );
|
2010-01-18 15:55:18 +00:00
|
|
|
|
2014-07-04 13:53:41 +00:00
|
|
|
// column 2 (COLUMN_COLOR_LYR_CB)
|
|
|
|
col = COLUMN_COLOR_LYR_CB;
|
2010-01-18 15:55:18 +00:00
|
|
|
wxCheckBox* cb = new wxCheckBox( m_LayerScrolledWindow, encodeId( col, aSpec.id ), wxEmptyString );
|
|
|
|
cb->SetValue( aSpec.state );
|
2017-02-21 12:43:02 +00:00
|
|
|
cb->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED, &LAYER_WIDGET::OnLayerCheckBox, this );
|
2010-01-18 15:55:18 +00:00
|
|
|
cb->SetToolTip( _( "Enable this for visibility" ) );
|
2010-01-21 14:51:08 +00:00
|
|
|
m_LayersFlexGridSizer->wxSizer::Insert( index+col, cb, 0, flags );
|
2014-07-04 08:55:51 +00:00
|
|
|
|
2014-07-04 13:53:41 +00:00
|
|
|
// column 3 (COLUMN_COLOR_LYRNAME)
|
|
|
|
col = COLUMN_COLOR_LYRNAME;
|
2014-07-04 08:55:51 +00:00
|
|
|
wxStaticText* st = new wxStaticText( m_LayerScrolledWindow, encodeId( col, aSpec.id ), aSpec.rowName );
|
|
|
|
shrinkFont( st, m_PointSize );
|
2017-02-21 12:43:02 +00:00
|
|
|
st->Bind( wxEVT_LEFT_DOWN, &LAYER_WIDGET::OnLeftDownLayers, this );
|
2014-07-04 08:55:51 +00:00
|
|
|
st->SetToolTip( aSpec.tooltip );
|
|
|
|
m_LayersFlexGridSizer->wxSizer::Insert( index+col, st, 0, flags );
|
2017-09-21 16:09:17 +00:00
|
|
|
|
2018-02-21 16:29:24 +00:00
|
|
|
// column 4 (COLUMN_ALPHA_INDICATOR)
|
|
|
|
col = COLUMN_ALPHA_INDICATOR;
|
|
|
|
sbm = new INDICATOR_ICON( m_LayerScrolledWindow, *m_IconProvider,
|
|
|
|
ROW_ICON_PROVIDER::STATE::OFF, wxID_ANY );
|
|
|
|
m_LayersFlexGridSizer->wxSizer::Insert( index+col, sbm, 0, flags );
|
|
|
|
|
2017-09-21 16:09:17 +00:00
|
|
|
// Bind right click eventhandler to all columns
|
|
|
|
wxString layerName( aSpec.rowName );
|
|
|
|
|
|
|
|
sbm->Bind( wxEVT_RIGHT_DOWN, [this, bmb, layerName] ( wxMouseEvent& aEvt ) {
|
|
|
|
OnRightDownLayer( aEvt, bmb, layerName );
|
|
|
|
} );
|
|
|
|
bmb->Bind( wxEVT_RIGHT_DOWN, [this, bmb, layerName] ( wxMouseEvent& aEvt ) {
|
|
|
|
OnRightDownLayer( aEvt, bmb, layerName );
|
|
|
|
} );
|
|
|
|
cb->Bind( wxEVT_RIGHT_DOWN, [this, bmb, layerName] ( wxMouseEvent& aEvt ) {
|
|
|
|
OnRightDownLayer( aEvt, bmb, layerName );
|
|
|
|
} );
|
|
|
|
st->Bind( wxEVT_RIGHT_DOWN, [this, bmb, layerName] ( wxMouseEvent& aEvt ) {
|
|
|
|
OnRightDownLayer( aEvt, bmb, layerName );
|
|
|
|
} );
|
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 )
|
|
|
|
{
|
2013-04-06 16:46:03 +00:00
|
|
|
wxASSERT( aRow >= 0 );
|
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
|
|
|
|
2017-09-21 16:09:17 +00:00
|
|
|
wxString renderName( aSpec.rowName );
|
2018-02-22 04:39:14 +00:00
|
|
|
wxCheckBox* cb = nullptr;
|
2017-09-21 16:09:17 +00:00
|
|
|
|
|
|
|
// column 1
|
2018-02-22 04:39:14 +00:00
|
|
|
if( !aSpec.spacer )
|
|
|
|
{
|
|
|
|
col = 1;
|
|
|
|
cb = new wxCheckBox( m_RenderScrolledWindow, encodeId( col, aSpec.id ),
|
|
|
|
aSpec.rowName, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );
|
|
|
|
shrinkFont( cb, m_PointSize );
|
|
|
|
cb->SetValue( aSpec.state );
|
|
|
|
cb->Enable( aSpec.changeable );
|
|
|
|
cb->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED, &LAYER_WIDGET::OnRenderCheckBox, this );
|
|
|
|
cb->SetToolTip( aSpec.tooltip );
|
|
|
|
}
|
2017-09-21 16:09:17 +00:00
|
|
|
|
2010-01-18 15:55:18 +00:00
|
|
|
// column 0
|
|
|
|
col = 0;
|
2017-02-20 17:48:27 +00:00
|
|
|
if( aSpec.color != COLOR4D::UNSPECIFIED )
|
2010-01-18 15:55:18 +00:00
|
|
|
{
|
2017-02-21 12:31:19 +00:00
|
|
|
auto bmb = new COLOR_SWATCH( m_RenderScrolledWindow, aSpec.color, encodeId( col, aSpec.id ),
|
2018-01-03 22:38:25 +00:00
|
|
|
AreArbitraryColorsAllowed(), getBackgroundLayerColor() );
|
2017-02-21 12:31:19 +00:00
|
|
|
bmb->Bind( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnRenderSwatchChanged, this );
|
2016-01-28 08:02:25 +00:00
|
|
|
bmb->SetToolTip( _( "Left double click or middle click for color change" ) );
|
2017-02-21 12:31:19 +00:00
|
|
|
m_RenderFlexGridSizer->wxSizer::Insert( index+col, bmb, 0, flags );
|
2010-01-18 15:55:18 +00:00
|
|
|
|
2017-09-21 16:09:17 +00:00
|
|
|
bmb->Bind( wxEVT_RIGHT_DOWN, [this, bmb, renderName] ( wxMouseEvent& aEvt ) {
|
|
|
|
OnRightDownRender( aEvt, bmb, renderName );
|
|
|
|
} );
|
|
|
|
cb->Bind( wxEVT_RIGHT_DOWN, [this, bmb, renderName] ( wxMouseEvent& aEvt ) {
|
|
|
|
OnRightDownRender( aEvt, bmb, renderName );
|
|
|
|
} );
|
|
|
|
|
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.
|
2012-03-12 00:40:48 +00:00
|
|
|
wxPanel* invisible = new wxPanel( m_RenderScrolledWindow, encodeId( col, aSpec.id ) );
|
2010-01-21 14:51:08 +00:00
|
|
|
m_RenderFlexGridSizer->wxSizer::Insert( index+col, invisible, 0, flags );
|
2010-01-07 16:33:41 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 16:09:17 +00:00
|
|
|
// Items have to be inserted in order
|
2010-01-18 15:55:18 +00:00
|
|
|
col = 1;
|
2018-02-22 04:39:14 +00:00
|
|
|
|
|
|
|
if( aSpec.spacer )
|
|
|
|
{
|
|
|
|
wxPanel* invisible = new wxPanel( m_RenderScrolledWindow, wxID_ANY );
|
|
|
|
m_RenderFlexGridSizer->wxSizer::Insert( index+col, invisible, 0, flags );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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()
|
|
|
|
{
|
2010-01-22 19:59:27 +00:00
|
|
|
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
|
|
|
|
2018-05-02 14:46:09 +00:00
|
|
|
LAYER_WIDGET::LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner, wxWindowID id,
|
|
|
|
const wxPoint& pos, const wxSize& size, long style ) :
|
2010-01-24 02:05:07 +00:00
|
|
|
wxPanel( aParent, id, pos, size, style )
|
2010-01-18 15:55:18 +00:00
|
|
|
{
|
2018-05-02 14:46:09 +00:00
|
|
|
int indicatorSize = ConvertDialogToPixels( wxSize( 6, 6 ) ).x;
|
|
|
|
m_IconProvider = new ROW_ICON_PROVIDER( indicatorSize );
|
|
|
|
|
|
|
|
int pointSize = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize();
|
|
|
|
int screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
|
|
|
|
|
|
|
|
if( screenHeight <= 900 && pointSize >= indicatorSize )
|
|
|
|
pointSize = pointSize * 8 / 10;
|
|
|
|
|
|
|
|
m_PointSize = pointSize;
|
|
|
|
|
2018-08-04 11:59:04 +00:00
|
|
|
wxBoxSizer* mainSizer = 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();
|
2010-02-10 06:56:37 +00:00
|
|
|
|
2018-05-02 14:46:09 +00:00
|
|
|
// change the font size on the notebook's tabs to match aPointSize
|
|
|
|
font.SetPointSize( pointSize );
|
|
|
|
m_notebook->SetFont( font );
|
|
|
|
m_notebook->SetNormalFont( font );
|
|
|
|
m_notebook->SetSelectedFont( font );
|
|
|
|
m_notebook->SetMeasuringFont( font );
|
2018-02-21 16:29:24 +00:00
|
|
|
|
2010-01-24 02:05:07 +00:00
|
|
|
m_LayerPanel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
|
|
|
|
|
2018-08-04 11:59:04 +00:00
|
|
|
wxBoxSizer* layerPanelSizer;
|
|
|
|
layerPanelSizer = new wxBoxSizer( wxVERTICAL );
|
2010-01-24 02:05:07 +00:00
|
|
|
|
|
|
|
m_LayerScrolledWindow = new wxScrolledWindow( m_LayerPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER );
|
|
|
|
m_LayerScrolledWindow->SetScrollRate( 5, 5 );
|
2018-02-21 16:29:24 +00:00
|
|
|
m_LayersFlexGridSizer = new wxFlexGridSizer( 0, LYR_COLUMN_COUNT, 0, 1 );
|
2010-01-24 02:05:07 +00:00
|
|
|
m_LayersFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL );
|
2014-07-04 08:55:51 +00:00
|
|
|
m_LayersFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE );
|
2010-01-24 02:05:07 +00:00
|
|
|
|
|
|
|
m_LayerScrolledWindow->SetSizer( m_LayersFlexGridSizer );
|
|
|
|
m_LayerScrolledWindow->Layout();
|
|
|
|
m_LayersFlexGridSizer->Fit( m_LayerScrolledWindow );
|
2018-08-04 11:59:04 +00:00
|
|
|
layerPanelSizer->Add( m_LayerScrolledWindow, 1, wxBOTTOM|wxEXPAND|wxLEFT|wxTOP, 2 );
|
2010-01-24 02:05:07 +00:00
|
|
|
|
2018-08-04 11:59:04 +00:00
|
|
|
m_LayerPanel->SetSizer( layerPanelSizer );
|
2010-01-24 02:05:07 +00:00
|
|
|
m_LayerPanel->Layout();
|
2018-08-04 11:59:04 +00:00
|
|
|
layerPanelSizer->Fit( m_LayerPanel );
|
2018-02-22 23:54:50 +00:00
|
|
|
m_notebook->AddPage( m_LayerPanel, _( "Layers" ), true );
|
2010-01-24 02:05:07 +00:00
|
|
|
m_RenderingPanel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
|
|
|
|
|
2018-08-04 11:59:04 +00:00
|
|
|
wxBoxSizer* renderPanelSizer;
|
|
|
|
renderPanelSizer = new wxBoxSizer( wxVERTICAL );
|
2010-01-24 02:05:07 +00:00
|
|
|
|
|
|
|
m_RenderScrolledWindow = new wxScrolledWindow( m_RenderingPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER );
|
|
|
|
m_RenderScrolledWindow->SetScrollRate( 5, 5 );
|
2018-02-21 16:29:24 +00:00
|
|
|
m_RenderFlexGridSizer = new wxFlexGridSizer( 0, RND_COLUMN_COUNT, 0, 1 );
|
2010-01-24 02:05:07 +00:00
|
|
|
m_RenderFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL );
|
|
|
|
m_RenderFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE );
|
|
|
|
|
|
|
|
m_RenderScrolledWindow->SetSizer( m_RenderFlexGridSizer );
|
|
|
|
m_RenderScrolledWindow->Layout();
|
|
|
|
m_RenderFlexGridSizer->Fit( m_RenderScrolledWindow );
|
2018-08-04 11:59:04 +00:00
|
|
|
renderPanelSizer->Add( m_RenderScrolledWindow, 1, wxALL|wxEXPAND, 5 );
|
2010-01-24 02:05:07 +00:00
|
|
|
|
2018-08-04 11:59:04 +00:00
|
|
|
m_RenderingPanel->SetSizer( renderPanelSizer );
|
2010-01-24 02:05:07 +00:00
|
|
|
m_RenderingPanel->Layout();
|
2018-08-04 11:59:04 +00:00
|
|
|
renderPanelSizer->Fit( m_RenderingPanel );
|
2018-02-22 23:54:50 +00:00
|
|
|
m_notebook->AddPage( m_RenderingPanel, _( "Items" ), false );
|
2010-01-24 02:05:07 +00:00
|
|
|
|
2018-08-04 11:59:04 +00:00
|
|
|
mainSizer->Add( m_notebook, 1, wxEXPAND, 5 );
|
2010-01-24 02:05:07 +00:00
|
|
|
|
2018-08-04 11:59:04 +00:00
|
|
|
SetSizer( mainSizer );
|
2010-01-24 02:05:07 +00:00
|
|
|
|
2010-01-22 19:59:27 +00:00
|
|
|
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-22 19:59:27 +00:00
|
|
|
// trap the tab changes so that we can call passOnFocus().
|
2017-02-21 12:43:02 +00:00
|
|
|
m_notebook->Bind( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, &LAYER_WIDGET::OnTabChange, 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
|
|
|
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
LAYER_WIDGET::~LAYER_WIDGET()
|
|
|
|
{
|
2018-02-21 16:29:24 +00:00
|
|
|
delete m_IconProvider;
|
2014-07-09 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-18 15:55:18 +00:00
|
|
|
wxSize LAYER_WIDGET::GetBestSize() const
|
|
|
|
{
|
|
|
|
// size of m_LayerScrolledWindow --------------
|
|
|
|
wxArrayInt widths = m_LayersFlexGridSizer->GetColWidths();
|
|
|
|
int totWidth = 0;
|
2017-03-01 08:50:36 +00:00
|
|
|
|
2010-01-18 15:55:18 +00:00
|
|
|
if( widths.GetCount() )
|
2010-01-11 16:49:11 +00:00
|
|
|
{
|
2017-03-01 08:50:36 +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
|
|
|
}
|
2017-03-01 08:50:36 +00:00
|
|
|
|
2010-01-18 15:55:18 +00:00
|
|
|
// Account for the parent's frame:
|
2018-02-22 04:39:14 +00:00
|
|
|
totWidth += 32;
|
2010-01-11 16:49:11 +00:00
|
|
|
|
2010-01-18 15:55:18 +00:00
|
|
|
|
2014-07-04 08:55:51 +00:00
|
|
|
/* The minimum height is a small size to properly force computation
|
|
|
|
* of the panel's scrollbars (otherwise it will assume it *has* all
|
|
|
|
* this space) */
|
|
|
|
unsigned totHeight = 32;
|
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
|
|
|
|
2010-01-23 07:00:21 +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;
|
2017-03-01 08:50:36 +00:00
|
|
|
|
2010-01-18 15:55:18 +00:00
|
|
|
if( widths.GetCount() )
|
|
|
|
{
|
2017-03-01 08:50:36 +00:00
|
|
|
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:
|
2018-02-22 04:39:14 +00:00
|
|
|
totWidth += 32;
|
2010-01-18 15:55:18 +00:00
|
|
|
|
2014-07-04 08:55:51 +00:00
|
|
|
// For totHeight re-use the previous small one
|
2010-01-18 15:55:18 +00:00
|
|
|
wxSize renderz( totWidth, totHeight );
|
2010-01-16 07:50:01 +00:00
|
|
|
|
2010-01-23 07:00:21 +00:00
|
|
|
renderz += m_RenderingPanel->GetWindowBorderSize();
|
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
wxSize clientz( std::max(renderz.x,layerz.x), std::max(renderz.y,layerz.y) );
|
2010-01-23 07:00:21 +00:00
|
|
|
|
|
|
|
return clientz;
|
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-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-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
|
2010-01-23 07:00:21 +00:00
|
|
|
m_notebook->SetSelection( 0 );
|
2010-01-09 15:51:09 +00:00
|
|
|
|
2017-02-22 12:34:23 +00:00
|
|
|
INDICATOR_ICON* oldIndicator = (INDICATOR_ICON*) getLayerComp( m_CurrentRow, 0 );
|
|
|
|
if( oldIndicator )
|
2018-02-21 16:29:24 +00:00
|
|
|
{
|
|
|
|
if( useAlternateBitmap( m_CurrentRow ) )
|
|
|
|
oldIndicator->SetIndicatorState( ROW_ICON_PROVIDER::STATE::DIMMED );
|
|
|
|
else
|
|
|
|
oldIndicator->SetIndicatorState( ROW_ICON_PROVIDER::STATE::OFF );
|
|
|
|
}
|
2010-01-18 15:55:18 +00:00
|
|
|
|
2017-02-22 12:34:23 +00:00
|
|
|
INDICATOR_ICON* newIndicator = (INDICATOR_ICON*) getLayerComp( aRow, 0 );
|
|
|
|
if( newIndicator )
|
2010-01-09 15:51:09 +00:00
|
|
|
{
|
2017-02-22 12:34:23 +00:00
|
|
|
newIndicator->SetIndicatorState( ROW_ICON_PROVIDER::STATE::ON );
|
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
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
void LAYER_WIDGET::SelectLayer( LAYER_NUM aLayer )
|
2010-01-18 15:55:18 +00:00
|
|
|
{
|
|
|
|
int row = findLayerRow( aLayer );
|
|
|
|
SelectLayerRow( row );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
LAYER_NUM LAYER_WIDGET::GetSelectedLayer()
|
2010-01-18 15:55:18 +00:00
|
|
|
{
|
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
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
return UNDEFINED_LAYER;
|
2010-01-18 15:55:18 +00:00
|
|
|
}
|
2010-01-16 06:22:24 +00:00
|
|
|
|
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
void LAYER_WIDGET::SetLayerVisible( LAYER_NUM aLayer, bool isVisible )
|
2018-03-16 02:42:38 +00:00
|
|
|
{
|
|
|
|
setLayerCheckbox( aLayer, isVisible );
|
|
|
|
OnLayerVisible( aLayer, isVisible );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LAYER_WIDGET::setLayerCheckbox( LAYER_NUM aLayer, bool isVisible )
|
2010-01-18 15:55:18 +00:00
|
|
|
{
|
|
|
|
int row = findLayerRow( aLayer );
|
|
|
|
if( row >= 0 )
|
2010-01-16 06:22:24 +00:00
|
|
|
{
|
2014-07-04 14:22:38 +00:00
|
|
|
wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
|
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
|
|
|
|
2010-01-30 17:12:43 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
bool LAYER_WIDGET::IsLayerVisible( LAYER_NUM aLayer )
|
2010-01-30 17:12:43 +00:00
|
|
|
{
|
|
|
|
int row = findLayerRow( aLayer );
|
|
|
|
if( row >= 0 )
|
|
|
|
{
|
2014-07-04 13:53:41 +00:00
|
|
|
wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
|
2010-01-30 17:12:43 +00:00
|
|
|
wxASSERT( cb );
|
|
|
|
return cb->GetValue();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
void LAYER_WIDGET::SetLayerColor( LAYER_NUM aLayer, COLOR4D aColor )
|
2010-01-30 17:12:43 +00:00
|
|
|
{
|
|
|
|
int row = findLayerRow( aLayer );
|
|
|
|
if( row >= 0 )
|
|
|
|
{
|
|
|
|
int col = 1; // bitmap button is column 1
|
2017-11-27 00:02:35 +00:00
|
|
|
auto swatch = static_cast<COLOR_SWATCH*>( getLayerComp( row, col ) );
|
|
|
|
wxASSERT( swatch );
|
2010-01-30 17:12:43 +00:00
|
|
|
|
2017-11-27 00:02:35 +00:00
|
|
|
swatch->SetSwatchColor( aColor, false );
|
2010-01-30 17:12:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D LAYER_WIDGET::GetLayerColor( LAYER_NUM aLayer ) const
|
2010-01-30 17:12:43 +00:00
|
|
|
{
|
|
|
|
int row = findLayerRow( aLayer );
|
|
|
|
if( row >= 0 )
|
|
|
|
{
|
|
|
|
int col = 1; // bitmap button is column 1
|
2017-11-27 00:02:35 +00:00
|
|
|
auto swatch = static_cast<COLOR_SWATCH*>( getLayerComp( row, col ) );
|
|
|
|
wxASSERT( swatch );
|
2010-01-30 17:12:43 +00:00
|
|
|
|
2017-11-27 00:02:35 +00:00
|
|
|
return swatch->GetSwatchColor();
|
2010-01-30 17:12:43 +00:00
|
|
|
}
|
|
|
|
|
2017-02-20 17:48:27 +00:00
|
|
|
return COLOR4D::UNSPECIFIED; // it's caller fault, gave me a bad layer
|
2010-01-30 17:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LAYER_WIDGET::SetRenderState( int aId, bool isSet )
|
|
|
|
{
|
|
|
|
int row = findRenderRow( aId );
|
2017-03-01 08:50:36 +00:00
|
|
|
|
2010-01-30 17:12:43 +00:00
|
|
|
if( row >= 0 )
|
|
|
|
{
|
|
|
|
int col = 1; // checkbox is column 1
|
2010-01-30 17:42:22 +00:00
|
|
|
wxCheckBox* cb = (wxCheckBox*) getRenderComp( row, col );
|
2010-01-30 17:12:43 +00:00
|
|
|
wxASSERT( cb );
|
|
|
|
cb->SetValue( isSet ); // does not fire an event
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LAYER_WIDGET::GetRenderState( int aId )
|
|
|
|
{
|
|
|
|
int row = findRenderRow( aId );
|
2017-03-01 08:50:36 +00:00
|
|
|
|
2010-01-30 17:12:43 +00:00
|
|
|
if( row >= 0 )
|
|
|
|
{
|
|
|
|
int col = 1; // checkbox is column 1
|
2010-01-30 17:42:22 +00:00
|
|
|
wxCheckBox* cb = (wxCheckBox*) getRenderComp( row, col );
|
2010-01-30 17:12:43 +00:00
|
|
|
wxASSERT( cb );
|
|
|
|
return cb->GetValue();
|
|
|
|
}
|
2017-03-01 08:50:36 +00:00
|
|
|
|
2010-01-30 17:12:43 +00:00
|
|
|
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();
|
2014-07-04 08:55:51 +00:00
|
|
|
m_LayerPanel->Layout();
|
|
|
|
m_RenderingPanel->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
|
|
|
|
2017-02-22 12:34:23 +00:00
|
|
|
|
|
|
|
void LAYER_WIDGET::UpdateLayerIcons()
|
|
|
|
{
|
|
|
|
int rowCount = GetLayerRowCount();
|
2017-03-01 08:50:36 +00:00
|
|
|
|
2017-02-22 12:34:23 +00:00
|
|
|
for( int row = 0; row < rowCount ; row++ )
|
|
|
|
{
|
|
|
|
INDICATOR_ICON* indicator = (INDICATOR_ICON*) getLayerComp( row, COLUMN_ICON_ACTIVE );
|
|
|
|
|
|
|
|
if( indicator )
|
|
|
|
{
|
2018-02-21 16:29:24 +00:00
|
|
|
ROW_ICON_PROVIDER::STATE state;
|
|
|
|
|
|
|
|
if( row == m_CurrentRow )
|
|
|
|
state = ROW_ICON_PROVIDER::STATE::ON;
|
|
|
|
else if( useAlternateBitmap( row ) )
|
|
|
|
state = ROW_ICON_PROVIDER::STATE::DIMMED;
|
|
|
|
else
|
|
|
|
state = ROW_ICON_PROVIDER::STATE::OFF;
|
|
|
|
|
2017-02-22 12:34:23 +00:00
|
|
|
indicator->SetIndicatorState( state );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
2010-01-23 07:00:21 +00:00
|
|
|
MYLAYERS( wxWindow* aParent ) :
|
|
|
|
LAYER_WIDGET( aParent, aParent )
|
2010-01-09 15:51:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
void OnLayerColorChange( int aLayer, COLOR4D 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
|
|
|
}
|
|
|
|
|
2015-12-14 17:45:11 +00:00
|
|
|
bool OnLayerSelect( LAYER_NUM 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
|
|
|
|
2015-12-14 17:45:11 +00:00
|
|
|
void OnLayerVisible( LAYER_NUM 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
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
void OnRenderColorChange( int aId, COLOR4D aColor )
|
2010-01-16 06:22:24 +00:00
|
|
|
{
|
|
|
|
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 ) :
|
2010-01-21 20:36:48 +00:00
|
|
|
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 );
|
|
|
|
|
2010-01-23 07:00:21 +00:00
|
|
|
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[] = {
|
2010-01-21 20:36:48 +00:00
|
|
|
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[] = {
|
2017-02-20 17:48:27 +00:00
|
|
|
LAYER_WIDGET::ROW( wxT("With Very Large Ears"), 0, COLOR4D::UNSPECIFIED, wxT("Spock here") ),
|
2010-01-21 07:41:30 +00:00
|
|
|
LAYER_WIDGET::ROW( wxT("With Legs"), 1, YELLOW ),
|
2010-01-21 20:36:48 +00:00
|
|
|
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
|
|
|
|
2010-01-21 20:36:48 +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
|
|
|
|
2010-01-21 20:36:48 +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
|