Panda3D
 All Classes Functions Variables Enumerations
mouseButton.cxx
00001 // Filename: mouseButton.cxx
00002 // Created by:  drose (01Mar00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "mouseButton.h"
00016 #include "buttonRegistry.h"
00017 #include "pnotify.h"
00018 
00019 #include <stdio.h>
00020 
00021 ButtonHandle MouseButton::_buttons[num_mouse_buttons];
00022 ButtonHandle MouseButton::_wheel_up;
00023 ButtonHandle MouseButton::_wheel_down;
00024 ButtonHandle MouseButton::_wheel_left;
00025 ButtonHandle MouseButton::_wheel_right;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: MouseButton::button
00029 //       Access: Public, Static
00030 //  Description: Returns the ButtonHandle associated with the
00031 //               particular numbered mouse button (zero-based), if
00032 //               there is one, or ButtonHandle::none() if there is
00033 //               not.
00034 ////////////////////////////////////////////////////////////////////
00035 ButtonHandle MouseButton::
00036 button(int button_number) {
00037   if (button_number >= 0 && button_number < num_mouse_buttons) {
00038     return _buttons[button_number];
00039   }
00040   return ButtonHandle::none();
00041 }
00042 
00043 ////////////////////////////////////////////////////////////////////
00044 //     Function: MouseButton::one
00045 //       Access: Public, Static
00046 //  Description: Returns the ButtonHandle associated with the
00047 //               first mouse button.
00048 ////////////////////////////////////////////////////////////////////
00049 ButtonHandle MouseButton::
00050 one() {
00051   return _buttons[0];
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: MouseButton::two
00056 //       Access: Public, Static
00057 //  Description: Returns the ButtonHandle associated with the
00058 //               second mouse button.
00059 ////////////////////////////////////////////////////////////////////
00060 ButtonHandle MouseButton::
00061 two() {
00062   return _buttons[1];
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: MouseButton::three
00067 //       Access: Public, Static
00068 //  Description: Returns the ButtonHandle associated with the
00069 //               third mouse button.
00070 ////////////////////////////////////////////////////////////////////
00071 ButtonHandle MouseButton::
00072 three() {
00073   return _buttons[2];
00074 }
00075 
00076 ////////////////////////////////////////////////////////////////////
00077 //     Function: MouseButton::four
00078 //       Access: Public, Static
00079 //  Description: Returns the ButtonHandle associated with the
00080 //               fourth mouse button.
00081 ////////////////////////////////////////////////////////////////////
00082 ButtonHandle MouseButton::
00083 four() {
00084   return _buttons[3];
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: MouseButton::five
00089 //       Access: Public, Static
00090 //  Description: Returns the ButtonHandle associated with the
00091 //               fifth mouse button.
00092 ////////////////////////////////////////////////////////////////////
00093 ButtonHandle MouseButton::
00094 five() {
00095   return _buttons[4];
00096 }
00097 
00098 ////////////////////////////////////////////////////////////////////
00099 //     Function: MouseButton::wheel_up
00100 //       Access: Public, Static
00101 //  Description: Returns the ButtonHandle generated when the mouse
00102 //               wheel is rolled one notch upwards.
00103 ////////////////////////////////////////////////////////////////////
00104 ButtonHandle MouseButton::
00105 wheel_up() {
00106   return _wheel_up;
00107 }
00108 
00109 ////////////////////////////////////////////////////////////////////
00110 //     Function: MouseButton::wheel_down
00111 //       Access: Public, Static
00112 //  Description: Returns the ButtonHandle generated when the mouse
00113 //               wheel is rolled one notch downwards.
00114 ////////////////////////////////////////////////////////////////////
00115 ButtonHandle MouseButton::
00116 wheel_down() {
00117   return _wheel_down;
00118 }
00119 
00120 ////////////////////////////////////////////////////////////////////
00121 //     Function: MouseButton::wheel_left
00122 //       Access: Public, Static
00123 //  Description: Returns the ButtonHandle generated when the mouse
00124 //               is scrolled to the left. Usually, you'll only
00125 //               find the horizontal scroll on laptops.
00126 ////////////////////////////////////////////////////////////////////
00127 ButtonHandle MouseButton::
00128 wheel_left() {
00129   return _wheel_left;
00130 }
00131 
00132 ////////////////////////////////////////////////////////////////////
00133 //     Function: MouseButton::wheel_right
00134 //       Access: Public, Static
00135 //  Description: Returns the ButtonHandle generated when the mouse
00136 //               is scrolled to the right. Usually, you'll only
00137 //               find the horizontal scroll on laptops.
00138 ////////////////////////////////////////////////////////////////////
00139 ButtonHandle MouseButton::
00140 wheel_right() {
00141   return _wheel_right;
00142 }
00143 
00144 ////////////////////////////////////////////////////////////////////
00145 //     Function: MouseButton::is_mouse_button
00146 //       Access: Public, Static
00147 //  Description: Returns true if the indicated ButtonHandle is a mouse
00148 //               button, false if it is some other kind of button.
00149 ////////////////////////////////////////////////////////////////////
00150 bool MouseButton::
00151 is_mouse_button(ButtonHandle button) {
00152   for (int i = 0; i < num_mouse_buttons; ++i) {
00153     if (button == _buttons[i]) {
00154       return true;
00155     }
00156   }
00157 
00158   return button == _wheel_up || button == _wheel_down || button == _wheel_left || button == _wheel_right;
00159 }
00160 
00161 ////////////////////////////////////////////////////////////////////
00162 //     Function: MouseButton::init_mouse_buttons
00163 //       Access: Public, Static
00164 //  Description: This is intended to be called only once, by the
00165 //               static initialization performed in config_util.cxx.
00166 ////////////////////////////////////////////////////////////////////
00167 void MouseButton::
00168 init_mouse_buttons() {
00169   char numstr[20];
00170 
00171   for (int i = 0; i < num_mouse_buttons; ++i) {
00172     sprintf(numstr, "mouse%d", i + 1);
00173     nassertv(strlen(numstr) < 20);
00174 
00175     ButtonRegistry::ptr()->register_button(_buttons[i], numstr);
00176   }
00177 
00178   ButtonRegistry::ptr()->register_button(_wheel_up, "wheel_up");
00179   ButtonRegistry::ptr()->register_button(_wheel_down, "wheel_down");
00180   ButtonRegistry::ptr()->register_button(_wheel_left, "wheel_left");
00181   ButtonRegistry::ptr()->register_button(_wheel_right, "wheel_right");
00182 }
 All Classes Functions Variables Enumerations