pingus-cvs
[Top][All Lists]
Advanced

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

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


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3141 - in trunk/pingus/src: . display editor gui
Date: Fri, 14 Sep 2007 17:14:08 +0200

Author: grumbel
Date: 2007-09-14 17:14:07 +0200 (Fri, 14 Sep 2007)
New Revision: 3141

Added:
   trunk/pingus/src/editor/object_selector_list.cpp
   trunk/pingus/src/editor/object_selector_list.hpp
Modified:
   trunk/pingus/src/SConscript
   trunk/pingus/src/display/drawing_context.cpp
   trunk/pingus/src/display/drawing_context.hpp
   trunk/pingus/src/editor/editor_screen.cpp
   trunk/pingus/src/editor/object_selector.cpp
   trunk/pingus/src/editor/object_selector.hpp
   trunk/pingus/src/gui/group_component.cpp
   trunk/pingus/src/gui/group_component.hpp
Log:
- splitted of the ObjectSelectorList

Modified: trunk/pingus/src/SConscript
===================================================================
--- trunk/pingus/src/SConscript 2007-09-13 11:55:55 UTC (rev 3140)
+++ trunk/pingus/src/SConscript 2007-09-14 15:14:07 UTC (rev 3141)
@@ -105,6 +105,7 @@
 'editor/level_objs.cpp',
 'editor/inputbox.cpp',
 'editor/object_selector.cpp',
+'editor/object_selector_list.cpp',
 'editor/object_properties.cpp',
 'editor/level_properties.cpp',
 'editor/action_properties.cpp', 

Modified: trunk/pingus/src/display/drawing_context.cpp
===================================================================
--- trunk/pingus/src/display/drawing_context.cpp        2007-09-13 11:55:55 UTC 
(rev 3140)
+++ trunk/pingus/src/display/drawing_context.cpp        2007-09-14 15:14:07 UTC 
(rev 3141)
@@ -251,9 +251,9 @@
 }
 
 void
-DrawingContext::draw(const Sprite& sprite, const Vector2i& pos)
+DrawingContext::draw(const Sprite& sprite, const Vector2i& pos, float z)
 {
-  draw(sprite, (float)pos.x, (float)pos.y, 0.f);
+  draw(sprite, (float)pos.x, (float)pos.y, z);
 }
 
 void

Modified: trunk/pingus/src/display/drawing_context.hpp
===================================================================
--- trunk/pingus/src/display/drawing_context.hpp        2007-09-13 11:55:55 UTC 
(rev 3140)
+++ trunk/pingus/src/display/drawing_context.hpp        2007-09-14 15:14:07 UTC 
(rev 3141)
@@ -71,7 +71,7 @@
       worth a try */
   void draw(DrawingContext& dc, float z = 0);
 
-  void draw(const Sprite& sprite, const Vector2i& pos);
+  void draw(const Sprite& sprite, const Vector2i& pos, float z = 0);
   void draw(const Sprite& sprite, const Vector3f& pos);
   void draw(const Sprite& sprite, float x, float y, float z = 0);
   

Modified: trunk/pingus/src/editor/editor_screen.cpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.cpp   2007-09-13 11:55:55 UTC (rev 
3140)
+++ trunk/pingus/src/editor/editor_screen.cpp   2007-09-14 15:14:07 UTC (rev 
3141)
@@ -70,8 +70,9 @@
 
   object_selector   = new ObjectSelector(this, Rect(Display::get_width()-244, 
38,
                                                     Display::get_width(), 
Display::get_height()));
+  gui_manager->add(object_selector, true);
 
