pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src Makefile.am,1.85,1.86 action_data.cxx


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src Makefile.am,1.85,1.86 action_data.cxx,1.3,1.4 client.cxx,1.5,1.6 client.hxx,1.3,1.4 game_delta.hxx,1.4,1.5 gui_obj.hxx,1.2,1.3 smallmap.cxx,1.5,1.6 smallmap.hxx,1.4,1.5 smallmap_image.cxx,1.3,1.4 smallmap_image.hxx,1.2,1.3
Date: 29 Jul 2002 10:44:14 -0000

Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv8543/src

Modified Files:
        Makefile.am action_data.cxx client.cxx client.hxx 
        game_delta.hxx gui_obj.hxx smallmap.cxx smallmap.hxx 
        smallmap_image.cxx smallmap_image.hxx 
Log Message:
some gui framework and some gui experiments here and there

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/Makefile.am,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- Makefile.am 3 Jul 2002 17:14:25 -0000       1.85
+++ Makefile.am 29 Jul 2002 10:44:12 -0000      1.86
@@ -31,6 +31,7 @@
        editor              \
        entrances           \
        generic             \
+        gui                 \
         input               \
        particles           \
        traps               \
@@ -64,6 +65,7 @@
         backgrounds/libpingus_backgrounds.a       \
         worldmap/libpingus_worldmap.a \
         generic/libpingus_generic.a \
+       gui/libpingus_gui.a \
         input/libpingus_input.a
 
 pingus_SOURCES = \

Index: action_data.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/action_data.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- action_data.cxx     29 Jun 2002 17:39:21 -0000      1.3
+++ action_data.cxx     29 Jul 2002 10:44:12 -0000      1.4
@@ -26,19 +26,23 @@
 
 void init_default_actions ()
 {
+  //default_actions.push_back (ActionData (Boarder, 20));
+  //default_actions.push_back (ActionData (Rocketlauncher, 20));
+  //default_actions.push_back (ActionData (Superman, 0));
+
   default_actions.push_back (ActionData (Basher, 20));
   default_actions.push_back (ActionData (Blocker, 20));
-  //default_actions.push_back (ActionData (Boarder, 20));
   default_actions.push_back (ActionData (Bomber, 20));
+
   default_actions.push_back (ActionData (Bridger, 20));
   default_actions.push_back (ActionData (Climber, 20));
+
   default_actions.push_back (ActionData (Digger, 20));
   default_actions.push_back (ActionData (Floater, 20));
   default_actions.push_back (ActionData (Jumper, 20));
+
   default_actions.push_back (ActionData (Miner, 20));
-  //default_actions.push_back (ActionData (Rocketlauncher, 20));
   default_actions.push_back (ActionData (Slider, 20));
-  //default_actions.push_back (ActionData (Superman, 0));
 }
 
 /* EOF */

Index: client.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/client.cxx,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- client.cxx  8 Jul 2002 17:05:09 -0000       1.5
+++ client.cxx  29 Jul 2002 10:44:12 -0000      1.6
@@ -41,6 +41,17 @@
 #include "server.hxx"
 #include "button_panel.hxx"
 
+// GUI
+#include "gui/root_gui_manager.hxx"
+#include "gui/surface_button.hxx"
+
+// Input Header files
+#include "input/event.hxx"
+#include "input/button_event.hxx"
+#include "input/axis_event.hxx"
+#include "input/pointer_event.hxx"
+#include "input/controller.hxx"
+
 Client::Client(Controller* arg_controller, Server * s)
   : server       (s),
     fast_forward (false),
@@ -48,6 +59,8 @@
     skip_frame   (0),
     do_replay    (false),
     is_finished  (false),
+    grabbed_gui_obj (0),
+    current_gui_obj (0),
     button_panel (0),
     pcounter     (0),
     playfield    (0),
@@ -61,6 +74,16 @@
  
   Display::add_flip_screen_hook(cursor);
   //Display::add_flip_screen_hook(new Cursor ("cursors/cursor", "core", 
