mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-30 03:46:35 -05:00
Use checkered bg for image export previews
This commit is contained in:
39
include/ui/checkeredbgscene.h
Normal file
39
include/ui/checkeredbgscene.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef CHECKEREDBGSCENE_H
|
||||
#define CHECKEREDBGSCENE_H
|
||||
|
||||
#include <QGraphicsScene>
|
||||
|
||||
// Custom scene that paints its background a gray checkered pattern.
|
||||
// Additionally there is a definable "valid" area which will paint the checkerboard green inside.
|
||||
class CheckeredBgScene : public QGraphicsScene {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CheckeredBgScene(const QSize &gridSize, QObject *parent = nullptr)
|
||||
: QGraphicsScene(parent),
|
||||
gridSize(gridSize)
|
||||
{};
|
||||
CheckeredBgScene(int width, int height, QObject *parent = nullptr)
|
||||
: CheckeredBgScene(QSize(width, height), parent)
|
||||
{};
|
||||
|
||||
void setValidRect(int x, int y, int width, int height) {
|
||||
this->validRect = QRect(x * this->gridSize.width(),
|
||||
y * this->gridSize.height(),
|
||||
width * this->gridSize.width(),
|
||||
height * this->gridSize.height());
|
||||
}
|
||||
void setValidRect(const QRect &rect) {
|
||||
this->validRect = rect;
|
||||
}
|
||||
QRect getValidRect() { return this->validRect; }
|
||||
|
||||
protected:
|
||||
void drawBackground(QPainter *painter, const QRectF &rect) override;
|
||||
|
||||
private:
|
||||
QSize gridSize;
|
||||
QRect validRect;
|
||||
};
|
||||
|
||||
#endif // CHECKEREDBGSCENE_H
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MAPIMAGEEXPORTER_H
|
||||
|
||||
#include "project.h"
|
||||
#include "checkeredbgscene.h"
|
||||
|
||||
class QGifImage;
|
||||
|
||||
@@ -52,7 +53,7 @@ private:
|
||||
Project *m_project = nullptr;
|
||||
Map *m_map = nullptr;
|
||||
Layout *m_layout = nullptr;
|
||||
QGraphicsScene *m_scene = nullptr;
|
||||
CheckeredBgScene *m_scene = nullptr;
|
||||
QGifImage *m_timelapseGifImage = nullptr;
|
||||
QBuffer *m_timelapseBuffer = nullptr;
|
||||
QMovie *m_timelapseMovie = nullptr;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define METATILEIMAGEEXPORTER_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QGraphicsScene>
|
||||
#include <QShowEvent>
|
||||
#include <QCloseEvent>
|
||||
#include <QListWidget>
|
||||
@@ -10,6 +9,7 @@
|
||||
#include <QRadioButton>
|
||||
|
||||
#include "config.h"
|
||||
#include "checkeredbgscene.h"
|
||||
|
||||
class Tileset;
|
||||
|
||||
@@ -73,7 +73,7 @@ private:
|
||||
Tileset *m_secondaryTileset;
|
||||
Settings *m_savedSettings;
|
||||
|
||||
QGraphicsScene *m_scene = nullptr;
|
||||
CheckeredBgScene *m_scene = nullptr;
|
||||
QGraphicsPixmapItem *m_preview = nullptr;
|
||||
bool m_previewUpdateQueued = false;
|
||||
QList<int> m_layerOrder;
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
#include "maplayout.h"
|
||||
#include "project.h"
|
||||
#include "checkeredbgscene.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPointer>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsLineItem>
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QDialogButtonBox>
|
||||
@@ -16,43 +16,6 @@ namespace Ui {
|
||||
class ResizeLayoutPopup;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Custom scene that paints its background a gray checkered pattern.
|
||||
/// Additionally there is a definable "valid" area which will paint the checkerboard green inside.
|
||||
class CheckeredBgScene : public QGraphicsScene {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CheckeredBgScene(const QSize &gridSize, QObject *parent = nullptr)
|
||||
: QGraphicsScene(parent),
|
||||
gridSize(gridSize)
|
||||
{};
|
||||
CheckeredBgScene(int width, int height, QObject *parent = nullptr)
|
||||
: CheckeredBgScene(QSize(width, height), parent)
|
||||
{};
|
||||
|
||||
void setValidRect(int x, int y, int width, int height) {
|
||||
this->validRect = QRect(x * this->gridSize.width(),
|
||||
y * this->gridSize.height(),
|
||||
width * this->gridSize.width(),
|
||||
height * this->gridSize.height());
|
||||
}
|
||||
void setValidRect(const QRect &rect) {
|
||||
this->validRect = rect;
|
||||
}
|
||||
QRect getValidRect() { return this->validRect; }
|
||||
|
||||
protected:
|
||||
void drawBackground(QPainter *painter, const QRectF &rect) override;
|
||||
|
||||
private:
|
||||
QSize gridSize;
|
||||
QRect validRect;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// PixmapItem subclass which allows for creating a boundary which determine whether
|
||||
/// the pixmap paints normally or with a black tint.
|
||||
/// This item is movable and snaps on a 'cellSize' grid.
|
||||
|
||||
@@ -66,6 +66,7 @@ SOURCES += src/core/advancemapparser.cpp \
|
||||
src/scriptapi/apiutility.cpp \
|
||||
src/scriptapi/scripting.cpp \
|
||||
src/ui/aboutporymap.cpp \
|
||||
src/ui/checkeredbgscene.cpp \
|
||||
src/ui/colorinputwidget.cpp \
|
||||
src/ui/connectionslistitem.cpp \
|
||||
src/ui/customattributesdialog.cpp \
|
||||
@@ -181,6 +182,7 @@ HEADERS += include/core/advancemapparser.h \
|
||||
include/lib/orderedmap.h \
|
||||
include/lib/orderedjson.h \
|
||||
include/ui/aboutporymap.h \
|
||||
include/ui/checkeredbgscene.h \
|
||||
include/ui/connectionslistitem.h \
|
||||
include/ui/customattributesdialog.h \
|
||||
include/ui/customattributestable.h \
|
||||
|
||||
32
src/ui/checkeredbgscene.cpp
Normal file
32
src/ui/checkeredbgscene.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "checkeredbgscene.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
void CheckeredBgScene::drawBackground(QPainter *painter, const QRectF &rect) {
|
||||
QRect r = rect.toRect();
|
||||
int w = this->gridSize.width();
|
||||
int h = this->gridSize.height();
|
||||
int xMin = r.left() - (r.left() % w) - w;
|
||||
int yMin = r.top() - (r.top() % h) - h;
|
||||
int xMax = r.right() - (r.right() % w) + w;
|
||||
int yMax = r.bottom() - (r.bottom() % h) + h;
|
||||
|
||||
// draw grid from top to bottom of scene
|
||||
QColor paintColor;
|
||||
for (int x = xMin; x <= xMax; x += w) {
|
||||
for (int y = yMin; y <= yMax; y += h) {
|
||||
if ((x/w + y/h) % 2) {
|
||||
if (this->validRect.contains(x, y))
|
||||
paintColor = QColor(132, 217, 165); // green light color
|
||||
else
|
||||
paintColor = 0xbcbcbc; // normal light color
|
||||
} else {
|
||||
if (this->validRect.contains(x, y))
|
||||
paintColor = QColor(76, 178, 121); // green dark color
|
||||
else
|
||||
paintColor = 0x969696; // normal dark color
|
||||
}
|
||||
painter->fillRect(QRect(x, y, w, h), paintColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ MapImageExporter::MapImageExporter(QWidget *parent, Project *project, Map *map,
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
ui->setupUi(this);
|
||||
|
||||
m_scene = new QGraphicsScene(this);
|
||||
m_scene = new CheckeredBgScene(QSize(8,8), this);
|
||||
m_preview = m_scene->addPixmap(QPixmap());
|
||||
ui->graphicsView_Preview->setScene(m_scene);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ MetatileImageExporter::MetatileImageExporter(QWidget *parent, Tileset *primaryTi
|
||||
ui->radioButton_TransparencyFirst,
|
||||
};
|
||||
|
||||
m_scene = new QGraphicsScene(this);
|
||||
m_scene = new CheckeredBgScene(QSize(8,8), this);
|
||||
m_preview = m_scene->addPixmap(QPixmap());
|
||||
ui->graphicsView_Preview->setScene(m_scene);
|
||||
|
||||
|
||||
@@ -7,39 +7,6 @@
|
||||
|
||||
#include "ui_resizelayoutpopup.h"
|
||||
|
||||
void CheckeredBgScene::drawBackground(QPainter *painter, const QRectF &rect) {
|
||||
QRect r = rect.toRect();
|
||||
int w = this->gridSize.width();
|
||||
int h = this->gridSize.height();
|
||||
int xMin = r.left() - (r.left() % w) - w;
|
||||
int yMin = r.top() - (r.top() % h) - h;
|
||||
int xMax = r.right() - (r.right() % w) + w;
|
||||
int yMax = r.bottom() - (r.bottom() % h) + h;
|
||||
|
||||
// draw grid from top to bottom of scene
|
||||
QColor paintColor;
|
||||
for (int x = xMin; x <= xMax; x += w) {
|
||||
for (int y = yMin; y <= yMax; y += h) {
|
||||
if ((x/w + y/h) % 2) {
|
||||
if (this->validRect.contains(x, y))
|
||||
paintColor = QColor(132, 217, 165); // green light color
|
||||
else
|
||||
paintColor = 0xbcbcbc; // normal light color
|
||||
} else {
|
||||
if (this->validRect.contains(x, y))
|
||||
paintColor = QColor(76, 178, 121); // green dark color
|
||||
else
|
||||
paintColor = 0x969696; // normal dark color
|
||||
}
|
||||
painter->fillRect(QRect(x, y, w, h), paintColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
************************************************************************
|
||||
******************************************************************************/
|
||||
|
||||
BoundedPixmapItem::BoundedPixmapItem(const QPixmap &pixmap, const QSize &cellSize, QGraphicsItem *parent) : QGraphicsPixmapItem(pixmap, parent) {
|
||||
setFlags(this->flags() | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemSendsGeometryChanges | QGraphicsItem::ItemIsSelectable);
|
||||
this->cellSize = cellSize;
|
||||
|
||||
Reference in New Issue
Block a user