Przeglądaj źródła

Display hovered block selection in status bar

Marcus Huderle 6 lat temu
rodzic
commit
4f838b979c
4 zmienionych plików z 36 dodań i 0 usunięć
  1. 20
    0
      editor.cpp
  2. 5
    0
      editor.h
  3. 9
    0
      map.cpp
  4. 2
    0
      map.h

+ 20
- 0
editor.cpp Wyświetl plik

@@ -257,6 +257,25 @@ void MetatilesPixmapItem::pick(uint tile) {
257 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 279
 void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
261 280
     QPointF pos = event->pos();
262 281
     int x = ((int)pos.x()) / 16;
@@ -269,6 +288,7 @@ void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
269 288
     }
270 289
 }
271 290
 void MetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
291
+    updateCurHoveredMetatile(event->pos());
272 292
     mousePressEvent(event);
273 293
 }
274 294
 void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {

+ 5
- 0
editor.h Wyświetl plik

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

+ 9
- 0
map.cpp Wyświetl plik

@@ -745,3 +745,12 @@ void Map::hoveredTileChanged(int x, int y, int block) {
745 745
 void Map::clearHoveredTile() {
746 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 Wyświetl plik

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