-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQTileEdit.h
126 lines (108 loc) · 3.21 KB
/
QTileEdit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef QTILEEDIT_H
#define QTILEEDIT_H
#include <QWidget>
#include <QMap>
#include <QStack>
class QTileSelector;
enum { BOTTOM = 0, FLIPPED = 1, TOP = 2, LEFT = 3, RIGHT = 4 };
struct QSprite
{
bool pixelPerfect;
int x, y;
QSize size;
QPointF drawOffset;
QPixmap *sprite;
int rotate;
int id;
quint8 flagByte;
};
class QTileEdit : public QWidget
{
Q_OBJECT
public:
explicit QTileEdit(QWidget *parent = 0);
bool isChanged();
bool loadTileSet(QString filename, int emptyTileNumber, int count);
void setLevelDimension(int width, int height);
void setTileSize(int width, int height);
void setLevelData(QByteArray data, int start, int length);
void setBackground(QImage backgroundImage);
int getSelectedSprite(int *id);
QString spriteNumToString(int sprite);
QString tileNumToString(int tile);
void getMouse(bool enable);
void setupTileSelector(QTileSelector *tileSelector, float scale = 1.25f, int limitTileCount = 0);
protected:
void paintEvent(QPaintEvent *e);
virtual void paintLevel(QPainter *painter);
void mouseMoveEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *);
void resizeEvent(QResizeEvent *e);
QPainter *getPainter();
void finishPainter(QPainter *painter);
void resized(QSize newSize);
void drawTile(int tileNumber, int x, int y);
QRect tileNumberToQRect(int tileNumber);
int getSpriteAtXY(int x, int y, QRect *spriteRect);
QRect getSpriteRect(int num);
int getTile(int x, int y);
int getTile(int offset);
void setTile(int x, int y, int tileNumber);
void setTile(int offset, int tileNumber);
QMap<int, QString> spriteNames;
QMap<int, QString> tileNames;
QStack<QPair<QByteArray, QVector<QSprite> > > undoStack;
bool keepUndo;
virtual void createUndoData();
virtual void clearUndoData();
virtual void deleteLastUndo();
QVector<QSprite> sprites;
QByteArray lvlData;
int lvlDataStart;
int lvlDataLength;
int emptyTile;
int tileToDraw;
int tileCount;
int spriteToMove;
int selectedSprite;
int mousePressed;
float scaleFactorX;
float scaleFactorY;
bool dataIsChanged;
bool tileDataIs16bit;
bool spriteContext;
bool keepAspect;
bool spriteMode;
QRect mouseOverTile;
QRect spriteSelection;
QSize orgSize;
QSize scaledSize;
QSize levelDimension;
QSize tileSetDimension;
QSize tileSize;
QPixmap tileSet;
QImage background;
QImage tiledLevel;
QImage originalSize;
QTileSelector *selector;
signals:
void dataChanged();
void singleTileChanged(int x, int y, int drawnTile);
void spriteSelected(int spriteNo);
void spriteAdded(QString text, int id);
void spriteRemoved(int index);
void flagByteChanged(int num);
public slots:
void updateLevel();
void keepUndoData();
virtual void clearLevel();
void setTileToDraw(int tileNumber);
void toggleSpriteMode(bool enabled);
void toggleSpriteMode(int enabled);
void getSpriteFlag(int num, quint8 *flag);
void setSpriteFlag(int num, quint8 flag);
void deleteSprite(int num);
virtual void undo();
};
#endif // QTILEEDIT_H