diff --git a/include/wx/generic/clrpickerg.h b/include/wx/generic/clrpickerg.h index 9f8327b422..2194d72c14 100644 --- a/include/wx/generic/clrpickerg.h +++ b/include/wx/generic/clrpickerg.h @@ -71,6 +71,8 @@ protected: void UpdateColour() wxOVERRIDE; + void OnDPIChanged(wxDPIChangedEvent& event); + // the colour data shown in wxColourPickerCtrlGeneric // controls. This member is static so that all colour pickers // in the program share the same set of custom colours. diff --git a/src/generic/clrpickerg.cpp b/src/generic/clrpickerg.cpp index d0f8434168..68dadc7d65 100644 --- a/src/generic/clrpickerg.cpp +++ b/src/generic/clrpickerg.cpp @@ -29,6 +29,10 @@ #include "wx/colordlg.h" #include "wx/dcmemory.h" +namespace // anonymous namespace +{ +const wxSize defaultBitmapSize(60, 13); +} // ============================================================================ // implementation @@ -46,8 +50,6 @@ bool wxGenericColourButton::Create( wxWindow *parent, wxWindowID id, const wxSize &size, long style, const wxValidator& validator, const wxString &name) { - m_bitmap = wxBitmap( 60, 13 ); - // create this button if (!wxBitmapButton::Create( parent, id, m_bitmap, pos, size, style, validator, name )) @@ -59,11 +61,14 @@ bool wxGenericColourButton::Create( wxWindow *parent, wxWindowID id, // and handle user clicks on it Bind(wxEVT_BUTTON, &wxGenericColourButton::OnButtonClick, this, GetId()); + m_bitmap = wxBitmap(FromDIP(defaultBitmapSize)); m_colour = col; UpdateColour(); InitColourData(); ms_data.SetChooseAlpha((style & wxCLRP_SHOW_ALPHA) != 0); + Bind(wxEVT_DPI_CHANGED, &wxGenericColourButton::OnDPIChanged, this); + return true; } @@ -118,6 +123,12 @@ void wxGenericColourButton::OnColourChanged(wxColourDialogEvent& ev) parent->ProcessWindowEvent(event); } +void wxGenericColourButton::OnDPIChanged(wxDPIChangedEvent&WXUNUSED(event)) +{ + m_bitmap = wxBitmap(FromDIP(defaultBitmapSize)); + UpdateColour(); +} + void wxGenericColourButton::UpdateColour() { wxMemoryDC dc(m_bitmap); @@ -130,7 +141,12 @@ void wxGenericColourButton::UpdateColour() wxColour col( ~m_colour.Red(), ~m_colour.Green(), ~m_colour.Blue() ); dc.SetTextForeground( col ); dc.SetFont( GetFont() ); - dc.DrawText( m_colour.GetAsString(wxC2S_HTML_SYNTAX), 0, 0 ); + + const wxString text = m_colour.GetAsString(wxC2S_HTML_SYNTAX); + const wxSize textSize = dc.GetTextExtent(text); + const int x = (m_bitmap.GetWidth() - textSize.GetWidth()) / 2; + const int y = (m_bitmap.GetHeight() - textSize.GetHeight()) / 2; + dc.DrawText(text, x, y); } dc.SelectObject( wxNullBitmap );