-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton_panel.cpp
151 lines (125 loc) · 4.08 KB
/
button_panel.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
/*********************************************************************************
ButtonPanel class
Build easily default buttons with different functionalities
@author: fenix
@email: franchuti688@gmail.com
GNU GENERAL PUBLIC LICENSE
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
*********************************************************************************/
#include "button_panel.h"
ButtonPanel::ButtonPanel()
{
tsPoint_t pos = {0,0};
tsPoint_t w_h = {150,50};
trian = new Button(pos, w_h, (char*)"Triangle", WHITE);
pos.y = pos.y + w_h.y + 10;
circ = new Button(pos, w_h, (char*)"Circle", WHITE);
pos.y = pos.y + w_h.y + 10;
rect = new Button(pos, w_h, (char*)"Rectangle", WHITE);
pos.y = pos.y + w_h.y + 10;
free = new Button(pos, w_h, (char*)"Free", WHITE);
pos.y = pos.y + w_h.y + 10;
free_random = new Button(pos, w_h, (char*)"Random", WHITE);
pos.y = pos.y + w_h.y + 10;
clear = new Button(pos, w_h, (char*)"Clear", WHITE);
width = w_h.x; height = w_h.y;
on_figure = ERROR;
color_free_random = WHITE;
}
ButtonPanel::~ButtonPanel(){}
void ButtonPanel::draw()
{
trian->draw();
circ->draw();
rect->draw();
free->draw();
free_random->draw();
clear->draw();
}
void ButtonPanel::OnTouch(tsPoint_t pos)
{
//Get position buttons
tsPoint_t trian_pos = trian->getPosition();
tsPoint_t circ_pos = circ->getPosition();
tsPoint_t rect_pos = rect->getPosition();
tsPoint_t free_pos = free->getPosition();
tsPoint_t free_random_pos = free_random->getPosition();
tsPoint_t clear_pos = clear->getPosition();
//Button pressed -> TRIANGLE
if (pos.x>=trian_pos.x && pos.x<=(trian_pos.x+width) &&
pos.y>=trian_pos.y && pos.y<=(trian_pos.y+height))
on_figure = ON_TRIAN;
//Button pressed -> CIRCLE
else if (pos.x>=circ_pos.x && pos.x<=(circ_pos.x+width) &&
pos.y>=circ_pos.y && pos.y<=(circ_pos.y+height))
on_figure = ON_CIRC;
//Button pressed -> RECTANGLE
else if (pos.x>=rect_pos.x && pos.x<=(rect_pos.x+width) &&
pos.y>=rect_pos.y && pos.y<=(rect_pos.y+height))
on_figure = ON_RECT;
//Button pressed -> FREE DRAWING
else if (pos.x>=free_pos.x && pos.x<=(free_pos.x+width) &&
pos.y>=free_pos.y && pos.y<=(free_pos.y+height))
on_figure = ON_FREE;
//Button pressed -> FREE DRAWING (random colors)
else if (pos.x>=free_random_pos.x && pos.x<=(free_random_pos.x+width) &&
pos.y>=free_random_pos.y && pos.y<=(free_random_pos.y+height))
{
on_figure = ON_FREE_RANDOM;
color_free_random = getRandomColor();
free_random->setColor(color_free_random);
free_random->draw();
}
//Button pressed -> CLEAR SCREEN
else if (pos.x>=clear_pos.x && pos.x<=(clear_pos.x+width) &&
pos.y>=clear_pos.y && pos.y<=(clear_pos.y+height))
on_figure = ON_CLEAR;
//Draw figures
OnDraw();
}
void ButtonPanel::OnDraw()
{
if (on_figure == ON_TRIAN)
{
Triangle triangle;
triangle.setRandomProperties();
triangle.draw();
}
else if (on_figure == ON_CIRC)
{
Circle circle;
circle.setRandomProperties();
circle.draw();
}
else if (on_figure == ON_RECT)
{
Rectangle rectangle;
rectangle.setRandomProperties();
rectangle.draw();
}
else if (on_figure == ON_CLEAR)
fillRect(width+1, 0, Adafruit_RA8875::width()-(width+2), Adafruit_RA8875::height()-1, BLACK);
}
void ButtonPanel::OnDrawFree(tsPoint_t pos)
{
if (on_figure == ON_FREE)
{
if (pos.x > (width+3))
fillCircle(pos.x, pos.y, 3, WHITE);
}
else if (on_figure == ON_FREE_RANDOM)
{
if (pos.x > (width+3))
fillCircle(pos.x, pos.y, 3, color_free_random);
}
}