-  object_properties = new ObjectProperties(this, Rect(Vector2i(0,450), 
Size(200, 150)));
+  object_properties = new ObjectProperties(this, 
Rect(Vector2i(0,Display::get_height()-150), Size(200, 150)));
   gui_manager->add(object_properties, true);
 
   file_load_dialog = new FileLoadDialog(this, Rect(Vector2i(50, 50), 

Modified: trunk/pingus/src/editor/object_selector.cpp
===================================================================
--- trunk/pingus/src/editor/object_selector.cpp 2007-09-13 11:55:55 UTC (rev 
3140)
+++ trunk/pingus/src/editor/object_selector.cpp 2007-09-14 15:14:07 UTC (rev 
3141)
@@ -33,6 +33,7 @@
 #include "math.hpp"
 #include "editor_viewport.hpp"
 #include "editor_level.hpp"
+#include "object_selector_list.hpp"
 #include "level_objs.hpp"
 #include "display/drawing_context.hpp"
 #include "gui/gui_manager.hpp"
@@ -42,110 +43,10 @@
 
 namespace Editor {
 
-struct Groundpiece : public ObjectSelector::Object 
-{
-  ResDescriptor desc;
-  std::string   type;
-  
-  Groundpiece(const std::string& name, const std::string& type)
-    : Object(Resource::load_sprite(name),
-             Resource::load_thumb_sprite(name)),
-      desc(name),
-      type(type)
-  {}      
-  
-  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
-    LevelObj* obj = new LevelObj("groundpiece", impl);
-    obj->set_pos(pos);
-    obj->set_res_desc(desc);
-    obj->set_type(type);
-    return obj;
-  }
-};
-
-struct Entrance : public ObjectSelector::Object 
-{
-  Entrance()
-    : Object(Resource::load_sprite("entrances/generic"),
-             Resource::load_thumb_sprite("entrances/generic"))
-  {}
-
-  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
-    LevelObj* obj = new LevelObj("entrance", impl);
-    obj->set_type("generic");
-    obj->set_pos(pos);
-    obj->set_direction("misc");
-    obj->set_release_rate(150);
-    obj->set_owner(0);
-    return obj;
-  }
-};
-
-struct Exit : public ObjectSelector::Object 
-{
-  ResDescriptor desc;
-  
-  Exit(const std::string& name)
-    : Object(Resource::load_sprite(name), 
-             Resource::load_thumb_sprite(name)),
-      desc(name)
-  {}
-
-  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
-    LevelObj* obj = new LevelObj("exit", impl);
-    obj->set_pos(pos);
-    obj->set_res_desc(desc);
-    // obj->set_para();
-    return obj;
-  }
-};
-
-struct Hotspot : public ObjectSelector::Object 
-{
-  ResDescriptor desc;
-  
-  Hotspot(const std::string& name)
-    : Object(Resource::load_sprite(name),
-             Resource::load_thumb_sprite(name)),
-      desc(name)
-  {}
-
-  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
-    LevelObj* obj = new LevelObj("hotspot", impl);
-    obj->set_pos(pos);
-    obj->set_res_desc(desc);
-    // obj->set_para();
-    return obj;
-  }
-};
-
-struct SurfaceBackground : public ObjectSelector::Object 
-{
-  ResDescriptor desc;
-  
-  SurfaceBackground(const std::string& name)
-    : Object(Resource::load_sprite(name),
-             Resource::load_thumb_sprite(name)),
-      desc(name)
-  {}
-
-  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
-    LevelObj* obj = new LevelObj("surface-background", impl);
-    obj->set_pos(pos);
-    obj->set_para_x(1.0f);
-    obj->set_para_y(1.0f);
-    obj->set_scroll_x(0.0f);
-    obj->set_scroll_y(0.0f);
-    obj->set_res_desc(desc);
-    // obj->set_para();
-    return obj;
-  }
-};
-
 class ObjectSelectorButton : public GUI::RectComponent
 {
 private:
-  ObjectSelector* object_selector;
+  ObjectSelectorList* object_list;
 
   Sprite button_raised;
   Sprite button_pressed;
@@ -154,15 +55,15 @@
   bool   mouse_down;
   std::string tooltip;
 
-  typedef void (ObjectSelector::*Callback)();
+  typedef void (ObjectSelectorList::*Callback)();
   Callback callback;
 
 public:
-  ObjectSelectorButton(ObjectSelector* object_selector_,
+  ObjectSelectorButton(ObjectSelectorList* object_list_,
                        const Vector2i& pos, const std::string& sprite, const 
std::string& tooltip_, 
                        Callback callback_ = 0)
     : RectComponent(Rect(pos, Size(30, 30))),
-      object_selector(object_selector_),
+      object_list(object_list_),
       button_raised(Resource::load_sprite("core/editor/obj_button-raised")),
       button_pressed(Resource::load_sprite("core/editor/obj_button-pressed")),
       sprite(Resource::load_sprite(sprite)),
@@ -214,7 +115,7 @@
   { 
     mouse_down = false;
     if (mouse_over && callback)
-      ((*object_selector).*callback)();
+      ((*object_list).*callback)();
   }
   
   void update (float delta)
@@ -229,34 +130,31 @@
   void update_layout() {}
 };
 
+
+
 ObjectSelector::ObjectSelector(EditorScreen* editor_, const Rect& rect_)
   : GroupComponent(rect_, false),
     editor(editor_),
-    button_pos(0,0),
-    drawing_context(new DrawingContext(Rect(2,64, rect.get_width() - 2, 
rect.get_height() - 2))),
-    offset(0),
-    old_offset(0),
-    mode(NOTHING),
-    current_object(-1),
-    drag_object(-1)
+    button_pos(0,0)
 {
-  editor->get_gui_manager()->add(this, true);
-  
-  add_button("core/editor/obj_entrance",   "Entrance", 
&ObjectSelector::set_entrance);
-  add_button("core/editor/obj_gp_ground",      "Groundpiece (ground)", 
&ObjectSelector::set_gp_ground);
-  add_button("core/editor/obj_gp_solid",       "Groundpiece (solid)", 
&ObjectSelector::set_gp_solid);
-  add_button("core/editor/obj_gp_bridge",      "Groundpiece (bridge)", 
&ObjectSelector::set_gp_bridge);
-  add_button("core/editor/obj_gp_transparent", "Groundpiece (transparent)", 
&ObjectSelector::set_gp_transparent);
-  add_button("core/editor/obj_gp_remove",      "Groundpiece (remove)", 
&ObjectSelector::set_gp_remove);
-  add_button("core/editor/obj_hotspot",    "Hotspot", 
&ObjectSelector::set_hotspot);
-  add_button("core/editor/obj_background", "Background", 
&ObjectSelector::set_background);
-  // -------------------------------
-  add_button("core/editor/obj_exit", "Exit", &ObjectSelector::set_exit);
-  add_button("core/editor/obj_liquid", "Liquid", &ObjectSelector::set_liquid);
-  add_button("core/editor/obj_trap", "Trap", &ObjectSelector::set_trap);
-  add_button("core/editor/obj_weather", "Weather", 
&ObjectSelector::set_weather);
-  add_button("core/editor/obj_worldobj", "Special Object", 
&ObjectSelector::set_worldobj);
+  add(object_list = new ObjectSelectorList(editor, this, 
+                                           Rect(2, 2 + 60 + 2, 
rect.get_width() - 2, rect.get_height() - 2)), 
+      true);
 
+  add_button("core/editor/obj_entrance",   "Entrance", 
&ObjectSelectorList::set_entrance);
+  add_button("core/editor/obj_gp_ground",  "Groundpiece (ground)", 
&ObjectSelectorList::set_gp_ground);
+  add_button("core/editor/obj_gp_solid",   "Groundpiece (solid)", 
&ObjectSelectorList::set_gp_solid);
+  add_button("core/editor/obj_gp_bridge",      "Groundpiece (bridge)", 
&ObjectSelectorList::set_gp_bridge);
+  add_button("core/editor/obj_gp_transparent", "Groundpiece (transparent)", 
&ObjectSelectorList::set_gp_transparent);
+  add_button("core/editor/obj_gp_remove",      "Groundpiece (remove)", 
&ObjectSelectorList::set_gp_remove);
+  add_button("core/editor/obj_hotspot",    "Hotspot", 
&ObjectSelectorList::set_hotspot);
+  add_button("core/editor/obj_background", "Background", 
&ObjectSelectorList::set_background);
+  // -------------------------------
+  add_button("core/editor/obj_exit", "Exit", &ObjectSelectorList::set_exit);
+  add_button("core/editor/obj_liquid", "Liquid", 
&ObjectSelectorList::set_liquid);
+  add_button("core/editor/obj_trap", "Trap", &ObjectSelectorList::set_trap);
+  add_button("core/editor/obj_weather", "Weather", 
&ObjectSelectorList::set_weather);
+  add_button("core/editor/obj_worldobj", "Special Object", 
&ObjectSelectorList::set_worldobj);
 }
 
 ObjectSelector::~ObjectSelector()
@@ -266,81 +164,13 @@
 void
 ObjectSelector::draw_background(DrawingContext& parent_gc)
 {
-  //  Rect rect(int(parent_gc.get_width()) - 244,  38,
-  //            int(parent_gc.get_width()),        
int(parent_gc.get_height()));
-
-  // FIXME: Should use draw_line
   GUIStyle::draw_raised_box(parent_gc, Rect(0,0, rect.get_width(), 
rect.get_height()));
-
-  DrawingContext& gc = *drawing_context;
-
-  gc.clear();
-
-  gc.push_modelview();
-  gc.translate(0, offset);
-
-  Objects::iterator i = objects.begin();
-
-  for(int y = 0; y < 20; ++y)
-    for(int x = 0; x < 5; ++x)
-      {
-        if (i != objects.end())
-          {
-            if (current_object != -1 && (i - objects.begin()) == 
current_object)
-              {
-                gc.draw_fillrect(x * 48,      y * 48, 
-                                 x * 48 + 48, y * 48 + 48, 
-                                 Color(150,150,150));
-
-
-                gc.draw_rect(x * 48,      y * 48, 
-                             x * 48 + 48, y * 48 + 48, 
-                             Color(255,255,255), 10000);
-              }
-            else
-              {
-                gc.draw_fillrect(x * 48,      y * 48, 
-                                 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)->thumbnail, 
-                    Vector2i(x * 48 + std::max(0, (48 - 
(*i)->sprite.get_width())/2), 
-                             y * 48 + std::max(0, (48 - 
(*i)->sprite.get_height())/2)));
-            ++i;
-          }
-        else
-          {
-            gc.draw_fillrect(x * 48,      y * 48, 
-                             x * 48 + 48, y * 48 + 48, 
-                             (((x-(y%2)) % 2) ? Color(0,0,0) : 
Color(100,100,100)));
-          }
-      }
-  
-  gc.pop_modelview();
-
-  if (mode == OBJECT_DRAG)
-    {
-      parent_gc.draw(objects[current_object]->sprite, 
Vector3f((float)real_mouse_pos.x,
-                                                               
(float)real_mouse_pos.y,
-                                                               2000.0f));
-    }
-  parent_gc.draw(gc);
 }
 
 void
