Panda3D

graphicsWindowInputDevice.h

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 &copy);
00051   void operator = (const GraphicsWindowInputDevice &copy);
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 public:
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 higlight_end, size_t cursor_pos);
00083 
00084   INLINE void set_pointer_in_window(int x, int y, double time = ClockObject::get_global_clock()->get_frame_time());
00085   INLINE void set_pointer_out_of_window(double time = ClockObject::get_global_clock()->get_frame_time());
00086   void set_pointer(bool inwin, int x, int y, double time);
00087 
00088 public:
00089   // We need these methods to make VC++ happy when we try to
00090   // instantiate a pvector<GraphicsWindowInputDevice>.  They don't do
00091   // anything useful.
00092   INLINE bool operator == (const GraphicsWindowInputDevice &other) const;
00093   INLINE bool operator != (const GraphicsWindowInputDevice &other) const;
00094   INLINE bool operator < (const GraphicsWindowInputDevice &other) const;
00095 
00096 private:
00097   enum InputDeviceFlags {
00098     IDF_has_pointer    = 0x01,
00099     IDF_has_keyboard   = 0x02
00100   };
00101   typedef pdeque<ButtonEvent> ButtonEvents;
00102 
00103   LightMutex _lock;
00104   
00105   GraphicsWindow *_host;
00106   
00107   string _name;
00108   int _flags;
00109   int _device_index;
00110   int _event_sequence;
00111   
00112   bool   _pointer_mode_enable;
00113   double _pointer_speed;
00114   double _pointer_true_x;
00115   double _pointer_true_y;
00116   
00117   bool _enable_pointer_events;
00118   MouseData _mouse_data;
00119   MouseData _true_mouse_data;
00120   ButtonEvents _button_events;
00121   PT(PointerEventList) _pointer_events;
00122 
00123 };
00124 
00125 #include "graphicsWindowInputDevice.I"
00126 
00127 #define EXPCL EXPCL_PANDA_DISPLAY
00128 #define EXPTP EXPTP_PANDA_DISPLAY
00129 #define TYPE GraphicsWindowInputDevice
00130 #define NAME vector_GraphicsWindowInputDevice
00131 
00132 #include "vector_src.h"
00133 
00134 // Tell GCC that we'll take care of the instantiation explicitly here.
00135 #ifdef __GNUC__
00136 #pragma interface
00137 #endif
00138 
00139 #endif
 All Classes Functions Variables Enumerations