Add wxRendererNative::DrawGauge() method.

Add the method with the native implementations for MSW and OS X and a generic
version fallback.

Closes #16406.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77023 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-08-08 01:03:31 +00:00
parent 7e6515e1ad
commit 86cf756ba9
8 changed files with 187 additions and 14 deletions

View File

@@ -50,6 +50,7 @@ All (GUI):
- Add support for embedding bitmaps in generated SVG in wxSVGFileDC (iwbnwif). - Add support for embedding bitmaps in generated SVG in wxSVGFileDC (iwbnwif).
- Add support for sorting wxDataViewCtrl by multiple columns (Trigve). - Add support for sorting wxDataViewCtrl by multiple columns (Trigve).
- Allow dropping data on wxDataViewCtrl background (Laurent Poujoulat). - Allow dropping data on wxDataViewCtrl background (Laurent Poujoulat).
- Add wxRendererNative::DrawGauge() (Tobias Taschner).
- Add wxHtmlWindow::SetDefaultHTMLCursor() (Jeff A. Marr). - Add wxHtmlWindow::SetDefaultHTMLCursor() (Jeff A. Marr).
- Add default ctor and Create() to wxContextHelpButton (Hanmac). - Add default ctor and Create() to wxContextHelpButton (Hanmac).
- Send events when toggling wxPropertyGrid nodes from keyboard (Armel Asselin). - Send events when toggling wxPropertyGrid nodes from keyboard (Armel Asselin).

View File

@@ -321,6 +321,13 @@ public:
int flags = 0) = 0; int flags = 0) = 0;
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
// Draw a gauge with native style like a wxGauge would display
virtual void DrawGauge(wxWindow* win,
wxDC& dc,
const wxRect& rect,
int value,
int max,
int flags = 0) = 0;
// geometry functions // geometry functions
// ------------------ // ------------------
@@ -500,6 +507,14 @@ public:
{ m_rendererNative.DrawTitleBarBitmap(win, dc, rect, button, flags); } { m_rendererNative.DrawTitleBarBitmap(win, dc, rect, button, flags); }
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
virtual void DrawGauge(wxWindow* win,
wxDC& dc,
const wxRect& rect,
int value,
int max,
int flags = 0)
{ m_rendererNative.DrawGauge(win, dc, rect, value, max, flags); }
virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win)
{ return m_rendererNative.GetSplitterParams(win); } { return m_rendererNative.GetSplitterParams(win); }

View File

