Make wxGenericColourDialog DPI aware

This commit is contained in:
Maarten Bent
2020-07-31 00:06:46 +02:00
parent 9e2615ac06
commit b10ba803f5
2 changed files with 36 additions and 19 deletions

View File

@@ -49,6 +49,7 @@ public:
// Internal functions // Internal functions
void OnMouseEvent(wxMouseEvent& event); void OnMouseEvent(wxMouseEvent& event);
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);
void OnDPIChanged(wxDPIChangedEvent& event);
#if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA #if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
void OnCustomColourMouseClick(wxMouseEvent& event); void OnCustomColourMouseClick(wxMouseEvent& event);
#endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA #endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA

View File

@@ -60,6 +60,7 @@ wxBEGIN_EVENT_TABLE(wxGenericColourDialog, wxDialog)
EVT_SLIDER(wxID_GREEN_SLIDER, wxGenericColourDialog::OnGreenSlider) EVT_SLIDER(wxID_GREEN_SLIDER, wxGenericColourDialog::OnGreenSlider)
EVT_SLIDER(wxID_BLUE_SLIDER, wxGenericColourDialog::OnBlueSlider) EVT_SLIDER(wxID_BLUE_SLIDER, wxGenericColourDialog::OnBlueSlider)
#endif #endif
EVT_DPI_CHANGED(wxGenericColourDialog::OnDPIChanged)
EVT_PAINT(wxGenericColourDialog::OnPaint) EVT_PAINT(wxGenericColourDialog::OnPaint)
EVT_MOUSE_EVENTS(wxGenericColourDialog::OnMouseEvent) EVT_MOUSE_EVENTS(wxGenericColourDialog::OnMouseEvent)
EVT_CLOSE(wxGenericColourDialog::OnCloseWindow) EVT_CLOSE(wxGenericColourDialog::OnCloseWindow)
@@ -155,8 +156,7 @@ void wxGenericColourDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
bool wxGenericColourDialog::Create(wxWindow *parent, const wxColourData *data) bool wxGenericColourDialog::Create(wxWindow *parent, const wxColourData *data)
{ {
if ( !wxDialog::Create(GetParentForModalDialog(parent, 0), wxID_ANY, if ( !wxDialog::Create(GetParentForModalDialog(parent, 0), wxID_ANY,
_("Choose colour"), _("Choose colour")) )
wxPoint(0, 0), wxSize(900, 900)) )
return false; return false;
if (data) if (data)
@@ -238,10 +238,13 @@ void wxGenericColourDialog::CreateCustomBitmaps()
wxBitmap customColourBmp(m_singleCustomColourRect.GetSize(), 32); wxBitmap customColourBmp(m_singleCustomColourRect.GetSize(), 32);
customColourBmp.UseAlpha(); customColourBmp.UseAlpha();
DoPreviewBitmap(customColourBmp, m_colourData.GetColour()); DoPreviewBitmap(customColourBmp, m_colourData.GetColour());
m_customColourBmp = new wxStaticBitmap(this, wxID_ANY, customColourBmp,
m_singleCustomColourRect.GetLeftTop(), if ( !m_customColourBmp )
m_singleCustomColourRect.GetSize(), {
wxBORDER_SUNKEN); m_customColourBmp = new wxStaticBitmap(this, wxID_ANY, customColourBmp);
}
m_customColourBmp->SetSize(m_singleCustomColourRect);
m_customColourBmp->SetBitmap(customColourBmp);
// 16 bitmaps to preview custom colours (with alpha channel) // 16 bitmaps to preview custom colours (with alpha channel)
for ( unsigned i = 0; i < WXSIZEOF(m_customColoursBmp); i++ ) for ( unsigned i = 0; i < WXSIZEOF(m_customColoursBmp); i++ )
@@ -252,11 +255,15 @@ void wxGenericColourDialog::CreateCustomBitmaps()
wxBitmap bmp(m_smallRectangleSize, 32); wxBitmap bmp(m_smallRectangleSize, 32);
bmp.UseAlpha(); bmp.UseAlpha();
DoPreviewBitmap(bmp, m_customColours[i]); 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);
if ( !m_customColoursBmp[i] )
{
m_customColoursBmp[i] = new wxStaticBitmap(this, wxID_ANY, bmp);
m_customColoursBmp[i]->Bind(wxEVT_LEFT_DOWN,
&wxGenericColourDialog::OnCustomColourMouseClick, this);
}
m_customColoursBmp[i]->SetSize(x, y, m_smallRectangleSize.x, m_smallRectangleSize.y);
m_customColoursBmp[i]->SetBitmap(bmp);
} }
} }
#endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA #endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
@@ -274,28 +281,37 @@ void wxGenericColourDialog::OnPaint(wxPaintEvent& WXUNUSED(event))
PaintHighlight(dc, true); PaintHighlight(dc, true);
} }
void wxGenericColourDialog::OnDPIChanged(wxDPIChangedEvent& WXUNUSED(event))
{
CalculateMeasurements();
#if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
CreateCustomBitmaps();
#endif
}
void wxGenericColourDialog::CalculateMeasurements() void wxGenericColourDialog::CalculateMeasurements()
{ {
// For single customizable colour // For single customizable colour
const wxSize customRectangleSize(40, 40); const wxSize customRectangleSize = FromDIP(wxSize(40, 40));
m_smallRectangleSize.Set(18, 14); m_smallRectangleSize = FromDIP(wxSize(18, 14));
m_gridSpacing = 6; m_gridSpacing = FromDIP(6);
m_sectionSpacing = 15; m_sectionSpacing = FromDIP(15);
m_standardColoursRect.x = 10; m_standardColoursRect.x = FromDIP(10);
m_standardColoursRect.y = 15; m_standardColoursRect.y = FromDIP(15);
m_standardColoursRect.width = (8*m_smallRectangleSize.x) + (7*m_gridSpacing); m_standardColoursRect.width = (8*m_smallRectangleSize.x) + (7*m_gridSpacing);
m_standardColoursRect.height = (6*m_smallRectangleSize.y) + (5*m_gridSpacing); m_standardColoursRect.height = (6*m_smallRectangleSize.y) + (5*m_gridSpacing);
m_customColoursRect.x = m_standardColoursRect.x; m_customColoursRect.x = m_standardColoursRect.x;
m_customColoursRect.y = m_standardColoursRect.y + m_standardColoursRect.height + 20; m_customColoursRect.y = m_standardColoursRect.y + m_standardColoursRect.height + FromDIP(20);
m_customColoursRect.width = (8*m_smallRectangleSize.x) + (7*m_gridSpacing); m_customColoursRect.width = (8*m_smallRectangleSize.x) + (7*m_gridSpacing);
m_customColoursRect.height = (2*m_smallRectangleSize.y) + (1*m_gridSpacing); m_customColoursRect.height = (2*m_smallRectangleSize.y) + (1*m_gridSpacing);
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 = FromDIP(80);
m_singleCustomColourRect.SetSize(customRectangleSize); m_singleCustomColourRect.SetSize(customRectangleSize);
} }
@@ -309,7 +325,7 @@ void wxGenericColourDialog::CreateWidgets()
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
const int sliderHeight = 160; const int sliderHeight = FromDIP(160);
// first sliders // first sliders
#if wxUSE_SLIDER #if wxUSE_SLIDER