summaryrefslogtreecommitdiff
path: root/src/interface/Checkbox.cpp
blob: 324455255368b19bf2a1557e391e9730c79deb29 (plain)
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
/*
 * Checkbox.cpp
 *
 *  Created on: Jan 26, 2012
 *      Author: Simon
 */

#include "Checkbox.h"

using namespace ui;

Checkbox::Checkbox(ui::Point position, ui::Point size, std::string text):
	Component(position, size),
	text(text),
	isMouseOver(false),
	checked(false),
	actionCallback(NULL)
{
	// TODO Auto-generated constructor stub

}

void Checkbox::SetText(std::string text)
{
	this->text = text;
}

void Checkbox::OnMouseClick(int x, int y, unsigned int button)
{
	if(checked)
	{
		checked = false;
	}
	else
	{
		checked = true;
	}
	if(actionCallback)
		actionCallback->ActionCallback(this);
}

void Checkbox::OnMouseUp(int x, int y, unsigned int button)
{

}


void Checkbox::OnMouseEnter(int x, int y)
{
	isMouseOver = true;
}

void Checkbox::OnMouseLeave(int x, int y)
{
	isMouseOver = false;
}

void Checkbox::Draw(const Point& screenPos)
{
	Graphics * g = Engine::Ref().g;
	if(checked)
	{
		g->fillrect(screenPos.X+4, screenPos.Y+4, 8, 8, 255, 255, 255, 255);
	}
	if(isMouseOver)
	{
		g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 255);
		g->fillrect(screenPos.X+4, screenPos.Y+4, 8, 8, 255, 255, 255, 170);
		g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 255);
	}
	else
	{
		g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 200);
		g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 200);
	}
}

void Checkbox::SetActionCallback(CheckboxAction * action)
{
	if(actionCallback)
		delete actionCallback;
	actionCallback = action;
}

Checkbox::~Checkbox() {
	if(actionCallback)
		delete actionCallback;
}