-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpm_checkbox.h
150 lines (122 loc) · 3.23 KB
/
pm_checkbox.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
/*
* File : pm_checkbox.h
* COPYRIGHT (C) 2012-2017, Shanghai Real-Thread Technology Co., Ltd
*
* Change Logs:
* Date Author Notes
* 2017-11-05 realthread the first version
*/
#pragma once
#include <vector>
#include <pm_container.h>
#include <pm_image.h>
#include "sigslot.h"
namespace Persimmon
{
class Checkbox : public Widget
{
public:
Checkbox(const Rect& rect);
virtual ~Checkbox();
bool isSelected(void) //whether or not selected
{
return selected;
}
void enableSelected(bool sel = true) //is selected
{
selected = sel;
}
void setSelectedImg(Image *image)
{
if (selectedImg)
delete selectedImg;
selectedImg = NULL;
if (image)
selectedImg = image;
}
Image *getSelectedImg(void)
{
return selectedImg;
}
void setNormalImg(Image *image)
{
if (normalImg)
delete normalImg;
normalImg = NULL;
if (image)
normalImg = image;
}
Image *getNormalImg(void)
{
return normalImg;
}
void setCheckboxNum(int num) //Set checkbox number
{
checkboxNum = num;
}
int getCheckboxNum(void) //Get checkbox number
{
return checkboxNum;
}
Signal<int, bool> clicked; //Event transfer
virtual bool handleGestureEvent(struct rtgui_event_gesture *, const struct rtgui_gesture *); //Touch gesture event
virtual void render(struct rtgui_dc* dc, const Point &dcPoint = Point(),
const Rect &srcRect = Rect(),
RenderFlag flags = DrawNormal);
private:
Image *selectedImg, *normalImg;
bool selected; //State
int checkboxNum; //Number
};
class GroupBox : public Container
{
public:
GroupBox(const Rect& rect);
virtual ~GroupBox();
virtual void handleClicked(int num, bool sel)
{
if (sel == true)
{
if (selCheckboxNum != num)
{
this->checkbox[selCheckboxNum]->enableSelected(false);
this->checkbox[selCheckboxNum]->refresh();
selCheckboxNum = num;
clicked(selCheckboxNum);
}
}
else
{
this->checkbox[selCheckboxNum]->enableSelected(true);
this->checkbox[selCheckboxNum]->refresh();
}
}
void addCheckbox(Checkbox* widget)
{
if (widget != NULL)
{
this->checkbox.push_back(widget);
widget->setCheckboxNum(this->checkbox.size() - 1);
widget->clicked.connect(this, &GroupBox::handleClicked);
this->addChild(widget);
}
}
void selectCheckbox(int num = 0)
{
if (selCheckboxNum != num)
this->checkbox[selCheckboxNum]->enableSelected(false);
this->checkbox[selCheckboxNum]->refresh();
selCheckboxNum = num;
this->checkbox[selCheckboxNum]->enableSelected();
this->checkbox[selCheckboxNum]->refresh();
}
int getselectNum(void)
{
return selCheckboxNum;
}
Signal<int> clicked;
private:
std::vector<Checkbox*> checkbox;
int selCheckboxNum;
};
}