pingus-cvs
[Top][All Lists]
Advanced

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

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


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3108 - in trunk/pingus/src: editor gui
Date: Sat, 8 Sep 2007 00:43:47 +0200

Author: grumbel
Date: 2007-09-08 00:43:46 +0200 (Sat, 08 Sep 2007)
New Revision: 3108

Modified:
   trunk/pingus/src/editor/editor_screen.cpp
   trunk/pingus/src/editor/editor_screen.hpp
   trunk/pingus/src/editor/file_load_dialog.cpp
   trunk/pingus/src/editor/file_load_dialog.hpp
   trunk/pingus/src/gui/group_component.cpp
   trunk/pingus/src/gui/group_component.hpp
Log:
- implemented GroupComponent

Modified: trunk/pingus/src/editor/editor_screen.cpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.cpp   2007-09-07 21:11:14 UTC (rev 
3107)
+++ trunk/pingus/src/editor/editor_screen.cpp   2007-09-07 22:43:46 UTC (rev 
3108)
@@ -49,8 +49,6 @@
     panel(0),
     viewport(0),
     object_selector(0),
-    filedialog(0),
-    close_dialog(false),
     show_help(false)
 {
   // Create the viewport for the images and data
@@ -62,17 +60,16 @@
 
   object_selector = new ObjectSelector(this);
 
-  FileLoadDialog* file_load_dialog = new FileLoadDialog(this, Rect(100, 150, 
700, 450));
-  gui_manager->add(file_load_dialog, true);
+  file_load_dialog = new FileLoadDialog(this, Rect(100, 150, 700, 450));
   file_load_dialog->set_directory("/tmp");
+  file_load_dialog->hide();
+  gui_manager->add(file_load_dialog, true);
 }
 
 // Destructor
 EditorScreen::~EditorScreen()
 {
   delete plf;
-  if (filedialog)
-    delete filedialog;
 }
 
 // Close the current screen
@@ -89,30 +86,10 @@
   close_screen();
 }
 
-// Show dialog box
-void
-EditorScreen::show_file_dialog(bool for_loading)
-{
-  if (filedialog)
-    delete filedialog;
-  close_dialog = false;
-  filedialog = new FileDialog(this, ".scm", 
-                              path_manager.complete("levels/"), for_loading);
-  filedialog->preload();       
-}
-
-// Close dialog box
-void
-EditorScreen::cancel()
-{
-  close_dialog = true;
-}
-
 // Save the current level
 void 
 EditorScreen::save(const std::string &file)
 {
-  close_dialog = true;
   plf->save_level(file);
 }
 
@@ -120,7 +97,6 @@
 void 
 EditorScreen::load(const Pathname& file)
 {
-  close_dialog = true;
   plf->load_level(file);
   viewport->refresh();
 }
@@ -180,27 +156,13 @@
                     "\n");
     }
   
-  if (filedialog)
-    filedialog->draw(gc);
-       
   return true;
 }
 
 void
 EditorScreen::update(const GameDelta &delta)
 {
-  if (filedialog)
-    {
-      if (close_dialog)
-        {
-          delete filedialog;
-          filedialog = 0;
-        }
-      else
-        filedialog->update(delta);
-    }
-  else
-    GUIScreen::update(delta);
+  GUIScreen::update(delta);
 
   SDL_Delay(33); // FIXME: Brute force delay to get CPU usage down
 }
@@ -228,7 +190,14 @@
 void 
 EditorScreen::level_load()
 {
-  std::cout << "Function at '" << __FILE__ << ":" << __LINE__ << "' is 
unimplemented" << std::endl; 
+  if (file_load_dialog->is_visible())
+    file_load_dialog->hide();
+  else 
+    {
+      //file_load_dialog->set_rect(Rect(Vector2i(rand() % 200, rand() % 200),
+      //                                 Size(400, 300)));
+      file_load_dialog->show();
+    }
 }
 
 void 

Modified: trunk/pingus/src/editor/editor_screen.hpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.hpp   2007-09-07 21:11:14 UTC (rev 
3107)
+++ trunk/pingus/src/editor/editor_screen.hpp   2007-09-07 22:43:46 UTC (rev 
3108)
@@ -22,9 +22,8 @@
 #define HEADER_PINGUS_EDITOR_SCREEN_HXX
 
 #include "../gui/gui_screen.hpp"
-#include "../file_dialog_listener.hpp"
+#include "file_load_dialog.hpp"
 
-
 class DrawingContext;
 class FileDialog;
 class GUI::GUIManager;
@@ -40,26 +39,16 @@
 
 /** This class is the screen that contains all of the
     editor objects */