boost::shared_ptr<Controller>(new MouseController ())));
+
+  std::cout << "Creating controller" << std::endl;
+  input_controller = new Input::Controller ("../doc/mycontroller.xml");
+  std::cout << "Creating controller done" << std::endl;
+  std::cout << "Creating guix" << std::endl;
+  gui_manager = new GUI::RootGUIManager (input_controller);
+  gui_manager->add (new GUI::SurfaceButton (400, 200,
+                                           ResDescriptor ("editor/button", 
"core", ResDescriptor::RD_RESOURCE),
+                                           ResDescriptor 
("editor/button_pressed", "core", ResDescriptor::RD_RESOURCE),
+                                           ResDescriptor ("editor/actions", 
"core", ResDescriptor::RD_RESOURCE)));
 }
 
 Client::~Client()
@@ -223,6 +246,8 @@
   for(GuiObjIter i = obj.begin (); i != obj.end (); ++i)
     (*i)->draw_clipped();
 
+  gui_manager->draw ();
+
   Display::flip_display();         
 }
 
@@ -230,14 +255,16 @@
 Client::update (float delta)
 {
   cursor->update (delta);
+  input_controller->update (delta);
+  gui_manager->update (delta);
+
+  // process input events
+  process_events ();
 
   // Let the window move its content
   for(GuiObjIter i = obj.begin (); i != obj.end (); ++i)
     (*i)->updateX();
   
-  // Update every 3/100 seconds
-  // if (last_update + 30 < CL_System::get_time())
-             
   for(GuiObjIter i = obj.begin (); i != obj.end (); ++i)
     (*i)->update(delta);
 
@@ -247,6 +274,117 @@
 }
 
 void
+Client::process_events ()
+{
+  std::list<Input::Event*>& events = input_controller->get_events ();
+
+  for (std::list<Input::Event*>::iterator i = events.begin (); i != events.end 
(); ++i)
+    {
+      //std::cout << "Events: " << (*i)->get_type () << std::endl;
+    
+      switch ((*i)->get_type ())
+       {
+       case Input::ButtonEventType:
+         process_button_event (static_cast<class Input::ButtonEvent*>(*i));
+         break;
+
+       case Input::PointerEventType:
+         process_pointer_event (static_cast<class Input::PointerEvent*>(*i));
+         break;
+
+       case Input::AxisEventType:
+         process_axis_event (static_cast<class Input::AxisEvent*>(*i));
+         break;
+         
+       default:
+         // unhandled event
+         //std::cout << "Client::process_events (): unhandled event: " << 
(*i)->get_type() << std::endl;
+         break;
+       }
+    }
+}
+
+void
+Client::process_button_event (Input::ButtonEvent* event)
+{
+  std::cout << "Client::process_button_event (): " << event->name << " " << 
event->state << std::endl;
+
+  switch (event->name)
+    {
+    case Input::primary:
+      {
+       if (event->state == Input::pressed)
+         {
+           //GuiObj* obj = get_gui_object (int(event->x), int(event->y));
+           //obj->on_mouse_press ();
+         }
+       else
+         {
+           //GuiObj* obj = get_gui_object (int(event->x), int(event->y));
+           //obj->on_mouse_leave ();
+         }
+      }
+      break;
+    case Input::secondary:
+      break;
+    default:
+      break;
+    }
+}
+
+void
+Client::process_pointer_event (Input::PointerEvent* event)
+{
+  if (event->type == 1)
+    std::cout << "Client::process_pointer_event (): " 
+             << event->x << " " << event->y << " " 
+             << event->type << std::endl;  
+  
+  switch (event->type)
+    {
+       /*
+
+    case Input::scroll: // FIXME: incorrect enum name
+      {
+       GuiObj* obj = get_gui_object (int(event->x), int(event->y));
+       if (obj)
+         {
+           if (obj != current_gui_obj)
+             {
+               current_gui_obj = obj;
+               obj->on_mouse_enter();
+             }
+           else
+             {
+               if (current_gui_obj) current_gui_obj->on_mouse_leave();
+               current_gui_obj = 0;
+             }
+         }
+       else
+         {
+           if (current_gui_obj) current_gui_obj->on_mouse_leave();
+           current_gui_obj = 0;
+         }
+      }
+      break;
+       */
+      
+      //se Input::scroll:
+      //reak;      
+      
+      //default:
+      //std::cout << "Client::process_pointer_event: unhandled event" << 
std::endl;
+      //break;
+    }
+}
+
+void
+Client::process_axis_event (Input::AxisEvent* event)
+{
+  std::cout << "Client::process_axis_event ()" << std::endl;    
+}
+
+void
 Client::send_next_event()
 {
 }
