From 65589e8c68201e1e0bdb973f568acf4aaa1f6ffa Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 3 Feb 2018 17:59:50 +0100 Subject: [PATCH 1/4] Remove unneeded wxRendererNative::GetDefault() in render sample This method is used to illustrate the difference between the default and the overridden GetHeaderButton() implementations, but doesn't need to be used for any other methods, that are not overridden in MyRenderer. No real changes, but just make the code shorter and less confusing. --- samples/render/render.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/samples/render/render.cpp b/samples/render/render.cpp index d626b301de..e1f68fe077 100644 --- a/samples/render/render.cpp +++ b/samples/render/render.cpp @@ -223,6 +223,8 @@ private: wxART_LIST); } + // Note that we need to use GetDefault() explicitly to show the default + // implementation. dc.DrawText("DrawHeaderButton() (default)", x1, y); wxRendererNative::GetDefault().DrawHeaderButton(this, dc, wxRect(x2, y, widthHdr, heightHdr), m_flags, @@ -282,7 +284,7 @@ private: const wxCoord widthGauge = 180; dc.DrawText("DrawGauge()", x1, y); - wxRendererNative::GetDefault().DrawGauge(this, dc, + renderer.DrawGauge(this, dc, wxRect(x2, y, widthGauge, heightGauge), 25, 100, m_flags); y += lineHeight + heightGauge; @@ -291,10 +293,10 @@ private: const wxCoord widthListItem = 260; dc.DrawText("DrawItemSelectionRect()", x1, y); - wxRendererNative::GetDefault().DrawItemSelectionRect(this, dc, + renderer.DrawItemSelectionRect(this, dc, wxRect(x2, y, widthListItem, heightListItem), m_flags | wxCONTROL_SELECTED); - wxRendererNative::GetDefault().DrawItemText(this, dc, "DrawItemText()", + renderer.DrawItemText(this, dc, "DrawItemText()", wxRect(x2, y, widthListItem, heightListItem).Inflate(-2, -2), m_align, m_flags | wxCONTROL_SELECTED); y += lineHeight + heightListItem; From 359eda1359521725fdb428ea8cb3c3e01f2e7e17 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 3 Feb 2018 18:02:31 +0100 Subject: [PATCH 2/4] Make render sample window bigger initially It wasn't big enough to show all of its contents. --- samples/render/render.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/render/render.cpp b/samples/render/render.cpp index e1f68fe077..46a527e128 100644 --- a/samples/render/render.cpp +++ b/samples/render/render.cpp @@ -424,9 +424,7 @@ bool MyApp::OnInit() MyFrame::MyFrame() : wxFrame(NULL, wxID_ANY, - wxT("Render wxWidgets Sample"), - wxPoint(50, 50), - wxSize(450, 340)) + wxT("Render wxWidgets Sample")) { // set the frame icon SetIcon(wxICON(sample)); @@ -481,6 +479,8 @@ MyFrame::MyFrame() m_panel = new MyPanel(this); + SetClientSize(600, 600); + #if wxUSE_STATUSBAR // create a status bar just for fun (by default with 1 pane only) CreateStatusBar(2); From 3284420b09754006d2f6cb45d85e950b0896c71b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 3 Feb 2018 18:08:13 +0100 Subject: [PATCH 3/4] Add a menu option to use generic renderer in the sample This makes it easier to compare the native and generic implementations of the functions shown. --- samples/render/render.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/samples/render/render.cpp b/samples/render/render.cpp index 46a527e128..2d899c58b6 100644 --- a/samples/render/render.cpp +++ b/samples/render/render.cpp @@ -138,6 +138,7 @@ private: void OnUseIcon(wxCommandEvent& event); void OnUseBitmap(wxCommandEvent& event); + void OnUseGeneric(wxCommandEvent& event); #if wxUSE_DYNLIB_CLASS void OnLoad(wxCommandEvent& event); void OnUnload(wxCommandEvent& event); @@ -163,7 +164,8 @@ public: m_flags = 0; m_align = wxALIGN_LEFT; m_useIcon = - m_useBitmap = false; + m_useBitmap = + m_useGeneric = false; } int GetFlags() const { return m_flags; } @@ -172,13 +174,15 @@ public: void SetAlignment(int align) { m_align = align; } void SetUseIcon(bool useIcon) { m_useIcon = useIcon; } void SetUseBitmap(bool useBitmap) { m_useBitmap = useBitmap; } + void SetUseGeneric(bool useGeneric) { m_useGeneric = useGeneric; } private: void OnPaint(wxPaintEvent&) { wxPaintDC dc(this); - wxRendererNative& renderer = wxRendererNative::Get(); + wxRendererNative& renderer = m_useGeneric ? wxRendererNative::GetGeneric() + : wxRendererNative::Get(); int x1 = 10, // text offset x2 = 300, // drawing offset @@ -305,7 +309,8 @@ private: int m_flags; int m_align; bool m_useIcon, - m_useBitmap; + m_useBitmap, + m_useGeneric; wxDECLARE_EVENT_TABLE(); }; @@ -337,6 +342,7 @@ enum Render_UseIcon, Render_UseBitmap, + Render_UseGeneric, #if wxUSE_DYNLIB_CLASS Render_Load, Render_Unload, @@ -373,6 +379,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Render_UseIcon, MyFrame::OnUseIcon) EVT_MENU(Render_UseBitmap, MyFrame::OnUseBitmap) + EVT_MENU(Render_UseGeneric, MyFrame::OnUseGeneric) #if wxUSE_DYNLIB_CLASS EVT_MENU(Render_Load, MyFrame::OnLoad) EVT_MENU(Render_Unload,MyFrame::OnUnload) @@ -457,6 +464,7 @@ MyFrame::MyFrame() menuFile->AppendCheckItem(Render_UseBitmap, "Draw &bitmap\tCtrl-B"); menuFile->AppendSeparator(); + menuFile->AppendCheckItem(Render_UseGeneric, "Use &generic renderer\tCtrl-G"); #if wxUSE_DYNLIB_CLASS menuFile->Append(Render_Load, wxT("&Load renderer...\tCtrl-L")); menuFile->Append(Render_Unload, wxT("&Unload renderer\tCtrl-U")); @@ -528,6 +536,12 @@ void MyFrame::OnUseBitmap(wxCommandEvent& event) m_panel->Refresh(); } +void MyFrame::OnUseGeneric(wxCommandEvent& event) +{ + m_panel->SetUseGeneric(event.IsChecked()); + m_panel->Refresh(); +} + #if wxUSE_DYNLIB_CLASS void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event)) From 5f8f60107ad942657759f5769175f9a0973becad Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 3 Feb 2018 18:12:13 +0100 Subject: [PATCH 4/4] Allow using wxRendererNative::DrawGauge() for vertical gauges too It was unexpected that this method could only be used for horizontal gauges, so make it work for the vertical ones if wxCONTROL_SPECIAL flag is specified. Update MSW and generic implementations and the render sample to show a vertical gauge as well. --- docs/changes.txt | 1 + include/wx/renderer.h | 4 +++- interface/wx/renderer.h | 2 ++ samples/render/render.cpp | 5 +++++ src/generic/renderg.cpp | 13 +++++++++++-- src/msw/renderer.cpp | 19 +++++++++++++++---- 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 41b4baba6d..5f1698d1b7 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -180,6 +180,7 @@ All (GUI): - Add "hint" property to wxSearchCtrl XRC handler. - Add wxEVT_SEARCH[_CANCEL] synonyms for wxSearchCtrl events. - Generate wxEVT_SEARCH on Enter under all platforms. +- Extend wxRendererNative::DrawGauge() to work for vertical gauges too. wxGTK: diff --git a/include/wx/renderer.h b/include/wx/renderer.h index fd67b7a760..e816725bbf 100644 --- a/include/wx/renderer.h +++ b/include/wx/renderer.h @@ -333,7 +333,9 @@ public: int flags = 0) = 0; #endif // wxHAS_DRAW_TITLE_BAR_BITMAP - // Draw a gauge with native style like a wxGauge would display + // Draw a gauge with native style like a wxGauge would display. + // + // wxCONTROL_SPECIAL flag must be used for drawing vertical gauges. virtual void DrawGauge(wxWindow* win, wxDC& dc, const wxRect& rect, diff --git a/interface/wx/renderer.h b/interface/wx/renderer.h index 92be723034..2a3772b78a 100644 --- a/interface/wx/renderer.h +++ b/interface/wx/renderer.h @@ -359,6 +359,8 @@ public: bar that is drawn as being filled in, @a max must be strictly positive and @a value must be between 0 and @a max. + @c wxCONTROL_SPECIAL must be set in @a flags for the vertical gauges. + @since 3.1.0 */ virtual void DrawGauge(wxWindow* win, diff --git a/samples/render/render.cpp b/samples/render/render.cpp index 2d899c58b6..1e4b819dcf 100644 --- a/samples/render/render.cpp +++ b/samples/render/render.cpp @@ -284,12 +284,17 @@ private: y += lineHeight + rBtn.height; #endif // wxHAS_DRAW_TITLE_BAR_BITMAP + // The meanings of those are reversed for the vertical gauge below. const wxCoord heightGauge = 24; const wxCoord widthGauge = 180; dc.DrawText("DrawGauge()", x1, y); renderer.DrawGauge(this, dc, wxRect(x2, y, widthGauge, heightGauge), 25, 100, m_flags); + renderer.DrawGauge(this, dc, + wxRect(x2 + widthGauge + 30, y + heightGauge - widthGauge, + heightGauge, widthGauge), + 25, 100, m_flags | wxCONTROL_SPECIAL); y += lineHeight + heightGauge; diff --git a/src/generic/renderg.cpp b/src/generic/renderg.cpp index 1961141fc4..5cf2656cef 100644 --- a/src/generic/renderg.cpp +++ b/src/generic/renderg.cpp @@ -910,7 +910,7 @@ void wxRendererGeneric::DrawGauge(wxWindow* win, const wxRect& rect, int value, int max, - int WXUNUSED(flags)) + int flags) { // Use same background as text controls. DrawTextCtrl(win, dc, rect); @@ -918,7 +918,16 @@ void wxRendererGeneric::DrawGauge(wxWindow* win, // Calculate the progress bar size. wxRect progRect(rect); progRect.Deflate(2); - progRect.width = wxMulDivInt32(progRect.width, value, max); + if ( flags & wxCONTROL_SPECIAL ) + { + const int h = wxMulDivInt32(progRect.height, value, max); + progRect.y += progRect.height - h; + progRect.height = h; + } + else // Horizontal. + { + progRect.width = wxMulDivInt32(progRect.width, value, max); + } dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); dc.SetPen(*wxTRANSPARENT_PEN); diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index fff5432e6d..7935e05dcc 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -1098,7 +1098,7 @@ void wxRendererXP::DrawGauge(wxWindow* win, ::DrawThemeBackground( hTheme, GetHdcOf(dc.GetTempHDC()), - PP_BAR, + flags & wxCONTROL_SPECIAL ? PP_BARVERT : PP_BAR, 0, &r, NULL); @@ -1107,20 +1107,31 @@ void wxRendererXP::DrawGauge(wxWindow* win, ::GetThemeBackgroundContentRect( hTheme, GetHdcOf(dc.GetTempHDC()), - PP_BAR, + flags & wxCONTROL_SPECIAL ? PP_BARVERT : PP_BAR, 0, &r, &contentRect); - contentRect.right = contentRect.left + + if ( flags & wxCONTROL_SPECIAL ) + { + // For a vertical gauge, the value grows from the bottom to the top. + contentRect.top = contentRect.bottom - + wxMulDivInt32(contentRect.bottom - contentRect.top, + value, + max); + } + else // Horizontal. + { + contentRect.right = contentRect.left + wxMulDivInt32(contentRect.right - contentRect.left, value, max); + } ::DrawThemeBackground( hTheme, GetHdcOf(dc.GetTempHDC()), - PP_CHUNK, + flags & wxCONTROL_SPECIAL ? PP_CHUNKVERT : PP_CHUNK, 0, &contentRect, NULL);