-class EditorScreen : public GUIScreen, 
-                     public FileDialogListener
+class EditorScreen : public GUIScreen
 {
 private:
-  /** The level currently being edited */
   EditorLevel* plf;
 
-  /** Panel which contains all of the buttons for each action */
   Panel* panel;
-
-  /** Viewport which holds all of the level images and data */
   EditorViewport* viewport;
-
   ObjectSelector* object_selector;
+  FileLoadDialog* file_load_dialog;
 
-  /** File Dialog box */
-  FileDialog* filedialog;
-
-  bool close_dialog;
-
   bool show_help;
 
 public:

Modified: trunk/pingus/src/editor/file_load_dialog.cpp
===================================================================
--- trunk/pingus/src/editor/file_load_dialog.cpp        2007-09-07 21:11:14 UTC 
(rev 3107)
+++ trunk/pingus/src/editor/file_load_dialog.cpp        2007-09-07 22:43:46 UTC 
(rev 3108)
@@ -33,12 +33,12 @@
 namespace Editor {
 
 FileLoadDialog::FileLoadDialog(EditorScreen* editor_, const Rect& rect)
-  : RectComponent(rect),
+  : GroupComponent(rect),
     editor(editor_),
-    file_list(Rect(rect.left  + 10, rect.top + 10,
-                   rect.right - 10, rect.bottom - 10))
+    file_list(Rect(10, 10,
+                   rect.get_width()-10, rect.get_height() - 10))
 {
-  editor->get_gui_manager()->add(&file_list, false);
+  add(&file_list, false);
   
   file_list.on_click.connect(boost::bind(&FileLoadDialog::load_file, this, 
_1));
 }
@@ -48,9 +48,9 @@
 }
 
 void
-FileLoadDialog::draw(DrawingContext& gc)
+FileLoadDialog::draw_background(DrawingContext& gc)
 {
-  gc.draw_fillrect(rect.left, rect.top, rect.right, rect.bottom, Color(100, 
100, 100), -10);
+  gc.draw_fillrect(0, 0, rect.get_width(), rect.get_height(), Color(255, 255, 
255));
 }
   
 void

Modified: trunk/pingus/src/editor/file_load_dialog.hpp
===================================================================
--- trunk/pingus/src/editor/file_load_dialog.hpp        2007-09-07 21:11:14 UTC 
(rev 3107)
+++ trunk/pingus/src/editor/file_load_dialog.hpp        2007-09-07 22:43:46 UTC 
(rev 3108)
@@ -27,14 +27,14 @@
 #define HEADER_FILE_LOAD_DIALOG_HPP
 
 #include "file_list.hpp"
-#include "gui/rect_component.hpp"
+#include "gui/group_component.hpp"
 
 namespace Editor {
 
 class EditorScreen;
 
 /** */
-class FileLoadDialog : public GUI::RectComponent
+class FileLoadDialog : public GUI::GroupComponent
 {
 private:
   EditorScreen* editor;
@@ -45,9 +45,7 @@
   FileLoadDialog(EditorScreen* editor, const Rect& rect);
   ~FileLoadDialog();
   
-  bool is_at(int x, int y) { return false; }
-
-  void draw(DrawingContext& gc);
+  void draw_background(DrawingContext& gc);
   void update_layout() {}
 
   void load_file(const std::string& file) const;

Modified: trunk/pingus/src/gui/group_component.cpp
===================================================================
--- trunk/pingus/src/gui/group_component.cpp    2007-09-07 21:11:14 UTC (rev 
3107)
+++ trunk/pingus/src/gui/group_component.cpp    2007-09-07 22:43:46 UTC (rev 
3108)
@@ -28,7 +28,10 @@
 namespace GUI {
 
 GroupComponent::GroupComponent(const Rect& rect)
-  : RectComponent(rect)
+  : RectComponent(rect),
+    drawing_context(rect),
+    mouse_over_comp(0),
+    press_over_comp(0)
 {
 }
 
@@ -37,13 +40,29 @@
 }
        
 void
-GroupComponent::draw (DrawingContext& gc)
+GroupComponent::draw (DrawingContext& parent_gc)
 {
+  drawing_context.clear();
+
+  draw_background(drawing_context);
+
+  for(Components::iterator i = children.begin(); i != children.end(); ++i)
+    {
+      if ((*i)->is_visible())
+        (*i)->draw(drawing_context);
+    }
+  
+  parent_gc.draw(drawing_context);
 }
 
 void
 GroupComponent::update (float delta)
 {
+  for(Components::iterator i = children.begin(); i != children.end(); ++i)
+    {
+      if ((*i)->is_visible())
+        (*i)->update(delta);
+    }
 }
 
 bool is_at (int x, int y);
@@ -51,62 +70,98 @@
 void
 GroupComponent::on_primary_button_press (int x, int y)
 {
+  Vector2i mouse_pos = drawing_context.screen_to_world(Vector2i(x, y));
+  Component* comp = component_at(mouse_pos);
+  if (comp)
+    comp->on_primary_button_press(mouse_pos.x, mouse_pos.y);
+  
+  press_over_comp = comp;
 }
 
 void
 GroupComponent::on_primary_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)
+    {
+      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;
+    }
 }
-
-void
-GroupComponent::on_primary_button_double_click (int x, int y)
-{
-}
   
 void
 GroupComponent::on_secondary_button_press (int x, int y)
 {
+  Vector2i mouse_pos = drawing_context.screen_to_world(Vector2i(x, y));
+  Component* comp = component_at(mouse_pos);
+  if (comp)
+    comp->on_secondary_button_press(mouse_pos.x, mouse_pos.y);
+
+  press_over_comp = comp;
 }
 
 void
 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)
