diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-07-03 00:27:27 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-07-03 00:52:12 +0300 |
commit | 9e4161f7324331498630fb25e72ff6d08c2db76f (patch) | |
tree | f903c8ba7c4d8c42e1327a673a9e42cafb5c42af /src/gui | |
parent | 1cafda1147c06a647e3d3f1e3f986d7296ccbd08 (diff) | |
download | plus-9e4161f7324331498630fb25e72ff6d08c2db76f.tar.gz plus-9e4161f7324331498630fb25e72ff6d08c2db76f.tar.bz2 plus-9e4161f7324331498630fb25e72ff6d08c2db76f.tar.xz plus-9e4161f7324331498630fb25e72ff6d08c2db76f.zip |
add support for drag skill from skills window.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui.cpp | 3 | ||||
-rw-r--r-- | src/gui/gui.h | 3 | ||||
-rw-r--r-- | src/gui/skilldialog.cpp | 64 |
3 files changed, 64 insertions, 6 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index debbe342f..1032e7e4e 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -95,6 +95,8 @@ Gui::Gui(Graphics *const graphics) : mLastMouseRealY(0), #endif mFocusListeners(), + mForegroundColor(Theme::getThemeColor(Theme::TEXT)), + mForegroundColor2(Theme::getThemeColor(Theme::TEXT_OUTLINE)), mCustomCursor(false) { logger->log1("Initializing GUI..."); @@ -449,6 +451,7 @@ void Gui::draw() { const int posX = mouseX - mGuiFont->getWidth(str) / 2; const int posY = mouseY + (image ? image->mBounds.h / 2 : 0); + g2->setColorAll(mForegroundColor, mForegroundColor2); mGuiFont->drawString(g2, str, posX, posY); } } diff --git a/src/gui/gui.h b/src/gui/gui.h index 94dbf638f..129dedfce 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -26,6 +26,7 @@ #include "resources/cursor.h" #include "resources/image.h" +#include <guichan/color.hpp> #include <guichan/focuslistener.hpp> #include <guichan/gui.hpp> @@ -182,6 +183,8 @@ class Gui final : public gcn::Gui typedef std::list<gcn::FocusListener*> FocusListenerList; typedef FocusListenerList::iterator FocusListenerIterator; FocusListenerList mFocusListeners; + gcn::Color mForegroundColor; + gcn::Color mForegroundColor2; bool mCustomCursor; /**< Show custom cursor */ }; diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 6365efcd8..d6fc3656c 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -22,6 +22,8 @@ #include "gui/skilldialog.h" +#include "dragdrop.h" + #include "gui/widgets/skillmodel.h" #include "debug.h" @@ -40,7 +42,8 @@ class SkillListBox final : public ListBox mTextColor2(getThemeColor(Theme::TEXT_OUTLINE)), mTextPadding(mSkin ? mSkin->getOption("textPadding", 34) : 34), mSpacing(mSkin ? mSkin->getOption("spacing", 0) : 0), - mRowHeight(getFont()->getHeight() * 2 + mSpacing + 2 * mPadding) + mRowHeight(getFont()->getHeight() * 2 + mSpacing + 2 * mPadding), + mSkillClicked(false) { if (mRowHeight < 34) mRowHeight = 34; @@ -127,16 +130,24 @@ class SkillListBox final : public ListBox unsigned int getRowHeight() const override { return mRowHeight; } + const SkillInfo *getSkillByEvent(const gcn::MouseEvent &event) const + { + const int y = (event.getY() + mPadding) / getRowHeight(); + if (!mModel || y >= mModel->getNumberOfElements()) + return nullptr; + const SkillInfo *const skill = mModel->getSkillAt(y); + if (!skill) + return nullptr; + return skill; + } + void mouseMoved(gcn::MouseEvent &event) override { ListBox::mouseMoved(event); - if (!viewport) + if (!viewport || !dragDrop.isEmpty()) return; - const int y = (event.getY() + mPadding) / getRowHeight(); - if (!mModel || y >= mModel->getNumberOfElements()) - return; - const SkillInfo *const skill = mModel->getSkillAt(y); + const SkillInfo *const skill = getSkillByEvent(event); if (!skill) return; @@ -144,6 +155,46 @@ class SkillListBox final : public ListBox skill->data->dispName, skill->data->description); } + void mouseDragged(gcn::MouseEvent &event) + { + if (event.getButton() == gcn::MouseEvent::LEFT) + { + if (dragDrop.isEmpty()) + { + if (mSkillClicked) + { + mSkillClicked = false; + const SkillInfo *const skill = getSkillByEvent(event); + if (!skill) + return; + dragDrop.dragSkill(skill, DRAGDROP_SOURCE_SKILLS); + } + ListBox::mouseDragged(event); + } + } + else + { + ListBox::mouseDragged(event); + } + } + + void mousePressed(gcn::MouseEvent &event) + { + ListBox::mousePressed(event); + if (event.getButton() == gcn::MouseEvent::LEFT) + { + const SkillInfo *const skill = getSkillByEvent(event); + if (!skill) + return; + mSkillClicked = true; + } + } + + void mouseReleased(gcn::MouseEvent &event) + { + ListBox::mouseReleased(event); + } + void mouseExited(gcn::MouseEvent &event A_UNUSED) override { mPopup->hide(); @@ -158,6 +209,7 @@ class SkillListBox final : public ListBox int mTextPadding; int mSpacing; int mRowHeight; + bool mSkillClicked; }; class SkillTab final : public Tab |