Browse Source

Display hovered block selection in status bar

Marcus Huderle 6 years ago
parent
commit
4f838b979c
4 changed files with 36 additions and 0 deletions
  1. 20
    0
      editor.cpp
  2. 5
    0
      editor.h
  3. 9
    0
      map.cpp
  4. 2
    0
      map.h

+ 20
- 0
editor.cpp View File

257
     emit map->paintTileChanged(map);
257
     emit map->paintTileChanged(map);
258
 }
258
 }
259
 
259
 
260
+void MetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
261
+    int x = ((int)pos.x()) / 16;
262
+    int y = ((int)pos.y()) / 16;
263
+    int width = pixmap().width() / 16;
264
+    int height = pixmap().height() / 16;
265
+    if (x < 0 || x >= width || y < 0 || y >= height) {
266
+        map->clearHoveredMetatile();
267
+    } else {
268
+        int block = y * width + x;
269
+        map->hoveredMetatileChanged(block);
270
+    }
271
+}
272
+
273
+void MetatilesPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
274
+    updateCurHoveredMetatile(event->pos());
275
+}
276
+void MetatilesPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
277
+    map->clearHoveredMetatile();
278
+}
260
 void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
279
 void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
261
     QPointF pos = event->pos();
280
     QPointF pos = event->pos();
262
     int x = ((int)pos.x()) / 16;
281
     int x = ((int)pos.x()) / 16;
269
     }
288
     }
270
 }
289
 }
271
 void MetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
290
 void MetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
291
+    updateCurHoveredMetatile(event->pos());
272
     mousePressEvent(event);
292
     mousePressEvent(event);
273
 }
293
 }
274
 void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
294
 void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {

+ 5
- 0
editor.h View File

241
     }
241
     }
242
     MetatilesPixmapItem(Map *map_) {
242
     MetatilesPixmapItem(Map *map_) {
243
         map = map_;
243
         map = map_;
244
+        setAcceptHoverEvents(true);
244
         connect(map, SIGNAL(paintTileChanged(Map*)), this, SLOT(paintTileChanged(Map *)));
245
         connect(map, SIGNAL(paintTileChanged(Map*)), this, SLOT(paintTileChanged(Map *)));
245
     }
246
     }
246
     Map* map = NULL;
247
     Map* map = NULL;
247
     virtual void pick(uint);
248
     virtual void pick(uint);
248
     virtual void draw();
249
     virtual void draw();
250
+private:
251
+    void updateCurHoveredMetatile(QPointF pos);
249
 private slots:
252
 private slots:
250
     void paintTileChanged(Map *map);
253
     void paintTileChanged(Map *map);
251
 protected:
254
 protected:
255
+    void hoverMoveEvent(QGraphicsSceneHoverEvent*);
256
+    void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
252
     void mousePressEvent(QGraphicsSceneMouseEvent*);
257
     void mousePressEvent(QGraphicsSceneMouseEvent*);
253
     void mouseMoveEvent(QGraphicsSceneMouseEvent*);
258
     void mouseMoveEvent(QGraphicsSceneMouseEvent*);
254
     void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
259
     void mouseReleaseEvent(QGraphicsSceneMouseEvent*);

+ 9
- 0
map.cpp View File

745
 void Map::clearHoveredTile() {
745
 void Map::clearHoveredTile() {
746
     emit statusBarMessage(QString(""));
746
     emit statusBarMessage(QString(""));
747
 }
747
 }
748
+
749
+void Map::hoveredMetatileChanged(int block) {
750
+    emit statusBarMessage(QString("Block: 0x%1")
751
+                          .arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper()));
752
+}
753
+
754
+void Map::clearHoveredMetatile() {
755
+    emit statusBarMessage(QString(""));
756
+}

+ 2
- 0
map.h View File

184
     bool hasUnsavedChanges();
184
     bool hasUnsavedChanges();
185
     void hoveredTileChanged(int x, int y, int block);
185
     void hoveredTileChanged(int x, int y, int block);
186
     void clearHoveredTile();
186
     void clearHoveredTile();
187
+    void hoveredMetatileChanged(int block);
188
+    void clearHoveredMetatile();
187
 
189
 
188
     QList<QList<QRgb> > getBlockPalettes(int metatile_index);
190
     QList<QList<QRgb> > getBlockPalettes(int metatile_index);
189
 
191