+    {
+      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);
 
-void
-GroupComponent::on_primary_button_click (int x, int y)
-{
+      press_over_comp = 0;
+    }
 }
 
 void
-GroupComponent::on_secondary_button_click (int x, int y)
+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)
+    {
+      comp->on_pointer_move(mouse_pos.x, mouse_pos.y); 
+    }
 
-void
-GroupComponent::on_pointer_enter () 
-{
-}
+  if (comp != mouse_over_comp)
+    {
+      if (mouse_over_comp)
+        mouse_over_comp->on_pointer_leave();
+      
+      if (comp)
+        comp->on_pointer_enter();
+    }
 
-void
-GroupComponent::on_pointer_leave () 
-{
+  mouse_over_comp = comp;
 }
 
 void
-GroupComponent::on_pointer_move (int x, int y)
+GroupComponent::on_key_pressed(const unsigned short c)
 {
+  
 }
 
-void
-GroupComponent::on_key_pressed(const unsigned short c)
+Component*
+GroupComponent::component_at (const Vector2i& pos)
 {
+  for(Components::iterator i = children.begin(); i != children.end(); ++i)
+    {
+      if ((*i)->is_at(pos.x, pos.y))
+        return *i;
+    }
+  return 0;
 }
 
 void
-GroupComponent::add(Component*)
+GroupComponent::add(Component* comp, bool delete_comp)
 {
-  
+  children.push_back(comp);
 }
 
 } // namespace GUI

Modified: trunk/pingus/src/gui/group_component.hpp
===================================================================
--- trunk/pingus/src/gui/group_component.hpp    2007-09-07 21:11:14 UTC (rev 
3107)
+++ trunk/pingus/src/gui/group_component.hpp    2007-09-07 22:43:46 UTC (rev 
3108)
@@ -35,39 +35,43 @@
 class GroupComponent : public RectComponent
 {
 private:
-  std::vector<Component> children;
+  typedef std::vector<Component*> Components;
+  Components     children;
   DrawingContext drawing_context;
+  Component*     mouse_over_comp;
+  Component*     press_over_comp;
   
 public:
   GroupComponent(const Rect& rect);
   ~GroupComponent();  
        
-  void draw (DrawingContext& gc);
-  void update (float delta);
+  void draw(DrawingContext& gc);
+  virtual void draw_background(DrawingContext& gc) {}
+
+  void update(float delta);
 
-  void on_primary_button_press (int x, int y);
-  void on_primary_button_release (int x, int y);
-
-  void on_primary_button_double_click (int x, int y);
+  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_secondary_button_press (int x, int y);
-  void on_secondary_button_release (int x, int y);
-  
-  void on_primary_button_click (int x, int y);
-  void on_secondary_button_click (int x, int y);
+  void on_primary_button_click(int x, int y) {}
+  void on_secondary_button_click(int x, int y) {}
 
-  void on_pointer_enter ();
-  void on_pointer_leave ();
+  void on_pointer_enter() {}
+  void on_pointer_leave() {}
 
-  void on_pointer_move (int x, int y);
+  void on_pointer_move(int x, int y);
 
   void on_key_pressed(const unsigned short c);
 
-  void add(Component*);
+  void add(Component*, bool delete_comp);
 
+  Component* component_at (const Vector2i& pos);
 private:
-  GroupComponent (const GroupComponent&);
-  GroupComponent& operator= (const GroupComponent&);
+  GroupComponent(const GroupComponent&);
+  GroupComponent& operator=(const GroupComponent&);
 };
 
 } // namespace GUI





reply via email to

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