~ubuntu-branches/ubuntu/precise/pingus/precise

« back to all changes in this revision

Viewing changes to src/MouseController.cc

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Goulais
  • Date: 2004-08-09 10:26:00 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040809102600-lg2q9lfars0q1p42
Tags: 0.6.0-8
Applied patch from Andreas Jochens (Closes: #263992)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//  $Id: MouseController.cc,v 1.8 2001/07/27 15:00:47 grumbel Exp $
2
 
//
3
 
//  Pingus - A free Lemmings clone
4
 
//  Copyright (C) 2000 Ingo Ruhnke <grumbel@gmx.de>
5
 
//
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.
10
 
//
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.
15
 
//
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.
19
 
 
20
 
#include <ClanLib/display.h>
21
 
#include "MouseController.hh"
22
 
 
23
 
/* All this should be rewritten to have a MultiplexButton, a KeyboardButton, etc. */
24
 
 
25
 
class LeftMouseButton : public ControllerButton
26
 
{
27
 
public:
28
 
  LeftMouseButton (Controller* c) : ControllerButton (c) {};
29
 
  bool is_pressed () { return CL_Mouse::left_pressed (); }
30
 
};
31
 
 
32
 
class MiddleMouseButton : public ControllerButton
33
 
{
34
 
public:
35
 
  MiddleMouseButton (Controller* c) : ControllerButton (c) {};
36
 
  bool is_pressed () { return CL_Mouse::middle_pressed (); }
37
 
};
38
 
 
39
 
class RightMouseButton : public ControllerButton
40
 
{
41
 
public:
42
 
  RightMouseButton (Controller* c) : ControllerButton (c) {};
43
 
  bool is_pressed () { return CL_Mouse::right_pressed (); }
44
 
};
45
 
 
46
 
class AbortMouseButton : public ControllerButton
47
 
{
48
 
public:
49
 
  AbortMouseButton (Controller* c) : ControllerButton (c) {};
50
 
  bool is_pressed () { return CL_Keyboard::get_keycode (CL_KEY_ESCAPE); }
51
 
};
52
 
 
53
 
class PauseMouseButton : public ControllerButton
54
 
{
55
 
public:
56
 
  PauseMouseButton (Controller* c) : ControllerButton (c) {};
57
 
  bool is_pressed () { 
58
 
    return (CL_Keyboard::get_keycode (CL_KEY_P) || CL_Keyboard::get_keycode (CL_KEY_PAUSE)); 
59
 
  }
60
 
};
61
 
 
62
 
class FastForwardMouseButton : public ControllerButton
63
 
{
64
 
public:
65
 
  FastForwardMouseButton (Controller* c) : ControllerButton (c) {};
66
 
  bool is_pressed () { 
67
 
    return (CL_Keyboard::get_keycode (CL_KEY_SPACE) || CL_Keyboard::get_keycode (CL_KEY_F)); 
68
 
  }
69
 
};
70
 
 
71
 
class ScrollLeftButton : public ControllerButton
72
 
{
73
 
public:
74
 
  ScrollLeftButton (Controller* c) : ControllerButton (c) {};
75
 
  bool is_pressed () { return (CL_Keyboard::get_keycode (CL_KEY_LEFT)); }
76
 
};
77
 
 
78
 
class ScrollRightButton : public ControllerButton
79
 
{
80
 
public:
81
 
  ScrollRightButton (Controller* c) : ControllerButton (c) {};
82
 
  bool is_pressed () { return (CL_Keyboard::get_keycode (CL_KEY_RIGHT)); }
83
 
};
84
 
 
85
 
class ScrollUpButton : public ControllerButton
86
 
{
87
 
public:
88
 
  ScrollUpButton (Controller* c) : ControllerButton (c) {};
89
 
  bool is_pressed () { return (CL_Keyboard::get_keycode (CL_KEY_UP)); }
90
 
};
91
 
 
92
 
class ScrollDownButton : public ControllerButton
93
 
{
94
 
public:
95
 
  ScrollDownButton (Controller* c) : ControllerButton (c) {};
96
 
  bool is_pressed () { return (CL_Keyboard::get_keycode (CL_KEY_DOWN)); }
97
 
};
98
 
 
99
 
 
100
 
MouseController::MouseController (int arg_owner_id)
101
 
  : Controller (arg_owner_id)
102
 
{
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));
113
 
}
114
 
 
115
 
MouseController::~MouseController ()
116
 
{
117
 
}
118
 
 
119
 
int 
120
 
MouseController::get_x ()
121
 
{
122
 
  return int(pos.x);
123
 
}
124
 
 
125
 
int 
126
 
MouseController::get_y ()
127
 
{
128
 
  return int(pos.y);
129
 
}
130
 
  
131
 
CL_Vector
132
 
MouseController::get_pos ()
133
 
{
134
 
  return pos;
135
 
}
136
 
 
137
 
void 
138
 
MouseController::keep_alive ()
139
 
{
140
 
  pos.x = CL_Mouse::get_x ();
141
 
  pos.y = CL_Mouse::get_y ();
142
 
 
143
 
  if (pos.x <= rect.x1)
144
 
    pos.x = rect.x1;
145
 
  if (pos.y <= rect.y1)
146
 
    pos.y = rect.y1;
147
 
 
148
 
  if (pos.x >= rect.x2)
149
 
    pos.x = rect.x2;
150
 
  if (pos.y >= rect.y2)
151
 
    pos.y = rect.y2;
152
 
 
153
 
  Controller::keep_alive ();
154
 
}
155
 
  
156
 
/* EOF */