Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/putil/mouseButton.cxx

Go to the documentation of this file.
00001 // Filename: mouseButton.cxx
00002 // Created by:  drose (01Mar00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "mouseButton.h"
00020 #include "buttonRegistry.h"
00021 
00022 #include <stdio.h>
00023 #include <notify.h>
00024 
00025 static const int num_mouse_buttons = 3;
00026 
00027 static ButtonHandle _buttons[num_mouse_buttons];
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: MouseButton::button
00031 //       Access: Public, Static
00032 //  Description: Returns the ButtonHandle associated with the
00033 //               particular numbered mouse button (zero-based), if
00034 //               there is one, or ButtonHandle::none() if there is
00035 //               not.
00036 ////////////////////////////////////////////////////////////////////
00037 ButtonHandle MouseButton::
00038 button(int button_number) {
00039   if (button_number >= 0 && button_number < num_mouse_buttons) {
00040     return _buttons[button_number];
00041   }
00042   return ButtonHandle::none();
00043 }
00044 
00045 ////////////////////////////////////////////////////////////////////
00046 //     Function: MouseButton::one
00047 //       Access: Public, Static
00048 //  Description: Returns the ButtonHandle associated with the
00049 //               first mouse button.
00050 ////////////////////////////////////////////////////////////////////
00051 ButtonHandle MouseButton::
00052 one() {
00053   return _buttons[0];
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: MouseButton::two
00058 //       Access: Public, Static
00059 //  Description: Returns the ButtonHandle associated with the
00060 //               second mouse button.
00061 ////////////////////////////////////////////////////////////////////
00062 ButtonHandle MouseButton::
00063 two() {
00064   return _buttons[1];
00065 }
00066 
00067 ////////////////////////////////////////////////////////////////////
00068 //     Function: MouseButton::three
00069 //       Access: Public, Static
00070 //  Description: Returns the ButtonHandle associated with the
00071 //               third mouse button.
00072 ////////////////////////////////////////////////////////////////////
00073 ButtonHandle MouseButton::
00074 three() {
00075   return _buttons[2];
00076 }
00077 
00078 ////////////////////////////////////////////////////////////////////
00079 //     Function: MouseButton::is_mouse_button
00080 //       Access: Public, Static
00081 //  Description: Returns true if the indicated ButtonHandle is a mouse
00082 //               button, false if it is some other kind of button.
00083 ////////////////////////////////////////////////////////////////////
00084 bool MouseButton::
00085 is_mouse_button(ButtonHandle button) {
00086   for (int i = 0; i < num_mouse_buttons; i++) {
00087     if (button == _buttons[i]) {
00088       return true;
00089     }
00090   }
00091 
00092   return false;
00093 }
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 //     Function: MouseButton::init_mouse_buttons
00097 //       Access: Public, Static
00098 //  Description: This is intended to be called only once, by the
00099 //               static initialization performed in config_util.cxx.
00100 ////////////////////////////////////////////////////////////////////
00101 void MouseButton::
00102 init_mouse_buttons() {
00103   char numstr[20];
00104 
00105   for (int i = 0; i < num_mouse_buttons; i++) {
00106     sprintf(numstr, "mouse%d", i + 1);
00107     nassertv(strlen(numstr) < 20);
00108 
00109     ButtonRegistry::ptr()->register_button(_buttons[i], numstr);
00110   }
00111 }

Generated on Fri May 2 00:43:40 2003 for Panda by doxygen1.3