openbox/otk/button.cc

82 lines
1.7 KiB
C++
Raw Normal View History

// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifdef HAVE_CONFIG_H
# include "../config.h"
#endif
2002-11-11 03:47:12 +00:00
#include "button.hh"
namespace otk {
Button::Button(Widget *parent)
: FocusLabel(parent), _pressed(false), _pressed_focus_tx(0),
2002-11-16 13:21:24 +00:00
_pressed_unfocus_tx(0), _unpr_focus_tx(0), _unpr_unfocus_tx(0)
2002-11-11 03:47:12 +00:00
{
setStyle(_style);
}
Button::~Button()
{
}
2003-01-22 22:46:16 +00:00
void Button::setStyle(RenderStyle *style)
{
FocusLabel::setStyle(style);
2003-01-20 06:11:12 +00:00
2003-01-22 22:46:16 +00:00
setTexture(style->buttonUnpressFocusBackground());
setUnfocusTexture(style->buttonUnpressUnfocusBackground());
_pressed_focus_tx = style->buttonPressFocusBackground();
_pressed_unfocus_tx = style->buttonPressUnfocusBackground();
2002-11-11 03:47:12 +00:00
}
void Button::press(unsigned int mouse_button)
2002-11-14 11:41:50 +00:00
{
2002-11-16 13:21:24 +00:00
if (_pressed) return;
2002-11-14 11:41:50 +00:00
if (_pressed_focus_tx)
FocusWidget::setTexture(_pressed_focus_tx);
2002-11-14 11:41:50 +00:00
if (_pressed_unfocus_tx)
FocusWidget::setUnfocusTexture(_pressed_unfocus_tx);
2002-11-14 11:41:50 +00:00
_pressed = true;
2002-11-16 13:21:24 +00:00
_mouse_button = mouse_button;
2002-11-11 03:47:12 +00:00
}
void Button::release(unsigned int mouse_button)
2002-11-11 03:47:12 +00:00
{
2002-11-16 13:21:24 +00:00
if (_mouse_button != mouse_button) return; // wrong button
FocusWidget::setTexture(_unpr_focus_tx);
FocusWidget::setUnfocusTexture(_unpr_unfocus_tx);
2002-11-14 11:41:50 +00:00
_pressed = false;
2002-11-11 03:47:12 +00:00
}
2003-01-20 06:11:12 +00:00
void Button::setTexture(RenderTexture *texture)
2002-11-11 03:47:12 +00:00
{
FocusWidget::setTexture(texture);
2002-11-14 11:41:50 +00:00
_unpr_focus_tx = texture;
}
2002-11-11 03:47:12 +00:00
2003-01-20 06:11:12 +00:00
void Button::setUnfocusTexture(RenderTexture *texture)
2002-11-14 11:41:50 +00:00
{
FocusWidget::setUnfocusTexture(texture);
2002-11-14 11:41:50 +00:00
_unpr_unfocus_tx = texture;
2002-11-11 03:47:12 +00:00
}
void Button::buttonPressHandler(const XButtonEvent &e)
{
2002-11-16 13:21:24 +00:00
press(e.button);
update();
FocusWidget::buttonPressHandler(e);
}
void Button::buttonReleaseHandler(const XButtonEvent &e)
{
2002-11-16 13:21:24 +00:00
release(e.button);
update();
FocusWidget::buttonReleaseHandler(e);
}
2002-11-11 03:47:12 +00:00
}