Panda3D
Loading...
Searching...
No Matches
pgItem.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 pgItem.h
10 * @author drose
11 * @date 2002-03-13
12 */
13
14#ifndef PGITEM_H
15#define PGITEM_H
16
17#include "pandabase.h"
18
20#include "pgFrameStyle.h"
21#include "pgItemNotify.h"
22
23#include "pandaNode.h"
24#include "nodePath.h"
25#include "luse.h"
26#include "pointerTo.h"
27#include "textNode.h"
28#include "plane.h"
29#include "pmap.h"
30#include "lightReMutex.h"
31#include "lightReMutexHolder.h"
32
33#ifdef HAVE_AUDIO
34#include "audioSound.h"
35#endif
36
37class PGTop;
39class AudioSound;
40class ClipPlaneAttrib;
41class ScissorAttrib;
42
43/**
44 * This is the base class for all the various kinds of gui widget objects.
45 *
46 * It is a Node which corresponds to a rectangular region on the screen, and
47 * it may have any number of "state" subgraphs, one of which is rendered at
48 * any given time according to its current state.
49 *
50 * The PGItem node must be parented to the scene graph somewhere beneath a
51 * PGTop node in order for this behavior to work.
52 */
53class EXPCL_PANDA_PGUI PGItem : public PandaNode {
54PUBLISHED:
55 explicit PGItem(const std::string &name);
56 virtual ~PGItem();
57
58 INLINE void set_name(const std::string &name);
59
60protected:
61 PGItem(const PGItem &copy);
62
63 virtual PandaNode *make_copy() const;
64 virtual void transform_changed();
65 virtual void draw_mask_changed();
66
67 virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
68 virtual bool is_renderable() const;
69
70 virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds,
71 int &internal_vertices,
72 int pipeline_stage,
73 Thread *current_thread) const;
74
76 const RenderState *node_state,
77 GeomTransformer &transformer,
78 Thread *current_thread);
79
80 virtual void xform(const LMatrix4 &mat);
81 bool activate_region(const LMatrix4 &transform, int sort,
82 const ClipPlaneAttrib *cpa,
83 const ScissorAttrib *sa);
84
85public:
86 INLINE PGMouseWatcherRegion *get_region() const;
87
88 virtual void enter_region(const MouseWatcherParameter &param);
89 virtual void exit_region(const MouseWatcherParameter &param);
90 virtual void within_region(const MouseWatcherParameter &param);
91 virtual void without_region(const MouseWatcherParameter &param);
92 virtual void focus_in();
93 virtual void focus_out();
94 virtual void press(const MouseWatcherParameter &param, bool background);
95 virtual void release(const MouseWatcherParameter &param, bool background);
96 virtual void keystroke(const MouseWatcherParameter &param, bool background);
97 virtual void candidate(const MouseWatcherParameter &param, bool background);
98 virtual void move(const MouseWatcherParameter &param);
99
100 static void background_press(const MouseWatcherParameter &param);
101 static void background_release(const MouseWatcherParameter &param);
102 static void background_keystroke(const MouseWatcherParameter &param);
103 static void background_candidate(const MouseWatcherParameter &param);
104
105 INLINE void set_notify(PGItemNotify *notify);
106 INLINE bool has_notify() const;
107 INLINE PGItemNotify *get_notify() const;
108
109PUBLISHED:
110 INLINE void set_frame(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top);
111 INLINE void set_frame(const LVecBase4 &frame);
112 INLINE const LVecBase4 &get_frame() const;
113 INLINE bool has_frame() const;
114 INLINE void clear_frame();
115
116 INLINE void set_state(int state);
117 INLINE int get_state() const;
118
119 virtual void set_active(bool active);
120 INLINE bool get_active() const;
121
122 virtual void set_focus(bool focus);
123 INLINE bool get_focus() const;
124
125 void set_background_focus(bool focus);
126 INLINE bool get_background_focus() const;
127
128 INLINE void set_suppress_flags(int suppress_flags);
129 INLINE int get_suppress_flags() const;
130
131 int get_num_state_defs() const;
132 void clear_state_def(int state);
133 bool has_state_def(int state) const;
134 INLINE NodePath &get_state_def(int state);
135 MAKE_SEQ(get_state_defs, get_num_state_defs, get_state_def);
136 NodePath instance_to_state_def(int state, const NodePath &path);
137
138 PGFrameStyle get_frame_style(int state);
139 void set_frame_style(int state, const PGFrameStyle &style);
140
141 INLINE const std::string &get_id() const;
142 INLINE void set_id(const std::string &id);
143
144 INLINE static std::string get_enter_prefix();
145 INLINE static std::string get_exit_prefix();
146 INLINE static std::string get_within_prefix();
147 INLINE static std::string get_without_prefix();
148 INLINE static std::string get_focus_in_prefix();
149 INLINE static std::string get_focus_out_prefix();
150 INLINE static std::string get_press_prefix();
151 INLINE static std::string get_repeat_prefix();
152 INLINE static std::string get_release_prefix();
153 INLINE static std::string get_keystroke_prefix();
154
155 INLINE std::string get_enter_event() const;
156 INLINE std::string get_exit_event() const;
157 INLINE std::string get_within_event() const;
158 INLINE std::string get_without_event() const;
159 INLINE std::string get_focus_in_event() const;
160 INLINE std::string get_focus_out_event() const;
161 INLINE std::string get_press_event(const ButtonHandle &button) const;
162 INLINE std::string get_repeat_event(const ButtonHandle &button) const;
163 INLINE std::string get_release_event(const ButtonHandle &button) const;
164 INLINE std::string get_keystroke_event() const;
165
166 INLINE LMatrix4 get_frame_inv_xform() const;
167
168#ifdef HAVE_AUDIO
169 void set_sound(const std::string &event, AudioSound *sound);
170 void clear_sound(const std::string &event);
171 AudioSound *get_sound(const std::string &event) const;
172 bool has_sound(const std::string &event) const;
173#endif
174
175 static TextNode *get_text_node();
176 INLINE static void set_text_node(TextNode *node);
177
178 INLINE static PGItem *get_focus_item();
179
180protected:
181 void play_sound(const std::string &event);
182
183 void reduce_region(LVecBase4 &clip, PGItem *obscurer) const;
184 void reduce_region(LVecBase4 &frame, PN_stdfloat px, PN_stdfloat py) const;
185 LVecBase4 get_relative_frame(PGItem *item) const;
186 LPoint3 mouse_to_local(const LPoint2 &mouse_point) const;
187
188 virtual void frame_changed();
189
190private:
191 NodePath &do_get_state_def(int state);
192 void slot_state_def(int state);
193 void update_frame(int state);
194 void mark_frames_stale();
195
196 INLINE static PN_stdfloat compute_area(const LVecBase4 &frame);
197 INLINE static void compare_largest(const LVecBase4 *&largest,
198 PN_stdfloat &largest_area,
199 const LVecBase4 *new_frame);
200
201 typedef pvector<LVecBase2> ClipPoints;
202 bool clip_frame(ClipPoints &source_points, const LPlane &plane) const;
203
204protected:
205 LightReMutex _lock;
206
207private:
208 PGItemNotify *_notify;
209
210 bool _has_frame;
211 LVecBase4 _frame;
212 int _state;
213 enum Flags {
214 F_active = 0x01,
215 F_focus = 0x02,
216 F_background_focus = 0x04,
217 };
218 int _flags;
219
220 PT(PGMouseWatcherRegion) const _region;
221
222 LMatrix4 _frame_inv_xform;
223
224 class StateDef {
225 public:
226 INLINE StateDef();
227 NodePath _root;
228 PGFrameStyle _frame_style;
229 NodePath _frame;
230 bool _frame_stale;
231 };
232 typedef pvector<StateDef> StateDefs;
233 StateDefs _state_defs;
234
235#ifdef HAVE_AUDIO
236 typedef pmap<std::string, PT(AudioSound) > Sounds;
237 Sounds _sounds;
238#endif
239
240 static PT(TextNode) _text_node;
241 static PGItem *_focus_item;
242
243 typedef pset<PGItem *> BackgroundFocus;
244 static BackgroundFocus _background_focus;
245
246public:
247 static TypeHandle get_class_type() {
248 return _type_handle;
249 }
250 static void init_type() {
251 PandaNode::init_type();
252 register_type(_type_handle, "PGItem",
253 PandaNode::get_class_type());
254 }
255 virtual TypeHandle get_type() const {
256 return get_class_type();
257 }
258 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
259
260private:
261 static TypeHandle _type_handle;
262};
263
264#include "pgItem.I"
265
266#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
This functions similarly to a LightAttrib.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
An object specifically designed to transform the vertices of a Geom without disturbing indexing or af...
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A lightweight reentrant mutex.
This is sent along as a parameter to most events generated for a region to indicate the mouse and but...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
Objects that inherit from this class can receive specialized messages when PGItems change in certain ...
void set_notify(PGItemNotify *notify)
Sets the object which will be notified when the PGItem changes.
Definition pgItem.I:43
static void background_release(const MouseWatcherParameter &param)
Calls release() on all the PGItems with background focus.
Definition pgItem.cxx:803
const LVecBase4 & get_frame() const
Returns the bounding rectangle of the item.
Definition pgItem.I:106
virtual void press(const MouseWatcherParameter &param, bool background)
This is a callback hook function, called whenever a mouse or keyboard button is depressed while the m...
Definition pgItem.cxx:674
bool get_active() const
Returns whether the PGItem is currently active for mouse events.
Definition pgItem.I:160
void set_frame_style(int state, const PGFrameStyle &style)
Changes the kind of frame that will be drawn behind the item when it is in the indicated state.
Definition pgItem.cxx:1021
static void background_candidate(const MouseWatcherParameter &param)
Calls candidate() on all the PGItems with background focus.
Definition pgItem.cxx:833
static std::string get_press_prefix()
Returns the prefix that is used to define the press event for all PGItems.
Definition pgItem.I:310
void clear_frame()
Removes the bounding rectangle from the item.
Definition pgItem.I:126
static std::string get_focus_out_prefix()
Returns the prefix that is used to define the focus_out event for all PGItems.
Definition pgItem.I:300
std::string get_keystroke_event() const
Returns the event name that will be thrown when the item is active and any key is pressed by the user...
Definition pgItem.I:446
std::string get_without_event() const
Returns the event name that will be thrown when the item is active and the mouse moves completely out...
Definition pgItem.I:383
std::string get_focus_out_event() const
Returns the event name that will be thrown when the item loses the keyboard focus.
Definition pgItem.I:403
PGItemNotify * get_notify() const
Returns the object which will be notified when the PGItem changes, if any.
Definition pgItem.I:69
static std::string get_within_prefix()
Returns the prefix that is used to define the within event for all PGItems.
Definition pgItem.I:266
int get_suppress_flags() const
This is just an interface to get the suppress flags on the underlying MouseWatcherRegion.
Definition pgItem.I:200
void clear_state_def(int state)
Resets the NodePath assigned to the indicated state to its initial default, with only a frame represe...
Definition pgItem.cxx:967
std::string get_exit_event() const
Returns the event name that will be thrown when the item is active and the mouse exits its frame,...
Definition pgItem.I:359
void set_frame(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top)
Sets the bounding rectangle of the item, in local coordinates.
Definition pgItem.I:81
static std::string get_focus_in_prefix()
Returns the prefix that is used to define the focus_in event for all PGItems.
Definition pgItem.I:288
static std::string get_keystroke_prefix()
Returns the prefix that is used to define the keystroke event for all PGItems.
Definition pgItem.I:340
static TextNode * get_text_node()
Returns the TextNode object that will be used by all PGItems to generate default labels given a strin...
Definition pgItem.cxx:1090
LMatrix4 get_frame_inv_xform() const
Returns the inverse of the frame transform matrix.
Definition pgItem.I:475
bool has_state_def(int state) const
Returns true if get_state_def() has ever been called for the indicated state (thus defining a render ...
Definition pgItem.cxx:954
bool get_focus() const
Returns whether the PGItem currently has focus for keyboard events.
Definition pgItem.I:170
bool get_background_focus() const
Returns whether background_focus is currently enabled.
Definition pgItem.I:180
get_num_state_defs
Returns one more than the highest-numbered state def that was ever assigned to the PGItem.
Definition pgItem.h:135
PGMouseWatcherRegion * get_region() const
Returns the MouseWatcherRegion associated with this item.
Definition pgItem.I:31
virtual void release(const MouseWatcherParameter &param, bool background)
This is a callback hook function, called whenever a mouse or keyboard button previously depressed wit...
Definition pgItem.cxx:703
PGFrameStyle get_frame_style(int state)
Returns the kind of frame that will be drawn behind the item when it is in the indicated state.
Definition pgItem.cxx:1008
NodePath instance_to_state_def(int state, const NodePath &path)
Parents an instance of the bottom node of the indicated NodePath to the indicated state index.
Definition pgItem.cxx:991
int get_state() const
Returns the "state" of this particular PGItem.
Definition pgItem.I:150
void set_background_focus(bool focus)
Sets the background_focus flag for this item.
Definition pgItem.cxx:916
virtual void without_region(const MouseWatcherParameter &param)
This is a callback hook function, called whenever the mouse moves completely outside the boundaries o...
Definition pgItem.cxx:610
static void set_text_node(TextNode *node)
Changes the TextNode object that will be used by all PGItems to generate default labels given a strin...
Definition pgItem.I:457
std::string get_press_event(const ButtonHandle &button) const
Returns the event name that will be thrown when the item is active and the indicated mouse or keyboar...
Definition pgItem.I:414
std::string get_within_event() const
Returns the event name that will be thrown when the item is active and the mouse moves within the bou...
Definition pgItem.I:371
const std::string & get_id() const
Returns the unique ID assigned to this PGItem.
Definition pgItem.I:224
void set_suppress_flags(int suppress_flags)
This is just an interface to set the suppress flags on the underlying MouseWatcherRegion.
Definition pgItem.I:190
get_state_def
Returns the Node that is the root of the subgraph that will be drawn when the PGItem is in the indica...
Definition pgItem.h:135
static std::string get_enter_prefix()
Returns the prefix that is used to define the enter event for all PGItems.
Definition pgItem.I:248
virtual void keystroke(const MouseWatcherParameter &param, bool background)
This is a callback hook function, called whenever the user presses a key.
Definition pgItem.cxx:726
virtual void exit_region(const MouseWatcherParameter &param)
This is a callback hook function, called whenever the mouse exits the region.
Definition pgItem.cxx:562
static PGItem * get_focus_item()
Returns the one PGItem in the world that currently has keyboard focus, if any, or NULL if no item has...
Definition pgItem.I:467
static void background_press(const MouseWatcherParameter &param)
Calls press() on all the PGItems with background focus.
Definition pgItem.cxx:786
virtual void set_focus(bool focus)
Sets whether the PGItem currently has keyboard focus.
Definition pgItem.cxx:874
std::string get_repeat_event(const ButtonHandle &button) const
Returns the event name that will be thrown when the item is active and the indicated mouse or keyboar...
Definition pgItem.I:425
virtual void focus_in()
This is a callback hook function, called whenever the widget gets the keyboard focus.
Definition pgItem.cxx:632
bool has_notify() const
Returns true if there is an object configured to be notified when the PGItem changes,...
Definition pgItem.I:59
virtual void focus_out()
This is a callback hook function, called whenever the widget loses the keyboard focus.
Definition pgItem.cxx:653
static std::string get_release_prefix()
Returns the prefix that is used to define the release event for all PGItems.
Definition pgItem.I:330
static std::string get_exit_prefix()
Returns the prefix that is used to define the exit event for all PGItems.
Definition pgItem.I:257
virtual void move(const MouseWatcherParameter &param)
This is a callback hook function, called whenever a mouse is moved while within the region.
Definition pgItem.cxx:770
bool has_frame() const
Returns true if the item has a bounding rectangle; see set_frame().
Definition pgItem.I:116
static std::string get_without_prefix()
Returns the prefix that is used to define the without event for all PGItems.
Definition pgItem.I:276
virtual void within_region(const MouseWatcherParameter &param)
This is a callback hook function, called whenever the mouse moves within the boundaries of the region...
Definition pgItem.cxx:588
std::string get_release_event(const ButtonHandle &button) const
Returns the event name that will be thrown when the item is active and the indicated mouse or keyboar...
Definition pgItem.I:436
virtual void candidate(const MouseWatcherParameter &param, bool background)
This is a callback hook function, called whenever the user highlights an option in the IME window.
Definition pgItem.cxx:750
static void background_keystroke(const MouseWatcherParameter &param)
Calls keystroke() on all the PGItems with background focus.
Definition pgItem.cxx:818
void set_id(const std::string &id)
Set the unique ID assigned to this PGItem.
Definition pgItem.I:238
std::string get_enter_event() const
Returns the event name that will be thrown when the item is active and the mouse enters its frame,...
Definition pgItem.I:349
static std::string get_repeat_prefix()
Returns the prefix that is used to define the repeat event for all PGItems.
Definition pgItem.I:320
std::string get_focus_in_event() const
Returns the event name that will be thrown when the item gets the keyboard focus.
Definition pgItem.I:393
virtual void enter_region(const MouseWatcherParameter &param)
This is a callback hook function, called whenever the mouse enters the region.
Definition pgItem.cxx:538
virtual void set_active(bool active)
Sets whether the PGItem is active for mouse watching.
Definition pgItem.cxx:851
This is a specialization on MouseWatcherRegion, to add a bit more fields that are relevant to the PG ...
The "top" node of the new Panda GUI system.
Definition pgTop.h:38
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
virtual void r_prepare_scene(GraphicsStateGuardianBase *gsg, const RenderState *node_state, GeomTransformer &transformer, Thread *current_thread)
The recursive implementation of prepare_scene().
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this PandaNode by the indicated matrix, if it means anything to do so.
set_state
Sets the complete RenderState that will be applied to all nodes at this level and below.
Definition pandaNode.h:173
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition renderState.h:47
This restricts rendering to within a rectangular region of the scene, without otherwise affecting the...
The primary interface to this module.
Definition textNode.h:48
A thread; that is, a lightweight process.
Definition thread.h:46
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.
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(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.