]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/guiTable.cpp
Add count based unload limit for mapblocks
[dragonfireclient.git] / src / guiTable.cpp
index 4d6fc195072add988769a3601c1cfa41512eee09..ed5b0d87b0e07ee27d1fd2a276fcd00354a8fb8a 100644 (file)
@@ -28,11 +28,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <IGUIScrollBar.h>
 #include "debug.h"
 #include "log.h"
-#include "tile.h"
+#include "client/tile.h"
 #include "gettime.h"
 #include "util/string.h"
 #include "util/numeric.h"
-#include "guiFormSpecMenu.h" // for parseColor()
+#include "util/string.h" // for parseColorString()
+#include "settings.h" // for settings
+#include "porting.h" // for dpi
+#include "guiscalingfilter.h"
 
 /*
        GUITable
@@ -89,6 +92,14 @@ GUITable::GUITable(gui::IGUIEnvironment *env,
        setTabStop(true);
        setTabOrder(-1);
        updateAbsolutePosition();
+
+       core::rect<s32> relative_rect = m_scrollbar->getRelativePosition();
+       s32 width = (relative_rect.getWidth()/(2.0/3.0)) * porting::getDisplayDensity() *
+                       g_settings->getFloat("gui_scaling");
+       m_scrollbar->setRelativePosition(core::rect<s32>(
+                       relative_rect.LowerRightCorner.X-width,relative_rect.UpperLeftCorner.Y,
+                       relative_rect.LowerRightCorner.X,relative_rect.LowerRightCorner.Y
+                       ));
 }
 
 GUITable::~GUITable()
@@ -153,7 +164,7 @@ void GUITable::setTextList(const std::vector<std::string> &content,
                        cell->content_index = allocString(s.substr(2));
                }
                else if (s[0] == '#' && s.size() >= 7 &&
-                               GUIFormSpecMenu::parseColor(
+                               parseColorString(
                                        s.substr(0,7), cell->color, false)) {
                        // single # for color
                        cell->color_defined = true;
@@ -183,6 +194,16 @@ void GUITable::setTable(const TableOptions &options,
        // j is always a column index, 0-based
        // k is another index, for example an option index
 
+       // Handle a stupid error case... (issue #1187)
+       if (columns.empty()) {
+               TableColumn text_column;
+               text_column.type = "text";
+               TableColumns new_columns;
+               new_columns.push_back(text_column);
+               setTable(options, new_columns, content);
+               return;
+       }
+
        // Handle table options
        video::SColor default_color(255, 255, 255, 255);
        s32 opendepth = 0;
@@ -190,15 +211,15 @@ void GUITable::setTable(const TableOptions &options,
                const std::string &name = options[k].name;
                const std::string &value = options[k].value;
                if (name == "color")
-                       GUIFormSpecMenu::parseColor(value, m_color, false);
+                       parseColorString(value, m_color, false);
                else if (name == "background")
-                       GUIFormSpecMenu::parseColor(value, m_background, false);
+                       parseColorString(value, m_background, false);
                else if (name == "border")
                        m_border = is_yes(value);
                else if (name == "highlight")
-                       GUIFormSpecMenu::parseColor(value, m_highlight, false);
+                       parseColorString(value, m_highlight, false);
                else if (name == "highlight_text")
-                       GUIFormSpecMenu::parseColor(value, m_highlight_text, false);
+                       parseColorString(value, m_highlight_text, false);
                else if (name == "opendepth")
                        opendepth = stoi(value);
                else
@@ -395,7 +416,7 @@ void GUITable::setTable(const TableOptions &options,
                else if (columntype == COLUMN_TYPE_COLOR) {
                        for (s32 i = 0; i < rowcount; ++i) {
                                video::SColor cellcolor(255, 255, 255, 255);
-                               if (GUIFormSpecMenu::parseColor(content[i * colcount + j], cellcolor, true))
+                               if (parseColorString(content[i * colcount + j], cellcolor, true))
                                        rows[i].colors.push_back(std::make_pair(cellcolor, j+span));
                        }
                }
@@ -446,7 +467,7 @@ void GUITable::setTable(const TableOptions &options,
        }
 
        if (m_has_tree_column) {
-               // Treeview: convent tree to indent cells on leaf rows
+               // Treeview: convert tree to indent cells on leaf rows
                for (s32 i = 0; i < rowcount; ++i) {
                        if (i == rowcount-1 || m_rows[i].indent >= m_rows[i+1].indent)
                                for (s32 j = 0; j < m_rows[i].cellcount; ++j)
@@ -617,10 +638,11 @@ void GUITable::draw()
        client_clip.UpperLeftCorner.Y += 1;
        client_clip.UpperLeftCorner.X += 1;
        client_clip.LowerRightCorner.Y -= 1;
-       client_clip.LowerRightCorner.X -=
-               m_scrollbar->isVisible() ?
-               skin->getSize(gui::EGDS_SCROLLBAR_SIZE) :
-               1;
+       client_clip.LowerRightCorner.X -= 1;
+       if (m_scrollbar->isVisible()) {
+               client_clip.LowerRightCorner.X =
+                               m_scrollbar->getAbsolutePosition().UpperLeftCorner.X;
+       }
        client_clip.clipAgainst(AbsoluteClippingRect);
 
        // draw visible rows
@@ -798,7 +820,7 @@ bool GUITable::OnEvent(const SEvent &event)
                        }
 
                        // find the selected item, starting at the current selection
-                       // dont change selection if the key buffer matches the current item
+                       // don't change selection if the key buffer matches the current item
                        s32 old_selected = m_selected;
                        s32 start = MYMAX(m_selected, 0);
                        s32 rowcount = m_visible_rows.size();
@@ -823,7 +845,7 @@ bool GUITable::OnEvent(const SEvent &event)
 
                if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) {
                        m_scrollbar->setPos(m_scrollbar->getPos() +
-                                       (event.MouseInput.Wheel < 0 ? -1 : 1) *
+                                       (event.MouseInput.Wheel < 0 ? -3 : 3) *
                                        - (s32) m_rowheight / 2);
                        return true;
                }
@@ -841,6 +863,14 @@ bool GUITable::OnEvent(const SEvent &event)
                // Update tooltip
                setToolTipText(cell ? m_strings[cell->tooltip_index].c_str() : L"");
 
+               // Fix for #1567/#1806:
+               // IGUIScrollBar passes double click events to its parent,
+               // which we don't want. Detect this case and discard the event
+               if (event.MouseInput.Event != EMIE_MOUSE_MOVED &&
+                               m_scrollbar->isVisible() &&
+                               m_scrollbar->isPointInside(p))
+                       return true;
+
                if (event.MouseInput.isLeftPressed() &&
                                (isPointInside(p) ||
                                 event.MouseInput.Event == EMIE_MOUSE_MOVED)) {
@@ -899,7 +929,7 @@ s32 GUITable::allocString(const std::string &text)
        std::map<std::string, s32>::iterator it = m_alloc_strings.find(text);
        if (it == m_alloc_strings.end()) {
                s32 id = m_strings.size();
-               std::wstring wtext = narrow_to_wide(text);
+               std::wstring wtext = utf8_to_wide(text);
                m_strings.push_back(core::stringw(wtext.c_str()));
                m_alloc_strings.insert(std::make_pair(text, id));
                return id;