[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3142 - in trunk/pingus/src: editor gui
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r3142 - in trunk/pingus/src: editor gui |
Date: |
Fri, 14 Sep 2007 17:39:33 +0200 |
Author: grumbel
Date: 2007-09-14 17:39:32 +0200 (Fri, 14 Sep 2007)
New Revision: 3142
Modified:
trunk/pingus/src/editor/context_menu.cpp
trunk/pingus/src/editor/editor_screen.cpp
trunk/pingus/src/editor/editor_viewport.cpp
trunk/pingus/src/editor/editor_viewport.hpp
trunk/pingus/src/gui/group_component.cpp
trunk/pingus/src/gui/group_component.hpp
trunk/pingus/src/gui/gui_manager.cpp
trunk/pingus/src/gui/gui_manager.hpp
Log:
- turned GUIManager into a GroupComponent, thus removing a bunch of duplicate
code (might cause bugs)
Modified: trunk/pingus/src/editor/context_menu.cpp
===================================================================
--- trunk/pingus/src/editor/context_menu.cpp 2007-09-14 15:14:07 UTC (rev
3141)
+++ trunk/pingus/src/editor/context_menu.cpp 2007-09-14 15:39:32 UTC (rev
3142)
@@ -135,7 +135,7 @@
break;
}
}
- viewport->remove_context_menu();
+ // FIXME: should be handled differently: viewport->remove_context_menu();
}
}
Modified: trunk/pingus/src/editor/editor_screen.cpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.cpp 2007-09-14 15:14:07 UTC (rev
3141)
+++ trunk/pingus/src/editor/editor_screen.cpp 2007-09-14 15:39:32 UTC (rev
3142)
@@ -56,8 +56,7 @@
show_help(false)
{
// Create the viewport for the images and data
- viewport = new EditorViewport(this, Rect(0,
- 38,
+ viewport = new EditorViewport(this, Rect(0, 38,
Display::get_width() - 244,
Display::get_height()));
gui_manager->add(viewport, true);
Modified: trunk/pingus/src/editor/editor_viewport.cpp
===================================================================
--- trunk/pingus/src/editor/editor_viewport.cpp 2007-09-14 15:14:07 UTC (rev
3141)
+++ trunk/pingus/src/editor/editor_viewport.cpp 2007-09-14 15:39:32 UTC (rev
3142)
@@ -29,7 +29,6 @@
#include "editor_level.hpp"
#include "editor_screen.hpp"
#include "editor_viewport.hpp"
-#include "context_menu.hpp"
#include "level_objs.hpp"
namespace Editor {
@@ -42,7 +41,6 @@
editor(e),
autoscroll(false),
highlighted_area(0,0,0,0),
- context_menu(0),
snap_to(false),
current_action(NOTHING)
{
@@ -83,23 +81,6 @@
{
mouse_world_pos = screen2world(x_, y_);
mouse_screen_pos = Vector2i(x_, y_);
-
- if (0) // old context menu code
- {
- remove_context_menu();
-
- //Vector3f mouse_pos(x - (state.get_width()/2 - state.get_pos().x),
- // y - (state.get_height()/2 - state.get_pos().y));
-
- // LevelObj* obj = object_at((int)mouse_pos.x, (int)mouse_pos.y);
- if (!selected_objs.empty())
- {
- // std::vector<LevelObj*> objs;
- // objs.push_back(obj);
- context_menu = new ContextMenu(selected_objs, Vector2i(x_, y_),
this);
- editor->get_gui_manager()->add(context_menu, true);
- }
- }
}
// Select 1 or more LevelObjs, or drag them.
@@ -109,8 +90,6 @@
mouse_world_pos = screen2world(x_, y_);
mouse_screen_pos = Vector2i(x_, y_);
- remove_context_menu();
-
if (current_action == NOTHING)
{
LevelObj* obj = object_at(mouse_world_pos.x, mouse_world_pos.y);
@@ -306,19 +285,7 @@
return 0;
}
-// Delete the context menu if it exists.
void
-EditorViewport::remove_context_menu()
-{
- if (context_menu)
- {
- editor->get_gui_manager()->remove(context_menu);
- context_menu->display(false);
- context_menu = 0;
- }
-}
-
-void
EditorViewport::refresh()
{
objs = editor->get_level()->get_objects();
Modified: trunk/pingus/src/editor/editor_viewport.hpp
===================================================================
--- trunk/pingus/src/editor/editor_viewport.hpp 2007-09-14 15:14:07 UTC (rev
3141)
+++ trunk/pingus/src/editor/editor_viewport.hpp 2007-09-14 15:39:32 UTC (rev
3142)
@@ -103,9 +103,6 @@
coordinates */
void on_pointer_move (int x, int y);
- /** Get rid of context menu if it exists */
- void remove_context_menu();
-
/** Refresh the list of objects (do when loading or creating a new level) */
void refresh();
Modified: trunk/pingus/src/gui/group_component.cpp
===================================================================
--- trunk/pingus/src/gui/group_component.cpp 2007-09-14 15:14:07 UTC (rev
3141)
+++ trunk/pingus/src/gui/group_component.cpp 2007-09-14 15:39:32 UTC (rev
3142)
@@ -197,7 +197,7 @@
Component*
GroupComponent::component_at (const Vector2i& pos)
{
- for(Components::iterator i = children.begin(); i != children.end(); ++i)
+ for(Components::reverse_iterator i = children.rbegin(); i !=
children.rend(); ++i)
{
if ((*i)->is_visible() && (*i)->is_at(pos.x, pos.y))
return *i;
Modified: trunk/pingus/src/gui/group_component.hpp
===================================================================
--- trunk/pingus/src/gui/group_component.hpp 2007-09-14 15:14:07 UTC (rev
3141)
+++ trunk/pingus/src/gui/group_component.hpp 2007-09-14 15:39:32 UTC (rev
3142)
@@ -52,7 +52,7 @@
public:
GroupComponent(const Rect& rect, bool clip = true);
- ~GroupComponent();
+ virtual ~GroupComponent();
void draw(DrawingContext& gc);
virtual void draw_background(DrawingContext& gc) {}
Modified: trunk/pingus/src/gui/gui_manager.cpp
===================================================================
--- trunk/pingus/src/gui/gui_manager.cpp 2007-09-14 15:14:07 UTC (rev
3141)
+++ trunk/pingus/src/gui/gui_manager.cpp 2007-09-14 15:39:32 UTC (rev
3142)
@@ -21,59 +21,39 @@
#include "../debug.hpp"
#include "../globals.hpp"
#include "../input/event.hpp"
+#include "display.hpp"
#include "game_delta.hpp"
#include "gui_manager.hpp"
-
-using namespace GUI;
using namespace Input;
+namespace GUI {
+
GUIManager::GUIManager ()
- : primary_pressed_component (0),
- secondary_pressed_component (0),
- focussed_component(0),
- mouse_over_component (0),
- x_pos (400), y_pos (300)
+ : GroupComponent(Rect(0, 0, Display::get_width(), Display::get_height())),
+ mouse_pos(400,300)
{
}
-
-GUIManager::~GUIManager ()
+
+GUIManager::GUIManager(const Rect& rect)
+ : GroupComponent(rect),
+ mouse_pos(400,300)
{
- for (std::vector<Component*>::iterator i = components_for_delete.begin ();
- i != components_for_delete.end (); ++i)
- {
- delete (*i);
- }
-
- components_for_delete.clear();
}
-
-void
-GUIManager::draw (DrawingContext& gc)
+
+GUIManager::~GUIManager ()
{
- for (std::vector<Component*>::iterator i = components.begin ();
- i != components.end (); ++i)
- {
- if ((*i)->is_visible())
- (*i)->draw (gc);
- }
}
-
+
void
-GUIManager::update (const GameDelta& delta)
+GUIManager::update(const GameDelta& delta)
{
process_input (delta);
-
- for (std::vector<Component*>::iterator i = components.begin ();
- i != components.end (); ++i)
- {
- if ((*i)->is_visible())
- (*i)->update (delta.get_time ());
- }
+ GroupComponent::update(delta.get_time());
}
-
+
void
-GUIManager::process_input (const GameDelta& delta)
+GUIManager::process_input(const GameDelta& delta)
{
const std::vector<Input::Event>& events = delta.get_events();
@@ -82,11 +62,26 @@
switch (i->type)
{
case Input::POINTER_EVENT_TYPE:
- process_pointer_event (i->pointer);
+ mouse_pos.x = int(i->pointer.x);
+ mouse_pos.y = int(i->pointer.y);
+ on_pointer_move(mouse_pos.x, mouse_pos.y);
break;
case Input::BUTTON_EVENT_TYPE:
- process_button_event (delta.get_absolute_time(), i->button);
+ if (i->button.name == PRIMARY_BUTTON)
+ {
+ if (i->button.state == Input::BUTTON_PRESSED)
+ on_primary_button_press(mouse_pos.x, mouse_pos.y);
+ else if (i->button.state == Input::BUTTON_RELEASED)
+ on_primary_button_release(mouse_pos.x, mouse_pos.y);
+ }
+ else if (i->button.name == SECONDARY_BUTTON)
+ {
+ if (i->button.state == Input::BUTTON_PRESSED)
+ on_secondary_button_press(mouse_pos.x, mouse_pos.y);
+ else if (i->button.state == Input::BUTTON_RELEASED)
+ on_secondary_button_release(mouse_pos.x, mouse_pos.y);
+ }
break;
case Input::AXIS_EVENT_TYPE:
@@ -95,7 +90,7 @@
break;
case Input::KEYBOARD_EVENT_TYPE:
- process_keyboard_event(i->keyboard);
+ on_key_pressed(i->keyboard.key);
break;
default:
@@ -104,209 +99,7 @@
}
}
}
+
+} // namespace GUI
-void
-GUIManager::add(Component* c, bool delete_component)
-{
- components.push_back(c);
- if( delete_component )
- components_for_delete.push_back(c);
-}
-
-void
-GUIManager::remove(Component* c)
-{
- Components::iterator i = std::find(components.begin(), components.end(), c);
- if (i != components.end())
- components.erase(i);
-}
-
-Component*
-GUIManager::component_at(int x, int y)
-{
- // we travel reversly through the component list, so that we get the
- // top most component at first
- for (std::vector<Component*>::reverse_iterator i = components.rbegin ();
- i != components.rend (); ++i)
- {
- if ((*i)->is_visible() && (*i)->is_at (x, y))
- return *i;
- }
- return 0;
-}
-
-bool
-GUIManager::is_at (int x, int y)
-{
- for (std::vector<Component*>::iterator i = components.begin ();
- i != components.end (); ++i)
- {
- if ((*i)->is_visible() && (*i)->is_at (x, y))
- return true;
- }
-
- return false;
-}
-
-void
-GUIManager::process_pointer_event (const Input::PointerEvent& event)
-{
- x_pos = static_cast<int>(event.x);
- y_pos = static_cast<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 (unsigned int time_stamp, const
Input::ButtonEvent& event)
-{
- //std::cout << "GUIManager: Got button event: " << event.name << " " <<
event.state << std::endl;
-
- Component* comp = component_at (x_pos, y_pos);//FIXME: x/y_pos should be
inside controller
-
- if (comp)
- {
- if (event.name == PRIMARY_BUTTON && event.state == Input::BUTTON_PRESSED)
- {
- primary_pressed_component = comp;
- change_focussed_comp(comp);
- comp->on_primary_button_press (x_pos, y_pos);
-
- // FIXME: add double click detection here
- }
- else if (event.name == PRIMARY_BUTTON && event.state ==
Input::BUTTON_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 */
- if (maintainer_mode)
- std::cout << "GUIManager: Got a release without a press,
possibly a bug" << std::endl;
- }
- }
-
- // Secondary button
- if (event.name == SECONDARY_BUTTON && event.state ==
Input::BUTTON_PRESSED)
- {
- secondary_pressed_component = comp;
- change_focussed_comp(comp);
- comp->on_secondary_button_press (x_pos, y_pos);
- }
- else if (event.name == SECONDARY_BUTTON && event.state ==
Input::BUTTON_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 */
- if (maintainer_mode)
- 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;
- }
- }
-
- UNUSED_ARG(time_stamp);
-}
-
-void
-GUIManager::process_keyboard_event (const Input::KeyboardEvent &event)
-{
- // Pass key value to last pressed component.
- if (focussed_component)
- focussed_component->on_key_pressed(event.key);
-}
-
-void
-GUIManager::change_focussed_comp(Component* c)
-{
- if (focussed_component)
- focussed_component->set_focus(false);
-
- focussed_component = c;
-
- if (focussed_component)
- focussed_component->set_focus(true);
-}
-
-
/* EOF */
Modified: trunk/pingus/src/gui/gui_manager.hpp
===================================================================
--- trunk/pingus/src/gui/gui_manager.hpp 2007-09-14 15:14:07 UTC (rev
3141)
+++ trunk/pingus/src/gui/gui_manager.hpp 2007-09-14 15:39:32 UTC (rev
3142)
@@ -22,9 +22,8 @@
#include <vector>
#include "../input/event.hpp"
-#include "component.hpp"
+#include "group_component.hpp"
-
class DrawingContext;
class GameDelta;
@@ -39,56 +38,23 @@
which point it is best to split the GameDelta into
on_primary_button_press(), etc.
*/
-class GUIManager : public Component
+class GUIManager : public GroupComponent
{
private:
- typedef std::vector<Component*> Components;
- Components components;
- Components components_for_delete;
+ Vector2i mouse_pos;
- /** The component which recieved the last pressed event */
- Component* primary_pressed_component;
- Component* secondary_pressed_component;
-
- /** Component which currently has the focus (last clicked) */
- Component* focussed_component;
-
- /** The component over which the mouse was in the last update,
- used to detecte enter/leave events */
- Component* mouse_over_component;
-
- // FIXME: Hack: should be handled inside the controller
- int x_pos;
- int y_pos;
-
void process_input (const GameDelta& delta);
void process_pointer_event (const Input::PointerEvent& event);
void process_button_event (unsigned int time_stamp, const
Input::ButtonEvent& event);
void process_keyboard_event (const Input::KeyboardEvent& event);
- /** Change which component has the focus and notify the component */
- void change_focussed_comp(Component* c);
-
public:
- GUIManager ();
+ GUIManager();
+ GUIManager(const Rect&);
virtual ~GUIManager ();
- virtual void draw (DrawingContext& gc);
- virtual void update (const GameDelta& delta);
- virtual void update (float delta) { UNUSED_ARG (delta); }
+ void update(const GameDelta& delta);
- /** Add a component to the manager, if delete_component is true
- the component will get deleted on destruction of the manager,
- if false is supplied the user has to handle the component
- itself */
- void add (Component*, bool delete_component);
-
- /** */
- void remove (Component*);
-
- Component* component_at (int x, int y);
- virtual bool is_at (int x, int y);
-
private:
GUIManager (const GUIManager&);
GUIManager& operator= (const GUIManager&);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3142 - in trunk/pingus/src: editor gui,
grumbel at BerliOS <=