Merge branch 'colour_dialogs_alpha_generic' of https://github.com/a-wi/wxWidgets into wip

Add support for alpha channel to wxGenericColourDialog.

See #14127.
This commit is contained in:
Vadim Zeitlin
2015-11-15 00:49:01 +01:00
7 changed files with 306 additions and 75 deletions

View File

@@ -48,11 +48,11 @@ controls to select a precise colour, and add it to the custom colour palette.
Under non-MS Windows platforms, the colour selector is a simulation of most of Under non-MS Windows platforms, the colour selector is a simulation of most of
the features of the MS Windows selector. Two palettes of 48 standard and 16 the features of the MS Windows selector. Two palettes of 48 standard and 16
custom colours are presented, with the right-hand area containing three sliders custom colours are presented, with the right-hand area containing three or four sliders
for the user to select a colour from red, green and blue components. This for the user to select a colour from red, green, blue and opacity (optionally) components. This
colour may be added to the custom colour palette, and will replace either the colour may be added to the custom colour palette, and will replace either the
currently selected custom colour, or the first one in the palette if none is currently selected custom colour, or the first one in the palette if none is
selected. The RGB colour sliders are not optional in the generic colour selected. The RGB or ARGB colour sliders are not optional in the generic colour
selector. The generic colour selector is also available under MS Windows; use selector. The generic colour selector is also available under MS Windows; use
the name wxGenericColourDialog. the name wxGenericColourDialog.

View File

@@ -26,6 +26,8 @@ public:
void SetChooseFull(bool flag) { m_chooseFull = flag; } void SetChooseFull(bool flag) { m_chooseFull = flag; }
bool GetChooseFull() const { return m_chooseFull; } bool GetChooseFull() const { return m_chooseFull; }
void SetChooseAlpha(bool flag) { m_chooseAlpha = flag; }
bool GetChooseAlpha() const { return m_chooseAlpha; }
void SetColour(const wxColour& colour) { m_dataColour = colour; } void SetColour(const wxColour& colour) { m_dataColour = colour; }
const wxColour& GetColour() const { return m_dataColour; } const wxColour& GetColour() const { return m_dataColour; }
wxColour& GetColour() { return m_dataColour; } wxColour& GetColour() { return m_dataColour; }
@@ -45,6 +47,9 @@ public:
wxColour m_custColours[NUM_CUSTOM]; wxColour m_custColours[NUM_CUSTOM];
bool m_chooseFull; bool m_chooseFull;
protected:
bool m_chooseAlpha;
wxDECLARE_DYNAMIC_CLASS(wxColourData); wxDECLARE_DYNAMIC_CLASS(wxColourData);
}; };

View File

