Merge branch 'colour_dialogs_alpha' of https://github.com/a-wi/wxWidgets

Add support for alpha channel to wxColourPicker and wxColourDialog in wxGTK.

Closes #14127.
This commit is contained in:
Vadim Zeitlin
2015-11-17 22:47:49 +01:00
6 changed files with 23 additions and 7 deletions

View File

@@ -68,6 +68,7 @@ protected:
// NOTE: this style is supported just by wxColourButtonGeneric and // NOTE: this style is supported just by wxColourButtonGeneric and
// thus is not exposed in wxColourPickerCtrl // thus is not exposed in wxColourPickerCtrl
#define wxCLRP_SHOW_LABEL 0x0008 #define wxCLRP_SHOW_LABEL 0x0008
#define wxCLRP_SHOW_ALPHA 0x0010
// map platform-dependent controls which implement the wxColourPickerWidgetBase // map platform-dependent controls which implement the wxColourPickerWidgetBase
// under the name "wxColourPickerWidget". // under the name "wxColourPickerWidget".
@@ -146,7 +147,7 @@ public: // internal functions
protected: protected:
virtual long GetPickerStyle(long style) const wxOVERRIDE virtual long GetPickerStyle(long style) const wxOVERRIDE
{ return (style & wxCLRP_SHOW_LABEL); } { return (style & (wxCLRP_SHOW_LABEL | wxCLRP_SHOW_ALPHA)); }
private: private:
wxDECLARE_DYNAMIC_CLASS(wxColourPickerCtrl); wxDECLARE_DYNAMIC_CLASS(wxColourPickerCtrl);

View File

