all repos — openbox @ 0680daeef57748af17e0462def4852d408a62eb6

openbox fork - make it a bit more like ryudo

otk/button.cc (raw)

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
#include "button.hh"

namespace otk {

OtkButton::OtkButton(OtkWidget *parent)
  : OtkFocusWidget(parent), _text(""), _pressed(false), _dirty(false),
    _pressed_focus_tx(0), _pressed_unfocus_tx(0), _unpr_focus_tx(0),
    _unpr_unfocus_tx(0)
{
  setTexture(getStyle()->getButtonFocus());
  setUnfocusTexture(getStyle()->getButtonUnfocus());
  _pressed_focus_tx = getStyle()->getButtonPressedFocus();
  _pressed_unfocus_tx = getStyle()->getButtonPressedUnfocus();
}

OtkButton::~OtkButton()
{
  if (_pressed_focus_tx) delete _pressed_focus_tx;
  if (_pressed_unfocus_tx) delete _pressed_unfocus_tx;
}

void OtkButton::press(void)
{
  if (_pressed_focus_tx)
    OtkFocusWidget::setTexture(_pressed_focus_tx);
  if (_pressed_unfocus_tx)
    OtkFocusWidget::setUnfocusTexture(_pressed_unfocus_tx);
  _pressed = true;
}

void OtkButton::release(void)
{
  OtkFocusWidget::setTexture(_unpr_focus_tx);
  OtkFocusWidget::setUnfocusTexture(_unpr_unfocus_tx);
  _pressed = false;
}

void OtkButton::setTexture(BTexture *texture)
{
  OtkFocusWidget::setTexture(texture);
  _unpr_focus_tx = texture;
}

void OtkButton::setUnfocusTexture(BTexture *texture)
{
  OtkFocusWidget::setUnfocusTexture(texture);
  _unpr_unfocus_tx = texture;
}

void OtkButton::update(void)
{
  if (_dirty) {
    const BFont ft = getStyle()->getFont();
    BColor *text_color = (isFocused() ? getStyle()->getTextFocus()
                          : getStyle()->getTextUnfocus());
    unsigned int bevel = getStyle()->getBevelWidth();

    OtkFocusWidget::resize(ft.measureString(_text) + bevel * 2,
                           ft.height() + bevel * 2);
    OtkFocusWidget::update();

    ft.drawString(getWindow(), bevel, bevel, *text_color, _text);
  } else
    OtkFocusWidget::update();

  _dirty = false;
}

int OtkButton::exposeHandler(const XExposeEvent &e)
{
  _dirty = true;
  return OtkFocusWidget::exposeHandler(e);
}

int OtkButton::configureHandler(const XConfigureEvent &e)
{
  if (!(e.width == width() && e.height == height()))
    _dirty = true;
  return OtkFocusWidget::configureHandler(e);
}

}