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
20ButtonHandle MouseButton::_buttons[num_mouse_buttons];
21ButtonHandle MouseButton::_wheel_up;
22ButtonHandle MouseButton::_wheel_down;
23ButtonHandle MouseButton::_wheel_left;
24ButtonHandle 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 */
32button(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 */
43one() {
44 return _buttons[0];
45}
46
47/**
48 * Returns the ButtonHandle associated with the second mouse button.
49 */
51two() {
52 return _buttons[1];
53}
54
55/**
56 * Returns the ButtonHandle associated with the third mouse button.
57 */
59three() {
60 return _buttons[2];
61}
62
63/**
64 * Returns the ButtonHandle associated with the fourth mouse button.
65 */
67four() {
68 return _buttons[3];
69}
70
71/**
72 * Returns the ButtonHandle associated with the fifth mouse button.
73 */
75five() {
76 return _buttons[4];
77}
78
79/**
80 * Returns the ButtonHandle generated when the mouse wheel is rolled one notch
81 * upwards.
82 */
84wheel_up() {
85 return _wheel_up;
86}
87
88/**
89 * Returns the ButtonHandle generated when the mouse wheel is rolled one notch
90 * downwards.
91 */
93wheel_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 */
102wheel_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 */
111wheel_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 */
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 */
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}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:26
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...
static ButtonRegistry * ptr()
Returns the pointer to the global ButtonRegistry object.
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 button(int button_number)
Returns the ButtonHandle associated with the particular numbered mouse button (zero-based),...
Definition: mouseButton.cxx:32
static ButtonHandle four()
Returns the ButtonHandle associated with the fourth mouse button.
Definition: mouseButton.cxx:67
static ButtonHandle wheel_left()
Returns the ButtonHandle generated when the mouse is scrolled to the left.
static ButtonHandle wheel_up()
Returns the ButtonHandle generated when the mouse wheel is rolled one notch upwards.
Definition: mouseButton.cxx:84
static ButtonHandle one()
Returns the ButtonHandle associated with the first mouse button.
Definition: mouseButton.cxx:43
static ButtonHandle five()
Returns the ButtonHandle associated with the fifth mouse button.
Definition: mouseButton.cxx:75
static ButtonHandle two()
Returns the ButtonHandle associated with the second mouse button.
Definition: mouseButton.cxx:51
static ButtonHandle wheel_right()
Returns the ButtonHandle generated when the mouse is scrolled to the right.
static void init_mouse_buttons()
This is intended to be called only once, by the static initialization performed in config_putil....
static ButtonHandle wheel_down()
Returns the ButtonHandle generated when the mouse wheel is rolled one notch downwards.
Definition: mouseButton.cxx:93
static ButtonHandle three()
Returns the ButtonHandle associated with the third mouse button.
Definition: mouseButton.cxx:59
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.