-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorPicker.cpp
306 lines (245 loc) · 8.85 KB
/
ColorPicker.cpp
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
/*
* File: ColorPicker.cpp
* Author: scribble
*
* Created on March 25, 2013, 4:42 AM
*/
#include "ColorPicker.h"
#include "ScreenInterpreter.h"
#include "Menu.h"
ColorPicker::ColorPicker() {
}
ColorPicker::ColorPicker(const ColorPicker& orig) {
}
ColorPicker::~ColorPicker() {
for (uint i = 0; i < buttonArray->size(); i++) {
delete buttonArray->at(i);
}
buttonArray->clear();
delete buttonArray;
}
ColorPicker::ColorPicker(int _x, int _y, int _width, int _height) : Picker(_x, _y, _width, _height) {
buttonArray = new std::vector<PickerButton *>;
for (int i = 0; i < 10; ++i) {
int type;
int action;
int btnx;
int btny;
int btnw = 40;
int btnh = 40;
std::string buttonImage;
switch (i) {
case 0:
type = MOMENTARY;
action = BLACK_BUTTON;
buttonImage = "BlackButton.png";
btnx = _x + (9 + (btnw + 8) * i);
btny = _y + 21;
break;
case 1:
type = MOMENTARY;
action = WHITE_BUTTON;
buttonImage = "WhiteButton.png";
btnx = _x + (9 + (btnw + 8) * i);
btny = _y + 21;
break;
case 2:
type = MOMENTARY;
action = GRAY_BUTTON;
buttonImage = "GrayButton.png";
btnx = _x + (9 + (btnw + 8) * i);
btny = _y + 21;
break;
case 3:
type = MOMENTARY;
action = BLUE_BUTTON;
buttonImage = "BlueButton.png";
btnx = _x + (9 + (btnw + 8) * i);
btny = _y + 21;
break;
case 4:
type = MOMENTARY;
action = GREEN_BUTTON;
buttonImage = "GreenButton.png";
btnx = _x + (9 + (btnw + 8) * i);
btny = _y + 21;
break;
case 5:
type = MOMENTARY;
action = INDIGO_BUTTON;
buttonImage = "IndigoButton.png";
btnx = _x + (9 + (btnw + 8) * (i - 5));
btny = _y + 70;
break;
case 6:
type = MOMENTARY;
action = ORANGE_BUTTON;
buttonImage = "OrangeButton.png";
btnx = _x + (9 + (btnw + 8) * (i - 5));
btny = _y + 70;
break;
case 7:
type = MOMENTARY;
action = RED_BUTTON;
buttonImage = "RedButton.png";
btnx = _x + (9 + (btnw + 8) * (i - 5));
btny = _y + 70;
break;
case 8:
type = MOMENTARY;
action = VIOLET_BUTTON;
buttonImage = "VioletButton.png";
btnx = _x + (9 + (btnw + 8) * (i - 5));
btny = _y + 70;
break;
case 9:
type = MOMENTARY;
action = YELLOW_BUTTON;
buttonImage = "YellowButton.png";
btnx = _x + (9 + (btnw + 8) * (i - 5));
btny = _y + 70;
break;
default:
type = MOMENTARY;
action = NULL;
buttonImage = "";
break;
}
std::string imagePath;
if (buttonImage != "") {
imagePath = buttonImage.insert(0, IMAGE_PATH);
} else {
imagePath = "";
}
PickerButton *btn = new PickerButton(btnx, btny, btnw, btnh, type, action, NULL, NULL, NULL, NULL, imagePath);
buttonArray->push_back(btn);
}
}
void ColorPicker::setScreenInterpreter(ScreenInterpreter *s) {
screenInterpreter = s;
}
std::vector<PickerButton *> *ColorPicker::getButtonArray() {
return buttonArray;
}
void ColorPicker::screenPressEvent(Point* point) {
//if point is NULL return, nothing to do
if (point == NULL) {
return;
}
if (pointInsideArea(point) != 1) {
//release picker
screenInterpreter->showColorPicker(0);
}
else {
for (int i = 0; i < buttonArray->size(); ++i) {
if (buttonArray->at(i)->pointInsideArea(point) == 1) {
switch (buttonArray->at(i)->getMode()) {
case MOMENTARY:
callAction(buttonArray->at(i)->getAction());
break;
case TOGGLE:
callAction(buttonArray->at(i)->getAction());
break;
case PICKER:
break;
default:
break;
}
}
}
}
delete point;
point = NULL;
}
/*! Screen Move Event
*
* \param *point A pointer to a Point object
*
* This function draws a line between a last point and the new point in Write mode or tries to delete a path on which the point passes through in Erase mode
*/
void ColorPicker::screenMoveEvent(Point* point) {
/*if ( point == NULL )
{
return;
}
if ( scribbling == true )
{
pathsLock.lock();
lockForTempPath.lock();
mTempPath->addPoint(point);
lockForTempPath.unlock();
pathsLock.unlock();
}
//Here we can add more else if to enhance user experience by changing the color of the pressed button.
else
{
delete point;
point = NULL;
}*/
}
/*! Screen Release Event
*
* This function disables scribbling and informs the ScribbleArea that nothing is touching the screen anymore
*/
void ColorPicker::screenReleaseEvent(/*Points *point*/) {
}
void ColorPicker::callAction(int action) {
std::string _image;
switch (action) {
case BLACK_BUTTON:
_image = "Color_Black.png";
screenInterpreter->getMenu()->getButtonArray()->at(6)->setImagePath(_image.insert(0, IMAGE_PATH));
screenInterpreter->getScribbleArea()->setPenColor(Color(PALETTE_BLACK));
break;
case WHITE_BUTTON:
_image = "Color_White.png";
screenInterpreter->getMenu()->getButtonArray()->at(6)->setImagePath(_image.insert(0, IMAGE_PATH));
screenInterpreter->getScribbleArea()->setPenColor(Color(PALETTE_WHITE));
break;
case GRAY_BUTTON:
_image = "Color_Gray.png";
screenInterpreter->getMenu()->getButtonArray()->at(6)->setImagePath(_image.insert(0, IMAGE_PATH));
screenInterpreter->getScribbleArea()->setPenColor(Color(PALETTE_GRAY));
break;
case BLUE_BUTTON:
_image = "Color_Blue.png";
screenInterpreter->getMenu()->getButtonArray()->at(6)->setImagePath(_image.insert(0, IMAGE_PATH));
screenInterpreter->getScribbleArea()->setPenColor(Color(PALETTE_BLUE));
break;
case GREEN_BUTTON:
_image = "Color_Green.png";
screenInterpreter->getMenu()->getButtonArray()->at(6)->setImagePath(_image.insert(0, IMAGE_PATH));
screenInterpreter->getScribbleArea()->setPenColor(Color(PALETTE_GREEN));
break;
case INDIGO_BUTTON:
_image = "Color_Indigo.png";
screenInterpreter->getMenu()->getButtonArray()->at(6)->setImagePath(_image.insert(0, IMAGE_PATH));
screenInterpreter->getScribbleArea()->setPenColor(Color(PALETTE_INDIGO));
break;
case ORANGE_BUTTON:
_image = "Color_Orange.png";
screenInterpreter->getMenu()->getButtonArray()->at(6)->setImagePath(_image.insert(0, IMAGE_PATH));
screenInterpreter->getScribbleArea()->setPenColor(Color(PALETTE_ORANGE));
break;
case RED_BUTTON:
_image = "Color_Red.png";
screenInterpreter->getMenu()->getButtonArray()->at(6)->setImagePath(_image.insert(0, IMAGE_PATH));
screenInterpreter->getScribbleArea()->setPenColor(Color(PALETTE_RED));
break;
case VIOLET_BUTTON:
_image = "Color_Violet.png";
screenInterpreter->getMenu()->getButtonArray()->at(6)->setImagePath(_image.insert(0, IMAGE_PATH));
screenInterpreter->getScribbleArea()->setPenColor(Color(PALETTE_VIOLET));
break;
case YELLOW_BUTTON:
_image = "Color_Yellow.png";
screenInterpreter->getMenu()->getButtonArray()->at(6)->setImagePath(_image.insert(0, IMAGE_PATH));
screenInterpreter->getScribbleArea()->setPenColor(Color(PALETTE_YELLOW));
break;
default:
_image = "Color_Black.png";
screenInterpreter->getMenu()->getButtonArray()->at(6)->setImagePath(_image.insert(0, IMAGE_PATH));
screenInterpreter->getScribbleArea()->setPenColor(Color(PALETTE_BLACK));
break;
}
}