-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpadgui.h
141 lines (108 loc) · 3.24 KB
/
padgui.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#ifndef PADGUI_H
#define PADGUI_H
#include <vector>
#include <QQuickPaintedItem>
#include <QPainter>
#include "orb.h"
#include "combo.h"
#include "board.h"
#include "solver.h"
#include "solvestate.h"
#include "combothread.h"
#include "solvethread.h"
class PadGUI : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(int mouseX READ mouseX WRITE setMouseX NOTIFY mouseXChanged)
Q_PROPERTY(int mouseY READ mouseY WRITE setMouseY NOTIFY mouseYChanged)
Q_PROPERTY(bool mouseDown READ mouseDown WRITE setMouseDown NOTIFY mouseDownChanged)
Q_PROPERTY(int comboCount READ comboCount WRITE setComboCount NOTIFY comboCountChanged)
Q_PROPERTY(int movesCount READ movesCount WRITE setMovesCount NOTIFY movesCountChanged)
Q_PROPERTY(bool showPath READ showPath WRITE setShowPath NOTIFY showPathChanged)
Q_PROPERTY(bool loading READ loading WRITE setLoading NOTIFY loadingChanged)
public:
PadGUI(QQuickItem *parent = Q_NULLPTR);
void paint(QPainter *painter);
int mouseX();
int mouseY();
bool mouseDown();
void setMouseX(int mx);
void setMouseY(int my);
void setMouseDown(bool md);
int comboCount();
int movesCount();
void setComboCount(int n);
void setMovesCount(int n);
bool showPath();
bool loading();
void setShowPath(bool show);
void setLoading(bool load);
signals:
void mouseXChanged();
void mouseYChanged();
void mouseDownChanged(bool);
void comboCountChanged();
void movesCountChanged();
void showPathChanged();
void loadingChanged();
void repaintSignal();
void resetSignal();
public slots:
// these are called when the buttons are clicked
void resetBoard();
void newBoard();
// when combo thread finishes
void combosFinished();
// when solve thread finishes
void solveFinished();
// when mouse leaves the puzzle
void mouseExited();
private:
// thread for doing combos
ComboThread comboThread;
SolveThread solveThread;
// possible states
enum State {
SOLVING,
WAITING,
CLICKED,
MOVING,
COMBOING,
FINISHED
};
// the actual board
Board board;
Board originalBoard;
SolveState solution;
std::vector<Combo> solutionCombos;
// mouse status
int m_mouseX;
int m_mouseY;
bool m_mouseDown;
// solution status
int m_comboCount;
int m_movesCount;
// path status
bool m_showPath;
bool m_loading;
// board status
int orbX;
int orbY;
orb selectedOrb;
enum State state;
QPixmap getOrbImage(int color);
// painting helper functions
void paintHighlight(QPainter *painter, int x, int y);
void paintPath(QPainter *painter);
void findComboCount();
void runSolver();
void handleMouseMotion();
void handleMouseClick(bool type);
// convert mouse location to orb location, writing result with pointers
// return whether the new location is different than orbX, orbY
// box version is literal grid box
// circle version checks inscribed circle and allows for diagonal motion
bool mouseToOrbBox(int mx, int my, int *orbx, int *orby);
bool mouseToOrbCircle(int mx, int my, int *orbx, int *orby);
};
#endif // PADGUI_H