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
This commit is contained in:
Vadim Zeitlin
2014-09-20 22:07:45 +00:00
parent 8ad1e2698f
commit 4d561bf02c
2 changed files with 9 additions and 4 deletions

View File

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

View File

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