pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r3122 - trunk/pingus/src/editor


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3122 - trunk/pingus/src/editor
Date: Tue, 11 Sep 2007 17:01:26 +0200

Author: grumbel
Date: 2007-09-11 17:01:25 +0200 (Tue, 11 Sep 2007)
New Revision: 3122

Added:
   trunk/pingus/src/editor/inputbox.cpp
   trunk/pingus/src/editor/inputbox.hpp
Log:
- added inputbox

Added: trunk/pingus/src/editor/inputbox.cpp
===================================================================
--- trunk/pingus/src/editor/inputbox.cpp        2007-09-11 14:59:04 UTC (rev 
3121)
+++ trunk/pingus/src/editor/inputbox.cpp        2007-09-11 15:01:25 UTC (rev 
3122)
@@ -0,0 +1,79 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  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 (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.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#include <iostream>
+#include "fonts.hpp"
+#include "display/drawing_context.hpp"
+#include "inputbox.hpp"
+
+namespace Editor {
+
+Inputbox::Inputbox(const Rect& rect)
+  : RectComponent(rect)
+{
+}
+
+void
+Inputbox::draw(DrawingContext& gc)
+{
+  gc.draw_fillrect(rect, Color(255,255,255));
+  gc.draw_rect(rect, has_focus ? Color(255,128,0) : Color(0,0,0));
+  
+  gc.print_left(Fonts::verdana11, rect.left + 5, 
+                rect.top + rect.get_height()/2 - 
Fonts::verdana11.get_height()/2,
+                text);
+}
+
+void
+Inputbox::set_text(const std::string& text_)
+{
+  text = text_;
+}
+
+void
+Inputbox::on_key_pressed(const unsigned short c)
+{
+  if (c == 8) // backspace
+    {
+      if (!text.empty())
+        {
+          text = text.substr(0, text.size()-1);
+          on_change(text);
+        }      
+    }
+  else if (c == 13) // enter
+    {
+      on_change(text);      
+    }
+  else
+    { // FIXME: This doesn't handle UTF8 properly 
+      text += c;
+      on_change(text);
+    }
+}
+
+} // namespace Editor
+
+/* EOF */


Property changes on: trunk/pingus/src/editor/inputbox.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/editor/inputbox.hpp
===================================================================
--- trunk/pingus/src/editor/inputbox.hpp        2007-09-11 14:59:04 UTC (rev 
3121)
+++ trunk/pingus/src/editor/inputbox.hpp        2007-09-11 15:01:25 UTC (rev 
3122)
@@ -0,0 +1,61 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  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 (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.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#ifndef HEADER_INPUTBOX_HPP
+#define HEADER_INPUTBOX_HPP
+
+#include <boost/signal.hpp>
+#include "gui/rect_component.hpp"
+
+namespace Editor {
+
+/** */
+class Inputbox : public GUI::RectComponent
+{
+private:
+  std::string text;
+  
+public:
+  Inputbox(const Rect& rect);
+
+  void draw(DrawingContext& gc);
+  
+  void set_text(const std::string& text);
+  std::string get_text() const { return text; }
+  void on_key_pressed(const unsigned short c);
+
+  void update_layout() {}
+
+  boost::signal<void (const std::string&)> on_change;
+private:
+  Inputbox (const Inputbox&);
+  Inputbox& operator= (const Inputbox&);
+};
+
+} // namespace Editor
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/editor/inputbox.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native





reply via email to

[Prev in Thread] Current Thread [Next in Thread]