Make wxGenericColourDialog DPI aware
This commit is contained in:
@@ -49,6 +49,7 @@ public:
|
||||
// Internal functions
|
||||
void OnMouseEvent(wxMouseEvent& event);
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
void OnDPIChanged(wxDPIChangedEvent& event);
|
||||
#if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
|
||||
void OnCustomColourMouseClick(wxMouseEvent& event);
|
||||
#endif // wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
|
||||
|
@@ -60,6 +60,7 @@ wxBEGIN_EVENT_TABLE(wxGenericColourDialog, wxDialog)
|
||||
EVT_SLIDER(wxID_GREEN_SLIDER, wxGenericColourDialog::OnGreenSlider)
|
||||
EVT_SLIDER(wxID_BLUE_SLIDER, wxGenericColourDialog::OnBlueSlider)
|
||||
#endif
|
||||
EVT_DPI_CHANGED(wxGenericColourDialog::OnDPIChanged)
|
||||
EVT_PAINT(wxGenericColourDialog::OnPaint)
|
||||
EVT_MOUSE_EVENTS(wxGenericColourDialog::OnMouseEvent)
|
||||
EVT_CLOSE(wxGenericColourDialog::OnCloseWindow)
|
||||
@@ -155,8 +156,7 @@ void wxGenericColourDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
||||
bool wxGenericColourDialog::Create(wxWindow *parent, const wxColourData *data)
|
||||
{
|
||||
if ( !wxDialog::Create(GetParentForModalDialog(parent, 0), wxID_ANY,
|
||||
_("Choose colour"),
|
||||
wxPoint(0, 0), wxSize(900, 900)) )
|
||||
_("Choose colour")) )
|
||||
return false;
|
||||
|
||||
if (data)
|
||||
@@ -238,10 +238,13 @@ void wxGenericColourDialog::CreateCustomBitmaps()
|
||||
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);
|
||||
|
||||
if ( !m_customColourBmp )
|
||||
{
|
||||
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)
|
||||
for ( unsigned i = 0; i < WXSIZEOF(m_customColoursBmp); i++ )
|
||||
@@ -252,11 +255,15 @@ void wxGenericColourDialog::CreateCustomBitmaps()
|
||||
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);
|
||||
|
||||
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
|
||||
@@ -274,28 +281,37 @@ void wxGenericColourDialog::OnPaint(wxPaintEvent& WXUNUSED(event))
|
||||
PaintHighlight(dc, true);
|
||||
}
|
||||
|
||||
void wxGenericColourDialog::OnDPIChanged(wxDPIChangedEvent& WXUNUSED(event))
|
||||
{
|
||||
CalculateMeasurements();
|
||||
|
||||
#if wxCLRDLGG_USE_PREVIEW_WITH_ALPHA
|
||||
CreateCustomBitmaps();
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxGenericColourDialog::CalculateMeasurements()
|
||||
{
|
||||
// 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_sectionSpacing = 15;
|
||||
m_gridSpacing = FromDIP(6);
|
||||
m_sectionSpacing = FromDIP(15);
|
||||
|
||||
m_standardColoursRect.x = 10;
|
||||
m_standardColoursRect.y = 15;
|
||||
m_standardColoursRect.x = FromDIP(10);
|
||||
m_standardColoursRect.y = FromDIP(15);
|
||||
m_standardColoursRect.width = (8*m_smallRectangleSize.x) + (7*m_gridSpacing);
|
||||
m_standardColoursRect.height = (6*m_smallRectangleSize.y) + (5*m_gridSpacing);
|
||||
|
||||
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.height = (2*m_smallRectangleSize.y) + (1*m_gridSpacing);
|
||||
|
||||
m_singleCustomColourRect.x = m_customColoursRect.width + m_customColoursRect.x + m_sectionSpacing;
|
||||
m_singleCustomColourRect.y = 80;
|
||||
m_singleCustomColourRect.y = FromDIP(80);
|
||||
m_singleCustomColourRect.SetSize(customRectangleSize);
|
||||
}
|
||||
|
||||
@@ -309,7 +325,7 @@ void wxGenericColourDialog::CreateWidgets()
|
||||
|
||||
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
const int sliderHeight = 160;
|
||||
const int sliderHeight = FromDIP(160);
|
||||
|
||||
// first sliders
|
||||
#if wxUSE_SLIDER
|
||||
|
Reference in New Issue
Block a user