pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3105 - in trunk/pingus/src: components editor gui


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3105 - in trunk/pingus/src: components editor gui
Date: Fri, 7 Sep 2007 16:58:51 +0200

Author: grumbel
Date: 2007-09-07 16:58:50 +0200 (Fri, 07 Sep 2007)
New Revision: 3105

Added:
   trunk/pingus/src/gui/rect_component.hpp
Modified:
   trunk/pingus/src/components/action_button.cpp
   trunk/pingus/src/components/action_button.hpp
   trunk/pingus/src/editor/editor_screen.hpp
   trunk/pingus/src/editor/level_objs.cpp
   trunk/pingus/src/editor/object_selector.cpp
   trunk/pingus/src/gui/component.hpp
   trunk/pingus/src/gui/input_box.cpp
   trunk/pingus/src/gui/input_box.hpp
Log:
- added RectComponent class
- some misc other cleanup

Modified: trunk/pingus/src/components/action_button.cpp
===================================================================
--- trunk/pingus/src/components/action_button.cpp       2007-09-06 23:00:18 UTC 
(rev 3104)
+++ trunk/pingus/src/components/action_button.cpp       2007-09-07 14:58:50 UTC 
(rev 3105)
@@ -52,12 +52,6 @@
   sprite.set_play_loop(true);
 }
 
-bool
-ActionButton::is_pressed()
-{
-  return false;
-}
-
 void
 ActionButton::update(float delta)
 {

Modified: trunk/pingus/src/components/action_button.hpp
===================================================================
--- trunk/pingus/src/components/action_button.hpp       2007-09-06 23:00:18 UTC 
(rev 3104)
+++ trunk/pingus/src/components/action_button.hpp       2007-09-07 14:58:50 UTC 
(rev 3105)
@@ -153,9 +153,6 @@
   /// Returns the name of the action the button represents.
   Actions::ActionName get_action_name();
 
-  /// Returns true if the button is pressed.
-  bool   is_pressed();
-
   virtual bool   is_at(int x, int y) = 0;
 
 private:

Modified: trunk/pingus/src/editor/editor_screen.hpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.hpp   2007-09-06 23:00:18 UTC (rev 
3104)
+++ trunk/pingus/src/editor/editor_screen.hpp   2007-09-07 14:58:50 UTC (rev 
3105)
@@ -31,7 +31,7 @@
 class Pathname;
 
 namespace Editor {
-
+
 class EditorLevel;
 class LevelObj;
 class Panel;
@@ -144,8 +144,9 @@
   EditorScreen (const EditorScreen&);
   EditorScreen& operator= (const EditorScreen&);
 
-};     // EditorScreen
-}  // Editor namespace
+};
+
+} // namespace Editor 
 
 #endif
 

Modified: trunk/pingus/src/editor/level_objs.cpp
===================================================================
--- trunk/pingus/src/editor/level_objs.cpp      2007-09-06 23:00:18 UTC (rev 
3104)
+++ trunk/pingus/src/editor/level_objs.cpp      2007-09-07 14:58:50 UTC (rev 
3105)
@@ -72,8 +72,9 @@
       // If selected, draw a highlighted box around it
       if (selected)
         {
-          gc.draw_rect(translated_pos.x, translated_pos.y, translated_pos.x 
-                       + sprite.get_width(), translated_pos.y + 
sprite.get_height(), 
+          gc.draw_rect(translated_pos.x, translated_pos.y, 
+                       translated_pos.x + sprite.get_width(), 
+                       translated_pos.y + sprite.get_height(), 
                        Color(255,0,0), 5000);
         }
 

Modified: trunk/pingus/src/editor/object_selector.cpp
===================================================================
--- trunk/pingus/src/editor/object_selector.cpp 2007-09-06 23:00:18 UTC (rev 
3104)
+++ trunk/pingus/src/editor/object_selector.cpp 2007-09-07 14:58:50 UTC (rev 
3105)
@@ -217,6 +217,9 @@
                                  x * 48 + 48, y * 48 + 48, 
                                  (((x-(y%2)) % 2) ? Color(0,0,0) : 
Color(100,100,100)));
                 
