diff --git a/docsrc/manual/scripting-capabilities.rst b/docsrc/manual/scripting-capabilities.rst index d86208cc..ae79e08d 100644 --- a/docsrc/manual/scripting-capabilities.rst +++ b/docsrc/manual/scripting-capabilities.rst @@ -682,18 +682,18 @@ The following functions are related to an overlay that is drawn on top of the ma :param number layer: the layer id. Defaults to ``0`` :param boolean useCache: whether the image should be saved/loaded using the cache. Defaults to ``true``. Reading images from a file is slow. Setting ``useCache`` to ``true`` will save the image to memory so that the next time the filepath is encountered the image can be loaded from memory rather than the file. -.. js:function:: map.createImage(x, y, filepath, width = -1, height = -1, offset = 0, xflip = false, yflip = false, paletteId = -1, setTransparency = false, layer = 0, useCache = true) +.. js:function:: map.createImage(x, y, filepath, width = -1, height = -1, offset = 0, hScale = 1, vScale = 1, paletteId = -1, setTransparency = false, layer = 0, useCache = true) Creates an image item on the specified overlay layer. This differs from ``map.addImage`` by allowing the new image to be a transformation of the image file. :param number x: the x pixel coordinate of the image's top-left corner (relative to the layer's position) :param number y: the y pixel coordinate of the image's top-left corner (relative to the layer's position) :param string filepath: the image's filepath - :param number width: the image width. If ``-1``, use the full width of the original image. Defaults to ``-1`` - :param number height: the image height. If ``-1``, use the full height of the original image. Defaults to ``-1`` + :param number width: the width in pixels of the area to read in the image. If ``-1``, use the full width of the original image. Defaults to ``-1`` + :param number height: the height in pixels of the area to read in the image. If ``-1``, use the full height of the original image. Defaults to ``-1`` :param number offset: the pixel offset into the original image where data should be read from. Defaults to ``0`` - :param boolean xflip: whether the image should be a horizontal flip of the original image. Defaults to ``false`` - :param boolean yflip: whether the image should be a vertical flip of the original image. Defaults to ``false`` + :param number hScale: the horizontal scale for the image. Negative values will be a horizontal flip of the original image. Defaults to ``1`` + :param number vScale: the vertical scale for the image. Negative values will be a vertical flip of the original image. Defaults to ``1`` :param number paletteId: the id of which currently loaded tileset palette to use for the image. If ``-1``, use the original image's palette. Defaults to ``-1`` :param boolean setTransparency: whether the color at index 0 should be overwritten with transparent pixels. Defaults to ``false`` :param number layer: the layer id. Defaults to ``0`` diff --git a/include/mainwindow.h b/include/mainwindow.h index 1174060b..120aa3d1 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -96,7 +96,7 @@ public: 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, + qreal hScale = 1, qreal vScale = 1, 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 addTileImage(int x, int y, QJSValue tileObj, bool setTransparency = false, int layer = 0); diff --git a/include/ui/overlay.h b/include/ui/overlay.h index cc126e8d..0b35964d 100644 --- a/include/ui/overlay.h +++ b/include/ui/overlay.h @@ -95,7 +95,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, 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, QString filepath, bool useCache = true, int width = -1, int height = -1, unsigned offset = 0, qreal hScale = 1, qreal vScale = 1, 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 5875bb08..c021f7df 100644 --- a/src/mainwindow_scriptapi.cpp +++ b/src/mainwindow_scriptapi.cpp @@ -401,14 +401,14 @@ void MainWindow::addImage(int x, int y, QString filepath, int layer, bool useCac 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, bool useCache) { +void MainWindow::createImage(int x, int y, QString filepath, int width, int height, unsigned offset, qreal hScale, qreal vScale, 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, useCache, width, height, offset, xflip, yflip, palette, setTransparency)) + if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, filepath, useCache, width, height, offset, hScale, vScale, palette, setTransparency)) this->ui->graphicsView_Map->scene()->update(); } diff --git a/src/ui/overlay.cpp b/src/ui/overlay.cpp index 635d76f9..c8f56fb0 100644 --- a/src/ui/overlay.cpp +++ b/src/ui/overlay.cpp @@ -96,7 +96,7 @@ 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, bool useCache, int width, int height, unsigned offset, bool xflip, bool yflip, QList palette, bool setTransparency) { +bool Overlay::addImage(int x, int y, QString filepath, bool useCache, int width, int height, unsigned offset, qreal hScale, qreal vScale, QList palette, bool setTransparency) { QImage image = useCache ? Scripting::getImage(filepath) : QImage(filepath); if (image.isNull()) { logError(QString("Failed to load image '%1'").arg(filepath)); @@ -124,8 +124,8 @@ bool Overlay::addImage(int x, int y, QString filepath, bool useCache, int width, if (width != fullWidth || height != fullHeight) image = image.copy(offset % fullWidth, offset / fullWidth, width, height); - if (xflip || yflip) - image = image.transformed(QTransform().scale(xflip ? -1 : 1, yflip ? -1 : 1)); + if (hScale != 1 || vScale != 1) + image = image.transformed(QTransform().scale(hScale, vScale)); for (int i = 0; i < palette.size(); i++) image.setColor(i, palette.at(i));