-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPushButton.cpp
53 lines (40 loc) · 1.03 KB
/
PushButton.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
#include "PushButton.h"
PushButton::PushButton(const string& text, int mX, int mY, int mW, int mH) : BasicWidget(mX, mY, mW, mH), text(text) {}
void PushButton::show() {
//set color
setfillcolor(RGB(232, 232, 236));
::fillroundrect(m_x, m_y, m_x + m_w, m_y + m_h,10,10);
//set the color of font
settextcolor(RED);
int xx = m_x + (m_w - textwidth(text.c_str())) / 2;
int yy = m_y + (m_h - textheight(text.c_str())) / 2;
//put the title in center
::outtextxy(xx, yy, text.c_str());
//cout << getText() << endl;
}
string PushButton::getText()
{
return text;
}
bool PushButton::isOn()
{
if (M_Msg.x >= m_x && M_Msg.x <= m_x + m_w && M_Msg.y >= m_y && M_Msg.y <= m_y + m_h) {
return true;
}
return false;
}
bool PushButton::isClicked()
{
//check if is on
if (isOn()) {
//if is clicked
if (M_Msg.message == WM_LBUTTONDOWN) {
return true;
}
}
return false;
}
void PushButton::eventLoop(const ExMessage& msg)
{
M_Msg = msg;
}