]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/guiChatConsole.cpp
Fix use of uninit data in Sky and (potentially) GUIChatConsole constructors
[dragonfireclient.git] / src / guiChatConsole.cpp
index d11a50e20280c0bc7459774e3d07394963872069..19d9e3007e8a116cc3d266a52b0275296d00a815 100644 (file)
@@ -1,18 +1,18 @@
 /*
-Minetest-c55
-Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+GNU Lesser General Public License for more details.
 
-You should have received a copy of the GNU General Public License along
+You should have received a copy of the GNU Lesser General Public License along
 with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
@@ -27,11 +27,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "main.h"  // for g_settings
 #include "porting.h"
 #include "tile.h"
-#include "IGUIFont.h"
+#include "fontengine.h"
 #include <string>
 
 #include "gettext.h"
 
+#if USE_FREETYPE
+#include "xCGUITTFont.h"
+#endif
+
 inline u32 clamp_u8(s32 value)
 {
        return (u32) MYMIN(MYMAX(value, 0), 255);
@@ -68,33 +72,28 @@ GUIChatConsole::GUIChatConsole(
        m_animate_time_old = getTimeMs();
 
        // load background settings
-       bool console_color_set = !g_settings->get("console_color").empty();
        s32 console_alpha = g_settings->getS32("console_alpha");
+       m_background_color.setAlpha(clamp_u8(console_alpha));
 
        // load the background texture depending on settings
-       m_background_color.setAlpha(clamp_u8(console_alpha));
-       if (console_color_set)
-       {
+       ITextureSource *tsrc = client->getTextureSource();
+       if (tsrc->isKnownSourceImage("background_chat.jpg")) {
+               m_background = tsrc->getTexture("background_chat.jpg");
+               m_background_color.setRed(255);
+               m_background_color.setGreen(255);
+               m_background_color.setBlue(255);
+       } else {
                v3f console_color = g_settings->getV3F("console_color");
                m_background_color.setRed(clamp_u8(myround(console_color.X)));
                m_background_color.setGreen(clamp_u8(myround(console_color.Y)));
                m_background_color.setBlue(clamp_u8(myround(console_color.Z)));
        }
-       else
-       {
-               m_background = env->getVideoDriver()->getTexture(getTexturePath("background_chat.jpg").c_str());
-               m_background_color.setRed(255);
-               m_background_color.setGreen(255);
-               m_background_color.setBlue(255);
-       }
 
-       // load the font
-       // FIXME should a custom texture_path be searched too?
-       std::string font_name = "fontdejavusansmono.png";
-       m_font = env->getFont(getTexturePath(font_name).c_str());
+       m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono);
+
        if (m_font == NULL)
        {
-               dstream << "Unable to load font: " << font_name << std::endl;
+               errorstream << "GUIChatConsole: Unable to load mono font ";
        }
        else
        {
@@ -110,8 +109,7 @@ GUIChatConsole::GUIChatConsole(
 }
 
 GUIChatConsole::~GUIChatConsole()
-{
-}
+{}
 
 void GUIChatConsole::openConsole(f32 height)
 {
@@ -121,6 +119,11 @@ void GUIChatConsole::openConsole(f32 height)
        reformatConsole();
 }
 
+bool GUIChatConsole::isOpen() const
+{
+       return m_open;
+}
+
 bool GUIChatConsole::isOpenInhibited() const
 {
        return m_open_inhibited > 0;
@@ -501,6 +504,19 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
                                scope);
                        return true;
                }
+               else if(event.KeyInput.Key == KEY_KEY_V && event.KeyInput.Control)
+               {
+                       // Ctrl-V pressed
+                       // paste text from clipboard
+                       IOSOperator *os_operator = Environment->getOSOperator();
+                       const c8 *text = os_operator->getTextFromClipboard();
+                       if (text)
+                       {
+                               std::wstring wtext = narrow_to_wide(text);
+                               m_chat_backend->getPrompt().input(wtext);
+                       }
+                       return true;
+               }
                else if(event.KeyInput.Key == KEY_KEY_U && event.KeyInput.Control)
                {
                        // Ctrl-U pressed
@@ -525,14 +541,20 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
                {
                        // Tab or Shift-Tab pressed
                        // Nick completion
-                       core::list<std::wstring> names = m_client->getConnectedPlayerNames();
+                       std::list<std::string> names = m_client->getConnectedPlayerNames();
                        bool backwards = event.KeyInput.Shift;
                        m_chat_backend->getPrompt().nickCompletion(names, backwards);
                        return true;
                }
                else if(event.KeyInput.Char != 0 && !event.KeyInput.Control)
                {
-                       m_chat_backend->getPrompt().input(event.KeyInput.Char);
+                       #if (defined(linux) || defined(__linux))
+                               wchar_t wc = L'_';
+                               mbtowc( &wc, (char *) &event.KeyInput.Char, sizeof(event.KeyInput.Char) );
+                               m_chat_backend->getPrompt().input(wc);
+                       #else
+                               m_chat_backend->getPrompt().input(event.KeyInput.Char);
+                       #endif
                        return true;
                }
        }