@@ -14,18 +14,18 @@
#include "wx/gdicmn.h" #include "wx/gdicmn.h"
#include "wx/dialog.h" #include "wx/dialog.h"
#define wxID_ADD_CUSTOM 3000
#if wxUSE_SLIDER #if wxUSE_SLIDER
#define wxID_RED_SLIDER 3001
#define wxID_GREEN_SLIDER 3002
#define wxID_BLUE_SLIDER 3003
class WXDLLIMPEXP_FWD_CORE wxSlider; class WXDLLIMPEXP_FWD_CORE wxSlider;
#endif // wxUSE_SLIDER #endif // wxUSE_SLIDER
// Preview with opacity is possible only
// if wxGCDC and wxStaticBitmap are available.
#define wxCLRDLGG_USE_PREVIEW_WITH_ALPHA (wxUSE_GRAPHICS_CONTEXT && wxUSE_STATBMP)
#if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
class wxStaticBitmap;
#endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
class WXDLLIMPEXP_CORE wxGenericColourDialog : public wxDialog class WXDLLIMPEXP_CORE wxGenericColourDialog : public wxDialog
{ {
public: public:
@@ -43,13 +43,18 @@ public:
// Internal functions // Internal functions
void OnMouseEvent(wxMouseEvent& event); void OnMouseEvent(wxMouseEvent& event);
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);
#if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
void OnCustomColourMouseClick(wxMouseEvent& event);
#endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
virtual void CalculateMeasurements(); virtual void CalculateMeasurements();
virtual void CreateWidgets(); virtual void CreateWidgets();
virtual void InitializeColours(); virtual void InitializeColours();
virtual void PaintBasicColours(wxDC& dc); virtual void PaintBasicColours(wxDC& dc);
virtual void PaintCustomColours(wxDC& dc); #if !wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
virtual void PaintCustomColours(wxDC& dc, int clrIndex = -1);
#endif // !wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
virtual void PaintCustomColour(wxDC& dc); virtual void PaintCustomColour(wxDC& dc);
virtual void PaintHighlight(wxDC& dc, bool draw); virtual void PaintHighlight(wxDC& dc, bool draw);
@@ -62,10 +67,15 @@ public:
void OnRedSlider(wxCommandEvent& event); void OnRedSlider(wxCommandEvent& event);
void OnGreenSlider(wxCommandEvent& event); void OnGreenSlider(wxCommandEvent& event);
void OnBlueSlider(wxCommandEvent& event); void OnBlueSlider(wxCommandEvent& event);
void OnAlphaSlider(wxCommandEvent& event);
#endif // wxUSE_SLIDER #endif // wxUSE_SLIDER
void OnCloseWindow(wxCloseEvent& event); void OnCloseWindow(wxCloseEvent& event);
#if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
void DoPreviewBitmap(wxBitmap& bmp, const wxColour& colour);
#endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
protected: protected:
wxColourData m_colourData; wxColourData m_colourData;
@@ -75,10 +85,7 @@ protected:
wxRect m_singleCustomColourRect; wxRect m_singleCustomColourRect;
// Size of each colour rectangle // Size of each colour rectangle
wxPoint m_smallRectangleSize; wxSize m_smallRectangleSize;
// For single customizable colour
wxPoint m_customRectangleSize;
// Grid spacing (between rectangles) // Grid spacing (between rectangles)
int m_gridSpacing; int m_gridSpacing;
@@ -100,7 +107,14 @@ protected:
wxSlider *m_redSlider; wxSlider *m_redSlider;
wxSlider *m_greenSlider; wxSlider *m_greenSlider;
wxSlider *m_blueSlider; wxSlider *m_blueSlider;
wxSlider *m_alphaSlider;
#endif // wxUSE_SLIDER #endif // wxUSE_SLIDER
#if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
// Bitmap to preview selected colour (with alpha channel)
wxStaticBitmap *m_customColourBmp;
// Bitmaps to preview custom colours (with alpha channel)
wxStaticBitmap *m_customColoursBmp[16];
#endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
int m_buttonY; int m_buttonY;

View File

@@ -221,6 +221,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
#if USE_COLOURDLG_GENERIC #if USE_COLOURDLG_GENERIC
EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric) EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC_ALPHA, MyFrame::ChooseColourGeneric)
#endif // USE_COLOURDLG_GENERIC #endif // USE_COLOURDLG_GENERIC
#if wxUSE_PROGRESSDLG #if wxUSE_PROGRESSDLG
@@ -400,7 +401,10 @@ bool MyApp::OnInit()
#endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
#if USE_COLOURDLG_GENERIC #if USE_COLOURDLG_GENERIC
choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, wxT("&Choose colour (generic)")); wxMenu *colourGeneric_menu = new wxMenu;
colourGeneric_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, wxT("&No opacity"));
colourGeneric_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC_ALPHA, wxT("&With opacity"));
choices_menu->Append(wxID_ANY, wxT("&Choose colour (generic)"), colourGeneric_menu);
#endif // USE_COLOURDLG_GENERIC #endif // USE_COLOURDLG_GENERIC
#if USE_FONTDLG_GENERIC #if USE_FONTDLG_GENERIC
@@ -741,21 +745,18 @@ void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event))
#if USE_COLOURDLG_GENERIC #if USE_COLOURDLG_GENERIC
void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event)) void MyFrame::ChooseColourGeneric(wxCommandEvent& event)
{ {
m_clrData.SetColour(m_canvas->GetBackgroundColour()); m_clrData.SetColour(m_canvas->GetBackgroundColour());
//FIXME:TODO:This has no effect... //FIXME:TODO:This has no effect...
m_clrData.SetChooseFull(true); m_clrData.SetChooseFull(true);
m_clrData.SetChooseAlpha(event.GetId() == DIALOGS_CHOOSE_COLOUR_GENERIC_ALPHA);
for (int i = 0; i < 16; i++) for (int i = 0; i < wxColourData::NUM_CUSTOM; i++)
{ {
wxColour colour( unsigned char n = i*(256/wxColourData::NUM_CUSTOM);
(unsigned char)(i*16), m_clrData.SetCustomColour(i, wxColour(n, n, n));
(unsigned char)(i*16),
(unsigned char)(i*16)
);
m_clrData.SetCustomColour(i, colour);
} }
wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData); wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData);

