Display hovered block selection in status bar
This commit is contained in:
parent
f81ab6994a
commit
4f838b979c
4 changed files with 36 additions and 0 deletions
20
editor.cpp
20
editor.cpp
|
@ -257,6 +257,25 @@ void MetatilesPixmapItem::pick(uint tile) {
|
||||||
emit map->paintTileChanged(map);
|
emit map->paintTileChanged(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
||||||
|
int x = ((int)pos.x()) / 16;
|
||||||
|
int y = ((int)pos.y()) / 16;
|
||||||
|
int width = pixmap().width() / 16;
|
||||||
|
int height = pixmap().height() / 16;
|
||||||
|
if (x < 0 || x >= width || y < 0 || y >= height) {
|
||||||
|
map->clearHoveredMetatile();
|
||||||
|
} else {
|
||||||
|
int block = y * width + x;
|
||||||
|
map->hoveredMetatileChanged(block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MetatilesPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
||||||
|
updateCurHoveredMetatile(event->pos());
|
||||||
|
}
|
||||||
|
void MetatilesPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
|
||||||
|
map->clearHoveredMetatile();
|
||||||
|
}
|
||||||
void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
QPointF pos = event->pos();
|
QPointF pos = event->pos();
|
||||||
int x = ((int)pos.x()) / 16;
|
int x = ((int)pos.x()) / 16;
|
||||||
|
@ -269,6 +288,7 @@ void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void MetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
void MetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
updateCurHoveredMetatile(event->pos());
|
||||||
mousePressEvent(event);
|
mousePressEvent(event);
|
||||||
}
|
}
|
||||||
void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
|
5
editor.h
5
editor.h
|
@ -241,14 +241,19 @@ public:
|
||||||
}
|
}
|
||||||
MetatilesPixmapItem(Map *map_) {
|
MetatilesPixmapItem(Map *map_) {
|
||||||
map = map_;
|
map = map_;
|
||||||
|
setAcceptHoverEvents(true);
|
||||||
connect(map, SIGNAL(paintTileChanged(Map*)), this, SLOT(paintTileChanged(Map *)));
|
connect(map, SIGNAL(paintTileChanged(Map*)), this, SLOT(paintTileChanged(Map *)));
|
||||||
}
|
}
|
||||||
Map* map = NULL;
|
Map* map = NULL;
|
||||||
virtual void pick(uint);
|
virtual void pick(uint);
|
||||||
virtual void draw();
|
virtual void draw();
|
||||||
|
private:
|
||||||
|
void updateCurHoveredMetatile(QPointF pos);
|
||||||
private slots:
|
private slots:
|
||||||
void paintTileChanged(Map *map);
|
void paintTileChanged(Map *map);
|
||||||
protected:
|
protected:
|
||||||
|
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
|
||||||
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
|
9
map.cpp
9
map.cpp
|
@ -745,3 +745,12 @@ void Map::hoveredTileChanged(int x, int y, int block) {
|
||||||
void Map::clearHoveredTile() {
|
void Map::clearHoveredTile() {
|
||||||
emit statusBarMessage(QString(""));
|
emit statusBarMessage(QString(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Map::hoveredMetatileChanged(int block) {
|
||||||
|
emit statusBarMessage(QString("Block: 0x%1")
|
||||||
|
.arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::clearHoveredMetatile() {
|
||||||
|
emit statusBarMessage(QString(""));
|
||||||
|
}
|
||||||
|
|
2
map.h
2
map.h
|
@ -184,6 +184,8 @@ public:
|
||||||
bool hasUnsavedChanges();
|
bool hasUnsavedChanges();
|
||||||
void hoveredTileChanged(int x, int y, int block);
|
void hoveredTileChanged(int x, int y, int block);
|
||||||
void clearHoveredTile();
|
void clearHoveredTile();
|
||||||
|
void hoveredMetatileChanged(int block);
|
||||||
|
void clearHoveredMetatile();
|
||||||
|
|
||||||
QList<QList<QRgb> > getBlockPalettes(int metatile_index);
|
QList<QList<QRgb> > getBlockPalettes(int metatile_index);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue