Optimize updateFastFaceRow processing by removing some TileSpec copy (#5678)
[oweals/minetest.git] / src / guiChatConsole.cpp
index ec9d3ffdc45957dc978c3f8375f4de06816eca42..b3c11955533d1e7f3ecfae2db7e7312a40191f44 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 "xCGUITTFont.h"
 #endif
 
 inline u32 clamp_u8(s32 value)
@@ -55,7 +55,7 @@ GUIChatConsole::GUIChatConsole(
        m_client(client),
        m_menumgr(menumgr),
        m_screensize(v2u32(0,0)),
-       m_animate_time_old(0),
+       m_animate_time_old(porting::getTimeMs()),
        m_open(false),
        m_close_on_enter(false),
        m_height(0),
@@ -71,8 +71,6 @@ GUIChatConsole::GUIChatConsole(
        m_font(NULL),
        m_fontsize(0, 0)
 {
-       m_animate_time_old = getTimeMs();
-
        // load background settings
        s32 console_alpha = g_settings->getS32("console_alpha");
        m_background_color.setAlpha(clamp_u8(console_alpha));
@@ -116,13 +114,15 @@ GUIChatConsole::~GUIChatConsole()
                m_font->drop();
 }
 
-void GUIChatConsole::openConsole(f32 height)
+void GUIChatConsole::openConsole(f32 scale)
 {
+       assert(scale > 0.0f && scale <= 1.0f);
+
        m_open = true;
-       m_desired_height_fraction = height;
-       m_desired_height = height * m_screensize.Y;
+       m_desired_height_fraction = scale;
+       m_desired_height = scale * m_screensize.Y;
        reformatConsole();
-       m_animate_time_old = getTimeMs();
+       m_animate_time_old = porting::getTimeMs();
        IGUIElement::setVisible(true);
        Environment->setFocus(this);
        m_menumgr->createdMenu(this);
@@ -210,7 +210,7 @@ void GUIChatConsole::draw()
        }
 
        // Animation
-       u32 now = getTimeMs();
+       u64 now = porting::getTimeMs();
        animate(now - m_animate_time_old);
        m_animate_time_old = now;
 
@@ -247,7 +247,9 @@ void GUIChatConsole::animate(u32 msec)
        s32 goal = m_open ? m_desired_height : 0;
 
        // Set invisible if close animation finished (reset by openConsole)
-       if (!m_open && m_height == 0)
+       // This function (animate()) is never called once its visibility becomes false so do not
+       //              actually set visible to false before the inhibited period is over
+       if (!m_open && m_height == 0 && m_open_inhibited == 0)
                IGUIElement::setVisible(false);
 
        if (m_height != goal)
@@ -338,13 +340,28 @@ void GUIChatConsole::drawText()
                        s32 x = (fragment.column + 1) * m_fontsize.X;
                        core::rect<s32> destrect(
                                x, y, x + m_fontsize.X * fragment.text.size(), y + m_fontsize.Y);
-                       m_font->draw(
-                               fragment.text.c_str(),
-                               destrect,
-                               video::SColor(255, 255, 255, 255),
-                               false,
-                               false,
-                               &AbsoluteClippingRect);
+
+
+                       #if USE_FREETYPE
+                       // Draw colored text if FreeType is enabled
+                               irr::gui::CGUITTFont *tmp = static_cast<irr::gui::CGUITTFont*>(m_font);
+                               tmp->draw(
+                                       fragment.text,
+                                       destrect,
+                                       video::SColor(255, 255, 255, 255),
+                                       false,
+                                       false,
+                                       &AbsoluteClippingRect);
+                       #else
+                       // Otherwise use standard text
+                               m_font->draw(
+                                       fragment.text.c_str(),
+                                       destrect,
+                                       video::SColor(255, 255, 255, 255),
+                                       false,
+                                       false,
+                                       &AbsoluteClippingRect);
+                       #endif
                }
        }
 }
@@ -613,7 +630,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
                }
                else if(event.KeyInput.Char != 0 && !event.KeyInput.Control)
                {
-                       #if (defined(linux) || defined(__linux))
+                       #if defined(__linux__) && (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9)
                                wchar_t wc = L'_';
                                mbtowc( &wc, (char *) &event.KeyInput.Char, sizeof(event.KeyInput.Char) );
                                prompt.input(wc);