@@ -641,6 +779,17 @@
 {
   std::cout << "Action previous pressed" << std::endl;
   button_panel->previous_action();
+}
+
+GuiObj*
+Client::get_gui_object (int x, int y)
+{
+  for(GuiObjRIter i = obj.rbegin (); i != obj.rend (); ++i)
+    {
+      if ((*i)->mouse_over (x, y))
+       return *i;
+    }
+  return 0;
 }
 
 /* EOF */

Index: client.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/client.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- client.hxx  24 Jun 2002 22:52:54 -0000      1.3
+++ client.hxx  29 Jul 2002 10:44:12 -0000      1.4
@@ -24,8 +24,21 @@
 #include <ClanLib/Display/Input/inputdevice.h>
 #include <vector>
 
+namespace Input 
+{
+  class Controller;
+  class ButtonEvent;
+  class PointerEvent;
+  class AxisEvent;
+}
+
 #include "result.hxx"
 
+namespace GUI
+{
+  class RootGUIManager;
+}
+
 class CL_Key;
 class CL_Vector;
 class ButtonPanel;
@@ -57,6 +70,15 @@
 
   std::vector<GuiObj*> obj;
   typedef std::vector<GuiObj*>::iterator GuiObjIter;
+  typedef std::vector<GuiObj*>::reverse_iterator GuiObjRIter;
+
+  GUI::RootGUIManager* gui_manager;
+
+  /** The object that got a mouse_down() */
+  GuiObj* grabbed_gui_obj;
+
+  /** The object which is currently under the cursor */
+  GuiObj* current_gui_obj;
 
   ButtonPanel*   button_panel;
   PingusCounter* pcounter;
@@ -66,6 +88,7 @@
   HurryUp*       hurry_up;
 
   Controller* controller;
+  Input::Controller* input_controller;
   Cursor*     cursor;
 
   CL_Slot on_button_press_slot;
@@ -85,6 +108,13 @@
   CL_Slot slot_next_action_pressed;
   CL_Slot slot_previous_action_pressed;
   
+  void process_button_event (Input::ButtonEvent*);
+  void process_pointer_event (Input::PointerEvent*);
+  void process_axis_event (Input::AxisEvent*);
+
+  /** Return the GuiObj under the given coordinates */
+  GuiObj* get_gui_object (int x, int y);
+
   bool enabled;
 public:
   Client(Controller* arg_controller, Server * s);
@@ -123,6 +153,8 @@
 
   /** Update all parts of the world */
   void update (float delta);
+
+  void process_events ();
 
   ButtonPanel* get_button_panel () { return button_panel; }
 

Index: game_delta.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/game_delta.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- game_delta.hxx      2 Jul 2002 16:06:51 -0000       1.4
+++ game_delta.hxx      29 Jul 2002 10:44:12 -0000      1.5
@@ -26,19 +26,25 @@
 
 namespace Pingus 
 {
+  /** Input for the game engine */
   class GameDelta
   {
   private:
-    
+    std::list<Event*> events;
+    float time;
+
   public:
-    /**  */
-    InputEvent peek_event ();
+    void set_time (float t) { time = t; }
+
+    /** add an event (FIXME: Memory handling?!)*/
+    void add_event (Event* e) { events.push_back(); }
+
 
-    /**  */
-    InputEvent pop_event ();
-    
     /** Return the time that has passed in seconds */
-    float get_time ();
+    float get_time () { return time; }
+
+    /** Return the events */
+    std::list<Event*>& get_events () { return events; }
   };
 }
 

