1 #include "Checkbox.h"
2
3 #include "graphics/Graphics.h"
4
5 #include "gui/interface/Window.h"
6
7 using namespace ui;
8
Checkbox(ui::Point position,ui::Point size,String text,String toolTip)9 Checkbox::Checkbox(ui::Point position, ui::Point size, String text, String toolTip):
10 Component(position, size),
11 text(text),
12 toolTip(toolTip),
13 checked(false),
14 isMouseOver(false)
15 {
16
17 }
18
SetText(String text)19 void Checkbox::SetText(String text)
20 {
21 this->text = text;
22 }
23
GetText()24 String Checkbox::GetText()
25 {
26 return text;
27 }
28
SetIcon(Icon icon)29 void Checkbox::SetIcon(Icon icon)
30 {
31 Appearance.icon = icon;
32 iconPosition.X = 16;
33 iconPosition.Y = 3;
34 }
35
OnMouseClick(int x,int y,unsigned int button)36 void Checkbox::OnMouseClick(int x, int y, unsigned int button)
37 {
38 if(checked)
39 {
40 checked = false;
41 }
42 else
43 {
44 checked = true;
45 }
46 if (actionCallback.action)
47 actionCallback.action();
48 }
49
OnMouseUp(int x,int y,unsigned int button)50 void Checkbox::OnMouseUp(int x, int y, unsigned int button)
51 {
52
53 }
54
55
OnMouseEnter(int x,int y)56 void Checkbox::OnMouseEnter(int x, int y)
57 {
58 isMouseOver = true;
59 }
60
OnMouseHover(int x,int y)61 void Checkbox::OnMouseHover(int x, int y)
62 {
63 if(toolTip.length()>0 && GetParentWindow())
64 {
65 GetParentWindow()->ToolTip(Position, toolTip);
66 }
67 }
68
OnMouseLeave(int x,int y)69 void Checkbox::OnMouseLeave(int x, int y)
70 {
71 isMouseOver = false;
72 }
73
Draw(const Point & screenPos)74 void Checkbox::Draw(const Point& screenPos)
75 {
76 Graphics * g = GetGraphics();
77 if(checked)
78 {
79 g->fillrect(screenPos.X+5, screenPos.Y+5, 6, 6, 255, 255, 255, 255);
80 }
81 if(isMouseOver)
82 {
83 g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 255);
84 g->fillrect(screenPos.X+5, screenPos.Y+5, 6, 6, 255, 255, 255, 170);
85 if (!Appearance.icon)
86 g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 255);
87 else
88 g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon, 255);
89 }
90 else
91 {
92 g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 200);
93 if (!Appearance.icon)
94 g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 200);
95 else
96 g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon, 200);
97 }
98 }
99