Noise: Prevent unittest crash caused by division by zero
[oweals/minetest.git] / src / guiChatConsole.cpp
index 5bb80bbbe1b8c44931d5d7f2725f310b5bbcf718..0dbddf31cd530b097d4bbd85d7ebbca58ab8347b 100644 (file)
@@ -32,7 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <string>
 
 #if USE_FREETYPE
-       #include "xCGUITTFont.h"
+       #include "irrlicht_changes/CGUITTFont.h"
 #endif
 
 inline u32 clamp_u8(s32 value)
@@ -54,22 +54,7 @@ GUIChatConsole::GUIChatConsole(
        m_chat_backend(backend),
        m_client(client),
        m_menumgr(menumgr),
-       m_screensize(v2u32(0,0)),
-       m_animate_time_old(porting::getTimeMs()),
-       m_open(false),
-       m_close_on_enter(false),
-       m_height(0),
-       m_desired_height(0),
-       m_desired_height_fraction(0.0),
-       m_height_speed(5.0),
-       m_open_inhibited(0),
-       m_cursor_blink(0.0),
-       m_cursor_blink_speed(0.0),
-       m_cursor_height(0.0),
-       m_background(NULL),
-       m_background_color(255, 0, 0, 0),
-       m_font(NULL),
-       m_fontsize(0, 0)
+       m_animate_time_old(porting::getTimeMs())
 {
        // load background settings
        s32 console_alpha = g_settings->getS32("console_alpha");
@@ -91,12 +76,9 @@ GUIChatConsole::GUIChatConsole(
 
        m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono);
 
-       if (m_font == NULL)
-       {
+       if (!m_font) {
                errorstream << "GUIChatConsole: Unable to load mono font ";
-       }
-       else
-       {
+       } else {
                core::dimension2d<u32> dim = m_font->getDimension(L"M");
                m_fontsize = v2u32(dim.Width, dim.Height);
                m_font->grab();
@@ -204,8 +186,8 @@ void GUIChatConsole::draw()
                // scale current console height to new window size
                if (m_screensize.Y != 0)
                        m_height = m_height * screensize.Y / m_screensize.Y;
-               m_desired_height = m_desired_height_fraction * m_screensize.Y;
                m_screensize = screensize;
+               m_desired_height = m_desired_height_fraction * m_screensize.Y;
                reformatConsole();
        }
 
@@ -231,6 +213,7 @@ void GUIChatConsole::reformatConsole()
        s32 rows = m_desired_height / m_fontsize.Y - 1; // make room for the input prompt
        if (cols <= 0 || rows <= 0)
                cols = rows = 0;
+       recalculateConsolePosition();
        m_chat_backend->reformat(cols, rows);
 }
 
@@ -368,7 +351,7 @@ void GUIChatConsole::drawText()
 
 void GUIChatConsole::drawPrompt()
 {
-       if (m_font == NULL)
+       if (!m_font)
                return;
 
        u32 row = m_chat_backend->getConsoleBuffer().getRows();