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 #if !defined(NDEBUG) || !defined(CPPPARSER)
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  typedef pvector< PT(PandaNode) > Vizzes;
88 
89 #ifndef NDEBUG
90  PandaNode *make_viz_region(MouseWatcherRegion *region);
91 
92  Vizzes _vizzes;
93  bool _show_regions;
94  NodePath _show_regions_root;
95  LColor _color;
96 #else
97  Vizzes _vizzes_disabled;
98  bool _show_regions_disabled = false;
99  NodePath _show_regions_root_disabled;
100  LColor _color_disabled;
101 #endif // NDEBUG
102 
103 public:
104  static TypeHandle get_class_type() {
105  return _type_handle;
106  }
107  static void init_type() {
108  register_type(_type_handle, "MouseWatcherBase");
109  }
110 
111 private:
112  static TypeHandle _type_handle;
113 
114  friend class MouseWatcher;
115  friend class BlobWatcher;
116 };
117 
118 #include "mouseWatcherBase.I"
119 
120 #endif
nodePath.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
MouseWatcher
This TFormer maintains a list of rectangular regions on the screen that are considered special mouse ...
Definition: mouseWatcher.h:61
pvector
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
mouseWatcherRegion.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
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
MouseWatcherBase
This represents a collection of MouseWatcherRegions that may be managed as a group.
Definition: mouseWatcherBase.h:32
lightMutex.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LightMutex
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:41
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
ordered_vector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NodePath
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
MouseWatcherRegion
This is the class that defines a rectangular region on the screen for the MouseWatcher.
Definition: mouseWatcherRegion.h:31
mouseWatcherBase.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ov_set
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
Definition: ordered_vector.h:269
PandaNode
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.