Use our DIALOG_COLOR_PICKER in 3D viewer to set a color.

the wxWidgets color picker is not the best for the 3D viewer that does not use transparency color.
This commit is contained in:
jean-pierre charras 2018-10-12 21:02:11 +02:00
parent aa622994e1
commit 7df4ddc74d
4 changed files with 184 additions and 146 deletions

View File

@ -340,7 +340,7 @@ void EDA_3D_VIEWER::Process_Special_Functions( wxCommandEvent &event )
return;
case ID_MENU3D_BGCOLOR_BOTTOM_SELECTION:
if( Set3DColorFromUser( m_settings.m_BgColorBot, _( "Background Color, Bottom" ) ) )
if( Set3DColorFromUser( m_settings.m_BgColorBot, _( "Background Color, Bottom" ), nullptr ) )
{
if( m_settings.RenderEngineGet() == RENDER_ENGINE_OPENGL_LEGACY )
m_canvas->Request_refresh();
@ -350,7 +350,7 @@ void EDA_3D_VIEWER::Process_Special_Functions( wxCommandEvent &event )
return;
case ID_MENU3D_BGCOLOR_TOP_SELECTION:
if( Set3DColorFromUser( m_settings.m_BgColorTop, _( "Background Color, Top" ) ) )
if( Set3DColorFromUser( m_settings.m_BgColorTop, _( "Background Color, Top" ), nullptr ) )
{
if( m_settings.RenderEngineGet() == RENDER_ENGINE_OPENGL_LEGACY )
m_canvas->Request_refresh();
@ -716,7 +716,7 @@ void EDA_3D_VIEWER::LoadSettings( wxConfigBase *aCfg )
// m_CopperColor default value = gold
aCfg->Read( keyCopperColor_Red, &m_settings.m_CopperColor.r, 255.0 * 0.7 / 255.0 );
aCfg->Read( keyCopperColor_Green, &m_settings.m_CopperColor.g, 223.0 * 0.7 / 255.0 );
aCfg->Read( keyCopperColor_Blue, &m_settings.m_CopperColor.b, 0.0 /255.0 );
aCfg->Read( keyCopperColor_Blue, &m_settings.m_CopperColor.b, 0.0 );
// m_BoardBodyColor default value = FR4, in realistic mode
aCfg->Read( keyBoardBodyColor_Red, &m_settings.m_BoardBodyColor.r, 51.0 / 255.0 );
@ -995,32 +995,24 @@ void EDA_3D_VIEWER::RenderEngineChanged()
bool EDA_3D_VIEWER::Set3DColorFromUser( SFVEC3D &aColor, const wxString& aTitle,
wxColourData* aPredefinedColors )
CUSTOM_COLORS_LIST* aPredefinedColors )
{
wxColour newcolor, oldcolor;
KIGFX::COLOR4D newcolor;
KIGFX::COLOR4D oldcolor( aColor.r,aColor.g, aColor.b, 1.0 );
oldcolor.Set( KiROUND( aColor.r * 255 ),
KiROUND( aColor.g * 255 ),
KiROUND( aColor.b * 255 ) );
DIALOG_COLOR_PICKER picker( this, oldcolor, false, aPredefinedColors );
wxColourData emptyColorSet; // Provides a empty predefined set of colors
// if no color set available to avoid use of an
// old color set
if( aPredefinedColors == NULL )
aPredefinedColors = &emptyColorSet;
newcolor = wxGetColourFromUser( this, oldcolor, aTitle, aPredefinedColors );
if( !newcolor.IsOk() ) // Cancel command
if( picker.ShowModal() != wxID_OK )
return false;
if( newcolor != oldcolor )
{
aColor.r = (double) newcolor.Red() / 255.0;
aColor.g = (double) newcolor.Green() / 255.0;
aColor.b = (double) newcolor.Blue() / 255.0;
}
newcolor = picker.GetColor();
if( newcolor == oldcolor )
return false;
aColor.r = newcolor.r;
aColor.g = newcolor.g;
aColor.b = newcolor.b;
return true;
}
@ -1028,20 +1020,12 @@ bool EDA_3D_VIEWER::Set3DColorFromUser( SFVEC3D &aColor, const wxString& aTitle,
bool EDA_3D_VIEWER::Set3DSilkScreenColorFromUser()
{
wxColourData definedColors;
unsigned int i = 0;
definedColors.SetCustomColour( i++, wxColour( 241, 241, 241 ) ); // White
definedColors.SetCustomColour( i++, wxColour( 4, 18, 21 ) ); // Dark
for(; i < wxColourData::NUM_CUSTOM;)
{
definedColors.SetCustomColour( i++, wxColour( 0, 0, 0 ) );
}
CUSTOM_COLORS_LIST definedColors;
definedColors.push_back( CUSTOM_COLOR_ITEM( 241.0/255.0, 241.0/255.0, 241.0/255.0, "White" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 4.0/255.0, 18.0/255.0, 21.0/255.0, "Dark" ) );
bool change = Set3DColorFromUser( m_settings.m_SilkScreenColor,
_( "Silk Screen Color" ),
&definedColors );
_( "Solder Mask Color" ), &definedColors );
if( change )
NewDisplay( true );
@ -1052,28 +1036,22 @@ bool EDA_3D_VIEWER::Set3DSilkScreenColorFromUser()
bool EDA_3D_VIEWER::Set3DSolderMaskColorFromUser()
{
wxColourData definedColors;
unsigned int i = 0;
CUSTOM_COLORS_LIST definedColors;
definedColors.SetCustomColour( i++, wxColour( 20, 51, 36 ) ); // Green
definedColors.SetCustomColour( i++, wxColour( 91, 168, 12 ) ); // Light Green
definedColors.SetCustomColour( i++, wxColour( 13, 104, 11 ) ); // Saturated Green
definedColors.SetCustomColour( i++, wxColour(181, 19, 21 ) ); // Red
definedColors.SetCustomColour( i++, wxColour(239, 53, 41 ) ); // Red Light Orange
definedColors.SetCustomColour( i++, wxColour(210, 40, 14 ) ); // Red 2
definedColors.SetCustomColour( i++, wxColour( 2, 59, 162 ) ); // Blue
definedColors.SetCustomColour( i++, wxColour( 54, 79, 116 ) ); // Light blue 1
definedColors.SetCustomColour( i++, wxColour( 61, 85, 130 ) ); // Light blue 2
definedColors.SetCustomColour( i++, wxColour( 21, 70, 80 ) ); // Green blue (dark)
definedColors.SetCustomColour( i++, wxColour( 11, 11, 11 ) ); // Black
definedColors.SetCustomColour( i++, wxColour( 245, 245,245 ) ); // White
definedColors.SetCustomColour( i++, wxColour(119, 31, 91 ) ); // Purple
definedColors.SetCustomColour( i++, wxColour( 32, 2, 53 ) ); // Purple Dark
for(; i < wxColourData::NUM_CUSTOM;)
{
definedColors.SetCustomColour( i++, wxColour( 0, 0, 0 ) );
}
definedColors.push_back( CUSTOM_COLOR_ITEM( 20/255.0, 51/255.0, 36/255.0, "Green" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 91/255.0, 168/255.0, 12/255.0, "Light Green" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 13/255.0, 104/255.0, 11/255.0, "Saturated Green" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 181/255.0, 19/255.0, 21/255.0, "Red" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 239/255.0, 53/255.0, 41/255.0, "Red Light Orange" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 210/255.0, 40/255.0, 14/255.0, "Red 2" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 2/255.0, 59/255.0, 162/255.0, "Blue" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 54/255.0, 79/255.0, 116/255.0, "Light blue 1" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 61/255.0, 85/255.0, 130/255.0, "Light blue 2" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 21/255.0, 70/255.0, 80/255.0, "Green blue (dark)" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 11/255.0, 11/255.0, 11/255.0, "Black" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 245/255.0, 245/255.0, 245/255.0, "White" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 119/255.0, 31/255.0, 91/255.0, "Purple" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 32/255.0, 2/255.0, 53/255.0, "Purple Dark" ) );
bool change = Set3DColorFromUser( m_settings.m_SolderMaskColor,
_( "Solder Mask Color" ),
@ -1088,21 +1066,14 @@ bool EDA_3D_VIEWER::Set3DSolderMaskColorFromUser()
bool EDA_3D_VIEWER::Set3DCopperColorFromUser()
{
wxColourData definedColors;
unsigned int i = 0;
CUSTOM_COLORS_LIST definedColors;
definedColors.SetCustomColour( i++, wxColour( 184, 115, 50) ); // Copper
definedColors.SetCustomColour( i++, wxColour( 191, 155, 58) ); // Gold
definedColors.SetCustomColour( i++, wxColour( 213, 213, 213) ); // Silver
definedColors.SetCustomColour( i++, wxColour( 160, 160, 160) ); // tin
definedColors.push_back( CUSTOM_COLOR_ITEM( 184/255.0, 115/255.0, 50/255.0, "Copper" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 178/255.0, 156/255.0, 0.0, "Gold" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 213/255.0, 213/255.0, 213/255.0, "Silver" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 160/255.0, 160/255.0, 160/255.0, "Tin" ) );
for(; i < wxColourData::NUM_CUSTOM;)
{
definedColors.SetCustomColour( i++, wxColour( 0, 0, 0 ) );
}
bool change = Set3DColorFromUser( m_settings.m_CopperColor,
_( "Copper Color" ),
bool change = Set3DColorFromUser( m_settings.m_CopperColor, _( "Copper Color" ),
&definedColors );
if( change )
@ -1114,27 +1085,19 @@ bool EDA_3D_VIEWER::Set3DCopperColorFromUser()
bool EDA_3D_VIEWER::Set3DBoardBodyColorFromUser()
{
wxColourData definedColors;
unsigned int i = 0;
CUSTOM_COLORS_LIST definedColors;
definedColors.SetCustomColour( i++, wxColour( 51, 43, 22 ) ); // FR4 natural, dark
definedColors.SetCustomColour( i++, wxColour( 109, 116, 75 ) ); // FR4 natural
definedColors.SetCustomColour( i++, wxColour( 78, 14, 5 ) ); // brown/red
definedColors.SetCustomColour( i++, wxColour( 146, 99, 47 ) ); // brown 1
definedColors.SetCustomColour( i++, wxColour( 160, 123, 54 ) ); // brown 2
definedColors.SetCustomColour( i++, wxColour( 146, 99, 47 ) ); // brown 3
definedColors.SetCustomColour( i++, wxColour( 63, 126, 71 ) ); // green 1
definedColors.SetCustomColour( i++, wxColour( 117, 122, 90 ) ); // green 2
definedColors.push_back( CUSTOM_COLOR_ITEM( 51/255.0, 43/255.0, 22/255.0, "FR4 natural, dark" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 109/255.0, 116/255.0, 75/255.0, "FR4 natural" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 78/255.0, 14/255.0, 5/255.0, "brown/red" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 146/255.0, 99/255.0, 47/255.0, "brown 1" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 160/255.0, 123/255.0, 54/255.0, "brown 2" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 146/255.0, 99/255.0, 47/255.0, "brown 3" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 63/255.0, 126/255.0, 71/255.0, "green 1" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 117/255.0, 122/255.0, 90/255.0, "green 2" ) );
for(; i < wxColourData::NUM_CUSTOM;)
{
definedColors.SetCustomColour( i++, wxColour( 0, 0, 0 ) );
}
bool change = Set3DColorFromUser( m_settings.m_BoardBodyColor,
_( "Board Body Color" ),
bool change = Set3DColorFromUser( m_settings.m_BoardBodyColor, _( "Board Body Color" ),
&definedColors );
if( change )
NewDisplay( true );
@ -1144,21 +1107,14 @@ bool EDA_3D_VIEWER::Set3DBoardBodyColorFromUser()
bool EDA_3D_VIEWER::Set3DSolderPasteColorFromUser()
{
wxColourData definedColors;
unsigned int i = 0;
CUSTOM_COLORS_LIST definedColors;
definedColors.SetCustomColour( i++, wxColour( 128, 128, 128 ) ); // grey
definedColors.SetCustomColour( i++, wxColour( 213, 213, 213 ) ); // Silver
definedColors.SetCustomColour( i++, wxColour( 90, 90, 90 ) ); // grey 2
for(; i < wxColourData::NUM_CUSTOM;)
{
definedColors.SetCustomColour( i++, wxColour( 0, 0, 0 ) );
}
definedColors.push_back( CUSTOM_COLOR_ITEM( 128/255.0, 128/255.0, 128/255.0, "grey" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 213/255.0, 213/255.0, 213/255.0, "Silver" ) );
definedColors.push_back( CUSTOM_COLOR_ITEM( 90/255.0, 90/255.0, 90/255.0, "grey 2" ) );
bool change = Set3DColorFromUser( m_settings.m_SolderPasteColor,
_( "Solder Paste Color" ),
&definedColors );
_( "Solder Paste Color" ), &definedColors );
if( change )
NewDisplay( true );

View File

@ -32,11 +32,11 @@
#ifndef EDA_3D_VIEWER_H
#define EDA_3D_VIEWER_H
#include "../3d_canvas/cinfo3d_visu.h"
#include "../3d_canvas/eda_3d_canvas.h"
#include <kiway_player.h>
#include <wx/colourdata.h>
#include <../common/dialogs/dialog_color_picker.h> // for CUSTOM_COLORS_LIST definition
#define KICAD_DEFAULT_3D_DRAWFRAME_STYLE (wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS)
@ -112,14 +112,13 @@ class EDA_3D_VIEWER : public KIWAY_PLAYER
* Get a SFVEC3D from a wx colour dialog
* @param aColor is the SFVEC3D to change
* @param aTitle is the title displayed in the colordialog selector
* @param aPredefinedColors is a reference to a wxColourData
* @param aPredefinedColors is a reference to a CUSTOM_COLOR_ITEM list
* which contains a few predefined colors
* if it is NULL, no predefined colors are used
* @return true if a new color is chosen, false if
* no change or aborted by user
* if empty, no predefined colors are used.
* no change if aborted by user
*/
bool Set3DColorFromUser( SFVEC3D &aColor, const wxString& aTitle,
wxColourData* aPredefinedColors = NULL );
CUSTOM_COLORS_LIST* aPredefinedColors );
/**
* Function Set3DSolderMaskColorFromUser

View File

@ -24,7 +24,7 @@
#define ALPHA_MAX 100 // the max value returned by the alpha (opacity) slider
DIALOG_COLOR_PICKER::DIALOG_COLOR_PICKER( wxWindow* aParent, KIGFX::COLOR4D& aCurrentColor,
bool aAllowOpacityControl )
bool aAllowOpacityControl, CUSTOM_COLORS_LIST* aUserColors )
: DIALOG_COLOR_PICKER_BASE( aParent )
{
m_allowMouseEvents = false;
@ -48,7 +48,7 @@ DIALOG_COLOR_PICKER::DIALOG_COLOR_PICKER( wxWindow* aParent, KIGFX::COLOR4D& aCu
m_notebook->SetSelection( (unsigned) m_ActivePage );
// Build the defined colors panel:
initDefinedColors();
initDefinedColors( aUserColors );
m_sdbSizerOK->SetDefault();
}
@ -64,7 +64,8 @@ DIALOG_COLOR_PICKER::~DIALOG_COLOR_PICKER()
m_ActivePage = m_notebook->GetSelection();
for( auto button : m_buttonsColor )
button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COLOR_PICKER::buttColorClick ), NULL, this );
button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler( DIALOG_COLOR_PICKER::buttColorClick ), NULL, this );
}
@ -139,7 +140,7 @@ bool DIALOG_COLOR_PICKER::TransferDataToWindow()
}
void DIALOG_COLOR_PICKER::initDefinedColors()
void DIALOG_COLOR_PICKER::initDefinedColors( CUSTOM_COLORS_LIST* aPredefinedColors )
{
#define ID_COLOR_BLACK 2000 // colors_id = ID_COLOR_BLACK a ID_COLOR_BLACK + NBCOLORS-1
@ -156,48 +157,99 @@ void DIALOG_COLOR_PICKER::initDefinedColors()
int grid_row = 0;
int table_row_count = 6;
for( int jj = 0; jj < NBCOLORS; ++jj, grid_col++ )
// If no predefined list is given, build the default predefined colors:
if( aPredefinedColors )
{
if( grid_col*table_row_count >= NBCOLORS )
{ // the current grid row is filled, and we must fill the next grid row
grid_col = 0;
grid_row++;
for( unsigned jj = 0; jj < aPredefinedColors->size() && jj < NBCOLORS; ++jj )
{
CUSTOM_COLOR_ITEM* item = & *aPredefinedColors->begin() + jj;
int butt_ID = ID_COLOR_BLACK + jj;
wxMemoryDC iconDC;
wxBitmap ButtBitmap( w, h );
wxBrush brush;
iconDC.SelectObject( ButtBitmap );
KIGFX::COLOR4D buttcolor = item->m_Color;
iconDC.SetPen( *wxBLACK_PEN );
brush.SetColour( buttcolor.ToColour() );
brush.SetStyle( wxBRUSHSTYLE_SOLID );
iconDC.SetBrush( brush );
iconDC.SetBackground( *wxGREY_BRUSH );
iconDC.Clear();
iconDC.DrawRoundedRectangle( 0, 0, w, h, (double) h / 3 );
wxBitmapButton* bitmapButton = new wxBitmapButton( m_panelDefinedColors, butt_ID, ButtBitmap,
wxDefaultPosition, wxSize( w+8, h+6 ) );
m_fgridColor->Add( bitmapButton, 0,
wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
wxLEFT | wxBOTTOM, 5 );
wxStaticText* label = new wxStaticText( m_panelDefinedColors, -1,
item->m_ColorName,
wxDefaultPosition, wxDefaultSize, 0 );
m_fgridColor->Add( label, 1,
wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
wxLEFT | wxRIGHT | wxBOTTOM, 5 );
m_buttonsColor.push_back( bitmapButton );
m_Color4DList.push_back( buttcolor );
bitmapButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler( DIALOG_COLOR_PICKER::buttColorClick ), NULL, this );
}
}
else
{
m_Color4DList.assign( NBCOLORS, KIGFX::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) );
int ii = grid_row + (grid_col*table_row_count); // The index in g_ColorRefs
for( int jj = 0; jj < NBCOLORS; ++jj, grid_col++ )
{
if( grid_col*table_row_count >= NBCOLORS )
{ // the current grid row is filled, and we must fill the next grid row
grid_col = 0;
grid_row++;
}
int butt_ID = ID_COLOR_BLACK + ii;
wxMemoryDC iconDC;
wxBitmap ButtBitmap( w, h );
wxBrush brush;
int ii = grid_row + (grid_col*table_row_count); // The index in g_ColorRefs
iconDC.SelectObject( ButtBitmap );
int butt_ID = ID_COLOR_BLACK + ii;
wxMemoryDC iconDC;
wxBitmap ButtBitmap( w, h );
wxBrush brush;
KIGFX::COLOR4D buttcolor = KIGFX::COLOR4D( g_ColorRefs[ii].m_Numcolor );
iconDC.SelectObject( ButtBitmap );
iconDC.SetPen( *wxBLACK_PEN );
brush.SetColour( buttcolor.ToColour() );
brush.SetStyle( wxBRUSHSTYLE_SOLID );
KIGFX::COLOR4D buttcolor = KIGFX::COLOR4D( g_ColorRefs[ii].m_Numcolor );
m_Color4DList[ butt_ID - ID_COLOR_BLACK ] = buttcolor;
iconDC.SetBrush( brush );
iconDC.SetBackground( *wxGREY_BRUSH );
iconDC.Clear();
iconDC.DrawRoundedRectangle( 0, 0, w, h, (double) h / 3 );
iconDC.SetPen( *wxBLACK_PEN );
brush.SetColour( buttcolor.ToColour() );
brush.SetStyle( wxBRUSHSTYLE_SOLID );
wxBitmapButton* bitmapButton = new wxBitmapButton( m_panelDefinedColors, butt_ID, ButtBitmap,
wxDefaultPosition, wxSize( w+8, h+6 ) );
m_fgridColor->Add( bitmapButton, 0,
wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
wxLEFT | wxBOTTOM, 5 );
iconDC.SetBrush( brush );
iconDC.SetBackground( *wxGREY_BRUSH );
iconDC.Clear();
iconDC.DrawRoundedRectangle( 0, 0, w, h, (double) h / 3 );
wxStaticText* label = new wxStaticText( m_panelDefinedColors, -1,
wxGetTranslation( g_ColorRefs[ii].m_ColorName ),
wxDefaultPosition, wxDefaultSize, 0 );
m_fgridColor->Add( label, 1,
wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
wxLEFT | wxRIGHT | wxBOTTOM, 5 );
m_buttonsColor.push_back( bitmapButton );
bitmapButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COLOR_PICKER::buttColorClick ), NULL, this );
wxBitmapButton* bitmapButton = new wxBitmapButton( m_panelDefinedColors, butt_ID, ButtBitmap,
wxDefaultPosition, wxSize( w+8, h+6 ) );
m_fgridColor->Add( bitmapButton, 0,
wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
wxLEFT | wxBOTTOM, 5 );
wxStaticText* label = new wxStaticText( m_panelDefinedColors, -1,
wxGetTranslation( g_ColorRefs[ii].m_ColorName ),
wxDefaultPosition, wxDefaultSize, 0 );
m_fgridColor->Add( label, 1,
wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
wxLEFT | wxRIGHT | wxBOTTOM, 5 );
m_buttonsColor.push_back( bitmapButton );
bitmapButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler( DIALOG_COLOR_PICKER::buttColorClick ), NULL, this );
}
}
}
@ -498,7 +550,7 @@ void DIALOG_COLOR_PICKER::drawAll()
void DIALOG_COLOR_PICKER::buttColorClick( wxCommandEvent& event )
{
int id = event.GetId();
KIGFX::COLOR4D color( EDA_COLOR_T( id - ID_COLOR_BLACK ) );
KIGFX::COLOR4D color( m_Color4DList[id - ID_COLOR_BLACK] );//EDA_COLOR_T( id - ID_COLOR_BLACK ) );
m_newColor4D.r = color.r;
m_newColor4D.g = color.g;
m_newColor4D.b = color.b;

View File

@ -28,6 +28,31 @@
#include <gal/color4d.h>
#include "dialog_color_picker_base.h"
/** a class to handle a custom color (predefined color) for
* the color picker dialog
*/
struct CUSTOM_COLOR_ITEM
{
KIGFX::COLOR4D m_Color;
wxString m_ColorName;
CUSTOM_COLOR_ITEM( double red, double green, double blue, const wxString& aName )
{
m_Color.r = red;
m_Color.g = green;
m_Color.b = blue;
m_ColorName = aName;
}
CUSTOM_COLOR_ITEM( const KIGFX::COLOR4D& aColor, const wxString& aName )
: m_Color( aColor ), m_ColorName( aName)
{}
};
typedef std::vector<CUSTOM_COLOR_ITEM> CUSTOM_COLORS_LIST;
enum CHANGED_COLOR
{
ALL_CHANGED,
@ -48,8 +73,10 @@ public:
* @param aCurrentColor is the current color, used to show it in dialog
* @param aAllowOpacityControl = true to allow opacity (alpha channel) setting
* false to not show this setting (opacity = 1.0 always)
* @param aUserColors: if not null is a list of defined colors replacing the dialog predefined colors
*/
DIALOG_COLOR_PICKER( wxWindow* aParent, KIGFX::COLOR4D& aCurrentColor, bool aAllowOpacityControl );
DIALOG_COLOR_PICKER( wxWindow* aParent, KIGFX::COLOR4D& aCurrentColor,
bool aAllowOpacityControl, CUSTOM_COLORS_LIST* aUserColors = nullptr );
~DIALOG_COLOR_PICKER();
KIGFX::COLOR4D GetColor() { return m_newColor4D; };
@ -68,6 +95,8 @@ private:
///< false to keep alpha channel = 1.0
KIGFX::COLOR4D m_previousColor4D; ///< the inital color4d
KIGFX::COLOR4D m_newColor4D; ///< the current color4d
/// the list of color4d ordered by button ID, for predefined colors
std::vector<KIGFX::COLOR4D> m_Color4DList;
int m_cursorsSize;
wxPoint m_cursorBitmapRed; ///< the red cursor on the RGB bitmap palette.
@ -131,8 +160,10 @@ private:
///> called when creating the dialog
bool TransferDataToWindow() override;
///> creates the bitmap buttons for each defined colors
void initDefinedColors();
/** creates the bitmap buttons for each defined colors
* if aPredefinedColors is nullptr, a internal predefined list will be used
*/
void initDefinedColors( CUSTOM_COLORS_LIST* aPredefinedColors );
// convert double value 0 ... 1 to int 0 ... aValMax
int normalizeToInt( double aValue, int aValMax = 255 )