LuaVoxelManip: Add option to allocate blank data
[oweals/minetest.git] / src / guiFormSpecMenu.cpp
index 0a7a823999002acfedf4519345cd5c0d870fd576..6ef20ceade5cd634b595c5dad525cba63a3bc09a 100644 (file)
@@ -76,6 +76,21 @@ static unsigned int font_line_height(gui::IGUIFont *font)
 
 static gui::IGUIFont *select_font_by_line_height(double target_line_height)
 {
+       return g_fontengine->getFont();
+
+/* I have no idea what this is trying to achieve, but scaling the font according
+ * to the size of a formspec/dialog does not seem to be a standard (G)UI
+ * design and AFAIK no existing nor proposed GUI does this. Besides that it:
+ * a) breaks most (current) formspec layouts
+ * b) font sizes change depending on the size of the formspec/dialog (see above)
+ *    meaning that there is no UI consistency
+ * c) the chosen fonts are, in general, probably too large
+ *
+ * Disabling for now.
+ *
+ * FIXME
+ */
+#if 0
        // We don't get to directly select a font according to its
        // baseline-to-baseline height.  Rather, we select by em size.
        // The ratio between these varies between fonts.  The font
@@ -105,6 +120,7 @@ static gui::IGUIFont *select_font_by_line_height(double target_line_height)
                }
        }
        return g_fontengine->getFont(target_line_height - lohgt < hihgt - target_line_height ? loreq : hireq);
+#endif
 }
 
 GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
@@ -124,6 +140,7 @@ GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
        m_tooltip_element(NULL),
        m_hovered_time(0),
        m_old_tooltip_id(-1),
+       m_rmouse_auto_place(false),
        m_allowclose(true),
        m_lock(false),
        m_form_src(fsrc),
@@ -2217,10 +2234,23 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int phase)
                                m_tooltip_element->setVisible(true);
                                this->bringToFront(m_tooltip_element);
                                m_tooltip_element->setText(narrow_to_wide(tooltip_text).c_str());
-                               s32 tooltip_x = m_pointer.X + m_btn_height;
-                               s32 tooltip_y = m_pointer.Y + m_btn_height;
                                s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height;
                                s32 tooltip_height = m_tooltip_element->getTextHeight() * tt_rows.size() + 5;
+                               v2u32 screenSize = driver->getScreenSize();
+                               int tooltip_offset_x = m_btn_height;
+                               int tooltip_offset_y = m_btn_height;
+#ifdef __ANDROID__
+                               tooltip_offset_x *= 3;
+                               tooltip_offset_y  = 0;
+                               if (m_pointer.X > (s32)screenSize.X / 2)
+                                       tooltip_offset_x = (tooltip_offset_x + tooltip_width) * -1;
+#endif
+                               s32 tooltip_x = m_pointer.X + tooltip_offset_x;
+                               s32 tooltip_y = m_pointer.Y + tooltip_offset_y;
+                               if (tooltip_x + tooltip_width > (s32)screenSize.X)
+                                       tooltip_x = (s32)screenSize.X - tooltip_width  - m_btn_height;
+                               if (tooltip_y + tooltip_height > (s32)screenSize.Y)
+                                       tooltip_y = (s32)screenSize.Y - tooltip_height - m_btn_height;
                                m_tooltip_element->setRelativePosition(core::rect<s32>(
                                                core::position2d<s32>(tooltip_x, tooltip_y),
                                                core::dimension2d<s32>(tooltip_width, tooltip_height)));
@@ -2436,13 +2466,23 @@ void GUIFormSpecMenu::drawMenu()
                                        if (m_old_tooltip != m_tooltips[iter->fname].tooltip) {
                                                m_old_tooltip = m_tooltips[iter->fname].tooltip;
                                                m_tooltip_element->setText(narrow_to_wide(m_tooltips[iter->fname].tooltip).c_str());
-                                               s32 tooltip_x = m_pointer.X + m_btn_height;
-                                               s32 tooltip_y = m_pointer.Y + m_btn_height;
-                                               s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height;
-                                               if (tooltip_x + tooltip_width > (s32)screenSize.X)
-                                                       tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height;
                                                std::vector<std::string> tt_rows = str_split(m_tooltips[iter->fname].tooltip, '\n');
+                                               s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height;
                                                s32 tooltip_height = m_tooltip_element->getTextHeight() * tt_rows.size() + 5;
+                                               int tooltip_offset_x = m_btn_height;
+                                               int tooltip_offset_y = m_btn_height;
+#ifdef __ANDROID__
+                                               tooltip_offset_x *= 3;
+                                               tooltip_offset_y  = 0;
+                                               if (m_pointer.X > (s32)screenSize.X / 2)
+                                                       tooltip_offset_x = (tooltip_offset_x + tooltip_width) * -1;
+#endif
+                                               s32 tooltip_x = m_pointer.X + tooltip_offset_x;
+                                               s32 tooltip_y = m_pointer.Y + tooltip_offset_y;
+                                               if (tooltip_x + tooltip_width > (s32)screenSize.X)
+                                                       tooltip_x = (s32)screenSize.X - tooltip_width  - m_btn_height;
+                                               if (tooltip_y + tooltip_height > (s32)screenSize.Y)
+                                                       tooltip_y = (s32)screenSize.Y - tooltip_height - m_btn_height;
                                                m_tooltip_element->setRelativePosition(core::rect<s32>(
                                                core::position2d<s32>(tooltip_x, tooltip_y),
                                                core::dimension2d<s32>(tooltip_width, tooltip_height)));
@@ -2732,7 +2772,8 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
                gui::IGUIElement *hovered =
                        Environment->getRootGUIElement()->getElementFromPoint(
                                core::position2d<s32>(x, y));
-               if (hovered->getType() == gui::EGUIET_TAB_CONTROL) {
+               if (hovered && isMyChild(hovered) &&
+                               hovered->getType() == gui::EGUIET_TAB_CONTROL) {
                        gui::IGUISkin* skin = Environment->getSkin();
                        assert(skin != NULL);
                        gui::IGUIFont *old_font = skin->getFont();
@@ -3153,6 +3194,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
                                                m_selected_amount = s_count;
 
                                        m_selected_dragging = true;
+                                       m_rmouse_auto_place = false;
                                }
                        }
                        else { // m_selected_item != NULL
@@ -3205,6 +3247,11 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
                        }
 
                        m_selected_dragging = false;
+                       // Keep count of how many times right mouse button has been
+                       // clicked. One click is drag without dropping. Click + release
+                       // + click changes to drop one item when moved mode
+                       if(button == 1 && m_selected_item != NULL)
+                               m_rmouse_auto_place = !m_rmouse_auto_place;
                }
                else if(updown == -1) {
                        // Mouse has been moved and rmb is down and mouse pointer just
@@ -3213,7 +3260,18 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
                        if(m_selected_item != NULL && s.isValid()){
                                // Move 1 item
                                // TODO: middle mouse to move 10 items might be handy
-                               move_amount = 1;
+                               if (m_rmouse_auto_place) {
+                                       // Only move an item if the destination slot is empty
+                                       // or contains the same item type as what is going to be
+                                       // moved
+                                       InventoryList *list_from = inv_selected->getList(m_selected_item->listname);
+                                       InventoryList *list_to = inv_s->getList(s.listname);
+                                       assert(list_from && list_to);
+                                       ItemStack stack_from = list_from->getItem(m_selected_item->i);
+                                       ItemStack stack_to = list_to->getItem(s.i);
+                                       if (stack_to.empty() || stack_to.name == stack_from.name)
+                                               move_amount = 1;
+                               }
                        }
                }