diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-01-15 00:25:57 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-01-15 00:25:57 +0300 |
commit | f6d283961cfdac6779a6e7ac07de211b44fc7bc7 (patch) | |
tree | c133d33c7a63035be65fbc22f681fd4047796043 | |
parent | df9f983d747a430ed9c2fddbbf1496f265dad6a4 (diff) | |
download | manaplus-f6d283961cfdac6779a6e7ac07de211b44fc7bc7.tar.gz manaplus-f6d283961cfdac6779a6e7ac07de211b44fc7bc7.tar.bz2 manaplus-f6d283961cfdac6779a6e7ac07de211b44fc7bc7.tar.xz manaplus-f6d283961cfdac6779a6e7ac07de211b44fc7bc7.zip |
Add support moving shortcuts like windows by header.
-rw-r--r-- | src/gui/shortcutwindow.cpp | 38 | ||||
-rw-r--r-- | src/gui/shortcutwindow.h | 4 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index 888b97222..0e968efef 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -23,6 +23,7 @@ #include "gui/shortcutwindow.h" #include "configuration.h" +#include "logger.h" #include "gui/setup.h" @@ -64,6 +65,9 @@ ShortcutWindow::ShortcutWindow(const std::string &title, setDefaultVisible(false); setSaveVisible(true); + mDragOffsetX = 0; + mDragOffsetY = 0; + setupWindow->registerWindowForReset(this); mTabs = nullptr; @@ -110,6 +114,9 @@ ShortcutWindow::ShortcutWindow(const std::string &title, std::string skinFile, setDefaultVisible(false); setSaveVisible(true); + mDragOffsetX = 0; + mDragOffsetY = 0; + setupWindow->registerWindowForReset(this); mTabs = new TabbedArea; @@ -178,3 +185,34 @@ void ShortcutWindow::widgetHidden(const gcn::Event &event) } } } + +void ShortcutWindow::mousePressed(gcn::MouseEvent &event) +{ + Window::mousePressed(event); + + if (event.isConsumed()) + return; + + if (event.getButton() == gcn::MouseEvent::LEFT) + { + mDragOffsetX = event.getX(); + mDragOffsetY = event.getY(); + } +} + +void ShortcutWindow::mouseDragged(gcn::MouseEvent &event) +{ + Window::mouseDragged(event); + + if (event.isConsumed()) + return; + + if (canMove() && isMovable() && mMoved) + { + int newX = std::max(0, getX() + event.getX() - mDragOffsetX); + int newY = std::max(0, getY() + event.getY() - mDragOffsetY); + newX = std::min(mainGraphics->mWidth - getWidth(), newX); + newY = std::min(mainGraphics->mHeight - getHeight(), newY); + setPosition(newX, newY); + } +} diff --git a/src/gui/shortcutwindow.h b/src/gui/shortcutwindow.h index ceb82ef7b..bdff5ab0d 100644 --- a/src/gui/shortcutwindow.h +++ b/src/gui/shortcutwindow.h @@ -58,6 +58,10 @@ class ShortcutWindow : public Window void widgetHidden(const gcn::Event &event); + void mousePressed(gcn::MouseEvent &event); + + void mouseDragged(gcn::MouseEvent &event); + private: ShortcutWindow(); ShortcutContainer *mItems; |