summaryrefslogtreecommitdiff
path: root/src/gui/skilldialog.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-07-03 00:27:27 +0300
committerAndrei Karas <akaras@inbox.ru>2013-07-03 00:52:12 +0300
commit9e4161f7324331498630fb25e72ff6d08c2db76f (patch)
treef903c8ba7c4d8c42e1327a673a9e42cafb5c42af /src/gui/skilldialog.cpp
parent1cafda1147c06a647e3d3f1e3f986d7296ccbd08 (diff)
downloadmanaverse-9e4161f7324331498630fb25e72ff6d08c2db76f.tar.gz
manaverse-9e4161f7324331498630fb25e72ff6d08c2db76f.tar.bz2
manaverse-9e4161f7324331498630fb25e72ff6d08c2db76f.tar.xz
manaverse-9e4161f7324331498630fb25e72ff6d08c2db76f.zip
add support for drag skill from skills window.
Diffstat (limited to 'src/gui/skilldialog.cpp')
-rw-r--r--src/gui/skilldialog.cpp64
1 files changed, 58 insertions, 6 deletions
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