Make wxGenericColourButton DPI aware
This commit is contained in:
@@ -71,6 +71,8 @@ protected:
|
|||||||
|
|
||||||
void UpdateColour() wxOVERRIDE;
|
void UpdateColour() wxOVERRIDE;
|
||||||
|
|
||||||
|
void OnDPIChanged(wxDPIChangedEvent& event);
|
||||||
|
|
||||||
// the colour data shown in wxColourPickerCtrlGeneric
|
// the colour data shown in wxColourPickerCtrlGeneric
|
||||||
// controls. This member is static so that all colour pickers
|
// controls. This member is static so that all colour pickers
|
||||||
// in the program share the same set of custom colours.
|
// in the program share the same set of custom colours.
|
||||||
|
@@ -29,6 +29,10 @@
|
|||||||
#include "wx/colordlg.h"
|
#include "wx/colordlg.h"
|
||||||
#include "wx/dcmemory.h"
|
#include "wx/dcmemory.h"
|
||||||
|
|
||||||
|
namespace // anonymous namespace
|
||||||
|
{
|
||||||
|
const wxSize defaultBitmapSize(60, 13);
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// implementation
|
// implementation
|
||||||
@@ -46,8 +50,6 @@ bool wxGenericColourButton::Create( wxWindow *parent, wxWindowID id,
|
|||||||
const wxSize &size, long style,
|
const wxSize &size, long style,
|
||||||
const wxValidator& validator, const wxString &name)
|
const wxValidator& validator, const wxString &name)
|
||||||
{
|
{
|
||||||
m_bitmap = wxBitmap( 60, 13 );
|
|
||||||
|
|
||||||
// create this button
|
// create this button
|
||||||
if (!wxBitmapButton::Create( parent, id, m_bitmap, pos,
|
if (!wxBitmapButton::Create( parent, id, m_bitmap, pos,
|
||||||
size, style, validator, name ))
|
size, style, validator, name ))
|
||||||
@@ -59,11 +61,14 @@ bool wxGenericColourButton::Create( wxWindow *parent, wxWindowID id,
|
|||||||
// and handle user clicks on it
|
// and handle user clicks on it
|
||||||
Bind(wxEVT_BUTTON, &wxGenericColourButton::OnButtonClick, this, GetId());
|
Bind(wxEVT_BUTTON, &wxGenericColourButton::OnButtonClick, this, GetId());
|
||||||
|
|
||||||
|
m_bitmap = wxBitmap(FromDIP(defaultBitmapSize));
|
||||||
m_colour = col;
|
m_colour = col;
|
||||||
UpdateColour();
|
UpdateColour();
|
||||||
InitColourData();
|
InitColourData();
|
||||||
ms_data.SetChooseAlpha((style & wxCLRP_SHOW_ALPHA) != 0);
|
ms_data.SetChooseAlpha((style & wxCLRP_SHOW_ALPHA) != 0);
|
||||||
|
|
||||||
|
Bind(wxEVT_DPI_CHANGED, &wxGenericColourButton::OnDPIChanged, this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,6 +123,12 @@ void wxGenericColourButton::OnColourChanged(wxColourDialogEvent& ev)
|
|||||||
parent->ProcessWindowEvent(event);
|
parent->ProcessWindowEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxGenericColourButton::OnDPIChanged(wxDPIChangedEvent&WXUNUSED(event))
|
||||||
|
{
|
||||||
|
m_bitmap = wxBitmap(FromDIP(defaultBitmapSize));
|
||||||
|
UpdateColour();
|
||||||
|
}
|
||||||
|
|
||||||
void wxGenericColourButton::UpdateColour()
|
void wxGenericColourButton::UpdateColour()
|
||||||
{
|
{
|
||||||
wxMemoryDC dc(m_bitmap);
|
wxMemoryDC dc(m_bitmap);
|
||||||
@@ -130,7 +141,12 @@ void wxGenericColourButton::UpdateColour()
|
|||||||
wxColour col( ~m_colour.Red(), ~m_colour.Green(), ~m_colour.Blue() );
|
wxColour col( ~m_colour.Red(), ~m_colour.Green(), ~m_colour.Blue() );
|
||||||
dc.SetTextForeground( col );
|
dc.SetTextForeground( col );
|
||||||
dc.SetFont( GetFont() );
|
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 );
|
dc.SelectObject( wxNullBitmap );
|
||||||
|
Reference in New Issue
Block a user