View File

@@ -536,6 +536,7 @@ enum
DIALOGS_CHOOSE_COLOUR = wxID_HIGHEST, DIALOGS_CHOOSE_COLOUR = wxID_HIGHEST,
DIALOGS_GET_COLOUR, DIALOGS_GET_COLOUR,
DIALOGS_CHOOSE_COLOUR_GENERIC, DIALOGS_CHOOSE_COLOUR_GENERIC,
DIALOGS_CHOOSE_COLOUR_GENERIC_ALPHA,
DIALOGS_CHOOSE_FONT, DIALOGS_CHOOSE_FONT,
DIALOGS_CHOOSE_FONT_GENERIC, DIALOGS_CHOOSE_FONT_GENERIC,
DIALOGS_MESSAGE_BOX, DIALOGS_MESSAGE_BOX,

View File

@@ -25,6 +25,7 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject);
wxColourData::wxColourData() wxColourData::wxColourData()
{ {
m_chooseFull = false; m_chooseFull = false;
m_chooseAlpha = false;
m_dataColour.Set(0,0,0); m_dataColour.Set(0,0,0);
// m_custColours are wxNullColours initially // m_custColours are wxNullColours initially
} }
@@ -61,6 +62,7 @@ wxColourData& wxColourData::operator=(const wxColourData& data)
m_dataColour = data.m_dataColour; m_dataColour = data.m_dataColour;
m_chooseFull = data.m_chooseFull; m_chooseFull = data.m_chooseFull;
m_chooseAlpha = data.m_chooseAlpha;
return *this; return *this;
} }
@@ -85,6 +87,9 @@ wxString wxColourData::ToString() const
str += clr.GetAsString(wxC2S_HTML_SYNTAX); str += clr.GetAsString(wxC2S_HTML_SYNTAX);
} }
str.Append(wxCOL_DATA_SEP);
str.Append(m_chooseAlpha ? '1' : '0');
return str; return str;
} }
@@ -102,6 +107,14 @@ bool wxColourData::FromString(const wxString& str)
else else
success = m_custColours[i].Set(token); success = m_custColours[i].Set(token);
} }
if ( success )
{
token = tokenizer.GetNextToken();
m_chooseAlpha = token == wxS("1");
success = m_chooseAlpha || token == wxS("0");
}
return success; return success;
} }

View File

