Panda3D
|
00001 // Filename: graphicsWindowInputDevice.h 00002 // Created by: drose (24May00) 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 #ifndef GRAPHICSWINDOWINPUTDEVICE_H 00016 #define GRAPHICSWINDOWINPUTDEVICE_H 00017 00018 #include "pandabase.h" 00019 00020 #include "buttonEvent.h" 00021 #include "pointerEvent.h" 00022 #include "pointerEventList.h" 00023 #include "mouseData.h" 00024 #include "clockObject.h" 00025 00026 #include "pdeque.h" 00027 #include "pvector.h" 00028 #include "lightMutex.h" 00029 #include "lightMutexHolder.h" 00030 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Class : GraphicsWindowInputDevice 00034 // Description : This is a structure representing a single input 00035 // device that may be associated with a window. 00036 // Typically this will be a keyboard/mouse pair, and 00037 // there will be exactly one of these associated with 00038 // each window, but other variants are possible. 00039 //////////////////////////////////////////////////////////////////// 00040 class EXPCL_PANDA_DISPLAY GraphicsWindowInputDevice { 00041 private: 00042 GraphicsWindowInputDevice(GraphicsWindow *host, const string &name, int flags); 00043 00044 public: 00045 static GraphicsWindowInputDevice pointer_only(GraphicsWindow *host, const string &name); 00046 static GraphicsWindowInputDevice keyboard_only(GraphicsWindow *host, const string &name); 00047 static GraphicsWindowInputDevice pointer_and_keyboard(GraphicsWindow *host, const string &name); 00048 00049 INLINE GraphicsWindowInputDevice(); 00050 GraphicsWindowInputDevice(const GraphicsWindowInputDevice ©); 00051 void operator = (const GraphicsWindowInputDevice ©); 00052 ~GraphicsWindowInputDevice(); 00053 00054 INLINE string get_name() const; 00055 INLINE bool has_pointer() const; 00056 INLINE bool has_keyboard() const; 00057 00058 INLINE void set_device_index(int index); 00059 00060 INLINE MouseData get_pointer() const; 00061 INLINE MouseData get_raw_pointer() const; 00062 00063 INLINE void enable_pointer_events(); 00064 INLINE void disable_pointer_events(); 00065 00066 void enable_pointer_mode(double speed); 00067 void disable_pointer_mode(); 00068 00069 bool has_button_event() const; 00070 ButtonEvent get_button_event(); 00071 bool has_pointer_event() const; 00072 PT(PointerEventList) get_pointer_events(); 00073 00074 PUBLISHED: 00075 // The following interface is for the various kinds of 00076 // GraphicsWindows to record the data incoming on the device. 00077 void button_down(ButtonHandle button, double time = ClockObject::get_global_clock()->get_frame_time()); 00078 void button_resume_down(ButtonHandle button, double time = ClockObject::get_global_clock()->get_frame_time()); 00079 void button_up(ButtonHandle button, double time = ClockObject::get_global_clock()->get_frame_time()); 00080 void keystroke(int keycode, double time = ClockObject::get_global_clock()->get_frame_time()); 00081 void candidate(const wstring &candidate_string, size_t highlight_start, 00082 size_t highlight_end, size_t cursor_pos); 00083 void focus_lost(double time = ClockObject::get_global_clock()->get_frame_time()); 00084 00085 INLINE void set_pointer_in_window(int x, int y, double time = ClockObject::get_global_clock()->get_frame_time()); 00086 INLINE void set_pointer_out_of_window(double time = ClockObject::get_global_clock()->get_frame_time()); 00087 void set_pointer(bool inwin, int x, int y, double time); 00088 00089 public: 00090 // We need these methods to make VC++ happy when we try to 00091 // instantiate a pvector<GraphicsWindowInputDevice>. They don't do 00092 // anything useful. 00093 INLINE bool operator == (const GraphicsWindowInputDevice &other) const; 00094 INLINE bool operator != (const GraphicsWindowInputDevice &other) const; 00095 INLINE bool operator < (const GraphicsWindowInputDevice &other) const; 00096 00097 private: 00098 enum InputDeviceFlags { 00099 IDF_has_pointer = 0x01, 00100 IDF_has_keyboard = 0x02 00101 }; 00102 typedef pdeque<ButtonEvent> ButtonEvents; 00103 00104 LightMutex _lock; 00105 00106 GraphicsWindow *_host; 00107 00108 string _name; 00109 int _flags; 00110 int _device_index; 00111 int _event_sequence; 00112 00113 bool _pointer_mode_enable; 00114 double _pointer_speed; 00115 double _pointer_true_x; 00116 double _pointer_true_y; 00117 00118 bool _enable_pointer_events; 00119 MouseData _mouse_data; 00120 MouseData _true_mouse_data; 00121 ButtonEvents _button_events; 00122 PT(PointerEventList) _pointer_events; 00123 00124 typedef pset<ButtonHandle> ButtonsHeld; 00125 ButtonsHeld _buttons_held; 00126 }; 00127 00128 #include "graphicsWindowInputDevice.I" 00129 00130 #define EXPCL EXPCL_PANDA_DISPLAY 00131 #define EXPTP EXPTP_PANDA_DISPLAY 00132 #define TYPE GraphicsWindowInputDevice 00133 #define NAME vector_GraphicsWindowInputDevice 00134 00135 #include "vector_src.h" 00136 00137 // Tell GCC that we'll take care of the instantiation explicitly here. 00138 #ifdef __GNUC__ 00139 #pragma interface 00140 #endif 00141 00142 #endif