-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.cpp
More file actions
45 lines (39 loc) · 902 Bytes
/
Button.cpp
File metadata and controls
45 lines (39 loc) · 902 Bytes
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
#include "Button.h"
//#include <iostream>
Button::Button(Rect _pos, const Text& _text, Point _text_pos) :text(_text)
{
pos = _pos;
texture[0] = LoadTexture("img//button//button1.bmp");
texture[1] = LoadTexture("img//button//button2.bmp");
texture[2] = LoadTexture("img//button//button3.bmp");
text_pos = Point(pos.lx, pos.ly) + _text_pos;
state = 0;
}
void Button::SetText(const Text& _text)
{
text = _text;
}
void Button::Draw()
{
DrawTexture(pos, texture[state]);
DrawString(text, text_pos + (state == 2 ? Point(5, 5) : Point()));
}
void Button::OnMouse(Point u)
{
//std::cerr << "(" << u.x << "," << u.y << ")" << std::endl;
if (state != 2)
{
if (pos.inRect(u))
state = 1;
else
state = 0;
}
}
bool Button::OnClick(Point u, int mouse_state)
{
if (pos.inRect(u) && mouse_state == GLUT_DOWN)
state = 2;
if (mouse_state == GLUT_UP)
state = 0;
return pos.inRect(u);
}