1
// $Id: MouseController.cc,v 1.8 2001/07/27 15:00:47 grumbel Exp $
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.
20
#include <ClanLib/display.h>
21
#include "MouseController.hh"
23
/* All this should be rewritten to have a MultiplexButton, a KeyboardButton, etc. */
25
class LeftMouseButton : public ControllerButton
28
LeftMouseButton (Controller* c) : ControllerButton (c) {};
29
bool is_pressed () { return CL_Mouse::left_pressed (); }
32
class MiddleMouseButton : public ControllerButton
35
MiddleMouseButton (Controller* c) : ControllerButton (c) {};
36
bool is_pressed () { return CL_Mouse::middle_pressed (); }
39
class RightMouseButton : public ControllerButton
42
RightMouseButton (Controller* c) : ControllerButton (c) {};
43
bool is_pressed () { return CL_Mouse::right_pressed (); }
46
class AbortMouseButton : public ControllerButton
49
AbortMouseButton (Controller* c) : ControllerButton (c) {};
50
bool is_pressed () { return CL_Keyboard::get_keycode (CL_KEY_ESCAPE); }
53
class PauseMouseButton : public ControllerButton
56
PauseMouseButton (Controller* c) : ControllerButton (c) {};
58
return (CL_Keyboard::get_keycode (CL_KEY_P) || CL_Keyboard::get_keycode (CL_KEY_PAUSE));
62
class FastForwardMouseButton : public ControllerButton
65
FastForwardMouseButton (Controller* c) : ControllerButton (c) {};
67
return (CL_Keyboard::get_keycode (CL_KEY_SPACE) || CL_Keyboard::get_keycode (CL_KEY_F));
71
class ScrollLeftButton : public ControllerButton
74
ScrollLeftButton (Controller* c) : ControllerButton (c) {};
75
bool is_pressed () { return (CL_Keyboard::get_keycode (CL_KEY_LEFT)); }
78
class ScrollRightButton : public ControllerButton
81
ScrollRightButton (Controller* c) : ControllerButton (c) {};
82
bool is_pressed () { return (CL_Keyboard::get_keycode (CL_KEY_RIGHT)); }
85
class ScrollUpButton : public ControllerButton
88
ScrollUpButton (Controller* c) : ControllerButton (c) {};
89
bool is_pressed () { return (CL_Keyboard::get_keycode (CL_KEY_UP)); }
92
class ScrollDownButton : public ControllerButton
95
ScrollDownButton (Controller* c) : ControllerButton (c) {};
96
bool is_pressed () { return (CL_Keyboard::get_keycode (CL_KEY_DOWN)); }
100
MouseController::MouseController (int arg_owner_id)
101
: Controller (arg_owner_id)
103
left = boost::shared_ptr<ControllerButton> (new LeftMouseButton (this));
104
middle = boost::shared_ptr<ControllerButton> (new MiddleMouseButton (this));
105
right = boost::shared_ptr<ControllerButton> (new RightMouseButton (this));
106
abort = boost::shared_ptr<ControllerButton> (new AbortMouseButton (this));
107
pause = boost::shared_ptr<ControllerButton> (new PauseMouseButton (this));
108
fast_forward = boost::shared_ptr<ControllerButton> (new FastForwardMouseButton (this));
109
scroll_left = boost::shared_ptr<ControllerButton> (new ScrollLeftButton (this));
110
scroll_right = boost::shared_ptr<ControllerButton> (new ScrollRightButton(this));
111
scroll_up = boost::shared_ptr<ControllerButton> (new ScrollUpButton (this));
112
scroll_down = boost::shared_ptr<ControllerButton> (new ScrollDownButton(this));
115
MouseController::~MouseController ()
120
MouseController::get_x ()
126
MouseController::get_y ()
132
MouseController::get_pos ()
138
MouseController::keep_alive ()
140
pos.x = CL_Mouse::get_x ();
141
pos.y = CL_Mouse::get_y ();
143
if (pos.x <= rect.x1)
145
if (pos.y <= rect.y1)
148
if (pos.x >= rect.x2)
150
if (pos.y >= rect.y2)
153
Controller::keep_alive ();