@@ -349,6 +349,22 @@ public:
virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect,
int flags = 0) = 0; int flags = 0) = 0;
/**
Draw a progress bar in the specified rectangle.
The @a value and @a max arguments determine the part of the progress
bar that is drawn as being filled in, @a max must be strictly positive
and @a value must be between 0 and @a max.
@since 3.1.0
*/
virtual void DrawGauge(wxWindow* win,
wxDC& dc,
const wxRect& rect,
int value,
int max,
int flags = 0) = 0;
/** /**
Draw the header control button (used, for example, by wxListCtrl). Draw the header control button (used, for example, by wxListCtrl).

View File

@@ -267,6 +267,15 @@ private:
y += lineHeight + rBtn.height; y += lineHeight + rBtn.height;
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
const wxCoord heightGauge = 24;
const wxCoord widthGauge = 180;
dc.DrawText("DrawGauge()", x1, y);
wxRendererNative::GetDefault().DrawGauge(this, dc,
wxRect(x2, y, widthGauge, heightGauge), 25, 100, m_flags);
y += lineHeight + heightGauge;
} }
int m_flags; int m_flags;

View File

@@ -1211,20 +1211,12 @@ bool wxDataViewProgressRenderer::GetValue( wxVariant &value ) const
bool bool
wxDataViewProgressRenderer::Render(wxRect rect, wxDC *dc, int WXUNUSED(state)) wxDataViewProgressRenderer::Render(wxRect rect, wxDC *dc, int WXUNUSED(state))
{ {
// deflate the rect to leave a small border between bars in adjacent rows wxRendererNative::Get().DrawGauge(
wxRect bar = rect.Deflate(0, 1); GetOwner()->GetOwner(),
*dc,
dc->SetBrush( *wxTRANSPARENT_BRUSH ); rect,
dc->SetPen( *wxBLACK_PEN ); m_value,
dc->DrawRectangle( bar ); 100);
bar.width = (int)(bar.width * m_value / 100.);
dc->SetPen( *wxTRANSPARENT_PEN );
const wxDataViewItemAttr& attr = GetAttr();
dc->SetBrush( attr.HasColour() ? wxBrush(attr.GetColour())
: *wxBLUE_BRUSH );
dc->DrawRectangle( bar );
return true; return true;
} }

View File

@@ -130,6 +130,8 @@ public:
int flags = 0) wxOVERRIDE; int flags = 0) wxOVERRIDE;
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
virtual void DrawGauge(wxWindow* win, wxDC& dc, const wxRect& rect, int value, int max, int flags = 0) wxOVERRIDE;
virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) wxOVERRIDE; virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) wxOVERRIDE;
virtual wxRendererVersion GetVersion() const wxOVERRIDE virtual wxRendererVersion GetVersion() const wxOVERRIDE
@@ -792,6 +794,20 @@ void wxRendererGeneric::DrawTitleBarBitmap(wxWindow * WXUNUSED(win),
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
void wxRendererGeneric::DrawGauge(wxWindow* win, wxDC& dc, const wxRect& rect, int value, int max, int WXUNUSED(flags))
{
// Use same background as text controls.
DrawTextCtrl(win, dc, rect);
// Calculate the progress bar size.
wxRect progRect(rect);
progRect.Deflate(2);
progRect.SetWidth(progRect.GetWidth() * ((double)value / max));
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
dc.SetPen(*wxTRANSPARENT_PEN);
dc.DrawRectangle(progRect);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// A module to allow cleanup of generic renderer. // A module to allow cleanup of generic renderer.

View File

@@ -98,6 +98,10 @@
#define WP_CLOSEBUTTON 18 #define WP_CLOSEBUTTON 18
#define WP_RESTOREBUTTON 21 #define WP_RESTOREBUTTON 21
#define WP_HELPBUTTON 23 #define WP_HELPBUTTON 23
#define PP_BAR 1
#define PP_CHUNK 3
#endif #endif
#if defined(__WXWINCE__) #if defined(__WXWINCE__)
@@ -203,6 +207,13 @@ public:
wxTitleBarButton button, wxTitleBarButton button,
int flags = 0); int flags = 0);
virtual void DrawGauge(wxWindow* win,
wxDC& dc,
const wxRect& rect,
int value,
int max,
int flags = 0);
virtual wxSize GetCheckBoxSize(wxWindow *win); virtual wxSize GetCheckBoxSize(wxWindow *win);
virtual int GetHeaderButtonHeight(wxWindow *win); virtual int GetHeaderButtonHeight(wxWindow *win);
@@ -308,6 +319,14 @@ public:
wxTitleBarButton button, wxTitleBarButton button,
int flags = 0); int flags = 0);
virtual void DrawGauge(wxWindow* win,
wxDC& dc,
const wxRect& rect,
int value,
int max,
int flags = 0);
virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
private: private:
@@ -595,6 +614,25 @@ void wxRendererMSW::DrawTextCtrl(wxWindow* WXUNUSED(win),
dc.DrawRectangle(rect); dc.DrawRectangle(rect);
} }
void wxRendererMSW::DrawGauge(wxWindow* win,
wxDC& dc,
const wxRect& rect,
int value,
int max,
int WXUNUSED(flags))
{
// Use text ctrl back as background
DrawTextCtrl(win, dc, rect);
// Calc progress bar size
wxRect progRect(rect);
progRect.Deflate(2);
progRect.SetWidth(progRect.GetWidth() * ((double)value / max));
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
dc.SetPen(*wxTRANSPARENT_PEN);
dc.DrawRectangle(progRect);
}
// ============================================================================ // ============================================================================
// wxRendererXP implementation // wxRendererXP implementation
@@ -888,6 +926,51 @@ void wxRendererXP::DrawTextCtrl(wxWindow* win,
dc.DrawRectangle(rect); dc.DrawRectangle(rect);
} }
void wxRendererXP::DrawGauge(wxWindow* win,
wxDC& dc,
const wxRect& rect,
int value,
int max,
int flags)
{
wxUxThemeHandle hTheme(win, L"PROGRESS");
if ( !hTheme )
{
m_rendererNative.DrawGauge(win, dc, rect, value, max, flags);
return;
}
RECT r;
wxCopyRectToRECT(rect, r);
wxUxThemeEngine::Get()->DrawThemeBackground(
hTheme,
GetHdcOf(dc.GetTempHDC()),
PP_BAR,
0,
&r,
NULL);
RECT contentRect;
wxUxThemeEngine::Get()->GetThemeBackgroundContentRect(
hTheme,
GetHdcOf(dc.GetTempHDC()),
PP_BAR,
0,
&r,
&contentRect);
contentRect.right = contentRect.left + (contentRect.right - contentRect.left) * ((double)value / max);
wxUxThemeEngine::Get()->DrawThemeBackground(
hTheme,
GetHdcOf(dc.GetTempHDC()),
PP_CHUNK,
0,
&contentRect,
NULL);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// splitter drawing // splitter drawing
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -123,6 +123,13 @@ public:
int flags = 0) wxOVERRIDE; int flags = 0) wxOVERRIDE;
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
virtual void DrawGauge(wxWindow* win,
wxDC& dc,
const wxRect& rect,
int value,
int max,
int flags = 0);
virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) wxOVERRIDE; virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) wxOVERRIDE;
private: private:
@@ -863,4 +870,38 @@ void wxRendererMac::DrawTitleBarBitmap(wxWindow *win,
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
void wxRendererMac::DrawGauge(wxWindow* win,
wxDC& dc,
const wxRect& rect,
int value,
int max,
int flags)
{
const wxCoord x = rect.x;
const wxCoord y = rect.y;
const wxCoord w = rect.width;
const wxCoord h = rect.height;
HIThemeTrackDrawInfo tdi;
tdi.version = 0;
tdi.min = 0;
tdi.value = value;
tdi.max = max;
tdi.bounds = CGRectMake(x, y, w, h);
tdi.attributes = kThemeTrackHorizontal;
tdi.enableState = kThemeTrackActive;
tdi.kind = kThemeLargeProgressBar;
int milliSecondsPerStep = 1000 / 60;
wxLongLongNative localTime = wxGetLocalTimeMillis();
tdi.trackInfo.progress.phase = localTime.GetValue() / milliSecondsPerStep % 32;
CGContextRef cgContext;
wxGCDCImpl *impl = (wxGCDCImpl*) dc.GetImpl();
cgContext = (CGContextRef) impl->GetGraphicsContext()->GetNativeContext();
HIThemeDrawTrack(&tdi, NULL, cgContext, kHIThemeOrientationNormal);
}
#endif #endif