Panda3D
mouseWatcherBase.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file mouseWatcherBase.h
10  * @author rdb
11  * @date 2014-01-13
12  */
13 
14 #ifndef MOUSEWATCHERBASE_H
15 #define MOUSEWATCHERBASE_H
16 
17 #include "pandabase.h"
18 #include "mouseWatcherRegion.h"
19 
20 #include "pointerTo.h"
21 #include "pvector.h"
22 #include "nodePath.h"
23 #include "lightMutex.h"
24 #include "ordered_vector.h"
25 
26 /**
27  * This represents a collection of MouseWatcherRegions that may be managed as
28  * a group. This is the base class for both MouseWatcherGroup and
29  * MouseWatcher, and exists so that we don't have to make MouseWatcher inherit
30  * from ReferenceCount more than once.
31  */
32 class EXPCL_PANDA_TFORM MouseWatcherBase {
33 public:
35  virtual ~MouseWatcherBase();
36 
37 PUBLISHED:
38  void add_region(PT(MouseWatcherRegion) region);
39  bool has_region(MouseWatcherRegion *region) const;
40  bool remove_region(MouseWatcherRegion *region);
41  MouseWatcherRegion *find_region(const std::string &name) const;
42  void clear_regions();
43 
44  INLINE void sort_regions();
45  INLINE bool is_sorted() const;
46  MAKE_PROPERTY(sorted, is_sorted);
47 
48  size_t get_num_regions() const;
49  MouseWatcherRegion *get_region(size_t n) const;
50  MAKE_SEQ(get_regions, get_num_regions, get_region);
51  MAKE_SEQ_PROPERTY(regions, get_num_regions, get_region);
52 
53  void output(std::ostream &out) const;
54  void write(std::ostream &out, int indent_level = 0) const;
55 
56 #ifndef NDEBUG
57  void show_regions(const NodePath &render2d,
58  const std::string &bin_name, int draw_order);
59  void set_color(const LColor &color);
60  void hide_regions();
61 
62  void update_regions();
63 #endif // NDEBUG
64 
65 protected:
66  void do_sort_regions();
67  bool do_remove_region(MouseWatcherRegion *region);
68 
69 #ifndef NDEBUG
70  virtual void do_show_regions(const NodePath &render2d,
71  const std::string &bin_name, int draw_order);
72  virtual void do_hide_regions();
73  void do_update_regions();
74 #endif // NDEBUG
75 
76 protected:
77  typedef ov_set< PT(MouseWatcherRegion) > Regions;
78  Regions _regions;
79  bool _sorted;
80 
81  // This mutex protects the above list of regions, as well as the below list
82  // of vizzes. It is also referenced directly by MouseWatcher, a derived
83  // class.
84  LightMutex _lock;
85 
86 private:
87 #ifndef NDEBUG
88  PandaNode *make_viz_region(MouseWatcherRegion *region);
89 
90  typedef pvector< PT(PandaNode) > Vizzes;
91  Vizzes _vizzes;
92 
93  bool _show_regions;
94  NodePath _show_regions_root;
95  LColor _color;
96 #endif // NDEBUG
97 
98 public:
99  static TypeHandle get_class_type() {
100  return _type_handle;
101  }
102  static void init_type() {
103  register_type(_type_handle, "MouseWatcherBase");
104  }
105 
106 private:
107  static TypeHandle _type_handle;
108 
109  friend class MouseWatcher;
110  friend class BlobWatcher;
111 };
112 
113 #include "mouseWatcherBase.I"
114 
115 #endif
This TFormer maintains a list of rectangular regions on the screen that are considered special mouse ...
Definition: mouseWatcher.h:61
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the class that defines a rectangular region on the screen for the MouseWatcher.
This represents a collection of MouseWatcherRegions that may be managed as a group.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:39
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161