00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MOUSEWATCHER_H
00020 #define MOUSEWATCHER_H
00021
00022 #include "pandabase.h"
00023
00024 #include "mouseWatcherRegion.h"
00025 #include "mouseWatcherGroup.h"
00026 #include "dataNode.h"
00027 #include "luse.h"
00028 #include "pointerTo.h"
00029 #include "eventHandler.h"
00030 #include "modifierButtons.h"
00031 #include "buttonHandle.h"
00032 #include "buttonEventList.h"
00033 #include "linmath_events.h"
00034 #include "pvector.h"
00035
00036 class MouseWatcherParameter;
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 class EXPCL_PANDA MouseWatcher : public DataNode, public MouseWatcherGroup {
00057 PUBLISHED:
00058 MouseWatcher(const string &name = "");
00059 ~MouseWatcher();
00060
00061 bool remove_region(MouseWatcherRegion *region);
00062
00063 INLINE bool has_mouse() const;
00064 INLINE bool is_mouse_open() const;
00065 INLINE const LPoint2f &get_mouse() const;
00066 INLINE float get_mouse_x() const;
00067 INLINE float get_mouse_y() const;
00068
00069 INLINE bool is_over_region() const;
00070 INLINE bool is_over_region(float x, float y) const;
00071 INLINE bool is_over_region(const LPoint2f &pos) const;
00072
00073 INLINE MouseWatcherRegion *get_over_region() const;
00074 INLINE MouseWatcherRegion *get_over_region(float x, float y) const;
00075 MouseWatcherRegion *get_over_region(const LPoint2f &pos) const;
00076
00077 INLINE void set_button_down_pattern(const string &pattern);
00078 INLINE const string &get_button_down_pattern() const;
00079
00080 INLINE void set_button_up_pattern(const string &pattern);
00081 INLINE const string &get_button_up_pattern() const;
00082
00083 INLINE void set_enter_pattern(const string &pattern);
00084 INLINE const string &get_enter_pattern() const;
00085
00086 INLINE void set_leave_pattern(const string &pattern);
00087 INLINE const string &get_leave_pattern() const;
00088
00089 INLINE void set_within_pattern(const string &pattern);
00090 INLINE const string &get_within_pattern() const;
00091
00092 INLINE void set_without_pattern(const string &pattern);
00093 INLINE const string &get_without_pattern() const;
00094
00095 INLINE void set_geometry(PandaNode *node);
00096 INLINE bool has_geometry() const;
00097 INLINE PandaNode *get_geometry() const;
00098 INLINE void clear_geometry();
00099
00100 INLINE void set_extra_handler(EventHandler *eh);
00101 INLINE EventHandler *get_extra_handler(void) const;
00102
00103 INLINE void set_modifier_buttons(const ModifierButtons &mods);
00104 INLINE ModifierButtons get_modifier_buttons() const;
00105
00106 public:
00107 virtual void output(ostream &out) const;
00108 virtual void write(ostream &out, int indent_level = 0) const;
00109
00110 bool add_group(MouseWatcherGroup *group);
00111 bool remove_group(MouseWatcherGroup *group);
00112
00113 protected:
00114 typedef pvector< PT(MouseWatcherRegion) > VRegions;
00115 void get_over_regions(VRegions ®ions, const LPoint2f &pos) const;
00116 static MouseWatcherRegion *get_preferred_region(const VRegions ®ions);
00117
00118 void set_current_regions(VRegions ®ions);
00119 void clear_current_regions();
00120 static void intersect_regions(MouseWatcher::VRegions &result,
00121 const MouseWatcher::VRegions ®ions_a,
00122 const MouseWatcher::VRegions ®ions_b);
00123 static void remove_region_from(MouseWatcher::VRegions ®ions,
00124 MouseWatcherRegion *region);
00125 static void remove_regions_from(MouseWatcher::VRegions ®ions,
00126 MouseWatcherGroup *group);
00127
00128
00129 void throw_event_pattern(const string &pattern,
00130 const MouseWatcherRegion *region,
00131 const ButtonHandle &button);
00132
00133 void press(ButtonHandle button);
00134 void release(ButtonHandle button);
00135 void keystroke(int keycode);
00136 void global_keyboard_press(const MouseWatcherParameter ¶m);
00137 void global_keyboard_release(const MouseWatcherParameter ¶m);
00138
00139 INLINE void within_region(MouseWatcherRegion *region, const MouseWatcherParameter ¶m);
00140 INLINE void without_region(MouseWatcherRegion *region, const MouseWatcherParameter ¶m);
00141 void enter_region(MouseWatcherRegion *region, const MouseWatcherParameter ¶m);
00142 void exit_region(MouseWatcherRegion *region, const MouseWatcherParameter ¶m);
00143
00144
00145
00146 typedef pvector< PT(MouseWatcherGroup) > Groups;
00147 Groups _groups;
00148
00149 bool _has_mouse;
00150 int _suppress_flags;
00151 LPoint2f _mouse;
00152
00153 VRegions _current_regions;
00154 PT(MouseWatcherRegion) _preferred_region;
00155 PT(MouseWatcherRegion) _preferred_button_down_region;
00156 bool _button_down;
00157
00158 bool _enter_multiple;
00159 bool _implicit_click;
00160
00161 string _button_down_pattern;
00162 string _button_up_pattern;
00163 string _enter_pattern;
00164 string _leave_pattern;
00165 string _within_pattern;
00166 string _without_pattern;
00167
00168 PT(PandaNode) _geometry;
00169
00170 EventHandler *_eh;
00171
00172 ModifierButtons _mods;
00173
00174 protected:
00175
00176 virtual void do_transmit_data(const DataNodeTransmit &input,
00177 DataNodeTransmit &output);
00178
00179 private:
00180
00181 int _pixel_xy_input;
00182 int _xy_input;
00183 int _button_events_input;
00184
00185
00186 int _pixel_xy_output;
00187 int _xy_output;
00188 int _button_events_output;
00189
00190 PT(EventStoreVec2) _pixel_xy;
00191 PT(EventStoreVec2) _xy;
00192 PT(ButtonEventList) _button_events;
00193
00194 public:
00195 static TypeHandle get_class_type() {
00196 return _type_handle;
00197 }
00198 static void init_type() {
00199 DataNode::init_type();
00200 register_type(_type_handle, "MouseWatcher",
00201 DataNode::get_class_type());
00202 }
00203 virtual TypeHandle get_type() const {
00204 return get_class_type();
00205 }
00206 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00207
00208 private:
00209 static TypeHandle _type_handle;
00210 };
00211
00212 #include "mouseWatcher.I"
00213
00214 #endif