Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripting: add displayImage property to Tile to get pre-cropped image #3960

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading