From e4a41cf201b46dceda6a6a6ff0114ee92816a5a9 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 3 Apr 2020 16:29:40 -0400 Subject: [PATCH] Align border blocks --- include/core/map.h | 4 ++-- src/core/map.cpp | 12 ++++++------ src/editor.cpp | 20 ++++++++++++-------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/include/core/map.h b/include/core/map.h index 2873844f..425ce639 100644 --- a/include/core/map.h +++ b/include/core/map.h @@ -17,9 +17,9 @@ #define DEFAULT_BORDER_WIDTH 2 #define DEFAULT_BORDER_HEIGHT 2 -// Number of metatiles to draw out from edge of map. Could allow modification of this in the future. +// Number of border blocks to draw out from edge of map. Could allow modification of this in the future. // porymap will reflect changes to it, but the value is hard-coded in the projects at the moment -#define BORDER_DISTANCE 6 +#define NUM_BORDER_BLOCKS 3 class Map : public QObject { diff --git a/src/core/map.cpp b/src/core/map.cpp index 667c151a..2320152a 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -263,23 +263,23 @@ QPixmap Map::renderConnection(MapConnection connection, MapLayout * fromLayout) int x, y, w, h; if (connection.direction == "up") { x = 0; - y = getHeight() - BORDER_DISTANCE; + y = getHeight() - (getBorderHeight() * NUM_BORDER_BLOCKS); w = getWidth(); - h = BORDER_DISTANCE; + h = getBorderHeight() * NUM_BORDER_BLOCKS; } else if (connection.direction == "down") { x = 0; y = 0; w = getWidth(); - h = BORDER_DISTANCE; + h = getBorderHeight() * NUM_BORDER_BLOCKS; } else if (connection.direction == "left") { - x = getWidth() - BORDER_DISTANCE; + x = getWidth() - (getBorderWidth() * NUM_BORDER_BLOCKS); y = 0; - w = BORDER_DISTANCE; + w = getBorderWidth() * NUM_BORDER_BLOCKS; h = getHeight(); } else if (connection.direction == "right") { x = 0; y = 0; - w = BORDER_DISTANCE; + w = getBorderWidth() * NUM_BORDER_BLOCKS; h = getHeight(); } else { // this should not happen diff --git a/src/editor.cpp b/src/editor.cpp index ff0b6d8b..d87ad832 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1118,6 +1118,8 @@ void Editor::displayMetatileSelector() { } void Editor::displayMapMetatiles() { + int borderHorzDist = map->getBorderWidth() * NUM_BORDER_BLOCKS * 16; + int borderVertDist = map->getBorderHeight() * NUM_BORDER_BLOCKS * 16; map_item = new MapPixmapItem(map, this->metatile_selector_item, this->settings); connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)), this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*))); @@ -1133,13 +1135,11 @@ void Editor::displayMapMetatiles() { map_item->draw(true); scene->addItem(map_item); - int tw = 16; - int th = 16; scene->setSceneRect( - -BORDER_DISTANCE * tw, - -BORDER_DISTANCE * th, - map_item->pixmap().width() + (BORDER_DISTANCE * 2) * tw, - map_item->pixmap().height() + (BORDER_DISTANCE * 2) * th + -borderHorzDist, + -borderVertDist, + map_item->pixmap().width() + borderHorzDist * 2, + map_item->pixmap().height() + borderVertDist * 2 ); } @@ -1334,9 +1334,13 @@ void Editor::displayMapBorder() { } borderItems.clear(); + int borderWidth = map->getBorderWidth(); + int borderHeight = map->getBorderHeight(); + int borderHorzDist = borderWidth * NUM_BORDER_BLOCKS; + int borderVertDist = borderHeight * NUM_BORDER_BLOCKS; QPixmap pixmap = map->renderBorder(); - for (int y = -BORDER_DISTANCE; y < map->getHeight() + BORDER_DISTANCE; y += map->getBorderHeight()) - for (int x = -BORDER_DISTANCE; x < map->getWidth() + BORDER_DISTANCE; x += map->getBorderWidth()) { + for (int y = -borderVertDist; y < map->getHeight() + borderVertDist; y += borderHeight) + for (int x = -borderHorzDist; x < map->getWidth() + borderHorzDist; x += borderWidth) { QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap); item->setX(x * 16); item->setY(y * 16);