summaryrefslogtreecommitdiff
path: root/src/game/ToolButton.cpp
blob: 27bbab6fa713f79973b3dba8d79342c6b6ccd542 (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
/*
 * ToolButton.cpp
 *
 *  Created on: Jan 30, 2012
 *      Author: Simon
 */

#include "ToolButton.h"
#include "interface/Keys.h"

ToolButton::ToolButton(ui::Point position, ui::Point size, std::string text_):
	ui::Button(position, size, text_)
{
	SetSelectionState(-1);
}

void ToolButton::OnMouseClick(int x, int y, unsigned int button)
{
    isButtonDown = true;
}

void ToolButton::OnMouseUp(int x, int y, unsigned int button)
{
	if(isButtonDown)
	{
		if(button == BUTTON_LEFT)
			SetSelectionState(0);
		if(button == BUTTON_RIGHT)
			SetSelectionState(1);
		if(button == BUTTON_MIDDLE)
			SetSelectionState(2);
		DoAction();
	}
	isButtonDown = false;
}

void ToolButton::Draw(const ui::Point& screenPos)
{
	Graphics * g = ui::Engine::Ref().g;
	int totalColour = background.Red + 3*background.Green + 2*background.Blue;

	g->fillrect(screenPos.X, screenPos.Y, Size.X, Size.Y, background.Red, background.Green, background.Blue, 255);

	if (totalColour<544)
	{
		g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, buttonDisplayText.c_str(), 255, 255, 255, 255);
	}
	else
	{
		g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, buttonDisplayText.c_str(), 0, 0, 0, 255);
	}
	if(currentSelection!=-1)
	{
		//g->fillrect(screenPos.X+1, screenPos.Y+1, Size.X-2, Size.Y-2, 255, 255, 255, 170);
		g->fillrect(screenPos.X+2, screenPos.Y+2, Size.Y-4, Size.Y-4, 0, 0, 0, 170);
		g->drawtext(screenPos.X+5, screenPos.Y+4, selectionText, 255, 255, 255, 255);
	}
}

void ToolButton::SetSelectionState(int state)
{
	currentSelection = state;
	switch(state)
	{
	case 0:
		selectionText = "L";
		break;
	case 1:
		selectionText = "R";
		break;
	case 2:
		selectionText = "M";
		break;
	default:
		selectionText = "";
		break;
	}
}

int ToolButton::GetSelectionState()
{
	return currentSelection;
}

ToolButton::~ToolButton() {
	// TODO Auto-generated destructor stub
}