X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fbuttonwidget.cc;h=853b0339f448793948e60e93bb3ff7b9e6db6cbc;hb=b2079b56e4b2ea398d67fb5e15614797a0236f28;hp=867cc5be1c797d9fc2b8780c88f1ce415d224eff;hpb=83727b8e6404f7e00e7369c39da8779dfb85ae09;p=chaz%2Fopenbox diff --git a/src/buttonwidget.cc b/src/buttonwidget.cc index 867cc5be..853b0339 100644 --- a/src/buttonwidget.cc +++ b/src/buttonwidget.cc @@ -10,8 +10,10 @@ namespace ob { OBButtonWidget::OBButtonWidget(otk::OtkWidget *parent, OBWidget::WidgetType type) - : otk::OtkButton(parent), - OBWidget(type) + : otk::OtkWidget(parent), + OBWidget(type), + _pressed(false), + _button(0) { } @@ -21,36 +23,98 @@ OBButtonWidget::~OBButtonWidget() } +void OBButtonWidget::setTextures() +{ + switch (type()) { + case Type_LeftGrip: + case Type_RightGrip: + if (_focused) + setTexture(_style->getGripFocus()); + else + setTexture(_style->getGripUnfocus()); + break; + case Type_StickyButton: + case Type_CloseButton: + case Type_MaximizeButton: + case Type_IconifyButton: + if (_pressed) { + if (_focused) + setTexture(_style->getButtonPressedFocus()); + else + setTexture(_style->getButtonPressedUnfocus()); + } else { + if (_focused) + setTexture(_style->getButtonFocus()); + else + setTexture(_style->getButtonUnfocus()); + } + break; + default: + assert(false); // there's no other button widgets! + } +} + + void OBButtonWidget::setStyle(otk::Style *style) { - otk::OtkButton::setStyle(style); + otk::OtkWidget::setStyle(style); + setTextures(); switch (type()) { case Type_LeftGrip: case Type_RightGrip: - setTexture(style->getGripFocus()); - setUnfocusTexture(style->getGripUnfocus()); - setPressedFocusTexture(style->getGripFocus()); - setPressedUnfocusTexture(style->getGripUnfocus()); - setTexture(style->getGripFocus()); - setUnfocusTexture(style->getGripUnfocus()); - setPressedFocusTexture(style->getGripFocus()); - setPressedUnfocusTexture(style->getGripUnfocus()); setBorderColor(_style->getBorderColor()); - setUnfocusBorderColor(style->getBorderColor()); break; - default: + case Type_StickyButton: + case Type_CloseButton: + case Type_MaximizeButton: + case Type_IconifyButton: break; + default: + assert(false); // there's no other button widgets! } } -void OBButtonWidget::adjust() +void OBButtonWidget::focus() { - otk::OtkButton::adjust(); + otk::OtkWidget::focus(); + setTextures(); +} + +void OBButtonWidget::unfocus() +{ + otk::OtkWidget::unfocus(); + setTextures(); +} + + +void OBButtonWidget::adjust() +{ // XXX: adjust shit } +void OBButtonWidget::buttonPressHandler(const XButtonEvent &e) +{ + OtkWidget::buttonPressHandler(e); + if (_button) return; + _button = e.button; + _pressed = true; + setTextures(); + update(); +} + + +void OBButtonWidget::buttonReleaseHandler(const XButtonEvent &e) +{ + OtkWidget::buttonPressHandler(e); + if (e.button != _button) return; + _button = 0; + _pressed = false; + setTextures(); + update(); +} + }