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
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 collects together the pieces of data that are accumulated for each node while walking the scene ...
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 ...
This is the base class for all the various kinds of gui widget objects.
Definition pgItem.h:53
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
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
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
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
This is our own Panda specialization on the default STL map.
Definition pmap.h:49
This is our own Panda specialization on the default STL set.
Definition pset.h:49
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
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.