#include <string>
#if USE_FREETYPE
-#include "xCGUITTFont.h"
+ #include "irrlicht_changes/CGUITTFont.h"
#endif
inline u32 clamp_u8(s32 value)
m_chat_backend(backend),
m_client(client),
m_menumgr(menumgr),
- m_screensize(v2u32(0,0)),
- m_animate_time_old(0),
- 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())
{
- m_animate_time_old = getTimeMs();
-
// load background settings
s32 console_alpha = g_settings->getS32("console_alpha");
m_background_color.setAlpha(clamp_u8(console_alpha));
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();
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 = porting::getTimeMs();
+ IGUIElement::setVisible(true);
Environment->setFocus(this);
m_menumgr->createdMenu(this);
}
// 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();
}
// Animation
- u32 now = getTimeMs();
+ u64 now = porting::getTimeMs();
animate(now - m_animate_time_old);
m_animate_time_old = now;
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);
}
{
// animate the console height
s32 goal = m_open ? m_desired_height : 0;
+
+ // Set invisible if close animation finished (reset by openConsole)
+ // 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)
{
s32 max_change = msec * m_screensize.Y * (m_height_speed / 1000.0);
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
}
}
}
void GUIChatConsole::drawPrompt()
{
- if (m_font == NULL)
+ if (!m_font)
return;
u32 row = m_chat_backend->getConsoleBuffer().getRows();
bool backwards = event.KeyInput.Shift;
prompt.nickCompletion(names, backwards);
return true;
- }
- else if(event.KeyInput.Char != 0 && !event.KeyInput.Control)
- {
- #if (defined(linux) || defined(__linux))
+ } else if (!iswcntrl(event.KeyInput.Char) && !event.KeyInput.Control) {
+ #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);
return Parent ? Parent->OnEvent(event) : false;
}
+void GUIChatConsole::setVisible(bool visible)
+{
+ m_open = visible;
+ IGUIElement::setVisible(visible);
+ if (!visible) {
+ m_height = 0;
+ recalculateConsolePosition();
+ }
+}
+