From 5bdc263cda6286f3a0853e50ff99b3ae1cd58991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 3 Dec 2017 10:41:07 +0100 Subject: [PATCH] Moved all the map bounds checking where it belongs --- src/GUI/mapview.cpp | 9 ++++++--- src/map/offlinemap.cpp | 11 +++-------- src/map/onlinemap.cpp | 14 +++++--------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index 4d10a663..9a02c42c 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -738,11 +738,14 @@ void MapView::setBackgroundColor(const QColor &color) void MapView::drawBackground(QPainter *painter, const QRectF &rect) { if (_showMap) { - if (_opacity < 1.0) { + QRectF ir = rect.intersected(_map->bounds()); + + if (_opacity < 1.0 || ir != rect) painter->fillRect(rect, _backgroundColor); + if (_opacity < 1.0) painter->setOpacity(_opacity); - } - _map->draw(painter, rect); + + _map->draw(painter, ir); } else painter->fillRect(rect, _backgroundColor); } diff --git a/src/map/offlinemap.cpp b/src/map/offlinemap.cpp index 905c826c..321dba3a 100644 --- a/src/map/offlinemap.cpp +++ b/src/map/offlinemap.cpp @@ -610,17 +610,12 @@ void OfflineMap::drawImage(QPainter *painter, const QRectF &rect) void OfflineMap::draw(QPainter *painter, const QRectF &rect) { - QRectF ir = rect.intersected(bounds()); - - if (ir != rect) - painter->fillRect(rect, _backgroundColor); - if (_ozf.isOpen()) - drawOZF(painter, ir); + drawOZF(painter, rect); else if (_tileSize.isValid()) - drawTiled(painter, ir); + drawTiled(painter, rect); else - drawImage(painter, ir); + drawImage(painter, rect); } QPointF OfflineMap::ll2xy(const Coordinates &c) diff --git a/src/map/onlinemap.cpp b/src/map/onlinemap.cpp index ccfd0e7e..8f10df9f 100644 --- a/src/map/onlinemap.cpp +++ b/src/map/onlinemap.cpp @@ -228,18 +228,14 @@ qreal OnlineMap::zoomOut() void OnlineMap::draw(QPainter *painter, const QRectF &rect) { qreal scale = zoom2scale(_zoom); - QRectF ir = rect.intersected(bounds()); - if (ir != rect) - painter->fillRect(rect, _backgroundColor); - - QPoint tile = mercator2tile(QPointF(ir.topLeft().x() * scale, - -ir.topLeft().y() * scale), _zoom); - QPoint tl = QPoint((int)floor(ir.left() / (qreal)TILE_SIZE) - * TILE_SIZE, (int)floor(ir.top() / TILE_SIZE) * TILE_SIZE); + QPoint tile = mercator2tile(QPointF(rect.topLeft().x() * scale, + -rect.topLeft().y() * scale), _zoom); + QPoint tl = QPoint((int)floor(rect.left() / (qreal)TILE_SIZE) + * TILE_SIZE, (int)floor(rect.top() / TILE_SIZE) * TILE_SIZE); QList tiles; - QSizeF s(ir.right() - tl.x(), ir.bottom() - tl.y()); + QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y()); for (int i = 0; i < ceil(s.width() / TILE_SIZE); i++) for (int j = 0; j < ceil(s.height() / TILE_SIZE); j++) tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));