diff options
-rw-r--r-- | src/gui/gui.cpp | 32 | ||||
-rw-r--r-- | src/gui/gui.h | 6 | ||||
-rw-r--r-- | src/gui/widgets/window.cpp | 28 | ||||
-rw-r--r-- | src/gui/widgets/window.h | 4 |
4 files changed, 69 insertions, 1 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index c502ce04a..ce2fcef98 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -27,6 +27,7 @@ #include "gui/sdlfont.h" #include "gui/sdlinput.h" #include "gui/theme.h" +#include "gui/viewport.h" #include "gui/widgets/mouseevent.h" #include "gui/widgets/window.h" @@ -605,3 +606,34 @@ void Gui::resetClickCount() mClickCount = 1; mLastMousePressTimeStamp = 0; } + +MouseEvent *Gui::createMouseEvent(Window *widget) +{ + if (!viewport || !widget) + return nullptr; + + int x = 0; + int y = 0; + int mouseX = 0; + int mouseY = 0; + + getAbsolutePosition(widget, x, y); + SDL_GetMouseState(&mouseX, &mouseY); + + MouseEvent *mouseEvent = new MouseEvent(widget, mShiftPressed, + mControlPressed, mAltPressed, mMetaPressed, 0, 0, + mouseX - x, mouseY - y, mClickCount); + return mouseEvent; +} + +void Gui::getAbsolutePosition(gcn::Widget *widget, int &x, int &y) +{ + x = 0; + y = 0; + while (widget->getParent()) + { + x += widget->getX(); + y += widget->getY(); + widget = widget->getParent(); + } +} diff --git a/src/gui/gui.h b/src/gui/gui.h index ee1cb9092..4766a4bf4 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -28,8 +28,10 @@ class Graphics; class GuiConfigListener; class ImageSet; +class MouseEvent; class SDLFont; class SDLInput; +class Window; /** * \defgroup GUI Core GUI related classes (widgets) @@ -129,6 +131,10 @@ class Gui final : public gcn::Gui void resetClickCount(); + MouseEvent *createMouseEvent(Window *widget); + + void getAbsolutePosition(gcn::Widget *widget, int &x, int &y); + /** * Cursors are in graphic order from left to right. * CURSOR_POINTER should be left untouched. diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 19d0b2fea..879190932 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -490,14 +490,31 @@ void Window::setVisible(bool visible, bool forceSticky) // Check if the window is off screen... if (visible) + { ensureOnScreen(); + } else + { mResizeHandles = 0; + } if (isStickyButtonLock()) gcn::Window::setVisible(visible); else gcn::Window::setVisible((!forceSticky && isSticky()) || visible); + if (visible) + { + if (gui) + { + gcn::MouseEvent *event = reinterpret_cast<gcn::MouseEvent*>( + gui->createMouseEvent(this)); + if (event) + { + mouseMoved(*event); + delete event; + } + } + } } void Window::scheduleDelete() @@ -560,13 +577,18 @@ void Window::mouseReleased(gcn::MouseEvent &event A_UNUSED) mMoved = false; } +void Window::mouseEntered(gcn::MouseEvent &event) +{ + updateResizeHandler(event); +} + void Window::mouseExited(gcn::MouseEvent &event A_UNUSED) { if (mGrip && !mouseResize && gui) gui->setCursorType(Gui::CURSOR_POINTER); } -void Window::mouseMoved(gcn::MouseEvent &event) +void Window::updateResizeHandler(gcn::MouseEvent &event) { if (!gui) return; @@ -595,7 +617,11 @@ void Window::mouseMoved(gcn::MouseEvent &event) default: gui->setCursorType(Gui::CURSOR_POINTER); } +} +void Window::mouseMoved(gcn::MouseEvent &event) +{ + updateResizeHandler(event); if (viewport) viewport->hideBeingPopup(); } diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index 7ffa1eb2d..c8b8fb080 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -273,6 +273,10 @@ class Window : public gcn::Window, private gcn::WidgetListener */ void mouseExited(gcn::MouseEvent &event) override; + void mouseEntered(gcn::MouseEvent &event) override; + + void updateResizeHandler(gcn::MouseEvent &event); + /** * Sets the name of the window. This is not the window title. */ |