author | Wuzzy <Wuzzy2@mail.ru> |
Tue, 28 May 2019 00:48:17 +0200 | |
changeset 15073 | 6f51c75994a4 |
parent 13214 | f5d36be88c61 |
permissions | -rw-r--r-- |
4976 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
4976 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4976 | 17 |
*/ |
18 |
||
4423 | 19 |
#ifndef DRAWMAPSCENE_H |
20 |
#define DRAWMAPSCENE_H |
|
21 |
||
22 |
#include <QGraphicsScene> |
|
4442 | 23 |
#include <QPainterPath> |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
24 |
#include <QGraphicsEllipseItem> |
4423 | 25 |
|
13214
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
26 |
#define DRAWN_MAP_BRUSH_SIZE_STEP (10) |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
27 |
#define DRAWN_MAP_BRUSH_SIZE_MAX (516) |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
28 |
#define DRAWN_MAP_BRUSH_SIZE_MIN (16) |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
29 |
#define DRAWN_MAP_BRUSH_SIZE_START (76) |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
30 |
|
4426 | 31 |
class QGraphicsPathItem; |
32 |
||
6873 | 33 |
struct PathParams |
34 |
{ |
|
35 |
quint8 width; |
|
36 |
bool erasing; |
|
9551 | 37 |
QPoint initialPoint; |
6873 | 38 |
QList<QPoint> points; |
39 |
}; |
|
40 |
||
41 |
typedef QList<PathParams> Paths; |
|
4427 | 42 |
|
4423 | 43 |
class DrawMapScene : public QGraphicsScene |
44 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
45 |
Q_OBJECT |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
46 |
public: |
9551 | 47 |
enum PathType { |
48 |
Polyline = 0, |
|
49 |
Rectangle = 1, |
|
50 |
Ellipse = 2 |
|
51 |
}; |
|
52 |
||
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
53 |
explicit DrawMapScene(QObject *parent = 0); |
4423 | 54 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
55 |
QByteArray encode(); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
56 |
void decode(QByteArray data); |
6935 | 57 |
int pointsCount(); |
13214
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
58 |
int brushSize(); |
4427 | 59 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
60 |
signals: |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
61 |
void pathChanged(); |
13214
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
62 |
void brushSizeChanged(int brushSize); |
4423 | 63 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
64 |
public slots: |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
65 |
void undo(); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
66 |
void clearMap(); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
67 |
void simplifyLast(); |
10235 | 68 |
void optimize(); |
6873 | 69 |
void setErasing(bool erasing); |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
70 |
void showCursor(); |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
71 |
void hideCursor(); |
9551 | 72 |
void setPathType(PathType pathType); |
13214
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
73 |
void setBrushSize(int brushSize); |
4423 | 74 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
75 |
private: |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
76 |
QPen m_pen; |
6873 | 77 |
QBrush m_eraser; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
78 |
QBrush m_brush; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
79 |
QGraphicsPathItem * m_currPath; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
80 |
Paths paths; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
81 |
Paths oldPaths; |
6873 | 82 |
bool m_isErasing; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
83 |
QList<QGraphicsItem *> oldItems; |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
84 |
QGraphicsEllipseItem * m_cursor; |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
85 |
bool m_isCursorShown; |
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
86 |
QByteArray m_specialPoints; |
9551 | 87 |
PathType m_pathType; |
4424 | 88 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
89 |
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
90 |
virtual void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
91 |
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent); |
6781 | 92 |
virtual void wheelEvent(QGraphicsSceneWheelEvent *); |
4442 | 93 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
94 |
QPainterPath pointsToPath(const QList<QPoint> points); |
6781 | 95 |
|
96 |
quint8 serializePenWidth(int width); |
|
97 |
int deserializePenWidth(quint8 width); |
|
9551 | 98 |
QList<QPointF> makeEllipse(const QPointF & center, const QPointF & corner); |
9555 | 99 |
QPointF putSomeConstraints(const QPointF & initialPoint, const QPointF & point); |
4423 | 100 |
}; |
101 |
||
102 |
#endif // DRAWMAPSCENE_H |