00001 // Filename: graphicsWindowInputDevice.cxx 00002 // Created by: drose (24May00) 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 00020 #include "graphicsWindowInputDevice.h" 00021 #include "mouseButton.h" 00022 #include "keyboardButton.h" 00023 00024 #define EXPCL EXPCL_PANDA 00025 #define EXPTP EXPTP_PANDA 00026 #define TYPE GraphicsWindowInputDevice 00027 #define NAME vector_GraphicsWindowInputDevice 00028 00029 #include "vector_src.cxx" 00030 00031 // Tell GCC that we'll take care of the instantiation explicitly here. 00032 #ifdef __GNUC__ 00033 #pragma implementation 00034 #endif 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function: GraphicsWindowInputDevice::Constructor 00038 // Access: Private 00039 // Description: Defines a new InputDevice for the window. Most 00040 // windows will have exactly one InputDevice: a 00041 // keyboard/mouse pair. Some may also add joystick 00042 // data, or additional mice or something. 00043 // 00044 // This private constructor is only used internally by 00045 // the named constructors, below. 00046 //////////////////////////////////////////////////////////////////// 00047 GraphicsWindowInputDevice:: 00048 GraphicsWindowInputDevice(const string &name, int flags) : 00049 _name(name), 00050 _flags(flags) 00051 { 00052 } 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: GraphicsWindowInputDevice::pointer_only 00056 // Access: Public 00057 // Description: This named constructor returns an input device that 00058 // only has a pointing device, no keyboard. 00059 //////////////////////////////////////////////////////////////////// 00060 GraphicsWindowInputDevice GraphicsWindowInputDevice:: 00061 pointer_only(const string &name) { 00062 return GraphicsWindowInputDevice(name, IDF_has_pointer); 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: GraphicsWindowInputDevice::keyboard_only 00067 // Access: Public 00068 // Description: This named constructor returns an input device that 00069 // only has a keyboard, no pointing device. 00070 //////////////////////////////////////////////////////////////////// 00071 GraphicsWindowInputDevice GraphicsWindowInputDevice:: 00072 keyboard_only(const string &name) { 00073 return GraphicsWindowInputDevice(name, IDF_has_keyboard); 00074 } 00075 00076 //////////////////////////////////////////////////////////////////// 00077 // Function: GraphicsWindowInputDevice::pointer_and_keyboard 00078 // Access: Public 00079 // Description: This named constructor returns an input device that 00080 // has both a keyboard and pointer. 00081 //////////////////////////////////////////////////////////////////// 00082 GraphicsWindowInputDevice GraphicsWindowInputDevice:: 00083 pointer_and_keyboard(const string &name) { 00084 return 00085 GraphicsWindowInputDevice(name, IDF_has_pointer | IDF_has_keyboard); 00086 } 00087 00088 //////////////////////////////////////////////////////////////////// 00089 // Function: GraphicsWindowInputDevice::Copy Constructor 00090 // Access: Public 00091 // Description: 00092 //////////////////////////////////////////////////////////////////// 00093 GraphicsWindowInputDevice:: 00094 GraphicsWindowInputDevice(const GraphicsWindowInputDevice ©) : 00095 _name(copy._name), 00096 _flags(copy._flags), 00097 _mouse_data(copy._mouse_data), 00098 _button_events(copy._button_events) 00099 { 00100 } 00101 00102 //////////////////////////////////////////////////////////////////// 00103 // Function: GraphicsWindowInputDevice::Copy Assignment Operator 00104 // Access: Public 00105 // Description: 00106 //////////////////////////////////////////////////////////////////// 00107 void GraphicsWindowInputDevice:: 00108 operator = (const GraphicsWindowInputDevice ©) { 00109 _name = copy._name; 00110 _flags = copy._flags; 00111 _mouse_data = copy._mouse_data; 00112 _button_events = copy._button_events; 00113 } 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: GraphicsWindowInputDevice::Destructor 00117 // Access: Public 00118 // Description: 00119 //////////////////////////////////////////////////////////////////// 00120 GraphicsWindowInputDevice:: 00121 ~GraphicsWindowInputDevice() { 00122 } 00123 00124 //////////////////////////////////////////////////////////////////// 00125 // Function: GraphicsWindowInputDevice::has_button_event 00126 // Access: Public 00127 // Description: Returns true if this device has a pending button 00128 // event (a mouse button or keyboard button down/up), 00129 // false otherwise. If this returns true, the 00130 // particular event may be extracted via 00131 // get_button_event(). 00132 //////////////////////////////////////////////////////////////////// 00133 bool GraphicsWindowInputDevice:: 00134 has_button_event() const { 00135 return !_button_events.empty(); 00136 } 00137 00138 //////////////////////////////////////////////////////////////////// 00139 // Function: GraphicsWindowInputDevice::get_button_event 00140 // Access: Public 00141 // Description: Assuming a previous call to has_button_event() 00142 // returned true, this returns the pending button event. 00143 //////////////////////////////////////////////////////////////////// 00144 ButtonEvent GraphicsWindowInputDevice:: 00145 get_button_event() { 00146 ButtonEvent be = _button_events.front(); 00147 _button_events.pop_front(); 00148 return be; 00149 } 00150 00151 //////////////////////////////////////////////////////////////////// 00152 // Function: GraphicsWindowInputDevice::button_down 00153 // Access: Public 00154 // Description: Records that the indicated button has been depressed. 00155 //////////////////////////////////////////////////////////////////// 00156 void GraphicsWindowInputDevice:: 00157 button_down(ButtonHandle button) { 00158 _button_events.push_back(ButtonEvent(button, ButtonEvent::T_down)); 00159 } 00160 00161 //////////////////////////////////////////////////////////////////// 00162 // Function: GraphicsWindowInputDevice::button_resume_down 00163 // Access: Public 00164 // Description: Records that the indicated button was depressed 00165 // earlier, and we only just detected the event after 00166 // the fact. This is mainly useful for tracking the 00167 // state of modifier keys. 00168 //////////////////////////////////////////////////////////////////// 00169 void GraphicsWindowInputDevice:: 00170 button_resume_down(ButtonHandle button) { 00171 _button_events.push_back(ButtonEvent(button, ButtonEvent::T_resume_down)); 00172 } 00173 00174 //////////////////////////////////////////////////////////////////// 00175 // Function: GraphicsWindowInputDevice::button_up 00176 // Access: Public 00177 // Description: Records that the indicated button has been released. 00178 //////////////////////////////////////////////////////////////////// 00179 void GraphicsWindowInputDevice:: 00180 button_up(ButtonHandle button) { 00181 _button_events.push_back(ButtonEvent(button, ButtonEvent::T_up)); 00182 } 00183 00184 //////////////////////////////////////////////////////////////////// 00185 // Function: GraphicsWindowInputDevice::keystroke 00186 // Access: Public 00187 // Description: Records that the indicated keystroke has been 00188 // generated. 00189 //////////////////////////////////////////////////////////////////// 00190 void GraphicsWindowInputDevice:: 00191 keystroke(int keycode) { 00192 _button_events.push_back(ButtonEvent(keycode)); 00193 }