diff --git a/src/gui/TimeMachineDialog.cxx b/src/gui/TimeMachineDialog.cxx index 4f6011fba..5361393e8 100644 --- a/src/gui/TimeMachineDialog.cxx +++ b/src/gui/TimeMachineDialog.cxx @@ -256,11 +256,11 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent, xpos += buttonWidth + BUTTON_GAP; myRewind1Widget = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight, REWIND_1, - BUTTON_W, BUTTON_H, kRewind1); + BUTTON_W, BUTTON_H, kRewind1, true); xpos += buttonWidth + BUTTON_GAP; myUnwind1Widget = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight, UNWIND_1, - BUTTON_W, BUTTON_H, kUnwind1); + BUTTON_W, BUTTON_H, kUnwind1, true); xpos += buttonWidth + BUTTON_GAP; myUnwindAllWidget = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight, UNWIND_ALL, diff --git a/src/gui/Widget.cxx b/src/gui/Widget.cxx index 5cef6eb93..4b5e43816 100644 --- a/src/gui/Widget.cxx +++ b/src/gui/Widget.cxx @@ -368,10 +368,11 @@ void StaticTextWidget::drawWidget(bool hilite) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, - const string& label, int cmd) + const string& label, int cmd, bool repeat) : StaticTextWidget(boss, font, x, y, w, h, label, TextAlign::Center), CommandSender(boss), _cmd(cmd), + _repeat(repeat), _useBitmap(false), _bitmap(nullptr), _bmw(0), @@ -391,16 +392,16 @@ ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int dw, - const string& label, int cmd) - : ButtonWidget(boss, font, x, y, font.getStringWidth(label) + dw, font.getLineHeight() + 4, label, cmd) + const string& label, int cmd, bool repeat) + : ButtonWidget(boss, font, x, y, font.getStringWidth(label) + dw, font.getLineHeight() + 4, label, cmd, repeat) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, - const string& label, int cmd) - : ButtonWidget(boss, font, x, y, 20, label, cmd) + const string& label, int cmd, bool repeat) + : ButtonWidget(boss, font, x, y, 20, label, cmd, repeat) { } @@ -408,8 +409,8 @@ ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font, ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, uInt32* bitmap, int bmw, int bmh, - int cmd) - : ButtonWidget(boss, font, x, y, w, h, "", cmd) + int cmd, bool repeat) + : ButtonWidget(boss, font, x, y, w, h, "", cmd, repeat) { _bitmap = bitmap; _bmh = bmh; @@ -446,10 +447,25 @@ bool ButtonWidget::handleEvent(Event::Type e) } } +bool ButtonWidget::handleMouseClicks(int x, int y, MouseButton b) +{ + return _repeat; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ButtonWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount) +{ + if(_repeat && isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h) + { + clearFlags(Widget::FLAG_HILITED); + sendCommand(_cmd, 0, _id); + } +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ButtonWidget::handleMouseUp(int x, int y, MouseButton b, int clickCount) { - if(isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h) + if (!_repeat && isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h) { clearFlags(Widget::FLAG_HILITED); sendCommand(_cmd, 0, _id); diff --git a/src/gui/Widget.hxx b/src/gui/Widget.hxx index 042ce8d6c..fb48ade1f 100644 --- a/src/gui/Widget.hxx +++ b/src/gui/Widget.hxx @@ -219,17 +219,17 @@ class ButtonWidget : public StaticTextWidget, public CommandSender public: ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, - const string& label, int cmd = 0); + const string& label, int cmd = 0, bool repeat = false); ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int dw, - const string& label, int cmd = 0); + const string& label, int cmd = 0, bool repeat = false); ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, - const string& label, int cmd = 0); + const string& label, int cmd = 0, bool repeat = false); ButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int dw, int dh, uInt32* bitmap, int bmw, int bmh, - int cmd = 0); + int cmd = 0, bool repeat = false); void setCmd(int cmd) { _cmd = cmd; } int getCmd() const { return _cmd; } @@ -237,6 +237,8 @@ class ButtonWidget : public StaticTextWidget, public CommandSender void setBitmap(uInt32* bitmap, int bmw, int bmh); protected: + bool handleMouseClicks(int x, int y, MouseButton b) override; + void handleMouseDown(int x, int y, MouseButton b, int clickCount) override; void handleMouseUp(int x, int y, MouseButton b, int clickCount) override; void handleMouseEntered() override; void handleMouseLeft() override; @@ -246,6 +248,7 @@ class ButtonWidget : public StaticTextWidget, public CommandSender protected: int _cmd; + bool _repeat; // button repeats bool _useBitmap; uInt32* _bitmap; int _bmw, _bmh;