aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsruz25 <sruz25cz@gmail.com>2014-09-19 15:27:48 +0200
committerShadowNinja <shadowninja@minetest.net>2014-09-21 15:23:27 -0400
commitf6321e277bc423a0878ae239a73ad2cd6393106c (patch)
treefcfd1a5aaaff207a56b6ac623f11f229dc5e58de
parent2c16a11527f1358ac8ec37436c798f5a68f566c4 (diff)
downloadminetest-f6321e277bc423a0878ae239a73ad2cd6393106c.tar.gz
minetest-f6321e277bc423a0878ae239a73ad2cd6393106c.tar.bz2
minetest-f6321e277bc423a0878ae239a73ad2cd6393106c.zip
Add inventory right click drag and drop
-rw-r--r--src/guiFormSpecMenu.cpp23
-rw-r--r--src/guiFormSpecMenu.h2
2 files changed, 21 insertions, 4 deletions
diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp
index 3fdb5bd26..65dbc0187 100644
--- a/src/guiFormSpecMenu.cpp
+++ b/src/guiFormSpecMenu.cpp
@@ -2950,9 +2950,11 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
}
- if(event.EventType==EET_MOUSE_INPUT_EVENT
- && event.MouseInput.Event != EMIE_MOUSE_MOVED) {
- // Mouse event other than movement
+ if((event.EventType==EET_MOUSE_INPUT_EVENT &&
+ event.MouseInput.Event != EMIE_MOUSE_MOVED) ||
+ (event.MouseInput.Event == EMIE_MOUSE_MOVED &&
+ event.MouseInput.isRightPressed() && getItemAtPos(m_pointer).i != getItemAtPos(m_old_pointer).i)){
+ // Mouse event other than movement or crossing the border of inventory field while holding rmb
// Get selected item and hovered/clicked item (s)
@@ -3008,7 +3010,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
(m_selected_item->i == s.i);
// buttons: 0 = left, 1 = right, 2 = middle
- // up/down: 0 = down (press), 1 = up (release), 2 = unknown event
+ // up/down: 0 = down (press), 1 = up (release), 2 = unknown event, -1 movement
int button = 0;
int updown = 2;
if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
@@ -3023,6 +3025,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
{ button = 1; updown = 1; }
else if(event.MouseInput.Event == EMIE_MMOUSE_LEFT_UP)
{ button = 2; updown = 1; }
+ else if(event.MouseInput.Event == EMIE_MOUSE_MOVED)
+ { updown = -1;}
// Set this number to a positive value to generate a move action
// from m_selected_item to s.
@@ -3113,6 +3117,16 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
m_selected_dragging = false;
}
+ else if(updown == -1) {
+ // Mouse has been moved and rmb is down and mouse pointer just
+ // entered a new inventory field (checked in the entry-if, this
+ // is the only action here that is generated by mouse movement)
+ if(m_selected_item != NULL && s.isValid()){
+ // Move 1 item
+ // TODO: middle mouse to move 10 items might be handy
+ move_amount = 1;
+ }
+ }
// Possibly send inventory action to server
if(move_amount > 0)
@@ -3212,6 +3226,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
m_selected_dragging = false;
m_selected_content_guess = ItemStack();
}
+ m_old_pointer = m_pointer;
}
if(event.EventType==EET_GUI_EVENT) {
diff --git a/src/guiFormSpecMenu.h b/src/guiFormSpecMenu.h
index 583cad4a2..2ffa05308 100644
--- a/src/guiFormSpecMenu.h
+++ b/src/guiFormSpecMenu.h
@@ -301,6 +301,7 @@ protected:
std::string m_formspec_string;
InventoryLocation m_current_inventory_location;
+
std::vector<ListDrawSpec> m_inventorylists;
std::vector<ImageDrawSpec> m_backgrounds;
std::vector<ImageDrawSpec> m_images;
@@ -323,6 +324,7 @@ protected:
InventoryLocation m_selected_content_guess_inventory;
v2s32 m_pointer;
+ v2s32 m_old_pointer; // Mouse position after previous mouse event
gui::IGUIStaticText *m_tooltip_element;
u32 m_tooltip_show_delay;