-ObjectSelector::update(float delta)
-{
-}
-
-void
 ObjectSelector::add_button(const std::string& image, const std::string& 
tooltip, Callback callback)
 {
-  add(new ObjectSelectorButton(this,
+  add(new ObjectSelectorButton(object_list,
                                Vector2i(2 + button_pos.x * 30,  
                                         2 + button_pos.y * 30),
                                image, tooltip,
@@ -353,234 +183,6 @@
       button_pos.y += 1;
     }
 }
-
-void
-ObjectSelector::on_primary_button_press (int x, int y)
-{
-  GroupComponent::on_primary_button_press(x, y);
-
-  if (mode == NOTHING && current_object != -1)
-    {
-      drag_object = current_object;
-      mode = OBJECT_DRAG;
-    }
-}
-
-void
-ObjectSelector::on_primary_button_release (int x, int y)
-{
-  GroupComponent::on_primary_button_release(x, y);
-
-  if (mode == OBJECT_DRAG)
-    {
-      mode = NOTHING;
-      
-      if (current_object != -1)
-        {
-          LevelObj* obj = 
objects[current_object]->create(editor->get_viewport()->screen2world(x,y),
-                                                          
editor->get_level()->get_level_impl());
-          if (obj)
-            editor->add_object(obj);
-          else
-            std::cout << "ObjectSelector::Object: create() not implemented" << 
std::endl;
-        }
-    }
-}
-
-void
-ObjectSelector::on_secondary_button_press (int x, int y)
-{
-  GroupComponent::on_secondary_button_press(x, y);
-
-  if (mode == NOTHING)
-    {
-      drag_start = Vector2i(x,y);
-      mode = SCROLLING;
-      old_offset = offset;
-    }
-}
-
-void
-ObjectSelector::on_secondary_button_release (int x, int y)
-{  
-  GroupComponent::on_secondary_button_release(x, y);
-
-  if (mode == SCROLLING)
-    mode = NOTHING;
-}
-
-void
-ObjectSelector::on_pointer_move (int x, int y)
-{
-  GroupComponent::on_pointer_move(x, y);
-  real_mouse_pos = Vector2i(x - rect.left, y - rect.top);
-
-  mouse_pos = Vector2i(x - rect.left - drawing_context->get_rect().left,
-                       y - rect.top  - drawing_context->get_rect().top);
-
-  if (mode != OBJECT_DRAG)
-    {
-      int obj_x = Math::clamp(0, mouse_pos.x / 48, 4);
-      int obj_y = Math::clamp(0, int(mouse_pos.y - offset) / 48, 200); // 
FIXME: 200 is placeholder
-
-      current_object = Math::clamp(-1, (obj_y * 5) + obj_x, 
int(objects.size()-1));
-    }
-
-  if (mode == SCROLLING)
-    {
-      offset = old_offset + (y - drag_start.y);
-    }
-}
-
-void
-ObjectSelector::clear_object_list()
-{
-  for(Objects::iterator i = objects.begin(); i != objects.end(); ++i)
-    delete (*i);
-  objects.clear();
-}
-
-void
-ObjectSelector::set_objects(const std::string& prefix)
-{
-  clear_object_list();
-
-  // FIXME: Simple debugging aid, needs to be replaced with custom code for 
the object types
-  std::vector<std::string> lst = Resource::resmgr.get_section(prefix);
-  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
-    {
-      std::cout << "Objects: " << *i << std::endl;
-      //sprite.scale(48, 48);
-      // need to reset the align to top/left
-      objects.push_back(new Object(Resource::load_sprite(*i),
-                                   Resource::load_thumb_sprite(*i)));
-    }
-}
-
-void
-ObjectSelector::set_groundpiece(const std::string& prefix, const std::string& 
type)
-{
-  clear_object_list();
-
-  std::vector<std::string> lst = Resource::resmgr.get_section(prefix);
-  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
-    {
-      //sprite.scale(48, 48);
-      objects.push_back(new Groundpiece(*i, type));
-    }
-}
-
-void
-ObjectSelector::set_gp_ground()
-{
-  set_groundpiece("groundpieces/ground", "ground");
-}
-
-void
-ObjectSelector::set_gp_solid()
-{
-  set_groundpiece("groundpieces/solid", "solid");
-}
-
-void
-ObjectSelector::set_gp_bridge()
-{
-  set_groundpiece("groundpieces/bridge", "bridge");
-}
-
-void
-ObjectSelector::set_gp_transparent()
-{
-  set_groundpiece("groundpieces/transparent", "transparent");
-}
-
-void
-ObjectSelector::set_gp_remove()
-{
-  set_groundpiece("groundpieces/remove", "remove");
-}
-
-void
-ObjectSelector::set_hotspot()
-{
-  clear_object_list();
-
-  std::vector<std::string> lst = Resource::resmgr.get_section("hotspots");
-  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
-    {
-      //sprite.scale(48, 48);
-      objects.push_back(new Hotspot(*i));
-    }
-}
-
-void
-ObjectSelector::set_background()
-{
-  clear_object_list();
-
-  std::vector<std::string> lst = Resource::resmgr.get_section("textures");
-  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
-    {
-      //sprite.scale(48, 48);
-      objects.push_back(new SurfaceBackground(*i));
-    }
-}
-
-void
-ObjectSelector::set_entrance()
-{
-  clear_object_list();
-
-  objects.push_back(new Entrance());
-
-  std::vector<std::string> lst = Resource::resmgr.get_section("entrances");
-  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
-    {
-      //sprite.scale(48, 48);
-      if (*i != "entrances/generic")
-        objects.push_back(new Hotspot(*i));
-    }
-}
-
-void
-ObjectSelector::set_exit()
-{
-  clear_object_list();
-
-  std::vector<std::string> lst = Resource::resmgr.get_section("exit");
-  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
-    {
-      //sprite.scale(48, 48);
-      objects.push_back(new Exit(*i));
-    }
-}
-
-void
-ObjectSelector::set_liquid()
-{
-  set_objects("liquids");
-}
-
-void
-ObjectSelector::set_trap()
-{
-  // Need to differentiate the different trap types
-  set_objects("traps");
-}
-
-void
-ObjectSelector::set_weather()
-{
-  //set_objects("weather");
-  std::cout << "ObjectSelector: unimplemented: " << __FILE__ << ":" << 
__LINE__ << std::endl;
-}
-
-void
-ObjectSelector::set_worldobj()
-{
-  std::cout << "ObjectSelector: unimplemented: " << __FILE__ << ":" << 
__LINE__ << std::endl;
-}
-
 
 } // namespace Editor
 

Modified: trunk/pingus/src/editor/object_selector.hpp
===================================================================
--- trunk/pingus/src/editor/object_selector.hpp 2007-09-13 11:55:55 UTC (rev 
3140)
+++ trunk/pingus/src/editor/object_selector.hpp 2007-09-14 15:14:07 UTC (rev 
3141)
@@ -33,83 +33,27 @@
 namespace Editor {
 
 class EditorScreen;
+class ObjectSelectorList;
 
 /** */
 class ObjectSelector : public GUI::GroupComponent
 {
-public:
-  struct Object {
-    Sprite  sprite;
-    Sprite  thumbnail;
-    
-    Object(const Sprite& sprite_, const Sprite& thumbnail_) 
-      : sprite(sprite_),
-        thumbnail(thumbnail_)
-    {}      
-
-    virtual ~Object() {}
-
-    virtual LevelObj* create(const Vector2i&, LevelImpl* impl) { return 0; }
-  };
-
 private:
   EditorScreen* editor;
   Vector2i button_pos;
-  DrawingContext* drawing_context;
-  float    offset;
-  float    old_offset;
-  Vector2i drag_start;
-  Vector2i mouse_pos;
-  Vector2i real_mouse_pos;
-  
-  enum Mode { NOTHING, SCROLLING, OBJECT_DRAG };
-  Mode mode;
+  ObjectSelectorList* object_list;
 
-  typedef std::vector<Object*> Objects;
-  Objects objects;
-
-  int current_object;
-  int drag_object;
-
 public:
-  typedef void (ObjectSelector::*Callback)();
+  typedef void (ObjectSelectorList::*Callback)();
   Callback callback;
 
   ObjectSelector(EditorScreen* editor, const Rect& rect);
   ~ObjectSelector();
 
   void draw_background(DrawingContext& gc);
-  void update (float delta);
 
   void add_button(const std::string& image, const std::string& tooltip = "", 
Callback callback = 0);
 
-  void on_primary_button_press (int x, int y);
-  void on_primary_button_release (int x, int y);
-
-  void on_secondary_button_press (int x, int y);
-  void on_secondary_button_release (int x, int y);
-
-  void on_pointer_move (int x, int y);
-
-  void set_objects(const std::string& prefix);
-
-  void clear_object_list();
-
-  void set_groundpiece(const std::string& prefix, const std::string& type);
-  void set_gp_ground();
-  void set_gp_solid();
-  void set_gp_bridge();
-  void set_gp_transparent();
-  void set_gp_remove();
-  void set_hotspot();
-  void set_background();
-  void set_entrance();
-  void set_exit();
-  void set_liquid();
-  void set_trap();
-  void set_weather();
-  void set_worldobj();
-
 private:
   ObjectSelector (const ObjectSelector&);
   ObjectSelector& operator= (const ObjectSelector&);

Added: trunk/pingus/src/editor/object_selector_list.cpp
===================================================================
--- trunk/pingus/src/editor/object_selector_list.cpp    2007-09-13 11:55:55 UTC 
(rev 3140)
+++ trunk/pingus/src/editor/object_selector_list.cpp    2007-09-14 15:14:07 UTC 
(rev 3141)
@@ -0,0 +1,443 @@
+/*  $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 "math.hpp"
+#include "editor_screen.hpp"
+#include "object_selector.hpp"
+#include "editor_viewport.hpp"
+#include "editor_level.hpp"
+#include "groundtype.hpp"
+#include "resource.hpp"
+#include "display/drawing_context.hpp"
+#include "object_selector_list.hpp"
+
+namespace Editor {
+
+struct Groundpiece : public ObjectSelectorList::Object 
+{
+  ResDescriptor desc;
+  std::string   type;
+  
+  Groundpiece(const std::string& name, const std::string& type)
+    : Object(Resource::load_sprite(name),
+             Resource::load_thumb_sprite(name)),
+      desc(name),
+      type(type)
+  {}      
+  
+  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
+    LevelObj* obj = new LevelObj("groundpiece", impl);
+    obj->set_pos(pos);
+    obj->set_res_desc(desc);
+    obj->set_type(type);
+    return obj;
+  }
+};
+
+struct Entrance : public ObjectSelectorList::Object 
+{
+  Entrance()
+    : Object(Resource::load_sprite("entrances/generic"),
+             Resource::load_thumb_sprite("entrances/generic"))
+  {}
+
+  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
+    LevelObj* obj = new LevelObj("entrance", impl);
+    obj->set_type("generic");
+    obj->set_pos(pos);
+    obj->set_direction("misc");
+    obj->set_release_rate(150);
+    obj->set_owner(0);
+    return obj;
+  }
+};
+
+struct Exit : public ObjectSelectorList::Object 
+{
+  ResDescriptor desc;
+  
+  Exit(const std::string& name)
+    : Object(Resource::load_sprite(name), 
+             Resource::load_thumb_sprite(name)),
+      desc(name)
+  {}
+
+  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
+    LevelObj* obj = new LevelObj("exit", impl);
+    obj->set_pos(pos);
+    obj->set_res_desc(desc);
+    // obj->set_para();
+    return obj;
+  }
+};
+
+struct Hotspot : public ObjectSelectorList::Object 
+{
+  ResDescriptor desc;
+  
+  Hotspot(const std::string& name)
+    : Object(Resource::load_sprite(name),
+             Resource::load_thumb_sprite(name)),
+      desc(name)
+  {}
+
+  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
+    LevelObj* obj = new LevelObj("hotspot", impl);
+    obj->set_pos(pos);
+    obj->set_res_desc(desc);
+    // obj->set_para();
+    return obj;
+  }
+};
+
+struct SurfaceBackground : public ObjectSelectorList::Object 
+{
+  ResDescriptor desc;
+  
+  SurfaceBackground(const std::string& name)
+    : Object(Resource::load_sprite(name),
+             Resource::load_thumb_sprite(name)),
+      desc(name)
+  {}
+
+  LevelObj* create(const Vector2i& pos, LevelImpl* impl) { 
+    LevelObj* obj = new LevelObj("surface-background", impl);
+    obj->set_pos(pos);
+    obj->set_para_x(1.0f);
+    obj->set_para_y(1.0f);
+    obj->set_scroll_x(0.0f);
+    obj->set_scroll_y(0.0f);
+    obj->set_res_desc(desc);
+    // obj->set_para();
+    return obj;
+  }
+};
+
+ObjectSelectorList::ObjectSelectorList(EditorScreen* editor_, ObjectSelector* 
object_selector_, const Rect& rect_)
+  : RectComponent(rect_),
+    editor(editor_),
+    object_selector(object_selector_),
+    drawing_context(new DrawingContext(rect)),
+    offset(0),
+    old_offset(0),
+    mode(NOTHING),
+    current_object(-1),
+    drag_object(-1)
+{  
+}
+
+void
+ObjectSelectorList::draw(DrawingContext& parent_gc)
+{
+  parent_gc.fill_screen(Color(0,0,0));
+
+  DrawingContext& gc = *drawing_context;
+  gc.clear();
+
+  gc.push_modelview();
+  gc.translate(0, offset);
+
+  Objects::iterator i = objects.begin();
+
+  for(int y = 0; y < 20; ++y)
+    for(int x = 0; x < 5; ++x)
+      {
+        if (i != objects.end())
+          {
+            if (current_object != -1 && (i - objects.begin()) == 
current_object)
+              {
+                gc.draw_fillrect(x * 48,      y * 48, 
+                                 x * 48 + 48, y * 48 + 48, 
+                                 Color(150,150,150));
+
+
+                gc.draw_rect(x * 48,      y * 48, 
+                             x * 48 + 48, y * 48 + 48, 
+                             Color(255,255,255), 10000);
+              }
+            else
+              {
+                gc.draw_fillrect(x * 48,      y * 48, 
+                                 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)->thumbnail, 
+                    Vector2i(x * 48 + std::max(0, (48 - 
(*i)->sprite.get_width())/2), 
+                             y * 48 + std::max(0, (48 - 
(*i)->sprite.get_height())/2)));
+            ++i;
+          }
+        else
+          {
+            gc.draw_fillrect(x * 48,      y * 48, 
+                             x * 48 + 48, y * 48 + 48, 
+                             (((x-(y%2)) % 2) ? Color(0,0,0) : 
Color(100,100,100)));
+          }
+      }
+  
+  gc.pop_modelview();
+
+  parent_gc.draw(gc);
+
+  if (mode == OBJECT_DRAG)
+    {
+      parent_gc.draw(objects[current_object]->sprite, real_mouse_pos, 2000.0f);
+    }
+}
+
+void
+ObjectSelectorList::on_primary_button_press (int x, int y)
+{
+  if (mode == NOTHING && current_object != -1)
+    {
+      drag_object = current_object;
+      mode = OBJECT_DRAG;
+    }
+}
+
+void
+ObjectSelectorList::on_primary_button_release (int x, int y)
+{
+  if (mode == OBJECT_DRAG)
+    {
+      mode = NOTHING;
+      
+      if (current_object != -1)
+        {
+          // FIXME: Should check if the current mouse over component
+          // is the Viewport, else no drag should take place, this
+          // checks if the current mouse_over_comp is the
+          // ObjectSelector, which is good enough but not perfect 
+          if (!object_selector->get_rect().is_inside(Vector2i(x + 
object_selector->get_rect().left,
+                                                              y + 
object_selector->get_rect().top)))
+            {
+              LevelObj* obj = 
objects[current_object]->create(editor->get_viewport()->screen2world(x + 
object_selector->get_rect().left,
+                                                                               
                    y + object_selector->get_rect().top),
+                                                              
editor->get_level()->get_level_impl());
+              if (obj)
+                editor->add_object(obj);
+              else
+                std::cout << "ObjectSelectorList::Object: create() not 
implemented" << std::endl;
+            }
+        }
+    }
+}
+
+void
+ObjectSelectorList::on_secondary_button_press (int x, int y)
+{
+  if (mode == NOTHING)
+    {
+      drag_start = Vector2i(x,y);
+      mode = SCROLLING;
+      old_offset = offset;
+    }
+}
+
+void
+ObjectSelectorList::on_secondary_button_release (int x, int y)
+{  
+  if (mode == SCROLLING)
+    mode = NOTHING;
+}
+
+void
+ObjectSelectorList::on_pointer_move (int x, int y)
+{
+  real_mouse_pos = Vector2i(x, y);
+
+  mouse_pos = Vector2i(x - rect.left, y - rect.top);
+
+  if (mode != OBJECT_DRAG)
+    {
+      int obj_x = Math::clamp(0, mouse_pos.x / 48, 4);
+      int obj_y = Math::clamp(0, int(mouse_pos.y - offset) / 48, 200); // 
FIXME: 200 is placeholder
+
+      current_object = Math::clamp(-1, (obj_y * 5) + obj_x, 
int(objects.size()-1));
+    }
+
+  if (mode == SCROLLING)
+    {
+      offset = old_offset + (y - drag_start.y);
+    }
+}
+
+void
+ObjectSelectorList::clear_object_list()
+{
+  for(Objects::iterator i = objects.begin(); i != objects.end(); ++i)
+    delete (*i);
+  objects.clear();
+}
+
+void
+ObjectSelectorList::set_objects(const std::string& prefix)
+{
+  clear_object_list();
+
+  // FIXME: Simple debugging aid, needs to be replaced with custom code for 
the object types
+  std::vector<std::string> lst = Resource::resmgr.get_section(prefix);
+  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
+    {
+      std::cout << "Objects: " << *i << std::endl;
+      //sprite.scale(48, 48);
+      // need to reset the align to top/left
+      objects.push_back(new Object(Resource::load_sprite(*i),
+                                   Resource::load_thumb_sprite(*i)));
+    }
+}
+
+void
+ObjectSelectorList::set_groundpiece(const std::string& prefix, const 
std::string& type)
+{
+  clear_object_list();
+
+  std::vector<std::string> lst = Resource::resmgr.get_section(prefix);
+  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
+    {
+      //sprite.scale(48, 48);
+      objects.push_back(new Groundpiece(*i, type));
+    }
+}
+
+void
+ObjectSelectorList::set_gp_ground()
+{
+  set_groundpiece("groundpieces/ground", "ground");
+}
+
+void
+ObjectSelectorList::set_gp_solid()
+{
+  set_groundpiece("groundpieces/solid", "solid");
+}
+
+void
+ObjectSelectorList::set_gp_bridge()
+{
+  set_groundpiece("groundpieces/bridge", "bridge");
+}
+
+void
+ObjectSelectorList::set_gp_transparent()
+{
+  set_groundpiece("groundpieces/transparent", "transparent");
+}
+
+void
+ObjectSelectorList::set_gp_remove()
+{
+  set_groundpiece("groundpieces/remove", "remove");
+}
+
+void
+ObjectSelectorList::set_hotspot()
+{
+  clear_object_list();
+
+  std::vector<std::string> lst = Resource::resmgr.get_section("hotspots");
+  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
+    {
+      //sprite.scale(48, 48);
+      objects.push_back(new Hotspot(*i));
+    }
+}
+
+void
+ObjectSelectorList::set_background()
+{
+  clear_object_list();
+
+  std::vector<std::string> lst = Resource::resmgr.get_section("textures");
+  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
+    {
+      //sprite.scale(48, 48);
+      objects.push_back(new SurfaceBackground(*i));
+    }
+}
+
+void
+ObjectSelectorList::set_entrance()
+{
+  clear_object_list();
+
+  objects.push_back(new Entrance());
+
+  std::vector<std::string> lst = Resource::resmgr.get_section("entrances");
+  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
+    {
+      //sprite.scale(48, 48);
+      if (*i != "entrances/generic")
+        objects.push_back(new Hotspot(*i));
+    }
+}
+
+void
+ObjectSelectorList::set_exit()
+{
+  clear_object_list();
+
+  std::vector<std::string> lst = Resource::resmgr.get_section("exit");
+  for(std::vector<std::string>::const_iterator i = lst.begin(); i != 
lst.end(); ++i)
+    {
+      //sprite.scale(48, 48);
+      objects.push_back(new Exit(*i));
+    }
+}
+
+void
+ObjectSelectorList::set_liquid()
+{
+  set_objects("liquids");
+}
+
+void
+ObjectSelectorList::set_trap()
+{
+  // Need to differentiate the different trap types
+  set_objects("traps");
+}
+
+void
+ObjectSelectorList::set_weather()
+{
+  //set_objects("weather");
+  std::cout << "ObjectSelector: unimplemented: " << __FILE__ << ":" << 
__LINE__ << std::endl;
+}
+
+void
+ObjectSelectorList::set_worldobj()
+{
+  std::cout << "ObjectSelector: unimplemented: " << __FILE__ << ":" << 
__LINE__ << std::endl;
+}
+
+} // namespace Editor
+
+/* EOF */


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

Added: trunk/pingus/src/editor/object_selector_list.hpp
===================================================================
--- trunk/pingus/src/editor/object_selector_list.hpp    2007-09-13 11:55:55 UTC 
(rev 3140)
+++ trunk/pingus/src/editor/object_selector_list.hpp    2007-09-14 15:14:07 UTC 
(rev 3141)
@@ -0,0 +1,120 @@
+/*  $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_OBJECT_SELECTOR_LIST_HPP
+#define HEADER_OBJECT_SELECTOR_LIST_HPP
+
+#include "sprite.hpp"
+#include "gui/rect_component.hpp"
+
+class DrawingContext;
+
+namespace Editor {
+
+class LevelObj;
+class LevelImpl;
+class EditorScreen;
+class ObjectSelector;
+
+/** */
+class ObjectSelectorList : public GUI::RectComponent
+{
+public:
+  struct Object {
+    Sprite  sprite;
+    Sprite  thumbnail;
+    
+    Object(const Sprite& sprite_, const Sprite& thumbnail_) 
+      : sprite(sprite_),
+        thumbnail(thumbnail_)
+    {}      
+
+    virtual ~Object() {}
+
+    virtual LevelObj* create(const Vector2i&, LevelImpl* impl) { return 0; }
+  };
+
+private:
+  EditorScreen* editor;
+  ObjectSelector* object_selector;
+  DrawingContext* drawing_context;
+  float    offset;
+  float    old_offset;
+  Vector2i drag_start;
+  Vector2i mouse_pos;
+  Vector2i real_mouse_pos;
+  enum Mode { NOTHING, SCROLLING, OBJECT_DRAG };
+  Mode mode;
+
+
+  typedef std::vector<Object*> Objects;
+  Objects objects;
+
+  int current_object;
+  int drag_object;
+
+public:
+  ObjectSelectorList(EditorScreen* editor_, ObjectSelector* object_selector_, 
const Rect& rect);
+
+  void on_primary_button_press (int x, int y);
+  void on_primary_button_release (int x, int y);
+
+  void on_secondary_button_press (int x, int y);
+  void on_secondary_button_release (int x, int y);
+
+  void on_pointer_move (int x, int y);
+
+  void draw(DrawingContext& gc);
+
+  void set_objects(const std::string& prefix);
+
+  void clear_object_list();
+
+  void set_groundpiece(const std::string& prefix, const std::string& type);
+  void set_gp_ground();
+  void set_gp_solid();
+  void set_gp_bridge();
+  void set_gp_transparent();
+  void set_gp_remove();
+  void set_hotspot();
+  void set_background();
+  void set_entrance();
+  void set_exit();
+  void set_liquid();
+  void set_trap();
+  void set_weather();
+  void set_worldobj();
+
+  void update_layout() {}
+private:
+  ObjectSelectorList (const ObjectSelectorList&);
+  ObjectSelectorList& operator= (const ObjectSelectorList&);
+};
+
+} // namespace Editor
+
+#endif
+
+/* EOF */


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

Modified: trunk/pingus/src/gui/group_component.cpp
===================================================================
--- trunk/pingus/src/gui/group_component.cpp    2007-09-13 11:55:55 UTC (rev 
3140)
+++ trunk/pingus/src/gui/group_component.cpp    2007-09-14 15:14:07 UTC (rev 
3141)
@@ -32,8 +32,9 @@
   : RectComponent(rect),
     drawing_context(rect, clip),
     mouse_over_comp(0),
-    press_over_comp(0),
-    focused_comp(0)
+    focused_comp(0),
+    primary_pressed_comp(0),
+    secondary_pressed_comp(0)
 {
 }
 
@@ -90,8 +91,8 @@
       if (focused_comp)
         focused_comp->set_focus(true);
     }
-  
-  press_over_comp = comp;
+
+  primary_pressed_comp = comp;
 }
 
 void
@@ -99,14 +100,21 @@
 {
   Vector2i mouse_pos = drawing_context.screen_to_world(Vector2i(x, y));
   Component* comp = component_at(mouse_pos);
-  if (comp)
+      
+  if (primary_pressed_comp)
     {
-      comp->on_primary_button_release(mouse_pos.x, mouse_pos.y);
-      if (press_over_comp)
-        press_over_comp->on_secondary_button_click(mouse_pos.x, mouse_pos.y);
-      
-      press_over_comp = 0;
+      primary_pressed_comp->on_primary_button_release(mouse_pos.x, 
mouse_pos.y);
+
+      if (comp == primary_pressed_comp)
+        primary_pressed_comp->on_primary_button_click(mouse_pos.x, 
mouse_pos.y);
+
+      primary_pressed_comp = 0;
     }
+  else
+    {
+      if (comp)
+        comp->on_primary_button_release(mouse_pos.x, mouse_pos.y);
+    }
 }
   
 void
@@ -117,29 +125,36 @@
   if (comp)
     comp->on_secondary_button_press(mouse_pos.x, mouse_pos.y);
 
-  press_over_comp = comp;
+  if (!primary_pressed_comp)
+    secondary_pressed_comp = comp;
 }
 
 void
