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.
This commit is contained in:
Vadim Zeitlin 2018-02-03 18:12:13 +01:00
parent 3284420b09
commit 5f8f60107a
6 changed files with 37 additions and 7 deletions

View File

@ -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:

View File

@ -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,

View File

@ -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,

View File

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

View File

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

View File

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