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:
@@ -50,6 +50,7 @@ All (GUI):
|
||||
- Add support for embedding bitmaps in generated SVG in wxSVGFileDC (iwbnwif).
|
||||
- Add support for sorting wxDataViewCtrl by multiple columns (Trigve).
|
||||
- Allow dropping data on wxDataViewCtrl background (Laurent Poujoulat).
|
||||
- Add wxRendererNative::DrawGauge() (Tobias Taschner).
|
||||
- Add wxHtmlWindow::SetDefaultHTMLCursor() (Jeff A. Marr).
|
||||
- Add default ctor and Create() to wxContextHelpButton (Hanmac).
|
||||
- Send events when toggling wxPropertyGrid nodes from keyboard (Armel Asselin).
|
||||
|
@@ -321,6 +321,13 @@ public:
|
||||
int flags = 0) = 0;
|
||||
#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
|
||||
// ------------------
|
||||
@@ -500,6 +507,14 @@ public:
|
||||
{ m_rendererNative.DrawTitleBarBitmap(win, dc, rect, button, flags); }
|
||||
#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)
|
||||
{ return m_rendererNative.GetSplitterParams(win); }
|
||||
|
||||
|
@@ -349,6 +349,22 @@ public:
|
||||
virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect,
|
||||
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).
|
||||
|
||||
|
@@ -267,6 +267,15 @@ private:
|
||||
|
||||
y += lineHeight + rBtn.height;
|
||||
#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;
|
||||
|
@@ -1211,20 +1211,12 @@ bool wxDataViewProgressRenderer::GetValue( wxVariant &value ) const
|
||||
bool
|
||||
wxDataViewProgressRenderer::Render(wxRect rect, wxDC *dc, int WXUNUSED(state))
|
||||
{
|
||||
// deflate the rect to leave a small border between bars in adjacent rows
|
||||
wxRect bar = rect.Deflate(0, 1);
|
||||
|
||||
dc->SetBrush( *wxTRANSPARENT_BRUSH );
|
||||
dc->SetPen( *wxBLACK_PEN );
|
||||
dc->DrawRectangle( bar );
|
||||
|
||||
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 );
|
||||
wxRendererNative::Get().DrawGauge(
|
||||
GetOwner()->GetOwner(),
|
||||
*dc,
|
||||
rect,
|
||||
m_value,
|
||||
100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -130,6 +130,8 @@ public:
|
||||
int flags = 0) wxOVERRIDE;
|
||||
#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 wxRendererVersion GetVersion() const wxOVERRIDE
|
||||
@@ -792,6 +794,20 @@ void wxRendererGeneric::DrawTitleBarBitmap(wxWindow * WXUNUSED(win),
|
||||
|
||||
#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.
|
||||
|
@@ -98,6 +98,10 @@
|
||||
#define WP_CLOSEBUTTON 18
|
||||
#define WP_RESTOREBUTTON 21
|
||||
#define WP_HELPBUTTON 23
|
||||
|
||||
#define PP_BAR 1
|
||||
#define PP_CHUNK 3
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__WXWINCE__)
|
||||
@@ -203,6 +207,13 @@ public:
|
||||
wxTitleBarButton button,
|
||||
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 int GetHeaderButtonHeight(wxWindow *win);
|
||||
@@ -308,6 +319,14 @@ public:
|
||||
wxTitleBarButton button,
|
||||
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);
|
||||
|
||||
private:
|
||||
@@ -595,6 +614,25 @@ void wxRendererMSW::DrawTextCtrl(wxWindow* WXUNUSED(win),
|
||||
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
|
||||
@@ -888,6 +926,51 @@ void wxRendererXP::DrawTextCtrl(wxWindow* win,
|
||||
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
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@@ -123,6 +123,13 @@ public:
|
||||
int flags = 0) wxOVERRIDE;
|
||||
#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;
|
||||
|
||||
private:
|
||||
@@ -863,4 +870,38 @@ void wxRendererMac::DrawTitleBarBitmap(wxWindow *win,
|
||||
|
||||
#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
|
||||
|
Reference in New Issue
Block a user