]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/gui/guiTable.cpp
Various code improvements
[dragonfireclient.git] / src / gui / guiTable.cpp
index a2738afa9dac4d1f2d222a05a83a8bb85f8ea6ee..79ae1aea31525f9af2b3a08a35e0db4da0e947cf 100644 (file)
@@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <cstring>
 #include <IGUISkin.h>
 #include <IGUIFont.h>
-#include <IGUIScrollBar.h>
 #include "client/renderingengine.h"
 #include "debug.h"
 #include "log.h"
@@ -36,7 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "util/string.h" // for parseColorString()
 #include "settings.h" // for settings
 #include "porting.h" // for dpi
-#include "guiscalingfilter.h"
+#include "client/guiscalingfilter.h"
 
 /*
        GUITable
@@ -57,17 +56,17 @@ GUITable::GUITable(gui::IGUIEnvironment *env,
        m_font = skin->getFont();
        if (m_font) {
                m_font->grab();
-               m_rowheight = m_font->getDimension(L"A").Height + 4;
+               m_rowheight = m_font->getDimension(L"Ay").Height + 4;
                m_rowheight = MYMAX(m_rowheight, 1);
        }
 
        const s32 s = skin->getSize(gui::EGDS_SCROLLBAR_SIZE);
-       m_scrollbar = Environment->addScrollBar(false,
+       m_scrollbar = new GUIScrollBar(Environment, this, -1,
                        core::rect<s32>(RelativeRect.getWidth() - s,
                                        0,
                                        RelativeRect.getWidth(),
                                        RelativeRect.getHeight()),
-                       this, -1);
+                       false, true);
        m_scrollbar->setSubElement(true);
        m_scrollbar->setTabStop(false);
        m_scrollbar->setAlignment(gui::EGUIA_LOWERRIGHT, gui::EGUIA_LOWERRIGHT,
@@ -78,10 +77,13 @@ GUITable::GUITable(gui::IGUIEnvironment *env,
        setTabStop(true);
        setTabOrder(-1);
        updateAbsolutePosition();
-
+#ifdef HAVE_TOUCHSCREENGUI
+       float density = 1; // dp scaling is applied by the skin
+#else
+       float density = RenderingEngine::getDisplayDensity();
+#endif
        core::rect<s32> relative_rect = m_scrollbar->getRelativePosition();
-       s32 width = (relative_rect.getWidth()/(2.0/3.0)) *
-                       RenderingEngine::getDisplayDensity() *
+       s32 width = (relative_rect.getWidth() / (2.0 / 3.0)) * density *
                        g_settings->getFloat("gui_scaling");
        m_scrollbar->setRelativePosition(core::rect<s32>(
                        relative_rect.LowerRightCorner.X-width,relative_rect.UpperLeftCorner.Y,
@@ -97,7 +99,8 @@ GUITable::~GUITable()
        if (m_font)
                m_font->drop();
 
-       m_scrollbar->remove();
+       if (m_scrollbar)
+               m_scrollbar->drop();
 }
 
 GUITable::Option GUITable::splitOption(const std::string &str)
@@ -334,7 +337,6 @@ void GUITable::setTable(const TableOptions &options,
 
                // Make template for new cells
                Cell newcell;
-               memset(&newcell, 0, sizeof newcell);
                newcell.content_type = columntype;
                newcell.tooltip_index = tooltip_index;
                newcell.reported_column = j+1;
@@ -585,6 +587,31 @@ void GUITable::setSelected(s32 index)
        }
 }
 
+void GUITable::setOverrideFont(IGUIFont *font)
+{
+       if (m_font == font)
+               return;
+
+       if (font == nullptr)
+               font = Environment->getSkin()->getFont();
+
+       if (m_font)
+               m_font->drop();
+
+       m_font = font;
+       m_font->grab();
+
+       m_rowheight = m_font->getDimension(L"Ay").Height + 4;
+       m_rowheight = MYMAX(m_rowheight, 1);
+
+       updateScrollBar();
+}
+
+IGUIFont *GUITable::getOverrideFont() const
+{
+       return m_font;
+}
+
 GUITable::DynamicData GUITable::getDynamicData() const
 {
        DynamicData dyndata;
@@ -1074,6 +1101,7 @@ void GUITable::updateScrollBar()
        m_scrollbar->setMax(scrollmax);
        m_scrollbar->setSmallStep(m_rowheight);
        m_scrollbar->setLargeStep(2 * m_rowheight);
+       m_scrollbar->setPageSize(totalheight);
 }
 
 void GUITable::sendTableEvent(s32 column, bool doubleclick)