Panda3D

mouseButton.cxx
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file mouseButton.cxx
10 * @author drose
11 * @date 2000-03-01
12 */
13
14 #include "mouseButton.h"
15 #include "buttonRegistry.h"
16 #include "pnotify.h"
17
18 #include <stdio.h>
19
20 ButtonHandle MouseButton::_buttons[num_mouse_buttons];
21 ButtonHandle MouseButton::_wheel_up;
22 ButtonHandle MouseButton::_wheel_down;
23 ButtonHandle MouseButton::_wheel_left;
24 ButtonHandle MouseButton::_wheel_right;
25
26 /**
27 * Returns the ButtonHandle associated with the particular numbered mouse
28 * button (zero-based), if there is one, or ButtonHandle::none() if there is
29 * not.
30 */
31 ButtonHandle MouseButton::
32 button(int button_number) {
33 if (button_number >= 0 && button_number < num_mouse_buttons) {
34 return _buttons[button_number];
35 }
36 return ButtonHandle::none();
37 }
38
39 /**
40 * Returns the ButtonHandle associated with the first mouse button.
41 */
42 ButtonHandle MouseButton::
43 one() {
44 return _buttons[0];
45 }
46
47 /**
48 * Returns the ButtonHandle associated with the second mouse button.
49 */
50 ButtonHandle MouseButton::
51 two() {
52 return _buttons[1];
53 }
54
55 /**
56 * Returns the ButtonHandle associated with the third mouse button.
57 */
58 ButtonHandle MouseButton::
59 three() {
60 return _buttons[2];
61 }
62
63 /**
64 * Returns the ButtonHandle associated with the fourth mouse button.
65 */
66 ButtonHandle MouseButton::
67 four() {
68 return _buttons[3];
69 }
70
71 /**
72 * Returns the ButtonHandle associated with the fifth mouse button.
73 */
74 ButtonHandle MouseButton::
75 five() {
76 return _buttons[4];
77 }
78
79 /**
80 * Returns the ButtonHandle generated when the mouse wheel is rolled one notch
81 * upwards.
82 */
83 ButtonHandle MouseButton::
84 wheel_up() {
85 return _wheel_up;
86 }
87
88 /**
89 * Returns the ButtonHandle generated when the mouse wheel is rolled one notch
90 * downwards.
91 */
92 ButtonHandle MouseButton::
93 wheel_down() {
94 return _wheel_down;
95 }
96
97 /**
98 * Returns the ButtonHandle generated when the mouse is scrolled to the left.
99 * Usually, you'll only find the horizontal scroll on laptops.
100 */
101 ButtonHandle MouseButton::
102 wheel_left() {
103 return _wheel_left;
104 }
105
106 /**
107 * Returns the ButtonHandle generated when the mouse is scrolled to the right.
108 * Usually, you'll only find the horizontal scroll on laptops.
109 */
110 ButtonHandle MouseButton::
111 wheel_right() {
112 return _wheel_right;
113 }
114
115 /**
116 * Returns true if the indicated ButtonHandle is a mouse button, false if it
117 * is some other kind of button.
118 */
119 bool MouseButton::
120 is_mouse_button(ButtonHandle button) {
121 for (int i = 0; i < num_mouse_buttons; ++i) {
122 if (button == _buttons[i]) {
123 return true;
124 }
125 }
126
127 return button == _wheel_up || button == _wheel_down || button == _wheel_left || button == _wheel_right;
128 }
129
130 /**
131 * This is intended to be called only once, by the static initialization
132 * performed in config_putil.cxx.
133 */
134 void MouseButton::
135 init_mouse_buttons() {
136 char numstr[20];
137
138 for (int i = 0; i < num_mouse_buttons; ++i) {
139 sprintf(numstr, "mouse%d", i + 1);
140 nassertv(strlen(numstr) < 20);
141
142 ButtonRegistry::ptr()->register_button(_buttons[i], numstr);
143 }
144
145 ButtonRegistry::ptr()->register_button(_wheel_up, "wheel_up");
146 ButtonRegistry::ptr()->register_button(_wheel_down, "wheel_down");
147 ButtonRegistry::ptr()->register_button(_wheel_left, "wheel_left");
148 ButtonRegistry::ptr()->register_button(_wheel_right, "wheel_right");
149 }
buttonRegistry.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ButtonHandle
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:26
ButtonRegistry::register_button
bool register_button(ButtonHandle &button_handle, const std::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...
Definition: buttonRegistry.cxx:44
ButtonRegistry::ptr
static ButtonRegistry * ptr()
Returns the pointer to the global ButtonRegistry object.
Definition: buttonRegistry.I:29
MouseButton::is_mouse_button
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...
Definition: mouseButton.cxx:120
MouseButton::button
static ButtonHandle button(int button_number)
Returns the ButtonHandle associated with the particular numbered mouse button (zero-based),...
Definition: mouseButton.cxx:32
MouseButton::four
static ButtonHandle four()
Returns the ButtonHandle associated with the fourth mouse button.
Definition: mouseButton.cxx:67
MouseButton::wheel_left
static ButtonHandle wheel_left()
Returns the ButtonHandle generated when the mouse is scrolled to the left.
Definition: mouseButton.cxx:102
MouseButton::wheel_up
static ButtonHandle wheel_up()
Returns the ButtonHandle generated when the mouse wheel is rolled one notch upwards.
Definition: mouseButton.cxx:84
MouseButton::one
static ButtonHandle one()
Returns the ButtonHandle associated with the first mouse button.
Definition: mouseButton.cxx:43
MouseButton::five
static ButtonHandle five()
Returns the ButtonHandle associated with the fifth mouse button.
Definition: mouseButton.cxx:75
MouseButton::two
static ButtonHandle two()
Returns the ButtonHandle associated with the second mouse button.
Definition: mouseButton.cxx:51
MouseButton::wheel_right
static ButtonHandle wheel_right()
Returns the ButtonHandle generated when the mouse is scrolled to the right.
Definition: mouseButton.cxx:111
MouseButton::init_mouse_buttons
static void init_mouse_buttons()
This is intended to be called only once, by the static initialization performed in config_putil....
Definition: mouseButton.cxx:135
MouseButton::wheel_down
static ButtonHandle wheel_down()
Returns the ButtonHandle generated when the mouse wheel is rolled one notch downwards.
Definition: mouseButton.cxx:93
MouseButton::three
static ButtonHandle three()
Returns the ButtonHandle associated with the third mouse button.
Definition: mouseButton.cxx:59
mouseButton.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pnotify.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.