+                gc.draw_rect(x * 48,      y * 48, 
+                             x * 48 + 48, y * 48 + 48, 
+                             Color(155,155,155), 10000);
               }
 
             gc.draw(i->sprite, 

Modified: trunk/pingus/src/gui/component.hpp
===================================================================
--- trunk/pingus/src/gui/component.hpp  2007-09-06 23:00:18 UTC (rev 3104)
+++ trunk/pingus/src/gui/component.hpp  2007-09-07 14:58:50 UTC (rev 3105)
@@ -45,7 +45,7 @@
   virtual void update (float delta) { UNUSED_ARG(delta);}
 
   virtual bool is_at (int x, int y) { UNUSED_ARG(x); UNUSED_ARG(y); return 
false; }
-
+
   // Events
   /** Gets issued once the primary button is pressed */
   virtual void on_primary_button_press (int x, int y) { UNUSED_ARG(x); 
UNUSED_ARG(y); }
@@ -78,14 +78,6 @@
       components should implement this */
   virtual void on_key_pressed(const unsigned short c) { UNUSED_ARG(c); }
 
-  // status functions for use in the update() function
-  /** return true if currently pressed */
-  bool is_pressed ();
-
-  /** true if mouse is currently over, FIXME: these seem to be
-      unimplementable without renaming on_pointer_enter() and wrapp them */
-  bool pointer_over();
-
 private:
   Component (const Component&);
   Component& operator= (const Component&);

Modified: trunk/pingus/src/gui/input_box.cpp
===================================================================
--- trunk/pingus/src/gui/input_box.cpp  2007-09-06 23:00:18 UTC (rev 3104)
+++ trunk/pingus/src/gui/input_box.cpp  2007-09-07 14:58:50 UTC (rev 3105)
@@ -27,77 +27,76 @@
        
 InputBox::InputBox(float width_, Vector3f p, const std::string& default_value,
                    bool locked, const std::string& label_) 
-       :       str(default_value),
+  :    str(default_value),
        pos(p),
        width(width_),
        height((float)Fonts::pingus_small.get_height()),
        is_locked(locked),
        label(label_)
 {
-       
 }
 
 void
 InputBox::draw(DrawingContext &gc)
 {
-       // Draw the rectangle and border
-       gc.draw_fillrect(pos.x, pos.y, pos.x + width, pos.y + height, 
-                         Color(0,0,0));
-       gc.draw_rect(pos.x, pos.y, pos.x + width, pos.y + height, 
Color(255,255,255));  
+  // Draw the rectangle and border
+  gc.draw_fillrect(pos.x, pos.y, pos.x + width, pos.y + height, 
+                   Color(0,0,0));
+  gc.draw_rect(pos.x, pos.y, pos.x + width, pos.y + height, 
Color(255,255,255));       
 
-       // If there is text, draw it:
-       if (str != std::string())
-               gc.print_left(Fonts::pingus_small, pos.x + 10, pos.y, 
shrink_string(str));
+  // If there is text, draw it:
+  if (str != std::string())
+    gc.print_left(Fonts::pingus_small, pos.x + 10, pos.y, shrink_string(str));
 
-       if (label != std::string())
-               gc.print_right(Fonts::pingus_small, pos.x, pos.y, label);
+  if (label != std::string())
+    gc.print_right(Fonts::pingus_small, pos.x, pos.y, label);
      
-       if (has_focus)
-               gc.draw_line(pos.x + 
Fonts::pingus_small.get_size(shrink_string(str)).width + 12,
-                       pos.y, pos.x + 
Fonts::pingus_small.get_size(shrink_string(str)).width + 12, 
-                             pos.y + height,   Color(0,255,255));
+  if (has_focus)
+    gc.draw_line(pos.x + 
Fonts::pingus_small.get_size(shrink_string(str)).width + 12,
+                 pos.y, pos.x + 
Fonts::pingus_small.get_size(shrink_string(str)).width + 12, 
+                 pos.y + height,       Color(0,255,255));
 }
 
 bool
 InputBox::is_at(int x, int y)
 {
-       return (x > pos.x && x < pos.x + width &&
-               y > pos.y && y < pos.y + height);
+  return (x > pos.x && x < pos.x + width &&
+          y > pos.y && y < pos.y + height);
 }
 
 std::string
 InputBox::shrink_string(const std::string& s) const
 {
-       std::string ret_string;
-       int w = (int)width / Fonts::pingus_small.get_width('W');
+  std::string ret_string;
+  int w = (int)width / Fonts::pingus_small.get_width('W');
        
-       if ((int)s.length() > w - 1)
-               ret_string = s.substr(std::max(0, (int)s.length()-w), w - 1);
-       else
-               ret_string = s;
+  if ((int)s.length() > w - 1)
+    ret_string = s.substr(std::max(0, (int)s.length()-w), w - 1);
+  else
+    ret_string = s;
        
-       return ret_string;
+  return ret_string;
 }
 
 void
 InputBox::on_key_pressed(const unsigned short c)
 {
-       if (!is_locked)
-       {
-               // Verify input and escape out bad characters
-               if (c == 0x08)  // backspace
-               {
-                       str = str.substr(0, str.length()-1);
-               }
-               else if ((c > 0x2c && c < 0x3a)    // - . / 0-9
-                       || (c > 0x40 && c < 0x5b)        // capital letters
-                       || (c > 0x60 && c < 0x7b)        // lowercase letters
-                       || (c == 0x7e || c == 0x5f)      // ~ and _
-                       ||  c == 0x20)                   // space
-               {
-                       str += (unsigned char)c;
-               }
-       }
+  if (!is_locked)
+    {
+      // Verify input and escape out bad characters
+      if (c == 0x08)   // backspace
+        {
+          str = str.substr(0, str.length()-1);
+        }
+      else if ((c > 0x2c && c < 0x3a)    // - . / 0-9
+               || (c > 0x40 && c < 0x5b)        // capital letters
+               || (c > 0x60 && c < 0x7b)        // lowercase letters
+               || (c == 0x7e || c == 0x5f)      // ~ and _
+               ||  c == 0x20)                   // space
+        {
+          str += (unsigned char)c;
+        }
+    }
 }
 
 }      // GUI

