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);