pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3118 - in trunk/pingus/src: . display editor gui


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3118 - in trunk/pingus/src: . display editor gui
Date: Mon, 10 Sep 2007 01:18:43 +0200

Author: grumbel
Date: 2007-09-10 01:18:42 +0200 (Mon, 10 Sep 2007)
New Revision: 3118

Added:
   trunk/pingus/src/editor/combobox.cpp
   trunk/pingus/src/editor/combobox.hpp
Modified:
   trunk/pingus/src/SConscript
   trunk/pingus/src/display/drawing_context.cpp
   trunk/pingus/src/display/drawing_context.hpp
   trunk/pingus/src/editor/object_properties.cpp
   trunk/pingus/src/editor/object_properties.hpp
   trunk/pingus/src/editor/object_selector.hpp
   trunk/pingus/src/gui/combobox.cpp
   trunk/pingus/src/gui/combobox.hpp
Log:
- fitted combo box for the editor

Modified: trunk/pingus/src/SConscript
===================================================================
--- trunk/pingus/src/SConscript 2007-09-09 17:42:23 UTC (rev 3117)
+++ trunk/pingus/src/SConscript 2007-09-09 23:18:42 UTC (rev 3118)
@@ -98,7 +98,8 @@
 'editor/file_list.cpp',
 'editor/file_load_dialog.cpp',
 'editor/file_save_dialog.cpp', 
-'editor/editor_screen.cpp', 
+'editor/editor_screen.cpp',
+'editor/combobox.cpp', 
 'editor/editor_viewport.cpp', 
 'editor/level_objs.cpp',
 'editor/object_selector.cpp',

Modified: trunk/pingus/src/display/drawing_context.cpp
===================================================================
--- trunk/pingus/src/display/drawing_context.cpp        2007-09-09 17:42:23 UTC 
(rev 3117)
+++ trunk/pingus/src/display/drawing_context.cpp        2007-09-09 23:18:42 UTC 
(rev 3118)
@@ -274,6 +274,30 @@
 }
 
 void
+DrawingContext::draw_fillrect (const Rect& rect, const Color& color, float z)
+{
+  draw(new RectDrawingRequest(Rect(int(rect.left + translate_stack.back().x), 
+                                   int(rect.top + translate_stack.back().y), 
+                                   int(rect.right + translate_stack.back().x), 
+                                   int(rect.bottom + 
translate_stack.back().y)),
+                              color,
+                              true,
+                              z));  
+}
+
+void
+DrawingContext::draw_rect (const Rect& rect, const Color& color, float z)
+{
+  draw(new RectDrawingRequest(Rect(int(rect.left + translate_stack.back().x),
+                                   int(rect.top + translate_stack.back().y), 
+                                   int(rect.right + translate_stack.back().x),
+                                   int(rect.bottom + 
translate_stack.back().y)),
+                              color,
+                              false,
+                              z));  
+}
+
+void
 DrawingContext::draw_fillrect (float x1, float y1, float x2, float y2, 
                                const Color& color, float z)
 {

Modified: trunk/pingus/src/display/drawing_context.hpp
===================================================================
--- trunk/pingus/src/display/drawing_context.hpp        2007-09-09 17:42:23 UTC 
(rev 3117)
+++ trunk/pingus/src/display/drawing_context.hpp        2007-09-09 23:18:42 UTC 
(rev 3118)
@@ -85,6 +85,12 @@
                      const Color& color, float z = 0);
   void draw_rect (float x1, float y1, float x2, float y2, 
                  const Color& color, float z = 0);
