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.
This commit is contained in:
Vadim Zeitlin
2015-07-27 02:58:07 +02:00
parent 28587c97d8
commit 01af56440a
2 changed files with 20 additions and 18 deletions

View File

@@ -14,6 +14,7 @@
#if wxUSE_STC #if wxUSE_STC
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/math.h"
#include "wx/menu.h" #include "wx/menu.h"
#include "wx/dcmemory.h" #include "wx/dcmemory.h"
#include "wx/settings.h" #include "wx/settings.h"
@@ -50,8 +51,8 @@ Point Point::FromLong(long lpoint) {
} }
wxRect wxRectFromPRectangle(PRectangle prc) { wxRect wxRectFromPRectangle(PRectangle prc) {
wxRect r(prc.left, prc.top, wxRect r(wxRound(prc.left), wxRound(prc.top),
prc.Width(), prc.Height()); wxRound(prc.Width()), wxRound(prc.Height()));
return r; return r;
} }
@@ -140,7 +141,7 @@ void Font::Create(const FontParameters &fp) {
else else
weight = wxFONTWEIGHT_NORMAL; weight = wxFONTWEIGHT_NORMAL;
wxFont font(fp.size, wxFont font(wxRound(fp.size),
wxFONTFAMILY_DEFAULT, wxFONTFAMILY_DEFAULT,
fp.italic ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL, fp.italic ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL,
weight, weight,
@@ -320,8 +321,8 @@ void SurfaceImpl::Polygon(Point *pts, int npts, ColourDesired fore, ColourDesire
wxPoint *p = new wxPoint[npts]; wxPoint *p = new wxPoint[npts];
for (int i=0; i<npts; i++) { for (int i=0; i<npts; i++) {
p[i].x = pts[i].x; p[i].x = wxRound(pts[i].x);
p[i].y = pts[i].y; p[i].y = wxRound(pts[i].y);
} }
hdc->DrawPolygon(npts, p); hdc->DrawPolygon(npts, p);
delete [] p; delete [] p;
@@ -501,7 +502,7 @@ void SurfaceImpl::Copy(PRectangle rc, Point from, Surface &surfaceSource) {
wxRect r = wxRectFromPRectangle(rc); wxRect r = wxRectFromPRectangle(rc);
hdc->Blit(r.x, r.y, r.width, r.height, hdc->Blit(r.x, r.y, r.width, r.height,
((SurfaceImpl&)surfaceSource).hdc, ((SurfaceImpl&)surfaceSource).hdc,
from.x, from.y, wxCOPY); wxRound(from.x), wxRound(from.y), wxCOPY);
} }
void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font, XYPOSITION ybase, 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 // 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... // 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, 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)); hdc->SetClippingRegion(wxRectFromPRectangle(rc));
// see comments above // 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(); 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 // 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... // 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); hdc->SetBackgroundMode(wxBRUSHSTYLE_SOLID);
} }
@@ -784,7 +785,7 @@ PRectangle Window::GetMonitorRect(Point pt) {
if (! wid) return PRectangle(); if (! wid) return PRectangle();
#if wxUSE_DISPLAY #if wxUSE_DISPLAY
// Get the display the point is found on // 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); wxDisplay dpy(n == wxNOT_FOUND ? 0 : n);
rect = dpy.GetGeometry(); rect = dpy.GetGeometry();
#else #else
@@ -1428,7 +1429,7 @@ void Menu::Destroy() {
} }
void Menu::Show(Point pt, Window &w) { 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(); Destroy();
} }

View File

@@ -24,6 +24,7 @@
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/scrolbar.h" #include "wx/scrolbar.h"
#include "wx/math.h"
#include "wx/menu.h" #include "wx/menu.h"
#include "wx/timer.h" #include "wx/timer.h"
#endif // WX_PRECOMP #endif // WX_PRECOMP
@@ -433,7 +434,7 @@ bool ScintillaWX::ModifyScrollBars(int nMax, int nPage) {
horizEnd = 0; horizEnd = 0;
if (!horizontalScrollBarVisible || Wrapping()) if (!horizontalScrollBarVisible || Wrapping())
horizEnd = 0; horizEnd = 0;
int pageWidth = rcText.Width(); int pageWidth = wxRound(rcText.Width());
if (stc->m_hScrollBar == NULL) { // Use built-in scrollbar if (stc->m_hScrollBar == NULL) { // Use built-in scrollbar
int sbMax = stc->GetScrollRange(wxHORIZONTAL); int sbMax = stc->GetScrollRange(wxHORIZONTAL);
@@ -664,7 +665,7 @@ void ScintillaWX::UpdateSystemCaret() {
CreateSystemCaret(); CreateSystemCaret();
} }
Point pos = PointMainCaret(); Point pos = PointMainCaret();
::SetCaretPos(pos.x, pos.y); ::SetCaretPos(wxRound(pos.x), wxRound(pos.y));
} }
#endif #endif
} }
@@ -842,7 +843,7 @@ void ScintillaWX::FullPaintDC(wxDC* dc) {
void ScintillaWX::DoHScroll(int type, int pos) { void ScintillaWX::DoHScroll(int type, int pos) {
int xPos = xOffset; int xPos = xOffset;
PRectangle rcText = GetTextRectangle(); 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) if (type == wxEVT_SCROLLWIN_LINEUP || type == wxEVT_SCROLL_LINEUP)
xPos -= H_SCROLL_STEP; xPos -= H_SCROLL_STEP;
else if (type == wxEVT_SCROLLWIN_LINEDOWN || type == wxEVT_SCROLL_LINEDOWN) 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) { else if (type == wxEVT_SCROLLWIN_PAGEDOWN || type == wxEVT_SCROLL_PAGEDOWN) {
xPos += pageWidth; xPos += pageWidth;
if (xPos > scrollWidth - rcText.Width()) { if (xPos > scrollWidth - rcText.Width()) {
xPos = scrollWidth - rcText.Width(); xPos = wxRound(scrollWidth - rcText.Width());
} }
} }
else if (type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLL_TOP) 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; int pixels;
if (axis == wxMOUSE_WHEEL_HORIZONTAL) { if (axis == wxMOUSE_WHEEL_HORIZONTAL) {
wheelHRotation += rotation * (columnsPerAction * vs.spaceWidth); wheelHRotation += wxRound(rotation * (columnsPerAction * vs.spaceWidth));
pixels = wheelHRotation / delta; pixels = wheelHRotation / delta;
wheelHRotation -= pixels * delta; wheelHRotation -= pixels * delta;
if (pixels != 0) { if (pixels != 0) {
xPos += pixels; xPos += pixels;
PRectangle rcText = GetTextRectangle(); PRectangle rcText = GetTextRectangle();
if (xPos > scrollWidth - rcText.Width()) { if (xPos > scrollWidth - rcText.Width()) {
xPos = scrollWidth - rcText.Width(); xPos = wxRound(scrollWidth - rcText.Width());
} }
HorizontalScrollTo(xPos); HorizontalScrollTo(xPos);
} }
@@ -1190,7 +1191,7 @@ void ScintillaWX::DoScrollToLine(int line) {
void ScintillaWX::DoScrollToColumn(int column) { 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 // wxGTK doesn't appear to need this explicit clipping code any longer, but I