[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/gui gui_manager.cxx,1.10,1.11 gui_man
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/gui gui_manager.cxx,1.10,1.11 gui_manager.hxx,1.7,1.8 |
Date: |
17 Aug 2002 01:02:40 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/gui
In directory dark:/tmp/cvs-serv9540
Modified Files:
gui_manager.cxx gui_manager.hxx
Log Message:
- some cleanup, splitted event handling
Index: gui_manager.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/gui/gui_manager.cxx,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- gui_manager.cxx 15 Aug 2002 10:57:39 -0000 1.10
+++ gui_manager.cxx 17 Aug 2002 01:02:38 -0000 1.11
@@ -20,6 +20,8 @@
#include <iostream>
#include <vector>
#include <list>
+#include "../debug.hxx"
+#include "../globals.hxx"
#include "../input/event.hxx"
#include "../input/axis_event.hxx"
#include "../input/button_event.hxx"
@@ -71,148 +73,25 @@
case Input::PointerEventType:
{
PointerEvent* event = dynamic_cast<PointerEvent*>(*i);
- x_pos = int(event->x);
- y_pos = int(event->y);
-
- Component* comp = component_at (x_pos, y_pos);//FIXME
-
- if (primary_pressed_component)
- primary_pressed_component->on_pointer_move (x_pos, y_pos);
- else if (comp)
- {
- comp->on_pointer_move (x_pos, y_pos);
- }
-
- 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;
- }
- }
-
+ process_pointer_event (event);
break;
}
case Input::ButtonEventType:
{
ButtonEvent* event = dynamic_cast<ButtonEvent*>(*i);
- //std::cout << "GUIManager: 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)
- {
- primary_pressed_component = comp;
- comp->on_primary_button_press (x_pos, y_pos);
- }
- else if (event->name == primary && event->state ==
Input::released)
- {
- /** Send the release event to the same component
- which got the press event */
- if (primary_pressed_component)
- {
- primary_pressed_component->on_primary_button_release
(x_pos, y_pos);
-
- if (primary_pressed_component == comp)
- {
- //std::cout << "GUIManager: calling
on_primary_button_click ()" << std::endl;
- comp->on_primary_button_click (x_pos, y_pos);
- }
- else
- {
- // discard click
- }
- primary_pressed_component = 0;
- }
- else
- {
- /* FIXME: This happens when you press a button
- FIXME: in one GUIManager and switch in the
- FIXME: on_primary_button_press() method to another
- FIXME: manager, not sure if there is or
- FIXME: should be a workaround */
- std::cout << "GUIManager: Got a release without a
press, possibly a bug" << std::endl;
- }
- }
-
- // Secondary button
- if (event->name == secondary && event->state == Input::pressed)
- {
- secondary_pressed_component = comp;
- comp->on_secondary_button_press (x_pos, y_pos);
- }
- else if (event->name == secondary && event->state ==
Input::released)
- {
- /** Send the release event to the same component
- which got the press event */
- if (secondary_pressed_component)
- {
-
secondary_pressed_component->on_secondary_button_release (x_pos, y_pos);
-
- if (secondary_pressed_component == comp)
- {
- //std::cout << "GUIManager: calling
on_secondary_button_click ()" << std::endl;
- comp->on_secondary_button_click (x_pos, y_pos);
- }
- else
- {
- // discard click
- }
- secondary_pressed_component = 0;
- }
- else
- {
- /* FIXME: This happens when you press a button
- FIXME: in one GUIManager and switch in the
- FIXME: on_secondary_button_press() method to another
- FIXME: manager, not sure if there is or
- FIXME: should be a workaround */
- std::cout << "GUIManager: Got a release without a
press, possibly a bug" << std::endl;
- }
- }
-
- }
- else
- {
- std::cout << "GUIManager: Clicked into a non managed region" <<
std::endl;
- unhandled_event ();
-
- if (secondary_pressed_component)
- {
- secondary_pressed_component->on_secondary_button_release
(x_pos, y_pos);
- secondary_pressed_component = 0;
- }
- }
+ process_button_event (event);
break;
}
case Input::AxisEventType:
- {
+ { // AxisEvents can be ignored in the GUI, they are handled elsewhere
AxisEvent* event = dynamic_cast<AxisEvent*>(*i);
- std::cout << "GUIManager: AxisEvent: " << event->dir << std::endl;
+ pout (PINGUS_DEBUG_GUI) << "GUIManager: AxisEvent: " << event->dir
<< std::endl;
break;
}
default:
- std::cout << "GUIManager: unhandled event type " << (*i)->get_type()
<< std::endl;
+ pwarn (PINGUS_DEBUG_GUI) << "GUIManager: unhandled event type " <<
(*i)->get_type() << std::endl;
break;
}
}
@@ -260,9 +139,136 @@
}
void
-GUIManager::unhandled_event ()
+GUIManager::process_pointer_event (Input::PointerEvent* event)
{
- std::cout << "GUIManager::unhandled_event ()" << std::endl;
+ x_pos = int(event->x);
+ y_pos = int(event->y);
+
+ Component* comp = component_at (x_pos, y_pos);//FIXME
+
+ if (primary_pressed_component)
+ primary_pressed_component->on_pointer_move (x_pos, y_pos);
+ else if (comp)
+ {
+ comp->on_pointer_move (x_pos, y_pos);
+ }
+
+ 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;
+ }
+ }
+
+}
+
+void
+GUIManager::process_button_event (Input::ButtonEvent* event)
+{
+ //std::cout << "GUIManager: 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)
+ {
+ primary_pressed_component = comp;
+ comp->on_primary_button_press (x_pos, y_pos);
+ }
+ else if (event->name == primary && event->state == Input::released)
+ {
+ /** Send the release event to the same component
+ which got the press event */
+ if (primary_pressed_component)
+ {
+ primary_pressed_component->on_primary_button_release (x_pos,
y_pos);
+
+ if (primary_pressed_component == comp)
+ {
+ //std::cout << "GUIManager: calling on_primary_button_click
()" << std::endl;
+ comp->on_primary_button_click (x_pos, y_pos);
+ }
+ else
+ {
+ // discard click
+ }
+ primary_pressed_component = 0;
+ }
+ else
+ {
+ /* FIXME: This happens when you press a button
+ FIXME: in one GUIManager and switch in the
+ FIXME: on_primary_button_press() method to another
+ FIXME: manager, not sure if there is or
+ FIXME: should be a workaround */
+ std::cout << "GUIManager: Got a release without a press, possibly
a bug" << std::endl;
+ }
+ }
+
+ // Secondary button
+ if (event->name == secondary && event->state == Input::pressed)
+ {
+ secondary_pressed_component = comp;
+ comp->on_secondary_button_press (x_pos, y_pos);
+ }
+ else if (event->name == secondary && event->state == Input::released)
+ {
+ /** Send the release event to the same component
+ which got the press event */
+ if (secondary_pressed_component)
+ {
+ secondary_pressed_component->on_secondary_button_release (x_pos,
y_pos);
+
+ if (secondary_pressed_component == comp)
+ {
+ //std::cout << "GUIManager: calling on_secondary_button_click
()" << std::endl;
+ comp->on_secondary_button_click (x_pos, y_pos);
+ }
+ else
+ {
+ // discard click
+ }
+ secondary_pressed_component = 0;
+ }
+ else
+ {
+ /* FIXME: This happens when you press a button
+ FIXME: in one GUIManager and switch in the
+ FIXME: on_secondary_button_press() method to another
+ FIXME: manager, not sure if there is or
+ FIXME: should be a workaround */
+ std::cout << "GUIManager: Got a release without a press, possibly
a bug" << std::endl;
+ }
+ }
+
+ }
+ else
+ {
+ if (secondary_pressed_component)
+ {
+ secondary_pressed_component->on_secondary_button_release (x_pos,
y_pos);
+ secondary_pressed_component = 0;
+ }
+ }
+
}
/* EOF */
Index: gui_manager.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/gui/gui_manager.hxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- gui_manager.hxx 14 Aug 2002 12:45:02 -0000 1.7
+++ gui_manager.hxx 17 Aug 2002 01:02:38 -0000 1.8
@@ -29,6 +29,8 @@
namespace Input
{
class Event;
+ class PointerEvent;
+ class ButtonEvent;
}
namespace GUI
@@ -60,16 +62,15 @@
int y_pos;
void process_input (const std::list<Input::Event*>& events);
+ void process_pointer_event (Input::PointerEvent* event);
+ void process_button_event (Input::ButtonEvent* event);
public:
GUIManager ();
virtual ~GUIManager () {}
virtual void draw ();
virtual void update (const GameDelta& delta);
- virtual void update (float delta) { if(delta); }
-
- /** Called once an unhandled event is recieved */
- virtual void unhandled_event ();
+ virtual void update (float delta) { UNUSED_ARG (delta); }
/** Add a component to the manager, if delete_component is true
the component will get deleted on destruction of the manager,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/gui gui_manager.cxx,1.10,1.11 gui_manager.hxx,1.7,1.8,
grumbel <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src story.cxx,1.4,1.5 story.hxx,1.4,1.5
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src gui_screen.cxx,1.5,1.6 gui_screen.hxx,1.5,1.6 client.cxx,1.16,1.17 client.hxx,1.11,1.12
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src story.cxx,1.4,1.5 story.hxx,1.4,1.5
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src gui_screen.cxx,1.5,1.6 gui_screen.hxx,1.5,1.6 client.cxx,1.16,1.17 client.hxx,1.11,1.12
- Index(es):