Merge branch 'render-vert-gauge'

Allow using DrawRender() for vertical gauges too #712.

See https://github.com/wxWidgets/wxWidgets/pull/712
This commit is contained in:
Vadim Zeitlin
2018-02-04 00:12:26 +01:00
6 changed files with 62 additions and 16 deletions

View File

@@ -180,6 +180,7 @@ All (GUI):
- Add "hint" property to wxSearchCtrl XRC handler. - Add "hint" property to wxSearchCtrl XRC handler.
- Add wxEVT_SEARCH[_CANCEL] synonyms for wxSearchCtrl events. - Add wxEVT_SEARCH[_CANCEL] synonyms for wxSearchCtrl events.
- Generate wxEVT_SEARCH on Enter under all platforms. - Generate wxEVT_SEARCH on Enter under all platforms.
- Extend wxRendererNative::DrawGauge() to work for vertical gauges too.
wxGTK: wxGTK:

View File

@@ -333,7 +333,9 @@ 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 // 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, virtual void DrawGauge(wxWindow* win,
wxDC& dc, wxDC& dc,
const wxRect& rect, const wxRect& rect,

View File

@@ -359,6 +359,8 @@ public:
bar that is drawn as being filled in, @a max must be strictly positive bar that is drawn as being filled in, @a max must be strictly positive
and @a value must be between 0 and @a max. 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 @since 3.1.0
*/ */
virtual void DrawGauge(wxWindow* win, virtual void DrawGauge(wxWindow* win,

View File

@@ -138,6 +138,7 @@ private:
void OnUseIcon(wxCommandEvent& event); void OnUseIcon(wxCommandEvent& event);
void OnUseBitmap(wxCommandEvent& event); void OnUseBitmap(wxCommandEvent& event);
void OnUseGeneric(wxCommandEvent& event);
#if wxUSE_DYNLIB_CLASS #if wxUSE_DYNLIB_CLASS
void OnLoad(wxCommandEvent& event); void OnLoad(wxCommandEvent& event);
void OnUnload(wxCommandEvent& event); void OnUnload(wxCommandEvent& event);
@@ -163,7 +164,8 @@ public:
m_flags = 0; m_flags = 0;
m_align = wxALIGN_LEFT; m_align = wxALIGN_LEFT;
m_useIcon = m_useIcon =
m_useBitmap = false; m_useBitmap =
m_useGeneric = false;
} }
int GetFlags() const { return m_flags; } int GetFlags() const { return m_flags; }
@@ -172,13 +174,15 @@ public:
void SetAlignment(int align) { m_align = align; } void SetAlignment(int align) { m_align = align; }
void SetUseIcon(bool useIcon) { m_useIcon = useIcon; } void SetUseIcon(bool useIcon) { m_useIcon = useIcon; }
void SetUseBitmap(bool useBitmap) { m_useBitmap = useBitmap; } void SetUseBitmap(bool useBitmap) { m_useBitmap = useBitmap; }
void SetUseGeneric(bool useGeneric) { m_useGeneric = useGeneric; }
private: private:
void OnPaint(wxPaintEvent&) void OnPaint(wxPaintEvent&)
{ {
wxPaintDC dc(this); wxPaintDC dc(this);
wxRendererNative& renderer = wxRendererNative::Get(); wxRendererNative& renderer = m_useGeneric ? wxRendererNative::GetGeneric()
: wxRendererNative::Get();
int x1 = 10, // text offset int x1 = 10, // text offset
x2 = 300, // drawing offset x2 = 300, // drawing offset
@@ -223,6 +227,8 @@ private:
wxART_LIST); wxART_LIST);
} }
// Note that we need to use GetDefault() explicitly to show the default
// implementation.
dc.DrawText("DrawHeaderButton() (default)", x1, y); dc.DrawText("DrawHeaderButton() (default)", x1, y);
wxRendererNative::GetDefault().DrawHeaderButton(this, dc, wxRendererNative::GetDefault().DrawHeaderButton(this, dc,
wxRect(x2, y, widthHdr, heightHdr), m_flags, wxRect(x2, y, widthHdr, heightHdr), m_flags,
@@ -278,12 +284,17 @@ private:
y += lineHeight + rBtn.height; y += lineHeight + rBtn.height;
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
// The meanings of those are reversed for the vertical gauge below.
const wxCoord heightGauge = 24; const wxCoord heightGauge = 24;
const wxCoord widthGauge = 180; const wxCoord widthGauge = 180;
dc.DrawText("DrawGauge()", x1, y); dc.DrawText("DrawGauge()", x1, y);
wxRendererNative::GetDefault().DrawGauge(this, dc, renderer.DrawGauge(this, dc,
wxRect(x2, y, widthGauge, heightGauge), 25, 100, m_flags); 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; y += lineHeight + heightGauge;
@@ -291,10 +302,10 @@ private:
const wxCoord widthListItem = 260; const wxCoord widthListItem = 260;
dc.DrawText("DrawItemSelectionRect()", x1, y); dc.DrawText("DrawItemSelectionRect()", x1, y);
wxRendererNative::GetDefault().DrawItemSelectionRect(this, dc, renderer.DrawItemSelectionRect(this, dc,
wxRect(x2, y, widthListItem, heightListItem), m_flags | wxCONTROL_SELECTED); 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); wxRect(x2, y, widthListItem, heightListItem).Inflate(-2, -2), m_align, m_flags | wxCONTROL_SELECTED);
y += lineHeight + heightListItem; y += lineHeight + heightListItem;
@@ -303,7 +314,8 @@ private:
int m_flags; int m_flags;
int m_align; int m_align;
bool m_useIcon, bool m_useIcon,
m_useBitmap; m_useBitmap,
m_useGeneric;
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
}; };
@@ -335,6 +347,7 @@ enum
Render_UseIcon, Render_UseIcon,
Render_UseBitmap, Render_UseBitmap,
Render_UseGeneric,
#if wxUSE_DYNLIB_CLASS #if wxUSE_DYNLIB_CLASS
Render_Load, Render_Load,
Render_Unload, Render_Unload,
@@ -371,6 +384,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Render_UseIcon, MyFrame::OnUseIcon) EVT_MENU(Render_UseIcon, MyFrame::OnUseIcon)
EVT_MENU(Render_UseBitmap, MyFrame::OnUseBitmap) EVT_MENU(Render_UseBitmap, MyFrame::OnUseBitmap)
EVT_MENU(Render_UseGeneric, MyFrame::OnUseGeneric)
#if wxUSE_DYNLIB_CLASS #if wxUSE_DYNLIB_CLASS
EVT_MENU(Render_Load, MyFrame::OnLoad) EVT_MENU(Render_Load, MyFrame::OnLoad)
EVT_MENU(Render_Unload,MyFrame::OnUnload) EVT_MENU(Render_Unload,MyFrame::OnUnload)
@@ -422,9 +436,7 @@ bool MyApp::OnInit()
MyFrame::MyFrame() MyFrame::MyFrame()
: wxFrame(NULL, : wxFrame(NULL,
wxID_ANY, wxID_ANY,
wxT("Render wxWidgets Sample"), wxT("Render wxWidgets Sample"))
wxPoint(50, 50),
wxSize(450, 340))
{ {
// set the frame icon // set the frame icon
SetIcon(wxICON(sample)); SetIcon(wxICON(sample));
@@ -457,6 +469,7 @@ MyFrame::MyFrame()
menuFile->AppendCheckItem(Render_UseBitmap, "Draw &bitmap\tCtrl-B"); menuFile->AppendCheckItem(Render_UseBitmap, "Draw &bitmap\tCtrl-B");
menuFile->AppendSeparator(); menuFile->AppendSeparator();
menuFile->AppendCheckItem(Render_UseGeneric, "Use &generic renderer\tCtrl-G");
#if wxUSE_DYNLIB_CLASS #if wxUSE_DYNLIB_CLASS
menuFile->Append(Render_Load, wxT("&Load renderer...\tCtrl-L")); menuFile->Append(Render_Load, wxT("&Load renderer...\tCtrl-L"));
menuFile->Append(Render_Unload, wxT("&Unload renderer\tCtrl-U")); menuFile->Append(Render_Unload, wxT("&Unload renderer\tCtrl-U"));
@@ -479,6 +492,8 @@ MyFrame::MyFrame()
m_panel = new MyPanel(this); m_panel = new MyPanel(this);
SetClientSize(600, 600);
#if wxUSE_STATUSBAR #if wxUSE_STATUSBAR
// create a status bar just for fun (by default with 1 pane only) // create a status bar just for fun (by default with 1 pane only)
CreateStatusBar(2); CreateStatusBar(2);
@@ -526,6 +541,12 @@ void MyFrame::OnUseBitmap(wxCommandEvent& event)
m_panel->Refresh(); m_panel->Refresh();
} }
void MyFrame::OnUseGeneric(wxCommandEvent& event)
{
m_panel->SetUseGeneric(event.IsChecked());
m_panel->Refresh();
}
#if wxUSE_DYNLIB_CLASS #if wxUSE_DYNLIB_CLASS
void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event))

