From 01af56440a717f90022856611124a0d6c7b15290 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 27 Jul 2015 02:58:07 +0200 Subject: [PATCH] Use wxRound() instead of implicit float-to-int conversion in wxSTC. At the very least, this avoids tons of gcc warnings about implicit conversions from float to int and it could also be more correct if the coordinates can really be fractional. --- src/stc/PlatWX.cpp | 23 ++++++++++++----------- src/stc/ScintillaWX.cpp | 15 ++++++++------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index dbd2397134..3e44e8db78 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -14,6 +14,7 @@ #if wxUSE_STC #ifndef WX_PRECOMP + #include "wx/math.h" #include "wx/menu.h" #include "wx/dcmemory.h" #include "wx/settings.h" @@ -50,8 +51,8 @@ Point Point::FromLong(long lpoint) { } wxRect wxRectFromPRectangle(PRectangle prc) { - wxRect r(prc.left, prc.top, - prc.Width(), prc.Height()); + wxRect r(wxRound(prc.left), wxRound(prc.top), + wxRound(prc.Width()), wxRound(prc.Height())); return r; } @@ -140,7 +141,7 @@ void Font::Create(const FontParameters &fp) { else weight = wxFONTWEIGHT_NORMAL; - wxFont font(fp.size, + wxFont font(wxRound(fp.size), wxFONTFAMILY_DEFAULT, fp.italic ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL, weight, @@ -320,8 +321,8 @@ void SurfaceImpl::Polygon(Point *pts, int npts, ColourDesired fore, ColourDesire wxPoint *p = new wxPoint[npts]; for (int i=0; iDrawPolygon(npts, p); delete [] p; @@ -501,7 +502,7 @@ void SurfaceImpl::Copy(PRectangle rc, Point from, Surface &surfaceSource) { wxRect r = wxRectFromPRectangle(rc); hdc->Blit(r.x, r.y, r.width, r.height, ((SurfaceImpl&)surfaceSource).hdc, - from.x, from.y, wxCOPY); + wxRound(from.x), wxRound(from.y), wxCOPY); } void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font, XYPOSITION ybase, @@ -514,7 +515,7 @@ void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font, XYPOSITION ybase, // ybase is where the baseline should be, but wxWin uses the upper left // corner, so I need to calculate the real position for the text... - hdc->DrawText(stc2wx(s, len), rc.left, ybase - GetAscent(font)); + hdc->DrawText(stc2wx(s, len), wxRound(rc.left), wxRound(ybase - GetAscent(font))); } void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, XYPOSITION ybase, @@ -527,7 +528,7 @@ void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, XYPOSITION ybase, hdc->SetClippingRegion(wxRectFromPRectangle(rc)); // see comments above - hdc->DrawText(stc2wx(s, len), rc.left, ybase - GetAscent(font)); + hdc->DrawText(stc2wx(s, len), wxRound(rc.left), wxRound(ybase - GetAscent(font))); hdc->DestroyClippingRegion(); } @@ -542,7 +543,7 @@ void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font, XYPOSITION ybas // ybase is where the baseline should be, but wxWin uses the upper left // corner, so I need to calculate the real position for the text... - hdc->DrawText(stc2wx(s, len), rc.left, ybase - GetAscent(font)); + hdc->DrawText(stc2wx(s, len), wxRound(rc.left), wxRound(ybase - GetAscent(font))); hdc->SetBackgroundMode(wxBRUSHSTYLE_SOLID); } @@ -784,7 +785,7 @@ PRectangle Window::GetMonitorRect(Point pt) { if (! wid) return PRectangle(); #if wxUSE_DISPLAY // Get the display the point is found on - int n = wxDisplay::GetFromPoint(wxPoint(pt.x, pt.y)); + int n = wxDisplay::GetFromPoint(wxPoint(wxRound(pt.x), wxRound(pt.y))); wxDisplay dpy(n == wxNOT_FOUND ? 0 : n); rect = dpy.GetGeometry(); #else @@ -1428,7 +1429,7 @@ void Menu::Destroy() { } void Menu::Show(Point pt, Window &w) { - GETWIN(w.GetID())->PopupMenu((wxMenu*)mid, pt.x - 4, pt.y); + GETWIN(w.GetID())->PopupMenu((wxMenu*)mid, wxRound(pt.x - 4), wxRound(pt.y)); Destroy(); } diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index a6c7d01aef..b639c0320d 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -24,6 +24,7 @@ #ifndef WX_PRECOMP #include "wx/scrolbar.h" + #include "wx/math.h" #include "wx/menu.h" #include "wx/timer.h" #endif // WX_PRECOMP @@ -433,7 +434,7 @@ bool ScintillaWX::ModifyScrollBars(int nMax, int nPage) { horizEnd = 0; if (!horizontalScrollBarVisible || Wrapping()) horizEnd = 0; - int pageWidth = rcText.Width(); + int pageWidth = wxRound(rcText.Width()); if (stc->m_hScrollBar == NULL) { // Use built-in scrollbar int sbMax = stc->GetScrollRange(wxHORIZONTAL); @@ -664,7 +665,7 @@ void ScintillaWX::UpdateSystemCaret() { CreateSystemCaret(); } Point pos = PointMainCaret(); - ::SetCaretPos(pos.x, pos.y); + ::SetCaretPos(wxRound(pos.x), wxRound(pos.y)); } #endif } @@ -842,7 +843,7 @@ void ScintillaWX::FullPaintDC(wxDC* dc) { void ScintillaWX::DoHScroll(int type, int pos) { int xPos = xOffset; PRectangle rcText = GetTextRectangle(); - int pageWidth = rcText.Width() * 2 / 3; + int pageWidth = wxRound(rcText.Width() * 2 / 3); if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP) xPos -= H_SCROLL_STEP; else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN) @@ -852,7 +853,7 @@ void ScintillaWX::DoHScroll(int type, int pos) { else if (type == wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN) { xPos += pageWidth; if (xPos > scrollWidth - rcText.Width()) { - xPos = scrollWidth - rcText.Width(); + xPos = wxRound(scrollWidth - rcText.Width()); } } else if (type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP) @@ -894,14 +895,14 @@ void ScintillaWX::DoMouseWheel(wxMouseWheelAxis axis, int rotation, int delta, int pixels; if (axis == wxMOUSE_WHEEL_HORIZONTAL) { - wheelHRotation += rotation * (columnsPerAction * vs.spaceWidth); + wheelHRotation += wxRound(rotation * (columnsPerAction * vs.spaceWidth)); pixels = wheelHRotation / delta; wheelHRotation -= pixels * delta; if (pixels != 0) { xPos += pixels; PRectangle rcText = GetTextRectangle(); if (xPos > scrollWidth - rcText.Width()) { - xPos = scrollWidth - rcText.Width(); + xPos = wxRound(scrollWidth - rcText.Width()); } HorizontalScrollTo(xPos); } @@ -1190,7 +1191,7 @@ void ScintillaWX::DoScrollToLine(int line) { void ScintillaWX::DoScrollToColumn(int column) { - HorizontalScrollTo(column * vs.spaceWidth); + HorizontalScrollTo(wxRound(column * vs.spaceWidth)); } // wxGTK doesn't appear to need this explicit clipping code any longer, but I