diff options
Diffstat (limited to 'src/buttonwidget.cc')
| -rw-r--r-- | src/buttonwidget.cc | 94 |
1 files changed, 79 insertions, 15 deletions
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(); +} + } |
