diff --git a/src/dialogxml/widgets/button.cpp b/src/dialogxml/widgets/button.cpp index 716ff335..709b8541 100644 --- a/src/dialogxml/widgets/button.cpp +++ b/src/dialogxml/widgets/button.cpp @@ -13,6 +13,7 @@ #include "dialogxml/dialogs/dialog.hpp" #include "gfx/render_image.hpp" #include "gfx/render_text.hpp" +#include "tools/winutil.hpp" #include "fileio/resmgr/res_image.hpp" @@ -329,3 +330,35 @@ void cButton::initPreset() { break; } } + +// Parentless button handle input +bool cButton::handle_event(const sf::Event& event) { + // Not visible -> not interested + if(!this->isVisible()) + return false; + + switch(event.type) { + case sf::Event::MouseButtonPressed:{ + location where = {(int)(event.mouseButton.x / get_ui_scale()), (int)(event.mouseButton.y / get_ui_scale())}; + // Making a framerate limiter just for this is not great + cFramerateLimiter fps; + if(getBounds().contains(where)){ + // TODO handleClick calls redraw() but this doesn't seem to reach the drawable_manager + // because the button never appears depressed + if(this->handleClick(where, fps)){ + // Also bad: + cDialog dummy_dlg; + eKeyMod mod; + triggerClickHandler(dummy_dlg, "", mod); + } + return true; + } + }break; + case sf::Event::KeyPressed: + // TODO parentless button handle hotkey + break; + default: break; + } + + return false; +} \ No newline at end of file diff --git a/src/dialogxml/widgets/button.hpp b/src/dialogxml/widgets/button.hpp index 09cd9610..12551a56 100644 --- a/src/dialogxml/widgets/button.hpp +++ b/src/dialogxml/widgets/button.hpp @@ -10,6 +10,8 @@ #define BUTTON_H #include "control.hpp" +#include "drawable.hpp" +#include "event_listener.hpp" /// A button type. enum eBtnType { // w x h @@ -31,7 +33,7 @@ enum eBtnType { // w x h /// A clickable button control. -class cButton : public cControl { +class cButton : public cControl, public iEventListener, public iDrawable{ public: /// @copydoc cDialog::init() static void init(); @@ -64,6 +66,7 @@ public: } cButton& operator=(cButton& other) = delete; cButton(cButton& other) = delete; + bool handle_event(const sf::Event&) override; protected: /// The type of button. eBtnType type;