Index: gui_obj.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/gui_obj.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- gui_obj.hxx 24 Jun 2002 22:52:54 -0000      1.2
+++ gui_obj.hxx 29 Jul 2002 10:44:12 -0000      1.3
@@ -27,26 +27,24 @@
 class GuiObj 
 {
 protected:
-  ///
+  // FIXME: Do we need that here?! (its used for clipping)
   int x1;
-  ///
   int y1;
-  ///
   int x2;
-  ///
   int y2;
+
 public:
-  ///
   GuiObj();
-  ///
   virtual ~GuiObj();
 
-  ///
   void    set_clip_rect(int, int, int, int);
   
   /// Draw the gui element and do the clipping.
   virtual void draw_clipped();
 
+  /** Return true if the mouse is over this GUI component */
+  virtual bool mouse_over (int x, int y) { return false; }
+
   /// Draw the gui element
   virtual void draw() = 0;
 
@@ -56,6 +54,15 @@
   /** Update all elements, which are indepented of the world speed
       (for example scrolling). */
   virtual void updateX();
+
+  // Events
+  
+  // Called when 
+  virtual void on_mouse_enter () {}
+  virtual void on_mouse_leave () {}
+  virtual void on_mouse_click () {}
+  virtual void on_mouse_press () {}
+  virtual void on_mouse_release () {}
 };
 
 #endif

Index: smallmap.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/smallmap.cxx,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- smallmap.cxx        25 Jun 2002 18:15:18 -0000      1.5
+++ smallmap.cxx        29 Jul 2002 10:44:12 -0000      1.6
@@ -159,6 +159,12 @@
   int y_of = playfield->get_y_offset();
 
   sur.put_screen(0, CL_Display::get_height() - sur.get_height()); 
+
+  if (has_focus)
+    Display::draw_rect(0, CL_Display::get_height() - sur.get_height(),
+                      sur.get_width (), CL_Display::get_height() - 
sur.get_height() + sur.get_height () - 1, 
+                      1.0f, 1.0f, 1.0f, 1.0f);
+                      
   
   x_of = -x_of * width / 
client->get_server()->get_world()->get_colmap()->get_width();
   y_of = -y_of * height / 
client->get_server()->get_world()->get_colmap()->get_height();
@@ -228,6 +234,14 @@
 }
 
 bool
+SmallMap::mouse_over(int x, int y)
+{
+  std::cout << "............." << x << " " << y << std::endl;
+  return (x > x_pos && x < x_pos + (int)width
+         && y > y_pos && y < y_pos + (int)height);
+}
+
+bool
 SmallMap::on_button_press(const CL_Key& key)
 {
   switch(key.id)
@@ -253,6 +267,18 @@
       break;
     }
   return false;
+}
+
+void
+SmallMap::on_mouse_enter ()
+{
+  has_focus = true;  
+}
+
+void
+SmallMap::on_mouse_leave ()
+{
+  has_focus = false;  
 }
 
 /* EOF */

Index: smallmap.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/smallmap.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- smallmap.hxx        2 Jul 2002 15:46:58 -0000       1.4
+++ smallmap.hxx        29 Jul 2002 10:44:12 -0000      1.5
@@ -43,6 +43,7 @@
   bool scroll_mode;
   int rwidth;
   int rheight;
+  bool has_focus;
 public:
   SmallMap();
   ~SmallMap();
@@ -56,6 +57,12 @@
   void draw();
   void draw_pingus();
   void update(float delta);
+
+  bool mouse_over(int x, int y);
+
+  // Events
+  void on_mouse_enter ();
+  void on_mouse_leave ();
 };
 
 #endif

Index: smallmap_image.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/smallmap_image.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- smallmap_image.cxx  25 Jun 2002 18:15:18 -0000      1.3
+++ smallmap_image.cxx  29 Jul 2002 10:44:12 -0000      1.4
@@ -153,4 +153,12 @@
   return CL_Surface(canvas, true);
 }
 
+bool 
+SmallMapImage::mouse_over (int x, int y)
+{
+  return (pos.x < x && pos.x + sur.get_width () > x
+         && 
+         pos.y < y && pos.y + sur.get_height () > y);
+}
+
 /* EOF */

Index: smallmap_image.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/smallmap_image.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- smallmap_image.hxx  24 Jun 2002 22:52:56 -0000      1.2
+++ smallmap_image.hxx  29 Jul 2002 10:44:12 -0000      1.3
@@ -40,6 +40,8 @@
   void draw ();
   void update (float delta);
 
+  bool mouse_over (int x, int y);
+
   static CL_Surface create_surface (Server * server, int width, int height);
 };
 




reply via email to

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