Panda3D
 All Classes Functions Variables Enumerations
mouseButton.cxx
1 // Filename: mouseButton.cxx
2 // Created by: drose (01Mar00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "mouseButton.h"
16 #include "buttonRegistry.h"
17 #include "pnotify.h"
18 
19 #include <stdio.h>
20 
21 ButtonHandle MouseButton::_buttons[num_mouse_buttons];
22 ButtonHandle MouseButton::_wheel_up;
23 ButtonHandle MouseButton::_wheel_down;
24 ButtonHandle MouseButton::_wheel_left;
25 ButtonHandle MouseButton::_wheel_right;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: MouseButton::button
29 // Access: Public, Static
30 // Description: Returns the ButtonHandle associated with the
31 // particular numbered mouse button (zero-based), if
32 // there is one, or ButtonHandle::none() if there is
33 // not.
34 ////////////////////////////////////////////////////////////////////
36 button(int button_number) {
37  if (button_number >= 0 && button_number < num_mouse_buttons) {
38  return _buttons[button_number];
39  }
40  return ButtonHandle::none();
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: MouseButton::one
45 // Access: Public, Static
46 // Description: Returns the ButtonHandle associated with the
47 // first mouse button.
48 ////////////////////////////////////////////////////////////////////
50 one() {
51  return _buttons[0];
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: MouseButton::two
56 // Access: Public, Static
57 // Description: Returns the ButtonHandle associated with the
58 // second mouse button.
59 ////////////////////////////////////////////////////////////////////
61 two() {
62  return _buttons[1];
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: MouseButton::three
67 // Access: Public, Static
68 // Description: Returns the ButtonHandle associated with the
69 // third mouse button.
70 ////////////////////////////////////////////////////////////////////
72 three() {
73  return _buttons[2];
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: MouseButton::four
78 // Access: Public, Static
79 // Description: Returns the ButtonHandle associated with the
80 // fourth mouse button.
81 ////////////////////////////////////////////////////////////////////
83 four() {
84  return _buttons[3];
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: MouseButton::five
89 // Access: Public, Static
90 // Description: Returns the ButtonHandle associated with the
91 // fifth mouse button.
92 ////////////////////////////////////////////////////////////////////
94 five() {
95  return _buttons[4];
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: MouseButton::wheel_up
100 // Access: Public, Static
101 // Description: Returns the ButtonHandle generated when the mouse
102 // wheel is rolled one notch upwards.
103 ////////////////////////////////////////////////////////////////////
106  return _wheel_up;
107 }
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function: MouseButton::wheel_down
111 // Access: Public, Static
112 // Description: Returns the ButtonHandle generated when the mouse
113 // wheel is rolled one notch downwards.
114 ////////////////////////////////////////////////////////////////////
117  return _wheel_down;
118 }
119 
120 ////////////////////////////////////////////////////////////////////
121 // Function: MouseButton::wheel_left
122 // Access: Public, Static
123 // Description: Returns the ButtonHandle generated when the mouse
124 // is scrolled to the left. Usually, you'll only
125 // find the horizontal scroll on laptops.
126 ////////////////////////////////////////////////////////////////////
129  return _wheel_left;
130 }
131 
132 ////////////////////////////////////////////////////////////////////
133 // Function: MouseButton::wheel_right
134 // Access: Public, Static
135 // Description: Returns the ButtonHandle generated when the mouse
136 // is scrolled to the right. Usually, you'll only
137 // find the horizontal scroll on laptops.
138 ////////////////////////////////////////////////////////////////////
141  return _wheel_right;
142 }
143 
144 ////////////////////////////////////////////////////////////////////
145 // Function: MouseButton::is_mouse_button
146 // Access: Public, Static
147 // Description: Returns true if the indicated ButtonHandle is a mouse
148 // button, false if it is some other kind of button.
149 ////////////////////////////////////////////////////////////////////
150 bool MouseButton::
152  for (int i = 0; i < num_mouse_buttons; ++i) {
153  if (button == _buttons[i]) {
154  return true;
155  }
156  }
157 
158  return button == _wheel_up || button == _wheel_down || button == _wheel_left || button == _wheel_right;
159 }
160 
161 ////////////////////////////////////////////////////////////////////
162 // Function: MouseButton::init_mouse_buttons
163 // Access: Public, Static
164 // Description: This is intended to be called only once, by the
165 // static initialization performed in config_util.cxx.
166 ////////////////////////////////////////////////////////////////////
167 void MouseButton::
169  char numstr[20];
170 
171  for (int i = 0; i < num_mouse_buttons; ++i) {
172  sprintf(numstr, "mouse%d", i + 1);
173  nassertv(strlen(numstr) < 20);
174 
175  ButtonRegistry::ptr()->register_button(_buttons[i], numstr);
176  }
177 
178  ButtonRegistry::ptr()->register_button(_wheel_up, "wheel_up");
179  ButtonRegistry::ptr()->register_button(_wheel_down, "wheel_down");
180  ButtonRegistry::ptr()->register_button(_wheel_left, "wheel_left");
181  ButtonRegistry::ptr()->register_button(_wheel_right, "wheel_right");
182 }
static ButtonHandle none()
Returns a special zero-valued ButtonHandle that is used to indicate no button.
Definition: buttonHandle.I:205
static ButtonHandle three()
Returns the ButtonHandle associated with the third mouse button.
Definition: mouseButton.cxx:72
static ButtonHandle two()
Returns the ButtonHandle associated with the second mouse button.
Definition: mouseButton.cxx:61
static void init_mouse_buttons()
This is intended to be called only once, by the static initialization performed in config_util...
bool register_button(ButtonHandle &button_handle, const string &name, ButtonHandle alias=ButtonHandle::none(), char ascii_equivalent= '\0')
Registers a new ButtonHandle with the indicated name, and if specified, the indicated ASCII equivalen...
static ButtonHandle one()
Returns the ButtonHandle associated with the first mouse button.
Definition: mouseButton.cxx:50
static ButtonHandle four()
Returns the ButtonHandle associated with the fourth mouse button.
Definition: mouseButton.cxx:83
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
static ButtonRegistry * ptr()
Returns the pointer to the global ButtonRegistry object.
static ButtonHandle button(int button_number)
Returns the ButtonHandle associated with the particular numbered mouse button (zero-based), if there is one, or ButtonHandle::none() if there is not.
Definition: mouseButton.cxx:36
static ButtonHandle wheel_down()
Returns the ButtonHandle generated when the mouse wheel is rolled one notch downwards.
static ButtonHandle wheel_left()
Returns the ButtonHandle generated when the mouse is scrolled to the left.
static ButtonHandle five()
Returns the ButtonHandle associated with the fifth mouse button.
Definition: mouseButton.cxx:94
static ButtonHandle wheel_right()
Returns the ButtonHandle generated when the mouse is scrolled to the right.
static bool is_mouse_button(ButtonHandle button)
Returns true if the indicated ButtonHandle is a mouse button, false if it is some other kind of butto...
static ButtonHandle wheel_up()
Returns the ButtonHandle generated when the mouse wheel is rolled one notch upwards.