+
+  void draw_fillrect (const Rect& rect,
+                     const Color& color, float z = 0);
+  void draw_rect (const Rect& rect,
+                 const Color& color, float z = 0);
+
   void draw_pixel (float x_pos, float y_pos, 
                   const Color& color);
   void draw_circle (float x_pos, float y_pos, float radius,
@@ -133,6 +139,7 @@
   Vector2i screen_to_world(const Vector2i pos);
   Vector2i world_to_screen(const Vector2i pos);
 
+  void update_layout() {}
 private:
   DrawingContext (const DrawingContext&);
   DrawingContext& operator= (const DrawingContext&);

Added: trunk/pingus/src/editor/combobox.cpp
===================================================================
--- trunk/pingus/src/editor/combobox.cpp        2007-09-09 17:42:23 UTC (rev 
3117)
+++ trunk/pingus/src/editor/combobox.cpp        2007-09-09 23:18:42 UTC (rev 
3118)
@@ -0,0 +1,162 @@
+//  $Id$
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2005 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 <vector>
+#include <string>
+#include "combobox.hpp"
+#include "math.hpp"
+#include "../fonts.hpp"
+
+namespace Editor {
+
+Combobox::Combobox(const Rect& rect)
+  : RectComponent(rect),
+    current_item(-1),
+    drop_down(false)
+{
+}
+
+Combobox::~Combobox ()
+{
+  clear();
+}
+
+void
+Combobox::add(int id, const std::string& str)
+{
+  item_list.push_back(ComboItem(id, str));
+}
+
+// Remove all items from this combobox
+void
+Combobox::clear()
+{
+  item_list.clear();
+  current_item = -1;
+  drop_down    = false;
+}
+
+// Returns whether or not the combobox is at this location
+bool
+Combobox::is_at(int x, int y)
+{
+  if (drop_down)
+    return Rect(Vector2i(rect.left, rect.top + get_box_offset()),
+                Size(rect.get_width(), rect.get_height() * 
(item_list.size()))).is_inside(Vector2i(x,y));
+  else
+    return RectComponent::is_at(x,y);
+}
+
+void
+Combobox::on_primary_button_press(int x, int y)
+{
+  if (drop_down)
+    {
+      // Determine which item was selected, if any, and set the current item 
to it.
+      drop_down = false;
+      
+      if (hover_item != -1)
+        {
+          current_item = hover_item;
+          on_select(item_list[current_item]);
+        }
+    }
+  else
+    {
+      drop_down = true;
+      on_pointer_move(x,y);
+    }
+}
+
+void
+Combobox::draw(DrawingContext &gc)
+{
+  if (drop_down && !item_list.empty())
+    {
+      int y_offset = get_box_offset();
+
+      Rect list_rect(Vector2i(rect.left, 
+                              rect.top + y_offset),
+                     Size(rect.get_width(),
+                          item_list.size() * rect.get_height()));
+
+
+      gc.draw_fillrect(list_rect, Color(255,255,255), 90);
+
+      for (int i = 0; i < int(item_list.size()); ++i)
+        {
+          if (i == hover_item)
+            gc.draw_fillrect(Rect(Vector2i(rect.left, list_rect.top + 
rect.get_height()*i),
+                                  Size(rect.get_width(), rect.get_height())),
+                             Color(150,200,255), 95);
+
+          gc.print_left(Fonts::verdana11, 
+                        list_rect.left + 5, 
+                        list_rect.top + i * rect.get_height() + 
rect.get_height()/2 - Fonts::verdana11.get_height()/2,
+                        item_list[i].label, 100);
+        }
+
+      gc.draw_rect(list_rect, Color(0,0,0), 100);
+    }
+  else
+    {
+      gc.draw_fillrect(rect, Color(255,255,255));
+      gc.draw_rect(rect, Color(0,0,0));
+
+      if (current_item != -1)
+        {
+          gc.print_left(Fonts::verdana11, rect.left + 5, 
+                        rect.top + rect.get_height()/2 - 
Fonts::verdana11.get_height()/2,
+                        item_list[current_item].label);
+        }
+    }
+}
+
+int
+Combobox::get_box_offset()
+{
+  return -(rect.get_height() * current_item);
+}
+
+bool
+Combobox::set_selected_item(int id)
+{
+  for(int i = 0; i < int(item_list.size()); ++i)
+    if (item_list[i].id == id)
+      {
+        current_item = i;
+        return true;
+      }
+  return false;  
+}
+
+void
+Combobox::on_pointer_move(int x, int y) 
+{
+  if (drop_down)
+    {
+      hover_item = (y - rect.top - get_box_offset()) / rect.get_height();
+      if (hover_item < 0 || hover_item >= int(item_list.size()))
+        hover_item = -1;
+    }
+}
+
+} // namespace Editor 
+
+/* EOF */


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

Added: trunk/pingus/src/editor/combobox.hpp
===================================================================
--- trunk/pingus/src/editor/combobox.hpp        2007-09-09 17:42:23 UTC (rev 
3117)
+++ trunk/pingus/src/editor/combobox.hpp        2007-09-09 23:18:42 UTC (rev 
3118)
@@ -0,0 +1,105 @@
+//  $Id$
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2007 Jason Green <address@hidden>,
+//                     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_COMBOBOX_HXX
+#define HEADER_PINGUS_GUI_COMBOBOX_HXX
+
+#include <vector>
+#include <string>
+#include <boost/signal.hpp>
+#include "gui/component.hpp"
+#include "gui/rect_component.hpp"
+
+namespace Editor {
+      
+/** A ComboItems holds a specific item in a Combobox (string, id, etc.) */
+class ComboItem
+{
+public:
+  int id;
+  std::string label;
+
+  ComboItem(int id_, const std::string& label_)
+    : id(id_), label(label_)
+  {}
+};
+
+/** The Combobox class gives you a drop-down list of items to choose from. */
+class Combobox : public GUI::RectComponent
+{
+protected:
+  /** List of items in this Combobox */
+  std::vector<ComboItem> item_list;
+
+  /** item_list[current_item], -1 if none */
+  int current_item;
+  int hover_item;
+
+  /** Whether or not the list is showing right now */
+  bool drop_down;
+
+  int list_offset;
+
+public:
+  Combobox(const Rect& rect);
+  ~Combobox ();
+
+  void add(int id, const std::string& str);
+
+  /** Clears all items from combobox */
+  virtual void clear();
+
+  /** Return a pointer to the selected item.  Returns -1 if nothing is 
selected */
+  int get_selected_item() { return current_item; }
+
+  /** Sets the selected item to the given ComboItem.  Returns false if that 
item
+      doesn't exist */
+  bool set_selected_item(int id);
+
+  /** Draw this Combobox and all of it's items if selected */
+  void draw (DrawingContext& gc);
+
+  /** Tells the gui_manager if the mouse is on top of the Combobox */
+  bool is_at (int x, int y);
+
+  /** Gets emmited when a button is pressed and released over the
+      same component */
+  void on_primary_button_press(int x, int y);
+  
+  void on_pointer_move(int x, int y);
+  
+  int get_box_offset();
+  
+  void update_layout() {}
+  
+  boost::signal<void (const ComboItem&)> on_select;
+
+private:
+  Combobox();
+  Combobox (const Combobox&);
+  Combobox& operator= (const Combobox&);
+
+};
+
+} // namespace Editor 
+
+#endif
+
+/* EOF */


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

Modified: trunk/pingus/src/editor/object_properties.cpp
===================================================================
--- trunk/pingus/src/editor/object_properties.cpp       2007-09-09 17:42:23 UTC 
(rev 3117)
+++ trunk/pingus/src/editor/object_properties.cpp       2007-09-09 23:18:42 UTC 
(rev 3118)
@@ -17,12 +17,15 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include <boost/bind.hpp>
 #include "button.hpp"
 #include "editor_screen.hpp"
 #include "level_objs.hpp"
 #include "fonts.hpp"
 #include "label.hpp"
 #include "gui_style.hpp"
+#include "groundtype.hpp"
+#include "combobox.hpp"
 #include "object_properties.hpp"
 
 namespace Editor {
@@ -33,6 +36,19 @@
 {
   add(type_label = new Label(Rect(Vector2i(10, 10), Size(120, 20)), 
"Object:"), true);
 
+  add(gptype_label = new Label(Rect(Vector2i(10, 100), Size(120, 20)), 
"GPType:"), true);
+  add(gptype_type  = new Combobox(Rect(Vector2i(60, 100), Size(120, 20))), 
true);
+
+  gptype_type->add(Groundtype::GP_TRANSPARENT, "Transparent");
+  gptype_type->add(Groundtype::GP_SOLID,       "Solid");
+  gptype_type->add(Groundtype::GP_GROUND,      "Ground");
+  gptype_type->add(Groundtype::GP_BRIDGE,      "Bridge");
+  gptype_type->add(Groundtype::GP_WATER,       "Water");
+  gptype_type->add(Groundtype::GP_LAVA,        "Lava");
+  gptype_type->add(Groundtype::GP_REMOVE,      "Remove");
+  gptype_type->set_selected_item(Groundtype::GP_GROUND);
+  
gptype_type->on_select.connect(boost::bind(&ObjectProperties::on_gptype_change, 
this, _1));
+  
   add(new Label(Rect(Vector2i(  10,  30), Size( 80, 20)), "Type:"), true);
 
   add(new Button(Rect(Vector2i( 60,  30), Size( 80, 20)), "Ground"), true);
@@ -76,6 +92,13 @@
       type_label->set_text("Object: " + objects.front()->get_section_name());
     }
 }
+
+void
+ObjectProperties::on_gptype_change(const ComboItem& item)
+{
+  std::cout << "ObjectProperties::on_gpytpe_change: switch to: "
+            << Groundtype::type_to_string((Groundtype::GPType)item.id) << 
std::endl;
+}
 
 } // namespace Editor
 