Modified: trunk/pingus/src/gui/input_box.hpp
===================================================================
--- trunk/pingus/src/gui/input_box.hpp  2007-09-06 23:00:18 UTC (rev 3104)
+++ trunk/pingus/src/gui/input_box.hpp  2007-09-07 14:58:50 UTC (rev 3105)
@@ -24,45 +24,44 @@
 #include "../math/vector3f.hpp"
 #include <string>
 
+class DrawingContext;
 
-       class DrawingContext;
-
 namespace GUI {
-
+
 /** This class allows keyboard input to be displayed in a box */
 class InputBox : public GUI::Component {
 protected:
-       std::string str;
-       Vector3f pos;
-       float width;
-       float height;
-       bool is_locked;
+  std::string str;
+  Vector3f pos;
+  float width;
+  float height;
+  bool  is_locked;
 
-       /** Shrink the string to fit in the box */
-       std::string shrink_string(const std::string& s) const;
+  /** Shrink the string to fit in the box */
+  std::string shrink_string(const std::string& s) const;
   
-       /** Optional label to display */
-       std::string label;  
+  /** Optional label to display */
+  std::string label;  
 
 public:
   InputBox(float width_, Vector3f p, const std::string& 
-               default_value = std::string(), bool locked = false,
-       const std::string& label_ = std::string());
+           default_value = std::string(), bool locked = false,
+           const std::string& label_ = std::string());
 
-       void set_string(const std::string& s) { str = s; }
-       std::string get_string() { return str; }
+  void set_string(const std::string& s) { str = s; }
+  std::string get_string() { return str; }
        
-       void on_key_pressed(const unsigned short c);
+  void on_key_pressed(const unsigned short c);
        
-       /// GUI Component functions:
-       ///
-       void update(float delta) { }
+  /// GUI Component functions:
+  ///
+  void update(float delta) { }
        
-       bool is_at(int x, int y);
+  bool is_at(int x, int y);
        
-       void draw(DrawingContext &gc);
+  void draw(DrawingContext &gc);
 };     // InputBox class
-
+
 }      // GUI namespace
 
 #endif

Added: trunk/pingus/src/gui/rect_component.hpp
===================================================================
--- trunk/pingus/src/gui/rect_component.hpp     2007-09-06 23:00:18 UTC (rev 
3104)
+++ trunk/pingus/src/gui/rect_component.hpp     2007-09-07 14:58:50 UTC (rev 
3105)
@@ -0,0 +1,53 @@
+//  $Id$
+//
+//  Pingus - A free Lemmings clone
+//  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_PINGUS_GUI_RECT_COMPONENT_HPP
+#define HEADER_PINGUS_GUI_RECT_COMPONENT_HPP
+
+#include "component.hpp"
+
+namespace GUI {
+
+/** */
+class RectComponent : public Component
+{
+protected:
+  Rect rect;
+
+public:
+  RectComponent(const Rect& rect_)
+    : rect(rect_)
+  {}
+  
+  virtual bool is_at (int x, int y) { return rect.is_inside(Vector2i(x, y)); }
+  
+  void set_rect(const Rect& rect_) 
+  {
+    rect = rect_;
+    layout();
+  }
+
+  virtual void update_layout() =0;
+};
+
+} // namespace GUI
+
+#endif
+
+/* EOF */


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





reply via email to

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