porymap/include/ui/mappixmapitem.h

106 lines
3.7 KiB
C
Raw Normal View History

2018-09-27 00:30:05 +01:00
#ifndef MAPPIXMAPITEM_H
#define MAPPIXMAPITEM_H
#include "map.h"
#include "settings.h"
#include "metatileselector.h"
#include <QGraphicsPixmapItem>
class MapPixmapItem : public QObject, public QGraphicsPixmapItem {
Q_OBJECT
2019-08-07 04:35:02 +01:00
private:
using QGraphicsPixmapItem::paint;
2018-09-27 00:30:05 +01:00
public:
enum class PaintMode {
Disabled,
Metatiles,
EventObjects
};
2018-09-27 00:30:05 +01:00
MapPixmapItem(Map *map_, MetatileSelector *metatileSelector, Settings *settings) {
this->map = map_;
2020-07-29 20:51:04 +01:00
this->map->setMapItem(this);
2018-09-27 00:30:05 +01:00
this->metatileSelector = metatileSelector;
this->settings = settings;
this->paintingMode = PaintMode::Metatiles;
this->lockedAxis = MapPixmapItem::Axis::None;
this->prevStraightPathState = false;
2018-09-27 00:30:05 +01:00
setAcceptHoverEvents(true);
}
MapPixmapItem::PaintMode paintingMode;
2018-09-27 00:30:05 +01:00
Map *map;
MetatileSelector *metatileSelector;
Settings *settings;
bool active;
bool has_mouse = false;
2018-09-27 00:30:05 +01:00
bool right_click;
int paint_tile_initial_x;
int paint_tile_initial_y;
bool prevStraightPathState;
int straight_path_initial_x;
int straight_path_initial_y;
QPoint metatilePos;
enum Axis {
None = 0,
X,
Y
};
MapPixmapItem::Axis lockedAxis;
2018-09-27 00:30:05 +01:00
QPoint selection_origin;
QList<QPoint> selection;
virtual void paint(QGraphicsSceneMouseEvent*);
virtual void floodFill(QGraphicsSceneMouseEvent*);
2019-01-04 23:06:27 +00:00
virtual void magicFill(QGraphicsSceneMouseEvent*);
2020-05-01 00:30:24 +01:00
void magicFill(int x, int y, uint16_t metatileId, bool fromScriptCall = false);
void magicFill(int x, int y, bool fromScriptCall = false);
void magicFill(
int initialX,
int initialY,
QPoint selectionDimensions,
QList<MetatileSelectionItem> selectedMetatiles,
QList<CollisionSelectionItem> selectedCollisions,
2020-05-01 00:30:24 +01:00
bool fromScriptCall = false);
void floodFill(int x, int y, bool fromScriptCall = false);
void floodFill(int x, int y, uint16_t metatileId, bool fromScriptCall = false);
void floodFill(int initialX,
int initialY,
QPoint selectionDimensions,
QList<MetatileSelectionItem> selectedMetatiles,
QList<CollisionSelectionItem> selectedCollisions,
2020-05-01 00:30:24 +01:00
bool fromScriptCall = false);
2020-05-03 16:48:48 +01:00
void floodFillSmartPath(int initialX, int initialY, bool fromScriptCall = false);
2018-09-27 00:30:05 +01:00
virtual void pick(QGraphicsSceneMouseEvent*);
virtual void select(QGraphicsSceneMouseEvent*);
virtual void shift(QGraphicsSceneMouseEvent*);
void shift(int xDelta, int yDelta, bool fromScriptCall = false);
2018-09-27 00:30:05 +01:00
virtual void draw(bool ignoreCache = false);
void updateMetatileSelection(QGraphicsSceneMouseEvent *event);
2020-05-01 00:30:24 +01:00
void paintNormal(int x, int y, bool fromScriptCall = false);
void lockNondominantAxis(QGraphicsSceneMouseEvent *event);
QPoint adjustCoords(QPoint pos);
2018-09-27 00:30:05 +01:00
private:
2020-05-03 16:48:48 +01:00
void paintSmartPath(int x, int y, bool fromScriptCall = false);
2018-09-27 00:30:05 +01:00
static QList<int> smartPathTable;
unsigned actionId_ = 0;
2020-07-29 20:51:04 +01:00
2018-09-27 00:30:05 +01:00
signals:
void startPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *);
void endPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *);
2018-09-27 00:30:05 +01:00
void mouseEvent(QGraphicsSceneMouseEvent *, MapPixmapItem *);
2020-10-24 12:45:08 +01:00
void hoveredMapMetatileChanged(const QPoint &pos);
2018-09-27 00:30:05 +01:00
void hoveredMapMetatileCleared();
protected:
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
void hoverEnterEvent(QGraphicsSceneHoverEvent*);
2018-09-27 00:30:05 +01:00
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
void mousePressEvent(QGraphicsSceneMouseEvent*);
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
};
#endif // MAPPIXMAPITEM_H