Modified: trunk/pingus/src/editor/object_properties.hpp
===================================================================
--- trunk/pingus/src/editor/object_properties.hpp       2007-09-09 17:42:23 UTC 
(rev 3117)
+++ trunk/pingus/src/editor/object_properties.hpp       2007-09-09 23:18:42 UTC 
(rev 3118)
@@ -20,13 +20,14 @@
 #ifndef HEADER_EDITOR_OBJECT_PROPERTIES_HPP
 #define HEADER_EDITOR_OBJECT_PROPERTIES_HPP
 
-
 #include "gui/group_component.hpp"
 
 namespace Editor {
 
 class Label;
 class EditorScreen;
+class Combobox;
+class ComboItem;
 
 /** */
 class ObjectProperties : public GUI::GroupComponent
@@ -36,8 +37,9 @@
   std::vector<LevelObj*> objects;
   Label* type_label;
 
-  Label* gptype_label;
-  RadioButtonGroup* gptype_type;
+  // Groundpiece Type
+  Label*    gptype_label;
+  Combobox* gptype_type;
 
 public:
   ObjectProperties(EditorScreen* editor, const Rect& rect);
@@ -47,9 +49,9 @@
   void draw_background(DrawingContext& gc);
 
   void set_objects(const std::vector<LevelObj*>& objs);
-private:
-  ObjectProperties (const ObjectProperties&);
-  ObjectProperties& operator= (const ObjectProperties&);
+
+  void on_gptype_change(const ComboItem& item);
+
 };
 
 } // namespace Editor

