Skip to content

Commit

Permalink
add displayImage property to Tile to get pre-cropped image
Browse files Browse the repository at this point in the history
  • Loading branch information
dogboydog committed Jun 6, 2024
1 parent da60adc commit 16d59b3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/scripting-doc/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2473,6 +2473,16 @@ declare class Tile extends TiledObject {
*/
image: Image;

/**
* Returns the image of this tile, cropped to its {@link imageRect}
* to include only the visible portion of the image.
*
* This property is read-only.
*
* @since 1.11
*/
displayImage: Image;

/**
* The source rectangle (in pixels) for this tile.
*
Expand Down
6 changes: 6 additions & 0 deletions src/tiled/editabletile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ ScriptImage *EditableTile::image() const
return new ScriptImage(tile()->image().toImage());
}

ScriptImage *EditableTile::displayImage() const
{
QPixmap cropped = tile()->image().copy(tile()->imageRect());
return new ScriptImage(cropped.toImage());
}

EditableObjectGroup *EditableTile::objectGroup() const
{
if (!mAttachedObjectGroup) {
Expand Down
2 changes: 2 additions & 0 deletions src/tiled/editabletile.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class EditableTile : public EditableObject
Q_PROPERTY(QString type READ className WRITE setClassName) // compatibility with Tiled < 1.9
Q_PROPERTY(QString imageFileName READ imageFileName WRITE setImageFileName)
Q_PROPERTY(Tiled::ScriptImage *image READ image WRITE setImage)
Q_PROPERTY(Tiled::ScriptImage *displayImage READ displayImage)
Q_PROPERTY(QRect imageRect READ imageRect WRITE setImageRect)
Q_PROPERTY(qreal probability READ probability WRITE setProbability)
Q_PROPERTY(Tiled::EditableObjectGroup *objectGroup READ objectGroup WRITE setObjectGroup)
Expand Down Expand Up @@ -78,6 +79,7 @@ class EditableTile : public EditableObject
QSize size() const;
QString imageFileName() const;
ScriptImage *image() const;
ScriptImage *displayImage() const;
QRect imageRect() const;
qreal probability() const;
EditableObjectGroup *objectGroup() const;
Expand Down

0 comments on commit 16d59b3

Please sign in to comment.