X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Fbutton.cc;h=313d8acfcf52751e0b56162444763cba6a84ec4b;hb=7f590e53607ef1592d65a425b9cdcaa181912465;hp=e7340d1b875a2452df2bc5614c61d164a3a7a1a5;hpb=033e9843bcec8340c9e657fe0f0519f86075424b;p=chaz%2Fopenbox diff --git a/otk/button.cc b/otk/button.cc index e7340d1b..313d8acf 100644 --- a/otk/button.cc +++ b/otk/button.cc @@ -1,80 +1,77 @@ // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif +#include "config.h" #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) + : Label(parent), + _pressed(false) { + setHorizontalJustify(RenderStyle::CenterJustify); + setVerticalJustify(RenderStyle::CenterJustify); + styleChanged(*RenderStyle::style(screen())); } 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; + + styleChanged(*RenderStyle::style(screen())); + refresh(); } void Button::release(unsigned int mouse_button) { - if (_mouse_button != mouse_button) return; // wrong button + if (!_pressed || _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; + styleChanged(*RenderStyle::style(screen())); + refresh(); } void Button::buttonPressHandler(const XButtonEvent &e) { + Widget::buttonPressHandler(e); press(e.button); - update(); - FocusWidget::buttonPressHandler(e); } void Button::buttonReleaseHandler(const XButtonEvent &e) { + Widget::buttonReleaseHandler(e); + bool p = _pressed; release(e.button); - update(); - FocusWidget::buttonReleaseHandler(e); + if (p && !_pressed && e.x > 0 && e.y > 0 && + e.x < area().width() && e.y < area().height()) + clickHandler(_mouse_button); +} + +void Button::styleChanged(const RenderStyle &style) +{ + if (isHighlighted()) { + if (_pressed) + _texture = style.buttonPressFocusBackground(); + else + _texture = style.buttonUnpressFocusBackground(); + _forecolor = style.buttonFocusColor(); + } else { + if (_pressed) + _texture = style.buttonPressUnfocusBackground(); + else + _texture = style.buttonUnpressUnfocusBackground(); + _forecolor = style.buttonUnfocusColor(); + } + refresh(); } }