[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/gui Makefile.am,NONE,1.1 component.cx
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/gui Makefile.am,NONE,1.1 component.cxx,NONE,1.1 root_gui_manager.cxx,NONE,1.1 root_gui_manager.hxx,NONE,1.1 surface_button.cxx,NONE,1.1 surface_button.hxx,NONE,1.1 button.hxx,1.1,1.2 component.hxx,1.1,1.2 gui_manager.cxx,1.1,1.2 gui_manager.hxx,1.1,1.2 |
Date: |
29 Jul 2002 10:44:14 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/gui
In directory dark:/tmp/cvs-serv8543/src/gui
Modified Files:
button.hxx component.hxx gui_manager.cxx gui_manager.hxx
Added Files:
Makefile.am component.cxx root_gui_manager.cxx
root_gui_manager.hxx surface_button.cxx surface_button.hxx
Log Message:
some gui framework and some gui experiments here and there
--- NEW FILE: Makefile.am ---
# Pingus - A free Lemmings clone
# Copyright (C) 1999 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.
noinst_LIBRARIES = libpingus_gui.a
libpingus_gui_a_SOURCES = \
gui_manager.hxx \
gui_manager.cxx \
root_gui_manager.hxx \
root_gui_manager.cxx \
surface_button.hxx \
surface_button.cxx
# EOF #
--- NEW FILE: component.cxx ---
// $Id: component.cxx,v 1.1 2002/07/29 10:44:12 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2000 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 "component.hxx"
bool
Component::is_pressed ()
{
}
/** true if mouse is currently over */
bool
Component::pointer_over ()
{
}
/* EOF */
--- NEW FILE: root_gui_manager.cxx ---
// $Id: root_gui_manager.cxx,v 1.1 2002/07/29 10:44:12 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2000 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 <list>
#include "../input/event.hxx"
#include "../input/button_event.hxx"
#include "../input/pointer_event.hxx"
#include "root_gui_manager.hxx"
using namespace GUI;
using namespace Input;
RootGUIManager::RootGUIManager (Input::Controller* c)
: controller(c), pressed_component (0), mouse_over_component (0),
x_pos (400), y_pos (300)
{
}
RootGUIManager::~RootGUIManager ()
{
}
void
RootGUIManager::draw ()
{
for (std::vector<Component*>::iterator i = components.begin ();
i != components.end (); ++i)
{
(*i)->draw ();
}
}
void
RootGUIManager::update (float delta)
{
assert (controller);
for (std::vector<Component*>::iterator i = components.begin ();
i != components.end (); ++i)
{
(*i)->update (delta);
}
process_input (delta);
}
void
RootGUIManager::process_input (float delta)
{
assert (controller);
std::list<Event*>& events = controller->get_events ();
for (std::list<Event*>::iterator i = events.begin (); i != events.end (); ++i)
{
switch ((*i)->get_type())
{
case Input::PointerEventType:
{
PointerEvent* event = dynamic_cast<PointerEvent*>(*i);
x_pos = event->x;
y_pos = event->y;
Component* comp = component_at (x_pos, y_pos);//FIXME
if (comp)
{
if (comp != mouse_over_component)
{
if (mouse_over_component != 0)
mouse_over_component->on_pointer_leave ();
comp->on_pointer_enter ();
mouse_over_component = comp;
}
else
{
// nothing changed, so we don't trigger events
}
}
else
{
if (mouse_over_component)
{
mouse_over_component->on_pointer_leave ();
mouse_over_component = 0;
}
}
break;
}
case Input::ButtonEventType:
{
ButtonEvent* event = dynamic_cast<ButtonEvent*>(*i);
//std::cout << "RootGUIManager: Got button event: " << event->name
<< " " << event->state << std::endl;
Component* comp = component_at (x_pos, y_pos);//FIXME
if (comp)
{
if (event->name == primary && event->state == Input::pressed)
{
pressed_component = comp;
comp->on_button_press (x_pos, y_pos); // FIXME: dummy data
}
else if (event->name == primary && event->state ==
Input::released)
{
/** Send the release event to the same component
which got the press event */
assert (pressed_component);
pressed_component->on_button_release (x_pos, y_pos);
if (pressed_component == comp)
{
comp->on_button_click (x_pos, y_pos);
}
else
{
// discard click
}
pressed_component = 0;
}
}
else
{
std::cout << "RootGUIManager: Clicked into a non managed
region" << std::endl;
if (pressed_component)
{
pressed_component->on_button_release (x_pos, y_pos);
pressed_component = 0;
}
}
break;
}
default:
std::cout << "RootGUIManager: unhandled event type " <<
(*i)->get_type() << std::endl;
break;
}
}
}
Component*
RootGUIManager::component_at (int x, int y)
{
for (std::vector<Component*>::iterator i = components.begin ();
i != components.end (); ++i)
{
if ((*i)->is_at (x, y))
return *i;
}
return 0;
}
/* EOF */
--- NEW FILE: root_gui_manager.hxx ---
// $Id: root_gui_manager.hxx,v 1.1 2002/07/29 10:44:12 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2000 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_ROOT_GUI_MANAGER_HXX
#define HEADER_PINGUS_GUI_ROOT_GUI_MANAGER_HXX
#include "../input/controller.hxx"
#include "gui_manager.hxx"
namespace GUI
{
/** Root GUI manager
*/
class RootGUIManager : public GUIManager
{
private:
Input::Controller* controller;
std::vector<Component*> components;
/** The component which recieved the last pressed event */
Component* pressed_component;
/** The component over which the mouse was in the last update,
used to detecte enter/leave events */
Component* mouse_over_component;
// FIXME: Hack:
int x_pos;
int y_pos;
public:
RootGUIManager (Input::Controller* c);
~RootGUIManager ();
void draw ();
void update (float delta);
void process_input (float delta);
Component* component_at (int x, int y);
void add (Component* c) { components.push_back(c); }
void remove (Component* c) { /* components.erase(c); */ }
};
}
#endif
/* EOF */
--- NEW FILE: surface_button.cxx ---
// $Id: surface_button.cxx,v 1.1 2002/07/29 10:44:12 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2000 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 "../res_descriptor.hxx"
#include "../pingus_resource.hxx"
#include "surface_button.hxx"
using namespace GUI;
SurfaceButton::SurfaceButton (int arg_x_pos, int arg_y_pos,
const ResDescriptor& arg_button_surface,
const ResDescriptor& arg_button_pressed_surface,
const ResDescriptor&
arg_button_mouse_over_surface)
: x_pos (arg_x_pos), y_pos (arg_y_pos), pressed (false), mouse_over (false)
{
button_surface = PingusResource::load_surface (arg_button_surface);
button_pressed_surface = PingusResource::load_surface
(arg_button_pressed_surface);
button_mouse_over_surface = PingusResource::load_surface
(arg_button_mouse_over_surface);
}
SurfaceButton::~SurfaceButton ()
{
}
void
SurfaceButton::draw ()
{
if (pressed && mouse_over)
button_pressed_surface.put_screen (x_pos, y_pos);
else if (!pressed && mouse_over)
button_mouse_over_surface.put_screen (x_pos, y_pos);
else
button_surface.put_screen (x_pos, y_pos);
}
bool
SurfaceButton::is_at (int x, int y)
{
/*std::cout << "Is AT: " << (x > x_pos && x < x_pos +
int(button_surface.get_width ())
&& y > y_pos && y < y_pos +
int(button_surface.get_height ()))
<< std::endl;*/
return x > x_pos && x < x_pos + int(button_surface.get_width ())
&& y > y_pos && y < y_pos + int(button_surface.get_height ());
}
void
SurfaceButton::on_button_press (int x, int y)
{
std::cout << "XXXXXXXXX press" << std::endl;
pressed = true;
}
void
SurfaceButton::on_button_release (int x, int y)
{
std::cout << "XXXXXXXXX release" << std::endl;
pressed = false;
}
void
SurfaceButton::on_pointer_enter ()
{
std::cout << "XXXXXXXXX enter" << std::endl;
mouse_over = true;
}
void
SurfaceButton::on_pointer_leave ()
{
std::cout << "XXXXXXXXX leave" << std::endl;
mouse_over = false;
}
void
SurfaceButton::on_button_click (int x, int y)
{
std::cout << "Surfacebutton got click" << std::endl;
}
/* EOF */
--- NEW FILE: surface_button.hxx ---
// $Id: surface_button.hxx,v 1.1 2002/07/29 10:44:12 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2000 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_SURFACE_BUTTON_HXX
#define HEADER_PINGUS_GUI_SURFACE_BUTTON_HXX
#include <ClanLib/display.h>
#include "component.hxx"
class ResDescriptor;
namespace GUI
{
/** A simple surface button, which different surfaces for pressed,
released and mouse over */
class SurfaceButton : public Component
{
private:
int x_pos;
int y_pos;
CL_Surface button_surface;
CL_Surface button_pressed_surface;
CL_Surface button_mouse_over_surface;
bool pressed;
bool mouse_over;
public:
SurfaceButton (int x_pos, int y_pos,
const ResDescriptor& button_surface,
const ResDescriptor& button_pressed_surface,
const ResDescriptor& button_mouse_over_surface);
virtual ~SurfaceButton ();
void draw ();
bool is_at (int x, int y);
void on_button_press (int x, int y);
void on_button_release (int x, int y);
void on_button_click (int x, int y);
void on_pointer_enter ();
void on_pointer_leave ();
};
}
#endif
/* EOF */
Index: button.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/gui/button.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- button.hxx 12 Jul 2002 15:39:21 -0000 1.1
+++ button.hxx 29 Jul 2002 10:44:12 -0000 1.2
@@ -20,12 +20,22 @@
#ifndef HEADER_PINGUS_GUI_BUTTON_HXX
#define HEADER_PINGUS_GUI_BUTTON_HXX
-class Button
+namespace GUI
{
-private:
+ class Button
+ {
+ protected:
+ bool pressed;
+ bool mouse_over;
-public:
-};
+ public:
+ void on_button_press (int x, int y);
+ void on_button_release (int x, int y);
+
+ void on_pointer_enter ();
+ void on_pointer_leave ();
+ };
+}
#endif
Index: component.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/gui/component.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- component.hxx 12 Jul 2002 15:39:21 -0000 1.1
+++ component.hxx 29 Jul 2002 10:44:12 -0000 1.2
@@ -22,11 +22,41 @@
namespace GUI
{
+ /** A component represents an area which recivies events in the GUI,
+ some people might call it a widget */
class Component
{
private:
public:
+ virtual void draw () =0;
+ virtual void update (float delta) {}
+
+ virtual bool is_at (int x, int y) { return false; }
+
+ // Events
+ /** Gets issued once the primary button is pressed */
+ virtual void on_button_press (int x, int y) {}
+
+ /** Gets issued once the primary button is released */
+ virtual void on_button_release (int x, int y) {}
+
+ /** Gets emmited when a button is pressed and released over the
+ same component */
+ virtual void on_button_click (int x, int y) {}
+
+ /** Emmitted when pointer enters the region of the component */
+ virtual void on_pointer_enter () {}
+
+ /** Emmitted when pointer leaves the region of the component */
+ virtual void on_pointer_leave () {}
+
+ // status functions for use in the update() function
+ /** return true if currently pressed */
+ bool is_pressed ();
+
+ /** true if mouse is currently over */
+ bool pointer_over ();
};
}
Index: gui_manager.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/gui/gui_manager.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- gui_manager.cxx 12 Jul 2002 15:39:21 -0000 1.1
+++ gui_manager.cxx 29 Jul 2002 10:44:12 -0000 1.2
@@ -19,6 +19,8 @@
#include "gui_manager.hxx"
+using namespace GUI;
+
void
GUIManager::update (float delta)
{
Index: gui_manager.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/gui/gui_manager.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- gui_manager.hxx 12 Jul 2002 15:39:21 -0000 1.1
+++ gui_manager.hxx 29 Jul 2002 10:44:12 -0000 1.2
@@ -20,22 +20,24 @@
#ifndef HEADER_PINGUS_GUI_GUI_MANAGER_HXX
#define HEADER_PINGUS_GUI_GUI_MANAGER_HXX
+#include "component.hxx"
+
namespace GUI
{
- /** Manager class which holds all GUI components and displays them */
- class GUIManager
+ /** interface class which holds all GUI components and displays
+ them */
+ class GUIManager : public Component
{
private:
- std::vector<Component*> components;
-
public:
- GUIManager ();
- ~GUIManager ();
+ GUIManager () {}
+ virtual ~GUIManager () {}
- void update (float delta);
+ virtual void draw () =0;
+ virtual void update (float delta) =0;
- void add (Component*);
- void remove (Component*);
+ virtual void add (Component*) =0;
+ virtual void remove (Component*) =0;
};
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/gui Makefile.am,NONE,1.1 component.cxx,NONE,1.1 root_gui_manager.cxx,NONE,1.1 root_gui_manager.hxx,NONE,1.1 surface_button.cxx,NONE,1.1 surface_button.hxx,NONE,1.1 button.hxx,1.1,1.2 component.hxx,1.1,1.2 gui_manager.cxx,1.1,1.2 gui_manager.hxx,1.1,1.2,
grumbel <=
- Prev by Date:
[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
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src/gui component.hxx,1.2,1.3 root_gui_manager.cxx,1.1,1.2 root_gui_manager.hxx,1.1,1.2
- Previous by thread:
[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
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src/gui component.hxx,1.2,1.3 root_gui_manager.cxx,1.1,1.2 root_gui_manager.hxx,1.1,1.2
- Index(es):