-GroupComponent::on_secondary_button_release (int x, int y)
+GroupComponent::on_secondary_button_release(int x, int y)
 {
   Vector2i mouse_pos = drawing_context.screen_to_world(Vector2i(x, y));
+
   Component* comp = component_at(mouse_pos);
-  if (comp)
+  
+  if (secondary_pressed_comp)
     {
-      comp->on_secondary_button_release(mouse_pos.x, mouse_pos.y);
-      if (press_over_comp)
-        press_over_comp->on_secondary_button_click(mouse_pos.x, mouse_pos.y);
-
-      press_over_comp = 0;
+      secondary_pressed_comp->on_secondary_button_release(mouse_pos.x, 
mouse_pos.y);
+      
+      if (comp == secondary_pressed_comp)
+        secondary_pressed_comp->on_secondary_button_click(mouse_pos.x, 
mouse_pos.y);
+      
+      secondary_pressed_comp = 0;
     }
+  else
+    {
+      if (comp)
+        comp->on_secondary_button_release(mouse_pos.x, mouse_pos.y);
+    }
 }
 
 void
 GroupComponent::on_key_pressed(const unsigned short c)
 {
-  std::cout << "GroupComponent: " << int(c) << std::endl;
-
   if (focused_comp)
     focused_comp->on_key_pressed(c);
   else if (mouse_over_comp)
@@ -150,22 +165,33 @@
 GroupComponent::on_pointer_move(int x, int y)
 {
   Vector2i mouse_pos = drawing_context.screen_to_world(Vector2i(x, y));
-  Component* comp = component_at(mouse_pos);
-  if (comp)
+  if (primary_pressed_comp)
     {
-      comp->on_pointer_move(mouse_pos.x, mouse_pos.y); 
+      primary_pressed_comp->on_pointer_move(mouse_pos.x, mouse_pos.y);
     }
+  else if (secondary_pressed_comp)
+    {
+      secondary_pressed_comp->on_pointer_move(mouse_pos.x, mouse_pos.y);
+    }
+  else
+    {
+      Component* comp = component_at(mouse_pos);
+      if (comp)
+        {
+          comp->on_pointer_move(mouse_pos.x, mouse_pos.y); 
+        }
 
-  if (comp != mouse_over_comp)
-    {
-      if (mouse_over_comp)
-        mouse_over_comp->on_pointer_leave();
+      if (comp != mouse_over_comp)
+        {
+          if (mouse_over_comp)
+            mouse_over_comp->on_pointer_leave();
       
-      if (comp)
-        comp->on_pointer_enter();
+          if (comp)
+            comp->on_pointer_enter();
+        }
+
+      mouse_over_comp = comp;
     }
-
-  mouse_over_comp = comp;
 }
 
 Component*

Modified: trunk/pingus/src/gui/group_component.hpp
===================================================================
--- trunk/pingus/src/gui/group_component.hpp    2007-09-13 11:55:55 UTC (rev 
3140)
+++ trunk/pingus/src/gui/group_component.hpp    2007-09-14 15:14:07 UTC (rev 
3141)
@@ -38,9 +38,17 @@
   typedef std::vector<Component*> Components;
   Components     children;
   DrawingContext drawing_context;
+
+  /** Used to detect enter/leave events */
   Component*     mouse_over_comp;
-  Component*     press_over_comp;
+
+  /** Used to decide where keyboard events should go */
   Component*     focused_comp;
+
+  /** Used to do a mouse grab, as long as a button is pressed, the
+      component that got the press gets moves and release events */
+  Component* primary_pressed_comp;
+  Component* secondary_pressed_comp;
   
 public:
   GroupComponent(const Rect& rect, bool clip = true);





reply via email to

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