summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-06-17 23:07:29 +0300
committerAndrei Karas <akaras@inbox.ru>2012-06-17 23:07:29 +0300
commit1ec82e44a0ec44a3d342a68b42b318e4413410dc (patch)
treef3010c20fd90440c81921c612267d8a58e4f1ee3 /src
parent1f66ae673801e76f3574944628a7980b9bfbabda (diff)
downloadplus-1ec82e44a0ec44a3d342a68b42b318e4413410dc.tar.gz
plus-1ec82e44a0ec44a3d342a68b42b318e4413410dc.tar.bz2
plus-1ec82e44a0ec44a3d342a68b42b318e4413410dc.tar.xz
plus-1ec82e44a0ec44a3d342a68b42b318e4413410dc.zip
Fix double click support in gui class.
Add double click support to inventory and storage windows.
Diffstat (limited to 'src')
-rw-r--r--src/gui/gui.cpp6
-rw-r--r--src/gui/gui.h2
-rw-r--r--src/gui/inventorywindow.cpp48
-rw-r--r--src/gui/widgets/itemcontainer.cpp9
-rw-r--r--src/gui/widgets/itemcontainer.h4
5 files changed, 68 insertions, 1 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index f513c31a1..afced01b2 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -581,3 +581,9 @@ void Gui::distributeMouseEvent(gcn::Widget* source, int type, int button,
}
}
}
+
+void Gui::resetClickCount()
+{
+ mClickCount = 1;
+ mLastMousePressTimeStamp = 0;
+}
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 845c07660..9468d2b68 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -121,6 +121,8 @@ class Gui : public gcn::Gui
bool handleKeyInput2();
+ void resetClickCount();
+
/**
* Cursors are in graphic order from left to right.
* CURSOR_POINTER should be left untouched.
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index c20dd0036..ccfb12d8a 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -31,6 +31,7 @@
#include "playerinfo.h"
#include "units.h"
+#include "gui/gui.h"
#include "gui/itemamountwindow.h"
#include "gui/setup.h"
#include "gui/sdlinput.h"
@@ -322,7 +323,9 @@ void InventoryWindow::action(const gcn::ActionEvent &event)
Net::getInventoryHandler()->equipItem(item);
}
else
+ {
Net::getInventoryHandler()->useItem(item);
+ }
}
if (event.getId() == "equip")
{
@@ -334,7 +337,9 @@ void InventoryWindow::action(const gcn::ActionEvent &event)
Net::getInventoryHandler()->equipItem(item);
}
else
+ {
Net::getInventoryHandler()->useItem(item);
+ }
}
else if (event.getId() == "drop")
{
@@ -391,6 +396,11 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
{
Window::mouseClicked(event);
+ const int clicks = event.getClickCount();
+
+ if (clicks == 2 && gui)
+ gui->resetClickCount();
+
const bool mod = (isStorageActive() && inputManager.isActionActive(
Input::KEY_MOD));
@@ -469,6 +479,44 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
tradeWindow->tradeItem(item, item->getQuantity(), true);
}
}
+ else if (clicks == 2)
+ {
+ if (mInventory->isMainInventory())
+ {
+ if (isStorageActive())
+ {
+ ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd,
+ inventoryWindow, item);
+ }
+ else if (tradeWindow && tradeWindow->isVisible())
+ {
+ ItemAmountWindow::showWindow(ItemAmountWindow::TradeAdd,
+ tradeWindow, item);
+ }
+ else
+ {
+ if (item->isEquipment())
+ {
+ if (item->isEquipped())
+ Net::getInventoryHandler()->unequipItem(item);
+ else
+ Net::getInventoryHandler()->equipItem(item);
+ }
+ else
+ {
+ Net::getInventoryHandler()->useItem(item);
+ }
+ }
+ }
+ else
+ {
+ if (isStorageActive())
+ {
+ ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove,
+ inventoryWindow, item);
+ }
+ }
+ }
}
}
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 5994b1e1a..3f3bbe937 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -30,6 +30,7 @@
#include "logger.h"
#include "gui/chatwindow.h"
+#include "gui/gui.h"
#include "gui/itempopup.h"
#include "gui/outfitwindow.h"
#include "gui/palette.h"
@@ -167,6 +168,7 @@ ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity):
mSortType(0),
mItemPopup(new ItemPopup),
mShowMatrix(nullptr),
+ mClicks(1),
mEquipedColor(Theme::getThemeColor(Theme::ITEM_EQUIPPED)),
mUnEquipedColor(Theme::getThemeColor(Theme::ITEM_NOT_EQUIPPED))
{
@@ -347,6 +349,8 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
return;
const int button = event.getButton();
+ mClicks = event.getClickCount();
+
if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT)
{
const int index = getSlotIndex(event.getX(), event.getY());
@@ -359,7 +363,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
if (item && mDescItems && chatWindow)
chatWindow->addItemText(item->getInfo().getName());
- if (mSelectedIndex == index)
+ if (mSelectedIndex == index && mClicks != 2)
{
mSelectionStatus = SEL_DESELECTING;
}
@@ -400,6 +404,9 @@ void ItemContainer::mouseDragged(gcn::MouseEvent &event)
void ItemContainer::mouseReleased(gcn::MouseEvent &event)
{
+ if (mClicks == 2)
+ return;
+
switch (mSelectionStatus)
{
case SEL_SELECTING:
diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h
index ae6e4a35d..0ad95fd1b 100644
--- a/src/gui/widgets/itemcontainer.h
+++ b/src/gui/widgets/itemcontainer.h
@@ -126,6 +126,9 @@ class ItemContainer : public gcn::Widget,
void updateMatrix();
+ bool getClickCount()
+ { return mClicks; }
+
private:
enum Direction
{
@@ -197,6 +200,7 @@ class ItemContainer : public gcn::Widget,
ItemPopup *mItemPopup;
int *mShowMatrix;
+ int mClicks;
typedef std::list<gcn::SelectionListener*> SelectionListenerList;
typedef SelectionListenerList::iterator SelectionListenerIterator;