Skip to content

Commit

Permalink
LevelCelView: Inform user when an image doesn't fit in tileset
Browse files Browse the repository at this point in the history
Currently if user inserts an image to a tileset, with either drag'n'drop
feature or by menus - there won't be any message that the image that he
wants to insert is not fitting within the frame/tile/megatile
dimensions. This patch adds those warnings.
  • Loading branch information
tetektoza authored and AJenbo committed Oct 30, 2023
1 parent 4de2c92 commit c4e6328
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions source/levelcelview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <algorithm>
#include <set>

#include "d1image.h"
#include "mainwindow.h"
#include "ui_levelcelview.h"
#include <QAction>
#include <QDebug>
#include <QFileInfo>
Expand All @@ -12,10 +15,6 @@
#include <QMessageBox>
#include <QMimeData>

#include "d1image.h"
#include "mainwindow.h"
#include "ui_levelcelview.h"

LevelCelView::LevelCelView(QWidget *parent)
: QWidget(parent)
, ui(new Ui::LevelCelView())
Expand Down Expand Up @@ -279,6 +278,13 @@ void LevelCelView::assignFrames(const QImage &image, int subtileIndex, int frame
void LevelCelView::insertFrames(IMAGE_FILE_MODE mode, int index, const QImage &image)
{
if ((image.width() % MICRO_WIDTH) != 0 || (image.height() % MICRO_HEIGHT) != 0) {
QMessageBox::critical(this, tr("Error!"), tr("Wrong frame dimensions!\n"
"Image should have dimensions %1x%2px (w x h).\n"
"Image that you wanted to insert has %3x%4px dimensions.")
.arg(MICRO_WIDTH)
.arg(MICRO_HEIGHT)
.arg(image.width())
.arg(image.height()));
return;
}

Expand Down Expand Up @@ -400,6 +406,13 @@ void LevelCelView::insertSubtiles(IMAGE_FILE_MODE mode, int index, const QImage
unsigned subtileHeight = this->min->getSubtileHeight() * MICRO_HEIGHT;

if ((image.width() % subtileWidth) != 0 || (image.height() % subtileHeight) != 0) {
QMessageBox::critical(this, tr("Error!"), tr("Wrong tile dimensions!\n"
"Image should have dimensions %1x%2px (w x h).\n"
"Image that you wanted to insert has %3x%4px dimensions.")
.arg(subtileWidth)
.arg(subtileHeight)
.arg(image.width())
.arg(image.height()));
return;
}

Expand Down Expand Up @@ -549,6 +562,13 @@ void LevelCelView::insertTiles(IMAGE_FILE_MODE mode, int index, const QImage &im
unsigned tileHeight = this->min->getSubtileHeight() * MICRO_HEIGHT;

if ((image.width() % tileWidth) != 0 || (image.height() % tileHeight) != 0) {
QMessageBox::critical(this, tr("Error!"), tr("Wrong MegaTile dimensions!\n"
"Image should have dimensions %1x%2px (w x h).\n"
"Image that you wanted to insert has %3x%4px dimensions.")
.arg(tileWidth)
.arg(tileHeight)
.arg(image.width())
.arg(image.height()));
return;
}

Expand Down

0 comments on commit c4e6328

Please sign in to comment.