1
// $Id: gui_manager.cpp 3265 2007-09-30 16:07:08Z grumbel $
3
// Pingus - A free Lemmings clone
4
// Copyright (C) 2000 Ingo Ruhnke <grumbel@gmx.de>
6
// This program is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public License
8
// as published by the Free Software Foundation; either version 2
9
// of the License, or (at your option) any later version.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#include "../debug.hpp"
22
#include "../globals.hpp"
23
#include "../input/event.hpp"
24
#include "display/display.hpp"
25
#include "screen/game_delta.hpp"
26
#include "gui_manager.hpp"
28
using namespace Input;
32
GUIManager::GUIManager ()
33
: GroupComponent(Rect(0, 0, Display::get_width(), Display::get_height()), false),
38
GUIManager::GUIManager(const Rect& rect)
39
: GroupComponent(rect),
44
GUIManager::~GUIManager ()
49
GUIManager::update(const GameDelta& delta)
51
process_input (delta);
52
GroupComponent::update(delta.get_time());
56
GUIManager::process_input(const GameDelta& delta)
58
const std::vector<Input::Event>& events = delta.get_events();
60
for (std::vector<Input::Event>::const_iterator i = events.begin (); i != events.end (); ++i)
64
case Input::POINTER_EVENT_TYPE:
65
mouse_pos.x = int(i->pointer.x);
66
mouse_pos.y = int(i->pointer.y);
67
on_pointer_move(mouse_pos.x, mouse_pos.y);
70
case Input::BUTTON_EVENT_TYPE:
71
if (i->button.name == PRIMARY_BUTTON)
73
if (i->button.state == Input::BUTTON_PRESSED)
74
on_primary_button_press(mouse_pos.x, mouse_pos.y);
75
else if (i->button.state == Input::BUTTON_RELEASED)
76
on_primary_button_release(mouse_pos.x, mouse_pos.y);
78
else if (i->button.name == SECONDARY_BUTTON)
80
if (i->button.state == Input::BUTTON_PRESSED)
81
on_secondary_button_press(mouse_pos.x, mouse_pos.y);
82
else if (i->button.state == Input::BUTTON_RELEASED)
83
on_secondary_button_release(mouse_pos.x, mouse_pos.y);
87
case Input::AXIS_EVENT_TYPE:
88
// AxisEvents can be ignored in the GUI, they are handled elsewhere
89
pout (PINGUS_DEBUG_GUI) << "GUIManager: AxisEvent: " << i->axis.dir << std::endl;
92
case Input::KEYBOARD_EVENT_TYPE:
93
on_key_pressed(i->keyboard.key);
96
case Input::SCROLLER_EVENT_TYPE:
100
pwarn (PINGUS_DEBUG_GUI) << "GUIManager: unhandled event type " << i->type << std::endl;