Modified: trunk/pingus/src/editor/object_selector.hpp
===================================================================
--- trunk/pingus/src/editor/object_selector.hpp 2007-09-09 17:42:23 UTC (rev 
3117)
+++ trunk/pingus/src/editor/object_selector.hpp 2007-09-09 23:18:42 UTC (rev 
3118)
@@ -42,8 +42,8 @@
   Vector2i button_pos;
   Rect rect;
   DrawingContext* drawing_context;
-  float offset;
-  float old_offset;
+  float    offset;
+  float    old_offset;
   Vector2i drag_start;
   Vector2i mouse_pos;
   Vector2i real_mouse_pos;

Modified: trunk/pingus/src/gui/combobox.cpp
===================================================================
--- trunk/pingus/src/gui/combobox.cpp   2007-09-09 17:42:23 UTC (rev 3117)
+++ trunk/pingus/src/gui/combobox.cpp   2007-09-09 23:18:42 UTC (rev 3118)
@@ -1,7 +1,7 @@
 //  $Id$
 //
 //  Pingus - A free Lemmings clone
-//  Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+//  Copyright (C) 2007 Jason Green <address@hidden>
 //
 //  This program is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU General Public License

Modified: trunk/pingus/src/gui/combobox.hpp
===================================================================
--- trunk/pingus/src/gui/combobox.hpp   2007-09-09 17:42:23 UTC (rev 3117)
+++ trunk/pingus/src/gui/combobox.hpp   2007-09-09 23:18:42 UTC (rev 3118)
@@ -1,7 +1,7 @@
 //  $Id$
 //
 //  Pingus - A free Lemmings clone
-//  Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+//  Copyright (C) 2007 Jason Green <address@hidden>
 //
 //  This program is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU General Public License





reply via email to

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