diff options
author | André Nusser <andre.nusser@googlemail.com> | 2017-04-16 12:54:16 +0200 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2017-04-16 12:54:16 +0200 |
commit | 19b9cddf7d5ef3daac5cda481db492f28574d28d (patch) | |
tree | a3ca1d8ab84df69bd01c9bbab6d455c996cc462c /plugingui/button.cc | |
parent | f4114b68d903eb5828c93910853ea9fdea004952 (diff) |
Move button functionality to BaseButton. Create TabButton.
Diffstat (limited to 'plugingui/button.cc')
-rw-r--r-- | plugingui/button.cc | 84 |
1 files changed, 15 insertions, 69 deletions
diff --git a/plugingui/button.cc b/plugingui/button.cc index fb25390..0da79a0 100644 --- a/plugingui/button.cc +++ b/plugingui/button.cc @@ -28,49 +28,19 @@ #include "painter.h" -#include <stdio.h> #include <hugin.hpp> +#include <stdio.h> -namespace GUI { - -Button::Button(Widget *parent) - : Widget(parent) - , draw_state(up) - , button_state(up) +namespace GUI { -} -Button::~Button() +Button::Button(Widget* parent) + : ButtonBase(parent) { } -void Button::buttonEvent(ButtonEvent* buttonEvent) +Button::~Button() { - // Ignore everything except left clicks. - if(buttonEvent->button != MouseButton::left) - { - return; - } - - if(buttonEvent->direction == Direction::down) - { - draw_state = down; - button_state = down; - in_button = true; - redraw(); - } - - if(buttonEvent->direction == Direction::up) - { - draw_state = up; - button_state = up; - redraw(); - if(in_button) - { - clicked(); - clickNotifier(); - } - } } void Button::repaintEvent(RepaintEvent* repaintEvent) @@ -89,48 +59,24 @@ void Button::repaintEvent(RepaintEvent* repaintEvent) return; } - switch(draw_state) { - case up: + switch(draw_state) + { + case State::Up: box_up.setSize(w - padLeft, h - padTop); p.drawImage(padLeft, padTop, box_up); - break; - case down: + + case State::Down: box_down.setSize(w - padLeft, h - padTop); p.drawImage(padLeft, padTop, box_down); break; } p.setColour(Colour(0.1)); - p.drawText(width()/2-(text.length()*3)+(draw_state==up?0:1) + (padLeft / 2), - height()/2+5+1+(draw_state==up?0:1) + (padTop / 2), font, text, - true); -} - -void Button::setText(const std::string& text) -{ - this->text = text; - redraw(); -} - -void Button::mouseLeaveEvent() -{ - in_button = false; - if(button_state == down) - { - draw_state = up; - redraw(); - } -} - -void Button::mouseEnterEvent() -{ - in_button = true; - if(button_state == down) - { - draw_state = down; - redraw(); - } + auto x = (w / 2) - (3 * text.length()) + (draw_state == State::Up ? 0 : 1) + + (padLeft / 2); + auto y = (h / 2) + 5 + 1 + (draw_state == State::Up ? 0 : 1) + (padTop / 2); + p.drawText(x, y, font, text, true); } -} //GUI:: +} // GUI:: |