From 8ed891d5010d82be6a4eec9893d06b311f288acb Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 10 Dec 2021 11:55:21 -0500 Subject: [PATCH] Add option to bypass the API image cache --- include/mainwindow.h | 7 +++++-- include/ui/overlay.h | 2 +- src/mainwindow_scriptapi.cpp | 8 ++++---- src/ui/overlay.cpp | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/mainwindow.h b/include/mainwindow.h index f3031079..bc602bd1 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -90,8 +90,11 @@ public: Q_INVOKABLE void addText(QString text, int x, int y, QString color = "#000000", int fontSize = 12, int layer = 0); Q_INVOKABLE void addRect(int x, int y, int width, int height, QString color = "#000000", int layer = 0); Q_INVOKABLE void addFilledRect(int x, int y, int width, int height, QString color = "#000000", int layer = 0); - Q_INVOKABLE void addImage(int x, int y, QString filepath, int layer = 0); - Q_INVOKABLE void createImage(int x, int y, QString filepath, int width = -1, int height = -1, unsigned offset = 0, bool xflip = false, bool yflip = false, int paletteId = -1, bool setTransparency = false, int layer = 0); + Q_INVOKABLE void addImage(int x, int y, QString filepath, int layer = 0, bool useCache = true); + Q_INVOKABLE void createImage(int x, int y, QString filepath, + int width = -1, int height = -1, unsigned offset = 0, + bool xflip = false, bool yflip = false, int paletteId = -1, bool setTransparency = false, + int layer = 0, bool useCache = true); Q_INVOKABLE void addTileImage(int x, int y, int tileId, bool xflip, bool yflip, int paletteId, bool setTransparency = false, int layer = 0); Q_INVOKABLE void addTilesImage(int x, int y, QJSValue tilesObj, int layer = 0); Q_INVOKABLE void addMetatileImage(int x, int y, int metatileId, int layer = 0); diff --git a/include/ui/overlay.h b/include/ui/overlay.h index 7c134251..27987f52 100644 --- a/include/ui/overlay.h +++ b/include/ui/overlay.h @@ -92,7 +92,7 @@ public: void clearItems(); void addText(QString text, int x, int y, QString color = "#000000", int fontSize = 12); void addRect(int x, int y, int width, int height, QString color = "#000000", bool filled = false); - bool addImage(int x, int y, QString filepath, int width = -1, int height = -1, unsigned offset = 0, bool xflip = false, bool yflip = false, QList palette = QList(), bool setTransparency = false); + bool addImage(int x, int y, QString filepath, bool useCache = true, int width = -1, int height = -1, unsigned offset = 0, bool xflip = false, bool yflip = false, QList palette = QList(), bool setTransparency = false); bool addImage(int x, int y, QImage image); private: QList items; diff --git a/src/mainwindow_scriptapi.cpp b/src/mainwindow_scriptapi.cpp index 0ab2309e..9d15a02f 100644 --- a/src/mainwindow_scriptapi.cpp +++ b/src/mainwindow_scriptapi.cpp @@ -374,21 +374,21 @@ void MainWindow::addFilledRect(int x, int y, int width, int height, QString colo this->ui->graphicsView_Map->scene()->update(); } -void MainWindow::addImage(int x, int y, QString filepath, int layer) { +void MainWindow::addImage(int x, int y, QString filepath, int layer, bool useCache) { if (!this->ui || !this->ui->graphicsView_Map) return; - if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, filepath)) + if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, filepath, useCache)) this->ui->graphicsView_Map->scene()->update(); } -void MainWindow::createImage(int x, int y, QString filepath, int width, int height, unsigned offset, bool xflip, bool yflip, int paletteId, bool setTransparency, int layer) { +void MainWindow::createImage(int x, int y, QString filepath, int width, int height, unsigned offset, bool xflip, bool yflip, int paletteId, bool setTransparency, int layer, bool useCache) { if (!this->ui || !this->ui->graphicsView_Map || !this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary || !this->editor->map->layout->tileset_secondary) return; QList palette; if (paletteId != -1) palette = Tileset::getPalette(paletteId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary); - if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, filepath, width, height, offset, xflip, yflip, palette, setTransparency)) + if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, filepath, useCache, width, height, offset, xflip, yflip, palette, setTransparency)) this->ui->graphicsView_Map->scene()->update(); } diff --git a/src/ui/overlay.cpp b/src/ui/overlay.cpp index a111753d..f5483e39 100644 --- a/src/ui/overlay.cpp +++ b/src/ui/overlay.cpp @@ -83,8 +83,8 @@ void Overlay::addRect(int x, int y, int width, int height, QString color, bool f this->items.append(new OverlayRect(x, y, width, height, QColor(color), filled)); } -bool Overlay::addImage(int x, int y, QString filepath, int width, int height, unsigned offset, bool xflip, bool yflip, QList palette, bool setTransparency) { - QImage image = Scripting::getImage(filepath); +bool Overlay::addImage(int x, int y, QString filepath, bool useCache, int width, int height, unsigned offset, bool xflip, bool yflip, QList palette, bool setTransparency) { + QImage image = useCache ? Scripting::getImage(filepath) : QImage(filepath); if (image.isNull()) { logError(QString("Failed to load image '%1'").arg(filepath)); return false;