@@ -140,6 +140,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
#endif // wxUSE_RICHMSGDLG #endif // wxUSE_RICHMSGDLG
#if wxUSE_COLOURDLG #if wxUSE_COLOURDLG
EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour) EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
EVT_MENU(DIALOGS_CHOOSE_COLOUR_ALPHA, MyFrame::ChooseColour)
EVT_MENU(DIALOGS_GET_COLOUR, MyFrame::GetColour) EVT_MENU(DIALOGS_GET_COLOUR, MyFrame::GetColour)
#endif // wxUSE_COLOURDLG #endif // wxUSE_COLOURDLG
@@ -375,7 +376,10 @@ bool MyApp::OnInit()
wxMenu *choices_menu = new wxMenu; wxMenu *choices_menu = new wxMenu;
#if wxUSE_COLOURDLG #if wxUSE_COLOURDLG
choices_menu->Append(DIALOGS_CHOOSE_COLOUR, wxT("&Choose bg colour")); wxMenu *choices_bg_colour = new wxMenu;
choices_bg_colour->Append(DIALOGS_CHOOSE_COLOUR, wxT("&No opacity"));
choices_bg_colour->Append(DIALOGS_CHOOSE_COLOUR_ALPHA, wxT("&With opacity"));
choices_menu->Append(wxID_ANY, wxT("&Choose bg colour"), choices_bg_colour);
choices_menu->Append(DIALOGS_GET_COLOUR, wxT("&Choose fg colour")); choices_menu->Append(DIALOGS_GET_COLOUR, wxT("&Choose fg colour"));
#endif // wxUSE_COLOURDLG #endif // wxUSE_COLOURDLG
@@ -710,9 +714,10 @@ MyFrame::~MyFrame()
#if wxUSE_COLOURDLG #if wxUSE_COLOURDLG
void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event)) void MyFrame::ChooseColour(wxCommandEvent& event)
{ {
m_clrData.SetColour(m_canvas->GetBackgroundColour()); m_clrData.SetColour(m_canvas->GetBackgroundColour());
m_clrData.SetChooseAlpha(event.GetId() == DIALOGS_CHOOSE_COLOUR_ALPHA);
wxColourDialog dialog(this, &m_clrData); wxColourDialog dialog(this, &m_clrData);
dialog.SetTitle(_("Please choose the background colour")); dialog.SetTitle(_("Please choose the background colour"));

View File

@@ -65,8 +65,7 @@ of MSW, MAC and OS2
#define USE_DIRDLG_GENERIC \ #define USE_DIRDLG_GENERIC \
((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_DIRDLG) ((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_DIRDLG)
#define USE_FILEDLG_GENERIC \ #define USE_FILEDLG_GENERIC \
((((USE_WXMSW || USE_WXMAC || USE_WXGTK) \ ((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_FILEDLG)
&& USE_GENERIC_DIALOGS) ) && wxUSE_FILEDLG)
#define USE_FONTDLG_GENERIC \ #define USE_FONTDLG_GENERIC \
((USE_WXMSW || USE_WXMACFONTDLG) && USE_GENERIC_DIALOGS && wxUSE_FONTDLG) ((USE_WXMSW || USE_WXMACFONTDLG) && USE_GENERIC_DIALOGS && wxUSE_FONTDLG)
@@ -534,6 +533,7 @@ private:
enum enum
{ {
DIALOGS_CHOOSE_COLOUR = wxID_HIGHEST, DIALOGS_CHOOSE_COLOUR = wxID_HIGHEST,
DIALOGS_CHOOSE_COLOUR_ALPHA,
DIALOGS_GET_COLOUR, DIALOGS_GET_COLOUR,
DIALOGS_CHOOSE_COLOUR_GENERIC, DIALOGS_CHOOSE_COLOUR_GENERIC,
DIALOGS_CHOOSE_COLOUR_GENERIC_ALPHA, DIALOGS_CHOOSE_COLOUR_GENERIC_ALPHA,

View File

@@ -98,7 +98,8 @@ protected:
// -------------- // --------------
wxCheckBox *m_chkColourTextCtrl, wxCheckBox *m_chkColourTextCtrl,
*m_chkColourShowLabel; *m_chkColourShowLabel,
*m_chkColourShowAlpha;
wxBoxSizer *m_sizer; wxBoxSizer *m_sizer;
private: private:
@@ -145,6 +146,7 @@ void ColourPickerWidgetsPage::CreateContent()
wxStaticBoxSizer *clrbox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&ColourPicker style")); wxStaticBoxSizer *clrbox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&ColourPicker style"));
m_chkColourTextCtrl = CreateCheckBoxAndAddToSizer(clrbox, wxT("With textctrl")); m_chkColourTextCtrl = CreateCheckBoxAndAddToSizer(clrbox, wxT("With textctrl"));
m_chkColourShowLabel = CreateCheckBoxAndAddToSizer(clrbox, wxT("With label")); m_chkColourShowLabel = CreateCheckBoxAndAddToSizer(clrbox, wxT("With label"));
m_chkColourShowAlpha = CreateCheckBoxAndAddToSizer(clrbox, wxT("With opacity"));
boxleft->Add(clrbox, 0, wxALL|wxGROW, 5); boxleft->Add(clrbox, 0, wxALL|wxGROW, 5);
boxleft->Add(new wxButton(this, PickerPage_Reset, wxT("&Reset")), boxleft->Add(new wxButton(this, PickerPage_Reset, wxT("&Reset")),
@@ -189,6 +191,9 @@ long ColourPickerWidgetsPage::GetPickerStyle()
if ( m_chkColourShowLabel->GetValue() ) if ( m_chkColourShowLabel->GetValue() )
style |= wxCLRP_SHOW_LABEL; style |= wxCLRP_SHOW_LABEL;
if ( m_chkColourShowAlpha->GetValue() )
style |= wxCLRP_SHOW_ALPHA;
return style; return style;
} }
@@ -227,7 +232,8 @@ void ColourPickerWidgetsPage::OnColourChange(wxColourPickerEvent& event)
void ColourPickerWidgetsPage::OnCheckBox(wxCommandEvent &event) void ColourPickerWidgetsPage::OnCheckBox(wxCommandEvent &event)
{ {
if (event.GetEventObject() == m_chkColourTextCtrl || if (event.GetEventObject() == m_chkColourTextCtrl ||
event.GetEventObject() == m_chkColourShowLabel) event.GetEventObject() == m_chkColourShowLabel ||
event.GetEventObject() == m_chkColourShowAlpha)
RecreatePicker(); RecreatePicker();
} }

View File

@@ -78,6 +78,9 @@ bool wxColourButton::Create( wxWindow *parent, wxWindowID id,
#endif #endif
g_object_ref(m_widget); g_object_ref(m_widget);
// Display opacity slider
g_object_set(G_OBJECT(m_widget), "use-alpha",
static_cast<bool>(style & wxCLRP_SHOW_ALPHA), NULL);
// GtkColourButton signals // GtkColourButton signals
g_signal_connect(m_widget, "color-set", g_signal_connect(m_widget, "color-set",
G_CALLBACK(gtk_clrbutton_setcolor_callback), this); G_CALLBACK(gtk_clrbutton_setcolor_callback), this);

View File

@@ -65,6 +65,7 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
gtk_color_selection_dialog_get_color_selection( gtk_color_selection_dialog_get_color_selection(
GTK_COLOR_SELECTION_DIALOG(m_widget))); GTK_COLOR_SELECTION_DIALOG(m_widget)));
gtk_color_selection_set_has_palette(sel, true); gtk_color_selection_set_has_palette(sel, true);
gtk_color_selection_set_has_opacity_control(sel, m_data.GetChooseAlpha());
return true; return true;
} }