Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/tform/mouseWatcher.h

Go to the documentation of this file.
00001 // Filename: mouseWatcher.h
00002 // Created by:  drose (12Mar02)
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 #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 //       Class : MouseWatcher
00040 // Description : This TFormer maintains a list of rectangular regions
00041 //               on the screen that are considered special mouse
00042 //               regions; typically these will be click buttons.  When
00043 //               the mouse passes in or out of one of these regions,
00044 //               or when a button is clicked while the mouse is in one
00045 //               of these regions, an event is thrown.
00046 //
00047 //               Mouse events may also be suppressed from the rest of
00048 //               the datagraph in these special regions.
00049 //
00050 //               This class can also implement a software mouse
00051 //               pointer by automatically generating a transform to
00052 //               apply to a piece of geometry placed under the 2-d
00053 //               scene graph.  It will move the geometry around
00054 //               according to the mouse's known position.
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 &regions, const LPoint2f &pos) const;
00116   static MouseWatcherRegion *get_preferred_region(const VRegions &regions);
00117 
00118   void set_current_regions(VRegions &regions);
00119   void clear_current_regions();
00120   static void intersect_regions(MouseWatcher::VRegions &result,
00121                                 const MouseWatcher::VRegions &regions_a,
00122                                 const MouseWatcher::VRegions &regions_b);
00123   static void remove_region_from(MouseWatcher::VRegions &regions,
00124                                  MouseWatcherRegion *region);
00125   static void remove_regions_from(MouseWatcher::VRegions &regions,
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 &param);
00137   void global_keyboard_release(const MouseWatcherParameter &param);
00138 
00139   INLINE void within_region(MouseWatcherRegion *region, const MouseWatcherParameter &param);
00140   INLINE void without_region(MouseWatcherRegion *region, const MouseWatcherParameter &param);
00141   void enter_region(MouseWatcherRegion *region, const MouseWatcherParameter &param);
00142   void exit_region(MouseWatcherRegion *region, const MouseWatcherParameter &param);
00143 
00144   // This wants to be a set, but because you cannot export sets across
00145   // dlls in windows, we will make it a vector instead
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   // Inherited from DataNode
00176   virtual void do_transmit_data(const DataNodeTransmit &input,
00177                                 DataNodeTransmit &output);
00178 
00179 private:
00180   // inputs
00181   int _pixel_xy_input;
00182   int _xy_input;
00183   int _button_events_input;
00184 
00185   // outputs
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

Generated on Fri May 2 00:44:28 2003 for Panda by doxygen1.3