Panda3D
Loading...
Searching...
No Matches
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 */
32class EXPCL_PANDA_TFORM MouseWatcherBase {
33public:
34 MouseWatcherBase();
35 virtual ~MouseWatcherBase();
36
37PUBLISHED:
38 void add_region(PT(MouseWatcherRegion) region);
39 bool has_region(MouseWatcherRegion *region) const;
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
65protected:
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
76protected:
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
86private:
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
103public:
104 static TypeHandle get_class_type() {
105 return _type_handle;
106 }
107 static void init_type() {
108 register_type(_type_handle, "MouseWatcherBase");
109 }
110
111private:
112 static TypeHandle _type_handle;
113
114 friend class MouseWatcher;
115 friend class BlobWatcher;
116};
117
118#include "mouseWatcherBase.I"
119
120#endif
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition lightMutex.h:41
bool remove_region(MouseWatcherRegion *region)
Removes the indicated region from the group.
get_num_regions
Returns the number of regions in the group.
is_sorted
Returns true if the group has already been sorted, false otherwise.
void clear_regions()
Removes all the regions from the group.
void add_region(PT(MouseWatcherRegion) region)
Adds the indicated region to the set of regions in the group.
void show_regions(const NodePath &render2d, const std::string &bin_name, int draw_order)
Enables the visualization of all of the regions handled by this MouseWatcherBase.
void sort_regions()
Sorts all the regions in this group into pointer order.
MouseWatcherRegion * find_region(const std::string &name) const
Returns a pointer to the first region found with the indicated name.
get_region
Returns the nth region of the group; returns NULL if there is no nth region.
void set_color(const LColor &color)
Specifies the color used to draw the region rectangles for the regions visualized by show_regions().
void update_regions()
Refreshes the visualization created by show_regions().
void hide_regions()
Stops the visualization created by a previous call to show_regions().
bool has_region(MouseWatcherRegion *region) const
Returns true if the indicated region has already been added to the MouseWatcherBase,...
This is the class that defines a rectangular region on the screen for the MouseWatcher.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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(),...