From 9e4161f7324331498630fb25e72ff6d08c2db76f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 3 Jul 2013 00:27:27 +0300 Subject: add support for drag skill from skills window. --- src/gui/gui.cpp | 3 +++ src/gui/gui.h | 3 +++ src/gui/skilldialog.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 64 insertions(+), 6 deletions(-) (limited to 'src/gui') 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 #include #include @@ -182,6 +183,8 @@ class Gui final : public gcn::Gui typedef std::list 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 -- cgit v1.2.3-70-g09d2