View File

@@ -910,7 +910,7 @@ void wxRendererGeneric::DrawGauge(wxWindow* win,
const wxRect& rect, const wxRect& rect,
int value, int value,
int max, int max,
int WXUNUSED(flags)) int flags)
{ {
// Use same background as text controls. // Use same background as text controls.
DrawTextCtrl(win, dc, rect); DrawTextCtrl(win, dc, rect);
@@ -918,7 +918,16 @@ void wxRendererGeneric::DrawGauge(wxWindow* win,
// Calculate the progress bar size. // Calculate the progress bar size.
wxRect progRect(rect); wxRect progRect(rect);
progRect.Deflate(2); 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.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
dc.SetPen(*wxTRANSPARENT_PEN); dc.SetPen(*wxTRANSPARENT_PEN);

View File

@@ -1098,7 +1098,7 @@ void wxRendererXP::DrawGauge(wxWindow* win,
::DrawThemeBackground( ::DrawThemeBackground(
hTheme, hTheme,
GetHdcOf(dc.GetTempHDC()), GetHdcOf(dc.GetTempHDC()),
PP_BAR, flags & wxCONTROL_SPECIAL ? PP_BARVERT : PP_BAR,
0, 0,
&r, &r,
NULL); NULL);
@@ -1107,20 +1107,31 @@ void wxRendererXP::DrawGauge(wxWindow* win,
::GetThemeBackgroundContentRect( ::GetThemeBackgroundContentRect(
hTheme, hTheme,
GetHdcOf(dc.GetTempHDC()), GetHdcOf(dc.GetTempHDC()),
PP_BAR, flags & wxCONTROL_SPECIAL ? PP_BARVERT : PP_BAR,
0, 0,
&r, &r,
&contentRect); &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, wxMulDivInt32(contentRect.right - contentRect.left,
value, value,
max); max);
}
::DrawThemeBackground( ::DrawThemeBackground(
hTheme, hTheme,
GetHdcOf(dc.GetTempHDC()), GetHdcOf(dc.GetTempHDC()),
PP_CHUNK, flags & wxCONTROL_SPECIAL ? PP_CHUNKVERT : PP_CHUNK,
0, 0,
&contentRect, &contentRect,
NULL); NULL);