blob: e7340d1b875a2452df2bc5614c61d164a3a7a1a5 (
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
|
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifdef HAVE_CONFIG_H
# include "../config.h"
#endif
#include "button.hh"
namespace otk {
Button::Button(Widget *parent)
: FocusLabel(parent), _pressed(false), _pressed_focus_tx(0),
_pressed_unfocus_tx(0), _unpr_focus_tx(0), _unpr_unfocus_tx(0)
{
}
Button::~Button()
{
}
void Button::setStyle(RenderStyle *style)
{
FocusLabel::setStyle(style);
setTexture(style->buttonUnpressFocusBackground());
setUnfocusTexture(style->buttonUnpressUnfocusBackground());
_pressed_focus_tx = style->buttonPressFocusBackground();
_pressed_unfocus_tx = style->buttonPressUnfocusBackground();
}
void Button::press(unsigned int mouse_button)
{
if (_pressed) return;
if (_pressed_focus_tx)
FocusWidget::setTexture(_pressed_focus_tx);
if (_pressed_unfocus_tx)
FocusWidget::setUnfocusTexture(_pressed_unfocus_tx);
_pressed = true;
_mouse_button = mouse_button;
}
void Button::release(unsigned int mouse_button)
{
if (_mouse_button != mouse_button) return; // wrong button
FocusWidget::setTexture(_unpr_focus_tx);
FocusWidget::setUnfocusTexture(_unpr_unfocus_tx);
_pressed = false;
}
void Button::setTexture(RenderTexture *texture)
{
FocusWidget::setTexture(texture);
_unpr_focus_tx = texture;
}
void Button::setUnfocusTexture(RenderTexture *texture)
{
FocusWidget::setUnfocusTexture(texture);
_unpr_unfocus_tx = texture;
}
void Button::buttonPressHandler(const XButtonEvent &e)
{
press(e.button);
update();
FocusWidget::buttonPressHandler(e);
}
void Button::buttonReleaseHandler(const XButtonEvent &e)
{
release(e.button);
update();
FocusWidget::buttonReleaseHandler(e);
}
}
|