Skip to content

Commit

Permalink
Fix mapeditor#91 object tile position, to be same as other objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Romans Potasovs committed Feb 26, 2018
1 parent e895b61 commit f350d60
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/libtiled/orthogonalrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ QRectF OrthogonalRenderer::boundingRect(const MapObject *object) const

const QPointF bottomLeft = bounds.topLeft();
boundingRect = QRectF(bottomLeft.x() + (tileOffset.x() * scale.width()),
bottomLeft.y() + (tileOffset.y() * scale.height()) - objectSize.height(),
bottomLeft.y() + (tileOffset.y() * scale.height()),
objectSize.width(),
objectSize.height()).adjusted(-1, -1, 1, 1);
} else {
Expand Down Expand Up @@ -366,7 +366,7 @@ void OrthogonalRenderer::drawMapObject(QPainter *painter,

if (!cell.isEmpty()) {
const QSizeF size = object->size();
CellRenderer(painter).render(cell, QPointF(), size,
CellRenderer(painter).render(cell, QPointF(0, size.height()), size,
CellRenderer::BottomLeft);

if (testFlag(ShowTileObjectOutlines)) {
Expand All @@ -388,7 +388,8 @@ void OrthogonalRenderer::drawMapObject(QPainter *painter,
painter->setPen(pen);
painter->drawRect(rect);
}
} else {
}
else {
const qreal lineWidth = objectLineWidth();
const qreal scale = painterScale();
const qreal shadowDist = (lineWidth == 0 ? 1 : lineWidth) / scale;
Expand Down
2 changes: 1 addition & 1 deletion src/tiled/createtileobjecttool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void CreateTileObjectTool::mouseMovedWhileCreatingObject(const QPointF &pos, Qt:
const MapRenderer *renderer = mapDocument()->renderer();

const QSize imgSize = mNewMapObjectItem->mapObject()->cell().tile()->size();
const QPointF diff(-imgSize.width() / 2, imgSize.height() / 2);
const QPointF diff(-imgSize.width() / 2, -imgSize.height() / 2);
QPointF pixelCoords = renderer->screenToPixelCoords(pos + diff);

SnapHelper(renderer, modifiers).snap(pixelCoords);
Expand Down
5 changes: 4 additions & 1 deletion src/tiled/objectselectionitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ static QRectF objectBounds(const MapObject *object,
// Tile objects can have a tile offset, which is scaled along with the image
QSizeF imgSize;
QPoint tileOffset;
qreal moveDown = 0;

if (const Tile *tile = object->cell().tile()) {
imgSize = tile->size();
tileOffset = tile->offset();
moveDown = imgSize.height();
} else {
imgSize = object->size();
}
Expand All @@ -94,7 +96,7 @@ static QRectF objectBounds(const MapObject *object,
const qreal scaleY = imgSize.height() > 0 ? objectSize.height() / imgSize.height() : 0;

QRectF bounds(position.x() + (tileOffset.x() * scaleX),
position.y() + (tileOffset.y() * scaleY),
position.y() + ((tileOffset.y()+ moveDown) * scaleY),
objectSize.width(),
objectSize.height());

Expand Down Expand Up @@ -276,6 +278,7 @@ void MapObjectLabel::syncWithMapObject(MapRenderer *renderer)
transform.translate(-pixelPos.x(), -pixelPos.y());
bounds = transform.mapRect(bounds);


// Center the object name on the object bounding box
QPointF pos((bounds.left() + bounds.right()) / 2, bounds.top());

Expand Down
5 changes: 3 additions & 2 deletions src/tiled/objectselectiontool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,10 +820,11 @@ static QRectF objectBounds(const MapObject *object,
// Tile objects can have a tile offset, which is scaled along with the image
QSizeF imgSize;
QPoint tileOffset;

qreal moveDown = 0;
if (const Tile *tile = object->cell().tile()) {
imgSize = tile->size();
tileOffset = tile->offset();
moveDown = imgSize.height();
} else {
imgSize = object->size();
}
Expand All @@ -834,7 +835,7 @@ static QRectF objectBounds(const MapObject *object,
const qreal scaleY = imgSize.height() > 0 ? objectSize.height() / imgSize.height() : 0;

QRectF bounds(position.x() + (tileOffset.x() * scaleX),
position.y() + (tileOffset.y() * scaleY),
position.y() + ((tileOffset.y() + moveDown) * scaleY),
objectSize.width(),
objectSize.height());

Expand Down

0 comments on commit f350d60

Please sign in to comment.