graphicsWindowInputDevice.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Filename: graphicsWindowInputDevice.h
  2. // Created by: drose (24May00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef GRAPHICSWINDOWINPUTDEVICE_H
  15. #define GRAPHICSWINDOWINPUTDEVICE_H
  16. #include "pandabase.h"
  17. #include "buttonEvent.h"
  18. #include "pointerEvent.h"
  19. #include "pointerEventList.h"
  20. #include "mouseData.h"
  21. #include "clockObject.h"
  22. #include "pdeque.h"
  23. #include "pvector.h"
  24. #include "lightMutex.h"
  25. #include "lightMutexHolder.h"
  26. ////////////////////////////////////////////////////////////////////
  27. // Class : GraphicsWindowInputDevice
  28. // Description : This is a structure representing a single input
  29. // device that may be associated with a window.
  30. // Typically this will be a keyboard/mouse pair, and
  31. // there will be exactly one of these associated with
  32. // each window, but other variants are possible.
  33. ////////////////////////////////////////////////////////////////////
  34. class EXPCL_PANDA_DISPLAY GraphicsWindowInputDevice {
  35. private:
  36. GraphicsWindowInputDevice(GraphicsWindow *host, const string &name, int flags);
  37. public:
  38. static GraphicsWindowInputDevice pointer_only(GraphicsWindow *host, const string &name);
  39. static GraphicsWindowInputDevice keyboard_only(GraphicsWindow *host, const string &name);
  40. static GraphicsWindowInputDevice pointer_and_keyboard(GraphicsWindow *host, const string &name);
  41. INLINE GraphicsWindowInputDevice();
  42. GraphicsWindowInputDevice(const GraphicsWindowInputDevice &copy);
  43. void operator = (const GraphicsWindowInputDevice &copy);
  44. ~GraphicsWindowInputDevice();
  45. INLINE string get_name() const;
  46. INLINE bool has_pointer() const;
  47. INLINE bool has_keyboard() const;
  48. INLINE void set_device_index(int index);
  49. INLINE MouseData get_pointer() const;
  50. INLINE MouseData get_raw_pointer() const;
  51. INLINE void enable_pointer_events();
  52. INLINE void disable_pointer_events();
  53. void enable_pointer_mode(double speed);
  54. void disable_pointer_mode();
  55. bool has_button_event() const;
  56. ButtonEvent get_button_event();
  57. bool has_pointer_event() const;
  58. PT(PointerEventList) get_pointer_events();
  59. public:
  60. // The following interface is for the various kinds of
  61. // GraphicsWindows to record the data incoming on the device.
  62. void button_down(ButtonHandle button, double time = ClockObject::get_global_clock()->get_frame_time());
  63. void button_resume_down(ButtonHandle button, double time = ClockObject::get_global_clock()->get_frame_time());
  64. void button_up(ButtonHandle button, double time = ClockObject::get_global_clock()->get_frame_time());
  65. void keystroke(int keycode, double time = ClockObject::get_global_clock()->get_frame_time());
  66. void candidate(const wstring &candidate_string, size_t highlight_start,
  67. size_t higlight_end, size_t cursor_pos);
  68. INLINE void set_pointer_in_window(int x, int y, double time = ClockObject::get_global_clock()->get_frame_time());
  69. INLINE void set_pointer_out_of_window(double time = ClockObject::get_global_clock()->get_frame_time());
  70. void set_pointer(bool inwin, int x, int y, double time);
  71. public:
  72. // We need these methods to make VC++ happy when we try to
  73. // instantiate a pvector<GraphicsWindowInputDevice>. They don't do
  74. // anything useful.
  75. INLINE bool operator == (const GraphicsWindowInputDevice &other) const;
  76. INLINE bool operator != (const GraphicsWindowInputDevice &other) const;
  77. INLINE bool operator < (const GraphicsWindowInputDevice &other) const;
  78. private:
  79. enum InputDeviceFlags {
  80. IDF_has_pointer = 0x01,
  81. IDF_has_keyboard = 0x02
  82. };
  83. typedef pdeque<ButtonEvent> ButtonEvents;
  84. LightMutex _lock;
  85. GraphicsWindow *_host;
  86. string _name;
  87. int _flags;
  88. int _device_index;
  89. int _event_sequence;
  90. bool _pointer_mode_enable;
  91. double _pointer_speed;
  92. double _pointer_true_x;
  93. double _pointer_true_y;
  94. bool _enable_pointer_events;
  95. MouseData _mouse_data;
  96. MouseData _true_mouse_data;
  97. ButtonEvents _button_events;
  98. PT(PointerEventList) _pointer_events;
  99. };
  100. #include "graphicsWindowInputDevice.I"
  101. #define EXPCL EXPCL_PANDA_DISPLAY
  102. #define EXPTP EXPTP_PANDA_DISPLAY
  103. #define TYPE GraphicsWindowInputDevice
  104. #define NAME vector_GraphicsWindowInputDevice
  105. #include "vector_src.h"
  106. // Tell GCC that we'll take care of the instantiation explicitly here.
  107. #ifdef __GNUC__
  108. #pragma interface
  109. #endif
  110. #endif