From cdc004a9413861d7cb4f95009f5d718a26b368e4 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 7 Aug 2019 20:20:06 +0200 Subject: [PATCH 1/5] Use generic DrawCheckMark in MSW wxDC Use the generic implementation, so it looks like the check marks on all other platforms and graphics contexts and not like a Windows control. --- include/wx/msw/dc.h | 2 -- src/msw/dc.cpp | 18 ------------------ 2 files changed, 20 deletions(-) diff --git a/include/wx/msw/dc.h b/include/wx/msw/dc.h index e541499f9a..a27b70dab3 100644 --- a/include/wx/msw/dc.h +++ b/include/wx/msw/dc.h @@ -202,8 +202,6 @@ public: virtual void DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc) wxOVERRIDE; - virtual void DoDrawCheckMark(wxCoord x, wxCoord y, - wxCoord width, wxCoord height) wxOVERRIDE; virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea) wxOVERRIDE; diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index ddeb2d6ba9..1c97f14415 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -861,24 +861,6 @@ void wxMSWDCImpl::DoDrawArc(wxCoord x1, wxCoord y1, CalcBoundingBox(xc + r, yc + r); } -void wxMSWDCImpl::DoDrawCheckMark(wxCoord x1, wxCoord y1, - wxCoord width, wxCoord height) -{ - wxCoord x2 = x1 + width, - y2 = y1 + height; - - RECT rect; - rect.left = x1; - rect.top = y1; - rect.right = x2; - rect.bottom = y2; - - DrawFrameControl(GetHdc(), &rect, DFC_MENU, DFCS_MENUCHECK); - - CalcBoundingBox(x1, y1); - CalcBoundingBox(x2, y2); -} - void wxMSWDCImpl::DoDrawPoint(wxCoord x, wxCoord y) { COLORREF color = 0x00ffffff; From 698a20e625076c783d0b8cf0e91f1b7ddc930872 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 7 Aug 2019 20:31:33 +0200 Subject: [PATCH 2/5] Use numbers for accelerator keys to select renderer in drawing sample Determine if renderer is selected by comparing the renderer itself, not by name. --- samples/drawing/drawing.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 44bc383d18..f3dd750672 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -123,10 +123,6 @@ public: { if ( !m_renderer ) return false; return m_renderer == wxGraphicsRenderer::GetDefaultRenderer(); } - bool IsRendererName(const wxString& name) const - { if ( !m_renderer ) return name.empty(); - return m_renderer->GetName() == name; - } wxGraphicsRenderer* GetRenderer() const { return m_renderer; } #endif // wxUSE_GRAPHICS_CONTEXT void UseBuffer(bool use) { m_useBuffer = use; Refresh(); } @@ -206,7 +202,7 @@ public: void OnGraphicContextNoneUpdateUI(wxUpdateUIEvent& event) { - event.Check(m_canvas->IsRendererName(wxEmptyString)); + event.Check(m_canvas->GetRenderer() == NULL); } void OnGraphicContextDefault(wxCommandEvent& WXUNUSED(event)) @@ -227,7 +223,7 @@ public: void OnGraphicContextCairoUpdateUI(wxUpdateUIEvent& event) { - event.Check(m_canvas->IsRendererName("cairo")); + event.Check(m_canvas->GetRenderer() == wxGraphicsRenderer::GetCairoRenderer()); } #endif // wxUSE_CAIRO #ifdef __WXMSW__ @@ -239,7 +235,7 @@ public: void OnGraphicContextGDIPlusUpdateUI(wxUpdateUIEvent& event) { - event.Check(m_canvas->IsRendererName("gdiplus")); + event.Check(m_canvas->GetRenderer() == wxGraphicsRenderer::GetGDIPlusRenderer()); } #endif #if wxUSE_GRAPHICS_DIRECT2D @@ -250,7 +246,7 @@ public: void OnGraphicContextDirect2DUpdateUI(wxUpdateUIEvent& event) { - event.Check(m_canvas->IsRendererName("direct2d")); + event.Check(m_canvas->GetRenderer() == wxGraphicsRenderer::GetDirect2DRenderer()); } #endif #endif // __WXMSW__ @@ -2142,17 +2138,17 @@ 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\tCtrl-Y"); - m_menuItemUseDC = menuFile->AppendRadioItem(File_DC, "Use wx&DC\tShift-Ctrl-Y"); + menuFile->AppendCheckItem(File_GC_Default, "Use default wx&GraphicContext\t1"); + m_menuItemUseDC = menuFile->AppendRadioItem(File_DC, "Use wx&DC\t0"); #if wxUSE_CAIRO - menuFile->AppendRadioItem(File_GC_Cairo, "Use &Cairo\tCtrl-O"); + menuFile->AppendRadioItem(File_GC_Cairo, "Use &Cairo\t2"); #endif // wxUSE_CAIRO #ifdef __WXMSW__ #if wxUSE_GRAPHICS_GDIPLUS - menuFile->AppendRadioItem(File_GC_GDIPlus, "Use &GDI+\tCtrl-+"); + menuFile->AppendRadioItem(File_GC_GDIPlus, "Use &GDI+\t3"); #endif #if wxUSE_GRAPHICS_DIRECT2D - menuFile->AppendRadioItem(File_GC_Direct2D, "Use &Direct2D\tCtrl-2"); + menuFile->AppendRadioItem(File_GC_Direct2D, "Use &Direct2D\t4"); #endif #endif // __WXMSW__ #endif // wxUSE_GRAPHICS_CONTEXT From 97320c312e73b33f69ff13e954a596466f4da77f Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 7 Aug 2019 20:33:45 +0200 Subject: [PATCH 3/5] Add option to drawing sample to toggle anti-aliasing of graphics renderer --- samples/drawing/drawing.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index f3dd750672..d9cb0dfa8d 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -124,6 +124,7 @@ public: return m_renderer == wxGraphicsRenderer::GetDefaultRenderer(); } wxGraphicsRenderer* GetRenderer() const { return m_renderer; } + void EnableAntiAliasing(bool use) { m_useAntiAliasing = use; Refresh(); } #endif // wxUSE_GRAPHICS_CONTEXT void UseBuffer(bool use) { m_useBuffer = use; Refresh(); } void ShowBoundingBox(bool show) { m_showBBox = show; Refresh(); } @@ -172,6 +173,7 @@ private: wxPoint m_currentpoint; #if wxUSE_GRAPHICS_CONTEXT wxGraphicsRenderer* m_renderer; + bool m_useAntiAliasing; #endif bool m_useBuffer; bool m_showBBox; @@ -250,6 +252,15 @@ public: } #endif #endif // __WXMSW__ + void OnAntiAliasing(wxCommandEvent& event) + { + m_canvas->EnableAntiAliasing(event.IsChecked()); + } + + void OnAntiAliasingUpdateUI(wxUpdateUIEvent& event) + { + event.Enable(m_canvas->GetRenderer() != NULL); + } #endif // wxUSE_GRAPHICS_CONTEXT void OnBuffer(wxCommandEvent& event); @@ -335,6 +346,9 @@ enum File_BBox, File_Clip, File_Buffer, +#if wxUSE_GRAPHICS_CONTEXT + File_AntiAliasing, +#endif File_Copy, File_Save, @@ -519,6 +533,7 @@ MyCanvas::MyCanvas(MyFrame *parent) m_rubberBand = false; #if wxUSE_GRAPHICS_CONTEXT m_renderer = NULL; + m_useAntiAliasing = true; #endif m_useBuffer = false; m_showBBox = false; @@ -1822,6 +1837,8 @@ void MyCanvas::Draw(wxDC& pdc) return; } + context->SetAntialiasMode(m_useAntiAliasing ? wxANTIALIAS_DEFAULT : wxANTIALIAS_NONE); + gdc.SetBackground(GetBackgroundColour()); gdc.SetGraphicsContext(context); } @@ -2094,6 +2111,8 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_UPDATE_UI (File_GC_Direct2D, MyFrame::OnGraphicContextDirect2DUpdateUI) #endif #endif // __WXMSW__ + EVT_MENU (File_AntiAliasing, MyFrame::OnAntiAliasing) + EVT_UPDATE_UI (File_AntiAliasing, MyFrame::OnAntiAliasingUpdateUI) #endif // wxUSE_GRAPHICS_CONTEXT EVT_MENU (File_Buffer, MyFrame::OnBuffer) @@ -2157,6 +2176,12 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) "Show extents used in drawing operations"); menuFile->AppendCheckItem(File_Clip, "&Clip\tCtrl-C", "Clip/unclip drawing"); menuFile->AppendCheckItem(File_Buffer, "&Use wx&BufferedPaintDC\tCtrl-Z", "Buffer painting"); +#if wxUSE_GRAPHICS_CONTEXT + menuFile->AppendCheckItem(File_AntiAliasing, + "&Anti-Aliasing in wxGraphicContext\tCtrl-Shift-A", + "Enable Anti-Aliasing in wxGraphicContext") + ->Check(); +#endif menuFile->AppendSeparator(); #if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH) menuFile->Append(File_Copy, "Copy to clipboard"); From 2874dab7f004259d1d2aa9b79e68fc92543619f8 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Thu, 8 Aug 2019 00:52:06 +0200 Subject: [PATCH 4/5] Add DrawCheckMark and GetCheckMarkSize to wxRendererNative Show its use in the render sample. Also use the recently added GetExpanderSize for the size of DrawTreeItemButton. --- include/wx/renderer.h | 22 +++++++++++- interface/wx/renderer.h | 26 ++++++++++++++ samples/render/render.cpp | 11 ++++-- src/generic/renderg.cpp | 22 ++++++++++++ src/msw/renderer.cpp | 74 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 152 insertions(+), 3 deletions(-) diff --git a/include/wx/renderer.h b/include/wx/renderer.h index 8d984477e7..4a4b92375a 100644 --- a/include/wx/renderer.h +++ b/include/wx/renderer.h @@ -250,9 +250,20 @@ public: const wxRect& rect, int flags = 0) = 0; + // draw check mark + // + // flags may use wxCONTROL_DISABLED + virtual void DrawCheckMark(wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags = 0) = 0; + // Returns the default size of a check box. virtual wxSize GetCheckBoxSize(wxWindow *win) = 0; + // Returns the default size of a check mark. + virtual wxSize GetCheckMarkSize(wxWindow *win) = 0; + // Returns the default size of a expander. virtual wxSize GetExpanderSize(wxWindow *win) = 0; @@ -479,10 +490,19 @@ public: int flags = 0) wxOVERRIDE { m_rendererNative.DrawCheckBox( win, dc, rect, flags ); } + virtual void DrawCheckMark(wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags = 0) wxOVERRIDE + { m_rendererNative.DrawCheckMark( win, dc, rect, flags ); } + virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE { return m_rendererNative.GetCheckBoxSize(win); } - virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE + virtual wxSize GetCheckMarkSize(wxWindow *win) wxOVERRIDE + { return m_rendererNative.GetCheckMarkSize(win); } + + virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE { return m_rendererNative.GetExpanderSize(win); } virtual void DrawPushButton(wxWindow *win, diff --git a/interface/wx/renderer.h b/interface/wx/renderer.h index e2c5036d47..0cb0685fc7 100644 --- a/interface/wx/renderer.h +++ b/interface/wx/renderer.h @@ -234,8 +234,13 @@ public: virtual void DrawCheckBox(wxWindow *win, wxDC& dc, const wxRect& rect, int flags = 0 ); + virtual void DrawCheckMark(wxWindow *win, wxDC& dc, + const wxRect& rect, int flags = 0 ); + virtual wxSize GetCheckBoxSize(wxWindow *win); + virtual wxSize GetCheckMarkSize(wxWindow *win); + virtual wxSize GetExpanderSize(wxWindow* win); virtual void DrawPushButton(wxWindow *win, wxDC& dc, @@ -532,6 +537,17 @@ public: wxTitleBarButton button, int flags = 0) = 0; + /** + Draw a check mark. + + @a flags may have the @c wxCONTROL_DISABLED bit set, see + @ref wxCONTROL_FLAGS. + + @since 3.1.3 + */ + virtual void DrawCheckMark(wxWindow* win, wxDC& dc, const wxRect& rect, + int flags = 0) = 0; + /** Return the currently used renderer. */ @@ -560,6 +576,16 @@ public: */ virtual wxSize GetCheckBoxSize(wxWindow* win) = 0; + /** + Returns the size of a check mark. + + @param win A valid, i.e. non-null, window pointer which is used to get + the theme defining the checkmark size under some platforms. + + @since 3.1.3 + */ + virtual wxSize GetCheckMarkSize(wxWindow* win) = 0; + /** Returns the size of the expander used in tree-like controls. diff --git a/samples/render/render.cpp b/samples/render/render.cpp index 158e16d5ba..835490840f 100644 --- a/samples/render/render.cpp +++ b/samples/render/render.cpp @@ -247,6 +247,12 @@ private: wxRect(wxPoint(x2, y), sizeCheck), m_flags); y += lineHeight + sizeCheck.y; + dc.DrawText("DrawCheckMark()", x1, y); + const wxSize sizeMark = renderer.GetCheckMarkSize(this); + renderer.DrawCheckMark(this, dc, + wxRect(wxPoint(x2, y), sizeMark), m_flags); + y += lineHeight + sizeMark.y; + dc.DrawText("DrawRadioBitmap()", x1, y); renderer.DrawRadioBitmap(this, dc, wxRect(wxPoint(x2, y), sizeCheck), m_flags); @@ -259,9 +265,10 @@ private: y += lineHeight + sizeCollapse.y; dc.DrawText("DrawTreeItemButton()", x1, y); + const wxSize sizeExpand = renderer.GetExpanderSize(this); renderer.DrawTreeItemButton(this, dc, - wxRect(x2, y, 20, 20), m_flags); - y += lineHeight + 20; + wxRect(wxPoint(x2, y), sizeExpand), m_flags); + y += lineHeight + sizeExpand.y; #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP dc.DrawText("DrawTitleBarBitmap()", x1, y); diff --git a/src/generic/renderg.cpp b/src/generic/renderg.cpp index 19f540322c..4a328ffaa8 100644 --- a/src/generic/renderg.cpp +++ b/src/generic/renderg.cpp @@ -106,8 +106,15 @@ public: const wxRect& rect, int flags = 0) wxOVERRIDE; + virtual void DrawCheckMark(wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags = 0) wxOVERRIDE; + virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE; + virtual wxSize GetCheckMarkSize(wxWindow *win) wxOVERRIDE; + virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE; virtual void DrawPushButton(wxWindow *win, @@ -714,6 +721,16 @@ wxRendererGeneric::DrawCheckBox(wxWindow *WXUNUSED(win), } } +void +wxRendererGeneric::DrawCheckMark(wxWindow *WXUNUSED(win), + wxDC& dc, + const wxRect& rect, + int flags) +{ + dc.SetPen(*(flags & wxCONTROL_DISABLED ? wxGREY_PEN : wxBLACK_PEN)); + dc.DrawCheckMark(rect); +} + wxSize wxRendererGeneric::GetCheckBoxSize(wxWindow *win) { wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" ); @@ -721,6 +738,11 @@ wxSize wxRendererGeneric::GetCheckBoxSize(wxWindow *win) return win->FromDIP(wxSize(16, 16)); } +wxSize wxRendererGeneric::GetCheckMarkSize(wxWindow *win) +{ + return GetCheckBoxSize(win); +} + wxSize wxRendererGeneric::GetExpanderSize(wxWindow *win) { wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" ); diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index 0ccbbdb33a..2b1a5470af 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -135,6 +135,14 @@ public: DoDrawButton(DFCS_BUTTONCHECK, win, dc, rect, flags); } + virtual void DrawCheckMark(wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags = 0) wxOVERRIDE + { + DoDrawFrameControl(DFC_MENU, DFCS_MENUCHECK, win, dc, rect, flags); + } + virtual void DrawPushButton(wxWindow *win, wxDC& dc, const wxRect& rect, @@ -230,6 +238,15 @@ public: m_rendererNative.DrawCheckBox(win, dc, rect, flags); } + virtual void DrawCheckMark(wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags = 0) wxOVERRIDE + { + if ( !DoDrawCheckMark(MENU_POPUPCHECK, win, dc, rect, flags) ) + m_rendererNative.DrawCheckMark(win, dc, rect, flags); + } + virtual void DrawPushButton(wxWindow *win, wxDC& dc, const wxRect& rect, @@ -273,6 +290,8 @@ public: virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE; + virtual wxSize GetCheckMarkSize(wxWindow* win) wxOVERRIDE; + virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE; virtual void DrawGauge(wxWindow* win, @@ -309,6 +328,12 @@ private: const wxRect& rect, int flags); + bool DoDrawCheckMark(int kind, + wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags); + wxDECLARE_NO_COPY_CLASS(wxRendererXP); }; @@ -736,6 +761,38 @@ wxRendererXP::DoDrawXPButton(int kind, return true; } +bool +wxRendererXP::DoDrawCheckMark(int kind, + wxWindow *win, + wxDC& dc, + const wxRect& rect, + int flags) +{ + wxUxThemeHandle hTheme(win, L"MENU"); + if ( !hTheme ) + return false; + + wxCHECK_MSG( dc.GetImpl(), false, wxT("Invalid wxDC") ); + + RECT r = ConvertToRECT(dc, rect); + + int state = MC_CHECKMARKNORMAL; + if ( flags & wxCONTROL_DISABLED ) + state = MC_CHECKMARKDISABLED; + + ::DrawThemeBackground + ( + hTheme, + GetHdcOf(dc.GetTempHDC()), + kind, + state, + &r, + NULL + ); + + return true; +} + void wxRendererXP::DoDrawButtonLike(HTHEME htheme, int part, @@ -852,6 +909,23 @@ wxSize wxRendererXP::GetCheckBoxSize(wxWindow* win) return m_rendererNative.GetCheckBoxSize(win); } +wxSize wxRendererXP::GetCheckMarkSize(wxWindow* win) +{ + wxCHECK_MSG(win, wxSize(0, 0), "Must have a valid window"); + + wxUxThemeHandle hTheme(win, L"MENU"); + if (hTheme) + { + if (::IsThemePartDefined(hTheme, MENU_POPUPCHECK, 0)) + { + SIZE checkSize; + if (::GetThemePartSize(hTheme, NULL, MENU_POPUPCHECK, MC_CHECKMARKNORMAL, NULL, TS_DRAW, &checkSize) == S_OK) + return wxSize(checkSize.cx, checkSize.cy); + } + } + return m_rendererNative.GetCheckMarkSize(win); +} + wxSize wxRendererXP::GetExpanderSize(wxWindow* win) { wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" ); From 4dc5eb9a543b140e0fd2414fcf5909cd7e1d5f54 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 11 Aug 2019 22:17:38 +0200 Subject: [PATCH 5/5] Use default wxPen for DrawPoint in wxGCDC Match the default wxDC implementations by using a default wxPen with width 1, wxPENSTYLE_SOLID and default join and cap values. --- src/common/dcgraph.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index e0baafa06d..e9baee8b7c 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -752,6 +752,9 @@ void wxGCDCImpl::DoDrawPoint( wxCoord x, wxCoord y ) if (!m_logicalFunctionSupported) return; + wxPen pointPen(m_pen.GetColour()); + wxDCPenChanger penChanger(*GetOwner(), pointPen); + #if defined(__WXMSW__) && wxUSE_GRAPHICS_GDIPLUS // single point path does not work with GDI+ if (m_graphicContext->GetRenderer() == wxGraphicsRenderer::GetGDIPlusRenderer())