@@ -37,6 +37,19 @@
#include "wx/colourdata.h" #include "wx/colourdata.h"
#include "wx/generic/colrdlgg.h" #include "wx/generic/colrdlgg.h"
#if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
#include "wx/statbmp.h"
#include "wx/dcmemory.h"
#include "wx/dcgraph.h"
#endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
#define wxID_ADD_CUSTOM 3000
#if wxUSE_SLIDER
#define wxID_RED_SLIDER 3001
#define wxID_GREEN_SLIDER 3002
#define wxID_BLUE_SLIDER 3003
#endif // wxUSE_SLIDER
wxIMPLEMENT_DYNAMIC_CLASS(wxGenericColourDialog, wxDialog); wxIMPLEMENT_DYNAMIC_CLASS(wxGenericColourDialog, wxDialog);
wxBEGIN_EVENT_TABLE(wxGenericColourDialog, wxDialog) wxBEGIN_EVENT_TABLE(wxGenericColourDialog, wxDialog)
@@ -164,7 +177,7 @@ int wxGenericColourDialog::ShowModal()
// Internal functions // Internal functions
void wxGenericColourDialog::OnMouseEvent(wxMouseEvent& event) void wxGenericColourDialog::OnMouseEvent(wxMouseEvent& event)
{ {
if (event.ButtonDown(1)) if (event.ButtonDown(wxMOUSE_BTN_LEFT))
{ {
int x = (int)event.GetX(); int x = (int)event.GetX();
int y = (int)event.GetY(); int y = (int)event.GetY();
@@ -177,6 +190,8 @@ void wxGenericColourDialog::OnMouseEvent(wxMouseEvent& event)
int ptr = (int)(selX + selY*8); int ptr = (int)(selX + selY*8);
OnBasicColourClick(ptr); OnBasicColourClick(ptr);
} }
// wxStaticBitmap (used to ARGB preview) events are handled in the dedicated handler.
#if !wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
else if ((x >= m_customColoursRect.x && x <= (m_customColoursRect.x + m_customColoursRect.width)) && else if ((x >= m_customColoursRect.x && x <= (m_customColoursRect.x + m_customColoursRect.width)) &&
(y >= m_customColoursRect.y && y <= (m_customColoursRect.y + m_customColoursRect.height))) (y >= m_customColoursRect.y && y <= (m_customColoursRect.y + m_customColoursRect.height)))
{ {
@@ -185,6 +200,7 @@ void wxGenericColourDialog::OnMouseEvent(wxMouseEvent& event)
int ptr = (int)(selX + selY*8); int ptr = (int)(selX + selY*8);
OnCustomColourClick(ptr); OnCustomColourClick(ptr);
} }
#endif
else else
event.Skip(); event.Skip();
} }
@@ -192,22 +208,43 @@ void wxGenericColourDialog::OnMouseEvent(wxMouseEvent& event)
event.Skip(); event.Skip();
} }
#if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
void wxGenericColourDialog::OnCustomColourMouseClick(wxMouseEvent& event)
{
// Find index of custom colour
// and call the handler.
for (int i = 0; i < WXSIZEOF(m_customColoursBmp); i++)
{
if ( m_customColoursBmp[i]->GetId() == event.GetId() )
{
OnCustomColourClick(i);
return;
}
}
event.Skip();
}
#endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
void wxGenericColourDialog::OnPaint(wxPaintEvent& WXUNUSED(event)) void wxGenericColourDialog::OnPaint(wxPaintEvent& WXUNUSED(event))
{ {
wxPaintDC dc(this); wxPaintDC dc(this);
PaintBasicColours(dc); PaintBasicColours(dc);
PaintCustomColours(dc); // wxStaticBitmap controls are updated on their own.
#if !wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
PaintCustomColours(dc, -1);
PaintCustomColour(dc); PaintCustomColour(dc);
#endif // !wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
PaintHighlight(dc, true); PaintHighlight(dc, true);
} }
void wxGenericColourDialog::CalculateMeasurements() void wxGenericColourDialog::CalculateMeasurements()
{ {
m_smallRectangleSize.x = 18; // For single customizable colour
m_smallRectangleSize.y = 14; const wxSize customRectangleSize(40, 40);
m_customRectangleSize.x = 40;
m_customRectangleSize.y = 40; m_smallRectangleSize.Set(18, 14);
m_gridSpacing = 6; m_gridSpacing = 6;
m_sectionSpacing = 15; m_sectionSpacing = 15;
@@ -224,8 +261,7 @@ void wxGenericColourDialog::CalculateMeasurements()
m_singleCustomColourRect.x = m_customColoursRect.width + m_customColoursRect.x + m_sectionSpacing; m_singleCustomColourRect.x = m_customColoursRect.width + m_customColoursRect.x + m_sectionSpacing;
m_singleCustomColourRect.y = 80; m_singleCustomColourRect.y = 80;
m_singleCustomColourRect.width = m_customRectangleSize.x; m_singleCustomColourRect.SetSize(customRectangleSize);
m_singleCustomColourRect.height = m_customRectangleSize.y;
m_okButtonX = 10; m_okButtonX = 10;
m_customButtonX = m_singleCustomColourRect.x ; m_customButtonX = m_singleCustomColourRect.x ;
@@ -236,6 +272,33 @@ void wxGenericColourDialog::CreateWidgets()
{ {
wxBeginBusyCursor(); wxBeginBusyCursor();
#if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
// Bitmap to preview selected colour (with alpha channel)
wxBitmap customColourBmp(m_singleCustomColourRect.GetSize(), 32);
customColourBmp.UseAlpha();
DoPreviewBitmap(customColourBmp, m_colourData.GetColour());
m_customColourBmp = new wxStaticBitmap(this, wxID_ANY, customColourBmp,
m_singleCustomColourRect.GetLeftTop(),
m_singleCustomColourRect.GetSize(),
wxBORDER_SUNKEN);
// 16 bitmaps to preview custom colours (with alpha channel)
for (int i = 0; i < WXSIZEOF(m_customColoursBmp); i++)
{
int x = ((i % 8)*(m_smallRectangleSize.x+m_gridSpacing)) + m_customColoursRect.x;
int y = ((i / 8)*(m_smallRectangleSize.y+m_gridSpacing)) + m_customColoursRect.y;
wxBitmap bmp(m_smallRectangleSize, 32);
bmp.UseAlpha();
DoPreviewBitmap(bmp, m_customColours[i]);
m_customColoursBmp[i] = new wxStaticBitmap(this, wxID_ANY, bmp,
wxPoint(x, y), m_smallRectangleSize);
m_customColoursBmp[i]->Bind(wxEVT_LEFT_DOWN,
&wxGenericColourDialog::OnCustomColourMouseClick, this);
}
#endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
const int sliderHeight = 160; const int sliderHeight = 160;
@@ -244,23 +307,53 @@ void wxGenericColourDialog::CreateWidgets()
#if wxUSE_SLIDER #if wxUSE_SLIDER
const int sliderX = m_singleCustomColourRect.x + m_singleCustomColourRect.width + m_sectionSpacing; const int sliderX = m_singleCustomColourRect.x + m_singleCustomColourRect.width + m_sectionSpacing;
m_redSlider = new wxSlider(this, wxID_RED_SLIDER, m_colourData.m_dataColour.Red(), 0, 255, wxColour c = m_colourData.GetColour();
m_redSlider = new wxSlider(this, wxID_RED_SLIDER, c.Red(), 0, 255,
wxDefaultPosition, wxSize(wxDefaultCoord, sliderHeight), wxSL_VERTICAL|wxSL_LABELS|wxSL_INVERSE); wxDefaultPosition, wxSize(wxDefaultCoord, sliderHeight), wxSL_VERTICAL|wxSL_LABELS|wxSL_INVERSE);
m_greenSlider = new wxSlider(this, wxID_GREEN_SLIDER, m_colourData.m_dataColour.Green(), 0, 255, m_greenSlider = new wxSlider(this, wxID_GREEN_SLIDER, c.Green(), 0, 255,
wxDefaultPosition, wxSize(wxDefaultCoord, sliderHeight), wxSL_VERTICAL|wxSL_LABELS|wxSL_INVERSE); wxDefaultPosition, wxSize(wxDefaultCoord, sliderHeight), wxSL_VERTICAL|wxSL_LABELS|wxSL_INVERSE);
m_blueSlider = new wxSlider(this, wxID_BLUE_SLIDER, m_colourData.m_dataColour.Blue(), 0, 255, m_blueSlider = new wxSlider(this, wxID_BLUE_SLIDER, c.Blue(), 0, 255,
wxDefaultPosition, wxSize(wxDefaultCoord, sliderHeight), wxSL_VERTICAL|wxSL_LABELS|wxSL_INVERSE); wxDefaultPosition, wxSize(wxDefaultCoord, sliderHeight), wxSL_VERTICAL|wxSL_LABELS|wxSL_INVERSE);
if ( m_colourData.GetChooseAlpha() )
{
m_alphaSlider = new wxSlider(this, wxID_ANY, c.Alpha(), 0, 255,
wxDefaultPosition, wxSize(wxDefaultCoord, sliderHeight), wxSL_VERTICAL|wxSL_LABELS|wxSL_INVERSE);
m_alphaSlider->Bind(wxEVT_SLIDER, &wxGenericColourDialog::OnAlphaSlider, this);
}
else
{
m_alphaSlider = NULL;
}
wxBoxSizer *sliderSizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer *sliderSizer = new wxBoxSizer( wxHORIZONTAL );
sliderSizer->Add(sliderX, sliderHeight ); sliderSizer->Add(sliderX, sliderHeight );
const wxSizerFlags sliderLabelFlags = wxSizerFlags().Right().Border();
const wxSizerFlags onesliderFlags = wxSizerFlags().CenterHorizontal();
const wxSizerFlags sliderFlags const wxSizerFlags sliderFlags
= wxSizerFlags().CentreVertical().DoubleBorder(); = wxSizerFlags().CentreVertical().DoubleBorder();
sliderSizer->Add(m_redSlider, sliderFlags); wxBoxSizer *redSliderSizer = new wxBoxSizer(wxVERTICAL);
sliderSizer->Add(m_greenSlider, sliderFlags); redSliderSizer->Add(new wxStaticText(this, wxID_ANY, _("Red:")), sliderLabelFlags);
sliderSizer->Add(m_blueSlider, sliderFlags); redSliderSizer->Add(m_redSlider, onesliderFlags);
wxBoxSizer *greenSliderSizer = new wxBoxSizer(wxVERTICAL);
greenSliderSizer->Add(new wxStaticText(this, wxID_ANY, _("Green:")), sliderLabelFlags);
greenSliderSizer->Add(m_greenSlider, onesliderFlags);
wxBoxSizer *blueSliderSizer = new wxBoxSizer(wxVERTICAL);
blueSliderSizer->Add(new wxStaticText(this, wxID_ANY, _("Blue:")), sliderLabelFlags);
blueSliderSizer->Add(m_blueSlider, onesliderFlags);
sliderSizer->Add(redSliderSizer, sliderFlags);
sliderSizer->Add(greenSliderSizer, sliderFlags);
sliderSizer->Add(blueSliderSizer, sliderFlags);
if ( m_colourData.GetChooseAlpha() )
{
wxBoxSizer *alphaSliderSizer = new wxBoxSizer(wxVERTICAL);
alphaSliderSizer->Add(new wxStaticText(this, wxID_ANY, _("Opacity:")), sliderLabelFlags);
alphaSliderSizer->Add(m_alphaSlider, onesliderFlags);
sliderSizer->Add(alphaSliderSizer, sliderFlags);
}
topSizer->Add(sliderSizer, wxSizerFlags().Centre().DoubleBorder()); topSizer->Add(sliderSizer, wxSizerFlags().Centre().DoubleBorder());
#else #else
@@ -339,13 +432,13 @@ void wxGenericColourDialog::InitializeColours(void)
} }
} }
} }
m_colourData.m_dataColour.Set( curr.Red(), curr.Green(), curr.Blue() ); m_colourData.SetColour(curr);
} }
else else
{ {
m_whichKind = 1; m_whichKind = 1;
m_colourSelection = 0; m_colourSelection = 0;
m_colourData.m_dataColour.Set( 0, 0, 0 ); m_colourData.SetColour(wxColour(0, 0, 0));
} }
} }
@@ -371,28 +464,37 @@ void wxGenericColourDialog::PaintBasicColours(wxDC& dc)
} }
} }
void wxGenericColourDialog::PaintCustomColours(wxDC& dc) #if !wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
void wxGenericColourDialog::PaintCustomColours(wxDC& dc, int clrIndex)
{ {
int i; int idxStart;
for (i = 0; i < 2; i++) int idxEnd;
{ // For clrIndex == -1 redraw all custom colours
int j; if ( clrIndex < 0 || clrIndex >= WXSIZEOF(m_customColours) )
for (j = 0; j < 8; j++)
{ {
int ptr = i*8 + j; idxStart = 0;
idxEnd = WXSIZEOF(m_customColours) - 1;
int x = (j*(m_smallRectangleSize.x+m_gridSpacing)) + m_customColoursRect.x; }
int y = (i*(m_smallRectangleSize.y+m_gridSpacing)) + m_customColoursRect.y; else
{
dc.SetPen(*wxBLACK_PEN); idxStart = clrIndex;
idxEnd = clrIndex;
wxBrush brush(m_customColours[ptr]); }
dc.SetBrush(brush);
for (int i = idxStart; i <= idxEnd; i++)
dc.DrawRectangle( x, y, m_smallRectangleSize.x, m_smallRectangleSize.y); {
int x = ((i % 8)*(m_smallRectangleSize.x+m_gridSpacing)) + m_customColoursRect.x;
int y = ((i / 8)*(m_smallRectangleSize.y+m_gridSpacing)) + m_customColoursRect.y;
dc.SetPen(*wxBLACK_PEN);
wxBrush brush(m_customColours[i]);
dc.SetBrush(brush);
dc.DrawRectangle(x, y, m_smallRectangleSize.x, m_smallRectangleSize.y);
} }
}
} }
#endif // !wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
void wxGenericColourDialog::PaintHighlight(wxDC& dc, bool draw) void wxGenericColourDialog::PaintHighlight(wxDC& dc, bool draw)
{ {
@@ -442,16 +544,24 @@ void wxGenericColourDialog::PaintHighlight(wxDC& dc, bool draw)
void wxGenericColourDialog::PaintCustomColour(wxDC& dc) void wxGenericColourDialog::PaintCustomColour(wxDC& dc)
{ {
#if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
wxUnusedVar(dc);
wxBitmap bmp(m_singleCustomColourRect.GetSize(), 32);
bmp.UseAlpha();
DoPreviewBitmap(bmp, m_colourData.GetColour());
m_customColourBmp->SetBitmap(bmp);
#else
dc.SetPen(*wxBLACK_PEN); dc.SetPen(*wxBLACK_PEN);
wxBrush *brush = new wxBrush(m_colourData.m_dataColour); wxBrush *brush = new wxBrush(m_colourData.GetColour());
dc.SetBrush(*brush); dc.SetBrush(*brush);
dc.DrawRectangle( m_singleCustomColourRect.x, m_singleCustomColourRect.y, dc.DrawRectangle(m_singleCustomColourRect);
m_customRectangleSize.x, m_customRectangleSize.y);
dc.SetBrush(wxNullBrush); dc.SetBrush(wxNullBrush);
delete brush; delete brush;
#endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA/!wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
} }
void wxGenericColourDialog::OnBasicColourClick(int which) void wxGenericColourDialog::OnBasicColourClick(int which)
@@ -466,11 +576,13 @@ void wxGenericColourDialog::OnBasicColourClick(int which)
m_redSlider->SetValue( m_standardColours[m_colourSelection].Red() ); m_redSlider->SetValue( m_standardColours[m_colourSelection].Red() );
m_greenSlider->SetValue( m_standardColours[m_colourSelection].Green() ); m_greenSlider->SetValue( m_standardColours[m_colourSelection].Green() );
m_blueSlider->SetValue( m_standardColours[m_colourSelection].Blue() ); m_blueSlider->SetValue( m_standardColours[m_colourSelection].Blue() );
if ( m_colourData.GetChooseAlpha() )
{
m_alphaSlider->SetValue( m_standardColours[m_colourSelection].Alpha() );
}
#endif // wxUSE_SLIDER #endif // wxUSE_SLIDER
m_colourData.m_dataColour.Set(m_standardColours[m_colourSelection].Red(), m_colourData.SetColour(m_standardColours[m_colourSelection]);
m_standardColours[m_colourSelection].Green(),
m_standardColours[m_colourSelection].Blue());
PaintCustomColour(dc); PaintCustomColour(dc);
PaintHighlight(dc, true); PaintHighlight(dc, true);
@@ -487,11 +599,13 @@ void wxGenericColourDialog::OnCustomColourClick(int which)
m_redSlider->SetValue( m_customColours[m_colourSelection].Red() ); m_redSlider->SetValue( m_customColours[m_colourSelection].Red() );
m_greenSlider->SetValue( m_customColours[m_colourSelection].Green() ); m_greenSlider->SetValue( m_customColours[m_colourSelection].Green() );
m_blueSlider->SetValue( m_customColours[m_colourSelection].Blue() ); m_blueSlider->SetValue( m_customColours[m_colourSelection].Blue() );
if ( m_colourData.GetChooseAlpha() )
{
m_alphaSlider->SetValue( m_customColours[m_colourSelection].Alpha() );
}
#endif // wxUSE_SLIDER #endif // wxUSE_SLIDER
m_colourData.m_dataColour.Set(m_customColours[m_colourSelection].Red(), m_colourData.SetColour(m_customColours[m_colourSelection]);
m_customColours[m_colourSelection].Green(),
m_customColours[m_colourSelection].Blue());
PaintCustomColour(dc); PaintCustomColour(dc);
PaintHighlight(dc, true); PaintHighlight(dc, true);
@@ -521,13 +635,18 @@ void wxGenericColourDialog::OnAddCustom(wxCommandEvent& WXUNUSED(event))
PaintHighlight(dc, true); PaintHighlight(dc, true);
} }
m_customColours[m_colourSelection].Set(m_colourData.m_dataColour.Red(), m_customColours[m_colourSelection] = m_colourData.GetColour();
m_colourData.m_dataColour.Green(),
m_colourData.m_dataColour.Blue());
m_colourData.SetCustomColour(m_colourSelection, m_customColours[m_colourSelection]); m_colourData.SetCustomColour(m_colourSelection, m_customColours[m_colourSelection]);
PaintCustomColours(dc); #if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
wxBitmap bmp(m_smallRectangleSize, 32);
bmp.UseAlpha();
DoPreviewBitmap(bmp, m_customColours[m_colourSelection]);
m_customColoursBmp[m_colourSelection]->SetBitmap(bmp);
#else
PaintCustomColours(dc, m_colourSelection);
#endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA/!wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
} }
#if wxUSE_SLIDER #if wxUSE_SLIDER
@@ -538,7 +657,8 @@ void wxGenericColourDialog::OnRedSlider(wxCommandEvent& WXUNUSED(event))
return; return;
wxClientDC dc(this); wxClientDC dc(this);
m_colourData.m_dataColour.Set((unsigned char)m_redSlider->GetValue(), m_colourData.m_dataColour.Green(), m_colourData.m_dataColour.Blue()); wxColour c = m_colourData.GetColour();
m_colourData.SetColour(wxColour((unsigned char)m_redSlider->GetValue(), c.Green(), c.Blue(), c.Alpha()));
PaintCustomColour(dc); PaintCustomColour(dc);
} }
@@ -548,7 +668,8 @@ void wxGenericColourDialog::OnGreenSlider(wxCommandEvent& WXUNUSED(event))
return; return;
wxClientDC dc(this); wxClientDC dc(this);
m_colourData.m_dataColour.Set(m_colourData.m_dataColour.Red(), (unsigned char)m_greenSlider->GetValue(), m_colourData.m_dataColour.Blue()); wxColour c = m_colourData.GetColour();
m_colourData.SetColour(wxColour(c.Red(), (unsigned char)m_greenSlider->GetValue(), c.Blue(), c.Alpha()));
PaintCustomColour(dc); PaintCustomColour(dc);
} }
@@ -558,10 +679,86 @@ void wxGenericColourDialog::OnBlueSlider(wxCommandEvent& WXUNUSED(event))
return; return;
wxClientDC dc(this); wxClientDC dc(this);
m_colourData.m_dataColour.Set(m_colourData.m_dataColour.Red(), m_colourData.m_dataColour.Green(), (unsigned char)m_blueSlider->GetValue()); wxColour c = m_colourData.GetColour();
m_colourData.SetColour(wxColour(c.Red(), c.Green(), (unsigned char)m_blueSlider->GetValue(), c.Alpha()));
PaintCustomColour(dc); PaintCustomColour(dc);
} }
void wxGenericColourDialog::OnAlphaSlider(wxCommandEvent& WXUNUSED(event))
{
wxColour c = m_colourData.GetColour();
m_colourData.SetColour(wxColour(c.Red(), c.Green(), c.Blue(), (unsigned char)m_alphaSlider->GetValue()));
wxClientDC dc(this);
PaintCustomColour(dc);
}
#endif // wxUSE_SLIDER #endif // wxUSE_SLIDER
#if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
void wxGenericColourDialog::DoPreviewBitmap(wxBitmap& bmp, const wxColour& colour)
{
if ( bmp.HasAlpha() && colour.Alpha() != wxALPHA_OPAQUE )
{
// For real ARGB draw a chessboard grid
// with actual ARGB fields and reference RGB fields.
const int w = bmp.GetWidth();
const int h = bmp.GetHeight();
// Calculate field size: 4 fields per row/column,
// with size in range [2..10]
int dx = wxMax(wxMin(w / 4, 10), 2);
int dy = wxMax(wxMin(h / 4, 10), 2);
// We want a square field
dx = wxMax(dx, dy);
dy = dx;
// Prepare opaque colour
wxColour colourRGB(colour.Red(), colour.Green(), colour.Blue(), wxALPHA_OPAQUE);
{
wxBrush brushARGB(colour);
wxBrush brushRGB(colourRGB);
wxMemoryDC mdc(bmp);
{
wxGCDC gdc(mdc);
gdc.SetPen(*wxTRANSPARENT_PEN);
for (int x = 0, ix = 0; x < w; x += dx, ix++)
{
for (int y = 0, iy = 0; y < h; y += dy, iy++)
{
if ( (ix+iy) % 2 == 0 )
{
gdc.SetBrush(brushARGB);
}
else
{
gdc.SetBrush(brushRGB);
}
gdc.DrawRectangle(x, y, dx, dy);
}
}
// Draw a frame
gdc.SetPen(*wxBLACK_PEN);
gdc.SetBrush(*wxTRANSPARENT_BRUSH);
gdc.DrawRectangle(0, 0, w, h);
}
}
}
else
{
wxMemoryDC mdc(bmp);
// Fill with custom colour
wxBrush brush(colour);
mdc.SetPen(*wxBLACK_PEN);
mdc.SetBrush(brush);
mdc.DrawRectangle(wxPoint(0, 0), bmp.GetSize());
}
}
#endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
#endif // wxUSE_COLOURDLG #endif // wxUSE_COLOURDLG