mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-13 11:25:42 -05:00
add region map image editor with basic functionality
This commit is contained in:
36
include/ui/regionmappixmapitem.h
Normal file
36
include/ui/regionmappixmapitem.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef REGIONMAPPIXMAPITEM_H
|
||||
#define REGIONMAPPIXMAPITEM_H
|
||||
|
||||
#include "regionmapeditor.h"
|
||||
#include "tilemaptileselector.h"
|
||||
#include <QGraphicsPixmapItem>
|
||||
|
||||
class RegionMapPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
RegionMapPixmapItem(RegionMap *rmap, TilemapTileSelector *tile_selector) {
|
||||
this->region_map = rmap;
|
||||
this->tile_selector = tile_selector;
|
||||
setAcceptHoverEvents(true);
|
||||
}
|
||||
RegionMap *region_map;
|
||||
TilemapTileSelector *tile_selector;
|
||||
|
||||
virtual void paint(QGraphicsSceneMouseEvent*);
|
||||
virtual void select(QGraphicsSceneMouseEvent*);
|
||||
virtual void draw();
|
||||
|
||||
signals:
|
||||
void mouseEvent(QGraphicsSceneMouseEvent *, RegionMapPixmapItem *);
|
||||
void hoveredRegionMapTileChanged(int x, int y);
|
||||
void hoveredRegionMapTileCleared();
|
||||
|
||||
protected:
|
||||
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||
};
|
||||
|
||||
#endif // REGIONMAPPIXMAPITEM_H
|
||||
51
include/ui/tilemaptileselector.h
Normal file
51
include/ui/tilemaptileselector.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef TILEMAPTILESELECTOR_H
|
||||
#define TILEMAPTILESELECTOR_H
|
||||
|
||||
#include "selectablepixmapitem.h"
|
||||
|
||||
class TilemapTileSelector: public SelectablePixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TilemapTileSelector(QPixmap pixmap): SelectablePixmapItem(8, 8, 1, 1) {
|
||||
this->pixmap = pixmap;
|
||||
this->numTilesWide = 16;
|
||||
this->selectedTile = 0x00;
|
||||
setAcceptHoverEvents(true);
|
||||
}
|
||||
void draw();
|
||||
void select(unsigned tileId);
|
||||
unsigned getSelectedTile();
|
||||
|
||||
int pixelWidth;
|
||||
int pixelHeight;
|
||||
|
||||
unsigned selectedTile;
|
||||
|
||||
// TODO: which of these need to be made public?
|
||||
// call this tilemap? or is tilemap the binary file?
|
||||
QPixmap pixmap;// pointer?
|
||||
QImage currTile;// image of just the currently selected tile to draw onto graphicsview
|
||||
QImage tileImg(unsigned tileId);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
|
||||
|
||||
private:
|
||||
int numTilesWide;
|
||||
int numTiles;
|
||||
void updateSelectedTile();
|
||||
unsigned getTileId(int x, int y);
|
||||
QPoint getTileIdCoords(unsigned);
|
||||
unsigned getValidTileId(unsigned);// TODO: implement this to prevent segfaults
|
||||
|
||||
signals:
|
||||
void hoveredTileChanged(unsigned);
|
||||
void hoveredTileCleared();
|
||||
void selectedTileChanged(unsigned);
|
||||
};
|
||||
|
||||
#endif // TILEMAPTILESELECTOR_H
|
||||
Reference in New Issue
Block a user