From 62bb47cfdb54867c801314f2d93fa75ee105b68c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 27 Mar 2020 11:39:03 +0100 Subject: [PATCH 1/5] Use white background for drawing lines in the drawing sample This makes the display more readable, black on red was really not ideal. No real changes. --- samples/drawing/drawing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 8f5800a750..bea54ade03 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -639,7 +639,7 @@ void MyCanvas::DrawTestPoly(wxDC& dc) void MyCanvas::DrawTestLines( int x, int y, int width, wxDC &dc ) { dc.SetPen( wxPen( *wxBLACK, width ) ); - dc.SetBrush( *wxRED_BRUSH ); + dc.SetBrush( *wxWHITE_BRUSH ); dc.DrawText(wxString::Format("Testing lines of width %d", width), x + 10, y - 10); dc.DrawRectangle( x+10, y+10, 100, 190 ); From e7c8039d1355ae567d95f2a5db9891bfbe420183 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 27 Mar 2020 11:43:19 +0100 Subject: [PATCH 2/5] Simplify renderer selection in the drawing sample Make "Use default wxGraphicsContext" part of the renderer selection radio group and put it in correct order, as having "1, 0, 3, 4" accelerators order in the menu was really surprising. Remove wxEVT_UPDATE_UI handlers as they complicated things in the sample code (which is supposed to be simple, after all) without much benefit and arguably even added to the confusion during run-time as menu items could both be manually selected and checked automatically. --- samples/drawing/drawing.cpp | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index bea54ade03..2391d55b2b 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -203,31 +203,16 @@ public: m_canvas->UseGraphicRenderer(NULL); } - void OnGraphicContextNoneUpdateUI(wxUpdateUIEvent& event) - { - event.Check(m_canvas->GetRenderer() == NULL); - } - void OnGraphicContextDefault(wxCommandEvent& WXUNUSED(event)) { m_canvas->UseGraphicRenderer(wxGraphicsRenderer::GetDefaultRenderer()); } - void OnGraphicContextDefaultUpdateUI(wxUpdateUIEvent& event) - { - event.Check(m_canvas->IsDefaultRenderer()); - } - #if wxUSE_CAIRO void OnGraphicContextCairo(wxCommandEvent& WXUNUSED(event)) { m_canvas->UseGraphicRenderer(wxGraphicsRenderer::GetCairoRenderer()); } - - void OnGraphicContextCairoUpdateUI(wxUpdateUIEvent& event) - { - event.Check(m_canvas->GetRenderer() == wxGraphicsRenderer::GetCairoRenderer()); - } #endif // wxUSE_CAIRO #ifdef __WXMSW__ #if wxUSE_GRAPHICS_GDIPLUS @@ -235,22 +220,12 @@ public: { m_canvas->UseGraphicRenderer(wxGraphicsRenderer::GetGDIPlusRenderer()); } - - void OnGraphicContextGDIPlusUpdateUI(wxUpdateUIEvent& event) - { - event.Check(m_canvas->GetRenderer() == wxGraphicsRenderer::GetGDIPlusRenderer()); - } #endif #if wxUSE_GRAPHICS_DIRECT2D void OnGraphicContextDirect2D(wxCommandEvent& WXUNUSED(event)) { m_canvas->UseGraphicRenderer(wxGraphicsRenderer::GetDirect2DRenderer()); } - - void OnGraphicContextDirect2DUpdateUI(wxUpdateUIEvent& event) - { - event.Check(m_canvas->GetRenderer() == wxGraphicsRenderer::GetDirect2DRenderer()); - } #endif #endif // __WXMSW__ void OnAntiAliasing(wxCommandEvent& event) @@ -2230,21 +2205,16 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) #if wxUSE_GRAPHICS_CONTEXT EVT_MENU (File_GC_Default, MyFrame::OnGraphicContextDefault) - EVT_UPDATE_UI (File_GC_Default, MyFrame::OnGraphicContextDefaultUpdateUI) EVT_MENU (File_DC, MyFrame::OnGraphicContextNone) - EVT_UPDATE_UI (File_DC, MyFrame::OnGraphicContextNoneUpdateUI) #if wxUSE_CAIRO EVT_MENU (File_GC_Cairo, MyFrame::OnGraphicContextCairo) - EVT_UPDATE_UI (File_GC_Cairo, MyFrame::OnGraphicContextCairoUpdateUI) #endif // wxUSE_CAIRO #ifdef __WXMSW__ #if wxUSE_GRAPHICS_GDIPLUS EVT_MENU (File_GC_GDIPlus, MyFrame::OnGraphicContextGDIPlus) - EVT_UPDATE_UI (File_GC_GDIPlus, MyFrame::OnGraphicContextGDIPlusUpdateUI) #endif #if wxUSE_GRAPHICS_DIRECT2D EVT_MENU (File_GC_Direct2D, MyFrame::OnGraphicContextDirect2D) - EVT_UPDATE_UI (File_GC_Direct2D, MyFrame::OnGraphicContextDirect2DUpdateUI) #endif #endif // __WXMSW__ EVT_MENU (File_AntiAliasing, MyFrame::OnAntiAliasing) @@ -2292,8 +2262,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) wxMenu *menuFile = new wxMenu; #if wxUSE_GRAPHICS_CONTEXT - menuFile->AppendCheckItem(File_GC_Default, "Use default wx&GraphicContext\t1"); m_menuItemUseDC = menuFile->AppendRadioItem(File_DC, "Use wx&DC\t0"); + menuFile->AppendRadioItem(File_GC_Default, "Use default wx&GraphicContext\t1"); #if wxUSE_CAIRO menuFile->AppendRadioItem(File_GC_Cairo, "Use &Cairo\t2"); #endif // wxUSE_CAIRO From bb489418b092e15e4bf32770ead13016f6c4e242 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 27 Mar 2020 11:48:35 +0100 Subject: [PATCH 3/5] Number renderers using consecutive digits in the sample This has the disadvantage of not using the same accelerators in different wxWidgets builds, but the advantage of appearing logical to a casual user when running the sample, while having "0, 1, 3, 4" sequence was surprising. Alternatively, we could always add all menu items, but disable the ones that are not available in the current build. It could be surprising to see "GDI+" under non-MSW systems too though. --- samples/drawing/drawing.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 2391d55b2b..8a502ad97b 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -2262,17 +2262,39 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) wxMenu *menuFile = new wxMenu; #if wxUSE_GRAPHICS_CONTEXT - m_menuItemUseDC = menuFile->AppendRadioItem(File_DC, "Use wx&DC\t0"); - menuFile->AppendRadioItem(File_GC_Default, "Use default wx&GraphicContext\t1"); + // Number the different renderer choices consecutively, starting from 0. + int accel = 0; + m_menuItemUseDC = menuFile->AppendRadioItem + ( + File_DC, + wxString::Format("Use wx&DC\t%d", accel++) + ); + menuFile->AppendRadioItem + ( + File_GC_Default, + wxString::Format("Use default wx&GraphicContext\t%d", accel++) + ); #if wxUSE_CAIRO - menuFile->AppendRadioItem(File_GC_Cairo, "Use &Cairo\t2"); + menuFile->AppendRadioItem + ( + File_GC_Cairo, + wxString::Format("Use &Cairo\t%d", accel++) + ); #endif // wxUSE_CAIRO #ifdef __WXMSW__ #if wxUSE_GRAPHICS_GDIPLUS - menuFile->AppendRadioItem(File_GC_GDIPlus, "Use &GDI+\t3"); + menuFile->AppendRadioItem + ( + File_GC_GDIPlus, + wxString::Format("Use &GDI+\t%d", accel++) + ); #endif #if wxUSE_GRAPHICS_DIRECT2D - menuFile->AppendRadioItem(File_GC_Direct2D, "Use &Direct2D\t4"); + menuFile->AppendRadioItem + ( + File_GC_Direct2D, + wxString::Format("Use &Direct2D\t%d", accel++) + ); #endif #endif // __WXMSW__ #endif // wxUSE_GRAPHICS_CONTEXT From d245dc9e1f4e2d9416ff689b50d0650cafc5df50 Mon Sep 17 00:00:00 2001 From: Anton Triest Date: Fri, 27 Mar 2020 11:59:10 +0100 Subject: [PATCH 4/5] Fix drawing of dotted lines with wxDC in wxMSW Use ::ExtCreatePen() for creating pens for such lines, as it results in much better appearance for them than ::CreatePen(), which draws dashed, and not dotted, lines in this case. See #7097. --- src/msw/pen.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/msw/pen.cpp b/src/msw/pen.cpp index 0759f7b9c6..6ad3c57b33 100644 --- a/src/msw/pen.cpp +++ b/src/msw/pen.cpp @@ -284,9 +284,7 @@ bool wxPenRefData::Alloc() // CreatePen() if ( m_join == wxJOIN_ROUND && m_cap == wxCAP_ROUND && - m_style != wxPENSTYLE_USER_DASH && - m_style != wxPENSTYLE_STIPPLE && - (m_width <= 1 || m_style == wxPENSTYLE_SOLID) ) + m_style == wxPENSTYLE_SOLID ) { m_hPen = ::CreatePen(ConvertPenStyle(m_style), m_width, col); } From 53d51105bee5319a3f9c4453c851d6e154c463dc Mon Sep 17 00:00:00 2001 From: Anton Triest Date: Fri, 27 Mar 2020 12:02:36 +0100 Subject: [PATCH 5/5] Fix drawing of non-solid lines with width 0 using wxDC in wxMSW ::ExtCreatePen() doesn't allow the pen width to be 0, unlike ::CreatePen() and failed to create the brush in this case. Use width of 1 to draw e.g. hatched lines of width 0 correctly. See #7097. --- src/msw/pen.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/msw/pen.cpp b/src/msw/pen.cpp index 6ad3c57b33..44bcc3ebf6 100644 --- a/src/msw/pen.cpp +++ b/src/msw/pen.cpp @@ -356,7 +356,10 @@ bool wxPenRefData::Alloc() dash = NULL; } - m_hPen = ::ExtCreatePen(styleMSW, m_width, &lb, m_nbDash, (LPDWORD)dash); + // Note that width can't be 0 for ExtCreatePen(), unlike for CreatePen(). + int width = m_width == 0 ? 1 : m_width; + + m_hPen = ::ExtCreatePen(styleMSW, width, &lb, m_nbDash, (LPDWORD)dash); delete [] dash; }