-
Notifications
You must be signed in to change notification settings - Fork 1
/
sprite.h
317 lines (281 loc) · 8.87 KB
/
sprite.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#ifndef SPRITE_H
#define SPRITE_H
#include <QGraphicsWidget>
#include <QGraphicsScene>
#include <QGraphicsItem>
#include <QPainter>
#include <QList>
#include <QGraphicsSceneMouseEvent>
#include <QJsonObject>
#include <QJsonArray>
#include <QColor>
#include <QSettings>
enum BUTTONS {TRANSPARENT, COLOR, MC1, MC2, OVERLAY_COLOR, OVERLAY_TRANSPARENT };
class SpriteView;
class Sprite;
struct options {
int left_button = BUTTONS::COLOR;
int right_button = BUTTONS::TRANSPARENT;
QJsonObject data;
int selection_from = 0;
int selection_to = 0;
QList<Sprite*> sprite_list;
SpriteView *spriteview;
bool show_grid_lines = true;
bool show_numbers = false;
//auto export
QString last_exported_file;
int export_address = 0x3000;
int export_file_format;
int export_attribute_format;
//auto save
QString last_saved_file;
//hashquestion
QByteArray last_hash;
//
QList<QJsonObject> undoDB;
//QColor background = QColor(0xd9,0xd6,0xc8);
//QColor selection_color = QColor(0x00,0xff,0x00);
//int sprite_spacing_x = 30;
//int sprite_spacing_y = 30;
//int sprites_per_row = 4;
QStringList col_names = {"Black","White","Red","Cyan","Purple","Green","Blue","Yellow","Orange","Brown",
"Pink", "Dark Grey", "Grey","Light Green","Light Blue","Light Grey"};
QList<QColor> col_list = { QColor(0,0,0),
QColor(255,255,255),
QColor(0x92,0x4a,0x40),
QColor(0x84,0xc5,0xcc),
QColor(0x93,0x51,0xb6),
QColor(0x72,0xb1,0x4b),
QColor(0x48,0x3a,0xaa),
QColor(0xd5,0xdf,0x7c),
QColor(0x99,0x69,0x2d),
QColor(0x67,0x52,0x00),
QColor(0xc1,0x81,0x7a),
QColor(0x60,0x60,0x60),
QColor(0x8a,0x8a,0x8a),
QColor(0xb3,0xec,0x91),
QColor(0x86,0x7a,0xde),
QColor(0xb3,0xb3,0xb3)};
};
class Sprite : public QGraphicsItem
{
public:
Sprite(options *opt, int id);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
QRectF boundingRect() const override;
void change_tile(QPointF pos);
void mousePressEvent(QGraphicsSceneMouseEvent *ev) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *ev) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *ev) override;
bool get_bit(int x, int y);
void set_bit(int x, int y, bool value);
void slide_up(){
bool tmp[24];
for (int x = 0; x < 24; x++)
tmp[x] = this->get_bit(x,0);
for (int y = 0; y < 20; y++)
{
for (int x = 0; x < 24; x++)
{
this->set_bit(x,y, this->get_bit(x,y+1));
}
}
for (int x = 0; x < 24; x++)
this->set_bit(x,20, tmp[x]);
}
void slide_down(){
bool tmp[24];
for (int x = 0; x < 24; x++)
tmp[x] = this->get_bit(x,20);
for (int y = 20; y > 0; y--)
{
for (int x = 0; x < 24; x++)
{
this->set_bit(x,y, this->get_bit(x,y-1));
}
}
for (int x = 0; x < 24; x++)
this->set_bit(x,0, tmp[x]);
}
void slide_left(){
bool tmp[21];
for (int y = 0; y < 21; y++)
tmp[y] = this->get_bit(0,y);
for (int x = 0; x < 23; x++)
{
for (int y = 0; y < 21; y++)
{
this->set_bit(x,y, this->get_bit(x+1,y));
}
}
for (int y = 0; y < 21; y++)
this->set_bit(23,y, tmp[y]);
}
void slide_right(){
bool tmp[21];
for (int y = 0; y < 21; y++)
tmp[y] = this->get_bit(23,y);
for (int x = 23; x > 0; x--)
{
for (int y = 0; y < 21; y++)
{
this->set_bit(x,y, this->get_bit(x-1,y));
}
}
for (int y = 0; y < 21; y++)
this->set_bit(0,y, tmp[y]);
}
void flip_left()
{
bool tmp, tmp2;
if (this->opt->data.value("sprites").toArray().at(id).toObject().value("mc_mode").toBool())
{
for (int x = 0; x < 6; x++)
{
for (int y = 0; y < 21; y++)
{
tmp = this->get_bit(2*x,y);
tmp2 = this->get_bit(2*x+1,y);
this->set_bit(2*x+1,y, this->get_bit(23-2*x,y));
this->set_bit(2*x,y, this->get_bit(23-2*x-1,y));
this->set_bit(23-2*x,y,tmp2);
this->set_bit(23-2*x-1,y,tmp);
}
}
}
else
{
for (int x = 0; x < 12; x++)
{
for (int y = 0; y < 21; y++)
{
tmp = this->get_bit(x,y);
this->set_bit(x,y, this->get_bit(23-x,y));
this->set_bit(23-x,y,tmp);
}
}
}
}
void flip_top()
{
bool tmp;
for (int y = 0; y < 10; y++)
{
for (int x = 0; x < 24; x++)
{
tmp = this->get_bit(x,y);
this->set_bit(x,y, this->get_bit(x,20-y));
this->set_bit(x,20-y,tmp);
}
}
}
void reflect_top()
{
for (int y = 11; y <= 20; y++)
{
for (int x = 0; x < 24; x++)
{
this->set_bit(x,y, this->get_bit(x,20-y));
}
}
}
void reflect_left()
{
if (this->opt->data.value("sprites").toArray().at(id).toObject().value("mc_mode").toBool())
{
for (int x = 6; x < 12; x++)
{
for (int y = 0; y < 21; y++)
{
this->set_bit(2*x+1,y, this->get_bit(23-2*x,y));
this->set_bit(2*x,y, this->get_bit(23-2*x-1,y));
}
}
}
else
{
for (int x = 12; x <= 23; x++)
{
for (int y = 0; y < 21; y++)
{
this->set_bit(x,y, this->get_bit(23-x,y));
}
}
}
}
void switch_col_to_mc1()
{
if (this->opt->data.value("sprites").toArray().at(id).toObject().value("mc_mode").toBool())
{
for (int x = 0; x < 12; x++)
{
for (int y = 0; y < 21; y++)
{
if (this->get_bit(2*x,y) && !this->get_bit(2*x+1,y))
{
this->set_bit(2*x,y, false);
this->set_bit(2*x+1,y, true);
}
else if (!this->get_bit(2*x,y) && this->get_bit(2*x+1,y))
{
this->set_bit(2*x,y, true);
this->set_bit(2*x+1,y, false);
}
}
}
}
}
void switch_col_to_mc2()
{
if (this->opt->data.value("sprites").toArray().at(id).toObject().value("mc_mode").toBool())
{
for (int x = 0; x < 12; x++)
{
for (int y = 0; y < 21; y++)
{
if (this->get_bit(2*x,y) && !this->get_bit(2*x+1,y))
{
this->set_bit(2*x,y, true);
this->set_bit(2*x+1,y, true);
}
else if (this->get_bit(2*x,y) && this->get_bit(2*x+1,y))
{
this->set_bit(2*x,y, true);
this->set_bit(2*x+1,y, false);
}
}
}
}
}
void switch_mc1_to_mc2()
{
if (this->opt->data.value("sprites").toArray().at(id).toObject().value("mc_mode").toBool())
{
for (int x = 0; x < 12; x++)
{
for (int y = 0; y < 21; y++)
{
if (this->get_bit(2*x,y) && this->get_bit(2*x+1,y))
{
this->set_bit(2*x,y, false);
this->set_bit(2*x+1,y, true);
}
else if (!this->get_bit(2*x,y) && this->get_bit(2*x+1,y))
{
this->set_bit(2*x,y, true);
this->set_bit(2*x+1,y, true);
}
}
}
}
}
private:
int id;
bool overlay_next = false;
bool left_pressed = false;
bool right_pressed = false;
QSettings settings;
options *opt;
};
#endif // SPRITE_H