From 4d561bf02c00886b57fb946cc2ac99c436f694ad Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Sep 2014 22:07:45 +0000 Subject: [PATCH] Use wxMulDivInt32() instead of multiplying and dividing ints with doubles. This is mostly done to avoid warnings about converting the result of multiplying and dividing an int by doubles back to int, but is also more correct as wxMulDivInt32() rounds the result correctly instead of truncating the fractional part, and is also a tiny bit more efficient under MSW where the native ::MulDiv() is available. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77748 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/renderg.cpp | 5 +++-- src/msw/renderer.cpp | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/generic/renderg.cpp b/src/generic/renderg.cpp index a754440ea8..04f7b719c3 100644 --- a/src/generic/renderg.cpp +++ b/src/generic/renderg.cpp @@ -34,8 +34,9 @@ #include "wx/control.h" #endif //WX_PRECOMP -#include "wx/splitter.h" #include "wx/dcmirror.h" +#include "wx/math.h" +#include "wx/splitter.h" #ifdef __WXMAC__ #include "wx/osx/private.h" @@ -802,7 +803,7 @@ void wxRendererGeneric::DrawGauge(wxWindow* win, wxDC& dc, const wxRect& rect, i // Calculate the progress bar size. wxRect progRect(rect); progRect.Deflate(2); - progRect.SetWidth(progRect.GetWidth() * ((double)value / max)); + 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 18a2eef532..e0b46a35d5 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -31,6 +31,7 @@ #endif //WX_PRECOMP #include "wx/dcgraph.h" +#include "wx/math.h" #include "wx/scopeguard.h" #include "wx/splitter.h" #include "wx/renderer.h" @@ -627,7 +628,7 @@ void wxRendererMSW::DrawGauge(wxWindow* win, // Calc progress bar size wxRect progRect(rect); progRect.Deflate(2); - progRect.SetWidth(progRect.GetWidth() * ((double)value / max)); + progRect.width = wxMulDivInt32(progRect.width, value, max); dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); dc.SetPen(*wxTRANSPARENT_PEN); @@ -960,7 +961,10 @@ void wxRendererXP::DrawGauge(wxWindow* win, &r, &contentRect); - contentRect.right = contentRect.left + (contentRect.right - contentRect.left) * ((double)value / max); + contentRect.right = contentRect.left + + wxMulDivInt32(contentRect.right - contentRect.left, + value, + max); wxUxThemeEngine::Get()->DrawThemeBackground( hTheme,