-
Notifications
You must be signed in to change notification settings - Fork 5
/
button.cpp
68 lines (66 loc) · 1.42 KB
/
button.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "button.h"
#include "base/logging.h"
namespace gui
{
void button::draw(const s_int16 & x, const s_int16 & y, const gfx::drawing_area *da, gfx::surface *target) const
{
if (clicked) //have it drawn with the alternate image
{
Cache->set_offset (clickpush, clickpush);
Look->set_state("Activated");
label::draw(x, y, da, target);
}
else
{
Cache->set_offset (0, 0);
Look->set_state("Default");
label::draw(x, y, da, target);
}
}
bool button::keydown(input::keyboard_event& k)
{
if (!clicked && (k.key() == input::keyboard_event::SPACE_KEY || k.key() == input::keyboard_event::RETURN_KEY))
{
clicked = true;
downkey = k.key();
return true;
}
return false;
}
bool button::keyup(input::keyboard_event&k)
{
if (clicked && k.key() == downkey)
{
clicked = false;
activate();
return true;
}
return false;
}
//for if we have mouse support later
/*
bool button::mousedown(SDL_MouseButtonEvent & m)
{
LOG(INFO) << logging::indent() << "mouse down";
if (m.button == SDL_BUTTON_LEFT)
{
clicked = true;
downkey = SDLK_0;
return true;
}
return false;
}
bool button::mouseup(SDL_MouseButtonEvent & m)
{
LOG(INFO) << logging::indent() << "mouse up";
if (m.button == SDL_BUTTON_LEFT && clicked)
{
clicked = false;
if (m.x < w && m.y < h) //if within bounds, activate
activate();
return true;
}
return false;
}
// */
};