allow user to change layer color
This commit is contained in:
parent
816c1596f3
commit
cd27245c00
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
LAYER_PANEL_BASE::LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style )
|
LAYER_PANEL_BASE::LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style )
|
||||||
{
|
{
|
||||||
this->SetMinSize( wxSize( 400,400 ) );
|
this->SetMinSize( wxSize( 100,100 ) );
|
||||||
|
|
||||||
wxBoxSizer* boxSizer;
|
wxBoxSizer* boxSizer;
|
||||||
boxSizer = new wxBoxSizer( wxVERTICAL );
|
boxSizer = new wxBoxSizer( wxVERTICAL );
|
||||||
|
@ -51,7 +51,6 @@ LAYER_PANEL_BASE::LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id, const wxPoi
|
||||||
|
|
||||||
this->SetSizer( boxSizer );
|
this->SetSizer( boxSizer );
|
||||||
this->Layout();
|
this->Layout();
|
||||||
boxSizer->Fit( this );
|
|
||||||
|
|
||||||
// Connect Events
|
// Connect Events
|
||||||
m_LayerScrolledWindow->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( LAYER_PANEL_BASE::OnLeftDblClickLayers ), NULL, this );
|
m_LayerScrolledWindow->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( LAYER_PANEL_BASE::OnLeftDblClickLayers ), NULL, this );
|
||||||
|
|
|
@ -47,7 +47,7 @@ class LAYER_PANEL_BASE : public wxPanel
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxTAB_TRAVERSAL );
|
LAYER_PANEL_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 183,184 ), long style = wxTAB_TRAVERSAL );
|
||||||
~LAYER_PANEL_BASE();
|
~LAYER_PANEL_BASE();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#include <wx/statbmp.h>
|
#include <wx/statbmp.h>
|
||||||
#include <wx/aui/aui.h>
|
#include <wx/aui/aui.h>
|
||||||
|
|
||||||
//#include "fctsys.h"
|
#include "macros.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#include "layer_panel_base.h"
|
#include "layer_panel_base.h"
|
||||||
|
@ -101,13 +101,13 @@ struct LAYER_SPEC
|
||||||
{
|
{
|
||||||
wxString layerName;
|
wxString layerName;
|
||||||
int layer;
|
int layer;
|
||||||
int colorIndex;
|
int color;
|
||||||
|
|
||||||
LAYER_SPEC( const wxString& aLayerName, int aLayer, int aColorIndex = 0 )
|
LAYER_SPEC( const wxString& aLayerName, int aLayer, int aColor = 0 )
|
||||||
{
|
{
|
||||||
layerName = aLayerName;
|
layerName = aLayerName;
|
||||||
layer = aLayer;
|
layer = aLayer;
|
||||||
colorIndex = aColorIndex;
|
color = aColor;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -132,6 +132,8 @@ class LAYER_WIDGET : public LAYER_PANEL_BASE
|
||||||
|
|
||||||
#define MAX_LAYER_ROWS 64
|
#define MAX_LAYER_ROWS 64
|
||||||
#define LAYER_COLUMN_COUNT 4
|
#define LAYER_COLUMN_COUNT 4
|
||||||
|
#define BUTT_SIZE_X 32
|
||||||
|
#define BUTT_SIZE_Y 22
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxBitmap* m_BlankBitmap;
|
wxBitmap* m_BlankBitmap;
|
||||||
|
@ -140,34 +142,40 @@ protected:
|
||||||
wxStaticBitmap* m_Bitmaps[MAX_LAYER_ROWS];
|
wxStaticBitmap* m_Bitmaps[MAX_LAYER_ROWS];
|
||||||
int m_CurrentRow; ///< selected row of layer list
|
int m_CurrentRow; ///< selected row of layer list
|
||||||
|
|
||||||
|
wxBitmap makeBitmap( int aColor )
|
||||||
/**
|
|
||||||
* Function makeColorButton
|
|
||||||
* creates a wxBitmapButton and assigns it a solid color and a control ID
|
|
||||||
*/
|
|
||||||
wxBitmapButton* makeColorButton( int aColorIndex, int aID )
|
|
||||||
{
|
{
|
||||||
const int BUTT_SIZE_X = 32;
|
|
||||||
const int BUTT_SIZE_Y = 22;
|
|
||||||
|
|
||||||
// dynamically make a wxBitMap and brush it with the appropriate color,
|
|
||||||
// then create a wxBitmapButton from it.
|
|
||||||
|
|
||||||
wxBitmap bitmap( BUTT_SIZE_X, BUTT_SIZE_Y );
|
wxBitmap bitmap( BUTT_SIZE_X, BUTT_SIZE_Y );
|
||||||
wxBrush brush;
|
wxBrush brush;
|
||||||
wxMemoryDC iconDC;
|
wxMemoryDC iconDC;
|
||||||
|
|
||||||
iconDC.SelectObject( bitmap );
|
iconDC.SelectObject( bitmap );
|
||||||
|
|
||||||
brush.SetColour( MakeColour( aColorIndex ) );
|
brush.SetColour( MakeColour( aColor ) );
|
||||||
brush.SetStyle( wxSOLID );
|
brush.SetStyle( wxSOLID );
|
||||||
iconDC.SetBrush( brush );
|
iconDC.SetBrush( brush );
|
||||||
|
|
||||||
iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
|
iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
|
||||||
|
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function makeColorButton
|
||||||
|
* creates a wxBitmapButton and assigns it a solid color and a control ID
|
||||||
|
*/
|
||||||
|
wxBitmapButton* makeColorButton( 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( m_LayerScrolledWindow, aID, bitmap,
|
||||||
wxDefaultPosition, wxSize(BUTT_SIZE_X, BUTT_SIZE_Y), wxBORDER_RAISED );
|
wxDefaultPosition, wxSize(BUTT_SIZE_X, BUTT_SIZE_Y), wxBORDER_RAISED );
|
||||||
|
|
||||||
|
// save the color value in the name, no where else to put it.
|
||||||
|
ret->SetName( makeColorTxt( aColor ) );
|
||||||
|
|
||||||
ret->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this );
|
ret->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this );
|
||||||
ret->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this );
|
ret->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this );
|
||||||
|
|
||||||
|
@ -219,9 +227,40 @@ protected:
|
||||||
SelectLayerRow( row );
|
SelectLayerRow( row );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function makeColorTxt
|
||||||
|
* returns a string containing the numeric value of the color.
|
||||||
|
* in a form like 0x00000000. (Color is currently an index, not RGB).
|
||||||
|
*/
|
||||||
|
wxString makeColorTxt( int aColor )
|
||||||
|
{
|
||||||
|
char colorValue[64];
|
||||||
|
sprintf( colorValue, "0x%08x", aColor );
|
||||||
|
return wxString( CONV_FROM_UTF8(colorValue) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function OnRightDownLayers
|
||||||
|
* is called only from the color button when user right clicks.
|
||||||
|
*/
|
||||||
void OnRightDownLayers( wxMouseEvent& event )
|
void OnRightDownLayers( wxMouseEvent& event )
|
||||||
{
|
{
|
||||||
printf("OnRightDownLayers\n");
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -277,7 +316,7 @@ protected:
|
||||||
new wxSizerItem( m_Bitmaps[aRow], wxSizerFlags().Align( wxALIGN_CENTER_VERTICAL ) ) );
|
new wxSizerItem( m_Bitmaps[aRow], wxSizerFlags().Align( wxALIGN_CENTER_VERTICAL ) ) );
|
||||||
|
|
||||||
// column 1
|
// column 1
|
||||||
wxBitmapButton* bmb = makeColorButton( aSpec.colorIndex, aSpec.layer );
|
wxBitmapButton* bmb = makeColorButton( aSpec.color, aSpec.layer );
|
||||||
bmb->SetToolTip( _("Right click to change layer color, left click to select layer" ) );
|
bmb->SetToolTip( _("Right click to change layer color, left click to select layer" ) );
|
||||||
m_LayersFlexGridSizer->Insert( index+1,
|
m_LayersFlexGridSizer->Insert( index+1,
|
||||||
new wxSizerItem( bmb, flags ) );
|
new wxSizerItem( bmb, flags ) );
|
||||||
|
@ -317,10 +356,7 @@ public:
|
||||||
|
|
||||||
SelectLayerRow( 1 );
|
SelectLayerRow( 1 );
|
||||||
|
|
||||||
m_LayerScrolledWindow->FitInside();
|
FitInside();
|
||||||
m_LayerScrolledWindow->SetMinSize( m_LayerScrolledWindow->GetSize() );
|
|
||||||
|
|
||||||
Fit();
|
|
||||||
|
|
||||||
SetMinSize( GetSize() );
|
SetMinSize( GetSize() );
|
||||||
}
|
}
|
||||||
|
@ -463,7 +499,7 @@ public:
|
||||||
|
|
||||||
// add the panes to the manager
|
// add the panes to the manager
|
||||||
wxAuiPaneInfo li;
|
wxAuiPaneInfo li;
|
||||||
li.MinSize( ayerWidget->GetSize() ); // ignored on linux
|
li.MinSize( layerWidget->GetSize() ); // ignored on linux
|
||||||
li.BestSize( layerWidget->GetSize() );
|
li.BestSize( layerWidget->GetSize() );
|
||||||
li.Left();
|
li.Left();
|
||||||
li.MaximizeButton( false );
|
li.MaximizeButton( false );
|
||||||
|
@ -491,7 +527,8 @@ private:
|
||||||
|
|
||||||
|
|
||||||
// our normal wxApp-derived class, as usual
|
// our normal wxApp-derived class, as usual
|
||||||
class MyApp : public wxApp {
|
class MyApp : public wxApp
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool OnInit()
|
bool OnInit()
|
||||||
|
|
|
@ -27,10 +27,10 @@
|
||||||
<property name="hidden">0</property>
|
<property name="hidden">0</property>
|
||||||
<property name="id">wxID_ANY</property>
|
<property name="id">wxID_ANY</property>
|
||||||
<property name="maximum_size"></property>
|
<property name="maximum_size"></property>
|
||||||
<property name="minimum_size">400,400</property>
|
<property name="minimum_size">100,100</property>
|
||||||
<property name="name">LAYER_PANEL_BASE</property>
|
<property name="name">LAYER_PANEL_BASE</property>
|
||||||
<property name="pos"></property>
|
<property name="pos"></property>
|
||||||
<property name="size">-1,-1</property>
|
<property name="size">183,184</property>
|
||||||
<property name="subclass">; </property>
|
<property name="subclass">; </property>
|
||||||
<property name="tooltip"></property>
|
<property name="tooltip"></property>
|
||||||
<property name="window_extra_style"></property>
|
<property name="window_extra_style"></property>
|
||||||
|
|
Loading…
Reference in New Issue