-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgoboard.h
More file actions
154 lines (136 loc) · 4.46 KB
/
goboard.h
File metadata and controls
154 lines (136 loc) · 4.46 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef GOBOARD_H
#define GOBOARD_H
#include <QtCore>
#include <QtGui>
#include <QGraphicsView>
#include <QGraphicsTextItem>
#include <QGraphicsPixmapItem>
#include <QPixmap>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include <QDebug>
#include <QSound>
#include <map>
#include "highlight.h"
#define GO_BOARD_SIZE 1207
#define GO_GRID_SIZE 1007
#define GO_BORDER_SIZE (GO_BOARD_SIZE - GO_GRID_SIZE) /2
class GoBoard: public QGraphicsView
{
Q_OBJECT
public:
Highlight *highlight;
qreal pixelScale; //intended to scale for HDPI monitor. Not certain it is correct.
GoBoard(QWidget *parent);
~GoBoard();
bool isOnBoard(qreal i, qreal j);
bool isOnBoard(QPointF j);
enum MarkerMarks{
MarkEllipse,
MarkRect,
MarkRoundedRect
};
void dragonStones(QVector<QString> dragons);
void wormStones(QVector<QString> worms);
float randy(float max=255.0, float min=0.0);
QVector<QPen> makePenSet(int count, QPen example );
QVector<QPen> makePenSet(int count, QPen example, QVector<QColor> colors);
void showDragonLike(QVector<QString> stones,
QString name,
QVector<QPen> pens,
bool do_lines=true,
MarkerMarks mark_type=MarkEllipse
);
void drawBoard();
void clearAllMarkers();
QPointF alphaNumToPos(QString alphanum);
QString posToAlphaNum(QPointF point);
bool hasStone(QString location);
void clearBoard();
void removeMarkers(QString name);
void readSettings();
//Unfortunately, these won't compensate for pen width because pixmaps don't have pens.
//Why pen width isn't included is a mystery to me. So is the lack of constructors that
//would place symmetrical objects by their centres.
template <class T> void center(T* item){
item->setPos( item->pos().rx()-(item->sceneBoundingRect().width()/2.0), item->pos().ry()-(item->sceneBoundingRect().height()/2.0));
}
template <class T> void center(T* item, QPointF p){
item->setPos( p.rx()-(item->sceneBoundingRect().width()/2.0),
p.ry()-(item->sceneBoundingRect().height()/2.0)
);
}
template <class T> void center(T* item, qreal x, qreal y){
item->setPos( x-(item->sceneBoundingRect().width()/2.0), y-(item->sceneBoundingRect().height()/2.0));
}
QGraphicsItemGroup *gig;
QMap<QString, QGraphicsItemGroup*> markers;
QSettings config;
//vars
enum PseudoCursorData{
HALF_SIZE,
REAL_POS
};
QCursor cursor;
enum StoneColors {
Black,
White,
Blank
};
enum StoneData {
STONE_DATA_COLOR,
STONE_DATA_VERTEX
};
struct Stone {
QGraphicsPixmapItem* stone;
StoneColors color;
void setColor(QString c){
c = c.trimmed().toLower();
if(c == "white"){
color = White;
}else if( c=="black"){
color = Black;
}else{
color = Blank;
}
}
QString getColorText(StoneColors c ){
if(c == Black ) return "black";
if(c == Blank ) return "blank";
if(c == White ) return "white";
return "unknown";
}
QString getStoneColor(){ return getColorText(color); }
};
//std::map<QString, Stone> stoneHouse;
QMap<QString, Stone> stoneHouse;
int boardSize = 9;
qreal gridSizePixels = 0.0;
QString playerColor="black";
QBrush bgBrush;
QBrush redBrush;
QPen redPen;
QGraphicsScene* scene;
QGraphicsTextItem *text;
QPixmap blackStonePM;
QPixmap blackStoneCursorPM;
QPixmap whiteStoneCursorPM;
QPixmap whiteStonePM;
QPixmap backgroundPM;
QGraphicsPixmapItem* boardBackground;
QGraphicsPixmapItem* pseudoCursor;
void finalStatusList(QVector<QString> verticies, QString type);
public slots:
void placeStone(QString color, QString location);
void removeStone(QString location);
void checkStones(QString color, QStringList verticies);
void showTopMoves(const QString color, QStringList verticies);
signals:
//void boardLeftClicked(QString color, QString vertex);
void boardLeftClicked(QString vertex);//color kept track separately now
protected:
void resizeEvent(QResizeEvent *event);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
};
#endif // GOBOARD_H