Panda3D
 All Classes Functions Variables Enumerations
pgItem.h
1 // Filename: pgItem.h
2 // Created by: drose (13Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PGITEM_H
16 #define PGITEM_H
17 
18 #include "pandabase.h"
19 
20 #include "pgMouseWatcherRegion.h"
21 #include "pgFrameStyle.h"
22 #include "pgItemNotify.h"
23 
24 #include "pandaNode.h"
25 #include "nodePath.h"
26 #include "luse.h"
27 #include "pointerTo.h"
28 #include "textNode.h"
29 #include "plane.h"
30 #include "pmap.h"
31 #include "lightReMutex.h"
32 #include "lightReMutexHolder.h"
33 
34 #ifdef HAVE_AUDIO
35 #include "audioSound.h"
36 #endif
37 
38 class PGTop;
40 class AudioSound;
41 class ClipPlaneAttrib;
42 class ScissorAttrib;
43 
44 ////////////////////////////////////////////////////////////////////
45 // Class : PGItem
46 // Description : This is the base class for all the various kinds of
47 // gui widget objects.
48 //
49 // It is a Node which corresponds to a rectangular
50 // region on the screen, and it may have any number of
51 // "state" subgraphs, one of which is rendered at any
52 // given time according to its current state.
53 //
54 // The PGItem node must be parented to the scene graph
55 // somewhere beneath a PGTop node in order for this
56 // behavior to work.
57 ////////////////////////////////////////////////////////////////////
58 class EXPCL_PANDA_PGUI PGItem : public PandaNode {
59 PUBLISHED:
60  PGItem(const string &name);
61  virtual ~PGItem();
62 
63  INLINE void set_name(const string &name);
64 
65 protected:
66  PGItem(const PGItem &copy);
67 
68  virtual PandaNode *make_copy() const;
69  virtual void transform_changed();
70  virtual void draw_mask_changed();
71 
72  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
73  virtual bool is_renderable() const;
74 
75  virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds,
76  int &internal_vertices,
77  int pipeline_stage,
78  Thread *current_thread) const;
79 
81  const RenderState *node_state,
82  GeomTransformer &transformer,
83  Thread *current_thread);
84 
85 public:
86  virtual void xform(const LMatrix4 &mat);
87  bool activate_region(const LMatrix4 &transform, int sort,
88  const ClipPlaneAttrib *cpa,
89  const ScissorAttrib *sa);
90  INLINE PGMouseWatcherRegion *get_region() const;
91 
92  virtual void enter_region(const MouseWatcherParameter &param);
93  virtual void exit_region(const MouseWatcherParameter &param);
94  virtual void within_region(const MouseWatcherParameter &param);
95  virtual void without_region(const MouseWatcherParameter &param);
96  virtual void focus_in();
97  virtual void focus_out();
98  virtual void press(const MouseWatcherParameter &param, bool background);
99  virtual void release(const MouseWatcherParameter &param, bool background);
100  virtual void keystroke(const MouseWatcherParameter &param, bool background);
101  virtual void candidate(const MouseWatcherParameter &param, bool background);
102  virtual void move(const MouseWatcherParameter &param);
103 
104  static void background_press(const MouseWatcherParameter &param);
105  static void background_release(const MouseWatcherParameter &param);
106  static void background_keystroke(const MouseWatcherParameter &param);
107  static void background_candidate(const MouseWatcherParameter &param);
108 
109  INLINE void set_notify(PGItemNotify *notify);
110  INLINE bool has_notify() const;
111  INLINE PGItemNotify *get_notify() const;
112 
113 PUBLISHED:
114  INLINE void set_frame(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top);
115  INLINE void set_frame(const LVecBase4 &frame);
116  INLINE const LVecBase4 &get_frame() const;
117  INLINE bool has_frame() const;
118  INLINE void clear_frame();
119 
120  INLINE void set_state(int state);
121  INLINE int get_state() const;
122 
123  virtual void set_active(bool active);
124  INLINE bool get_active() const;
125 
126  virtual void set_focus(bool focus);
127  INLINE bool get_focus() const;
128 
129  void set_background_focus(bool focus);
130  INLINE bool get_background_focus() const;
131 
132  INLINE void set_suppress_flags(int suppress_flags);
133  INLINE int get_suppress_flags() const;
134 
135  int get_num_state_defs() const;
136  void clear_state_def(int state);
137  bool has_state_def(int state) const;
138  NodePath &get_state_def(int state);
139  MAKE_SEQ(get_state_defs, get_num_state_defs, get_state_def);
140  NodePath instance_to_state_def(int state, const NodePath &path);
141 
142  PGFrameStyle get_frame_style(int state);
143  void set_frame_style(int state, const PGFrameStyle &style);
144 
145  INLINE const string &get_id() const;
146  INLINE void set_id(const string &id);
147 
148  INLINE static string get_enter_prefix();
149  INLINE static string get_exit_prefix();
150  INLINE static string get_within_prefix();
151  INLINE static string get_without_prefix();
152  INLINE static string get_focus_in_prefix();
153  INLINE static string get_focus_out_prefix();
154  INLINE static string get_press_prefix();
155  INLINE static string get_repeat_prefix();
156  INLINE static string get_release_prefix();
157  INLINE static string get_keystroke_prefix();
158 
159  INLINE string get_enter_event() const;
160  INLINE string get_exit_event() const;
161  INLINE string get_within_event() const;
162  INLINE string get_without_event() const;
163  INLINE string get_focus_in_event() const;
164  INLINE string get_focus_out_event() const;
165  INLINE string get_press_event(const ButtonHandle &button) const;
166  INLINE string get_repeat_event(const ButtonHandle &button) const;
167  INLINE string get_release_event(const ButtonHandle &button) const;
168  INLINE string get_keystroke_event() const;
169 
170  INLINE LMatrix4 get_frame_inv_xform() const;
171 
172 #ifdef HAVE_AUDIO
173  void set_sound(const string &event, AudioSound *sound);
174  void clear_sound(const string &event);
175  AudioSound *get_sound(const string &event) const;
176  bool has_sound(const string &event) const;
177 #endif
178 
179  static TextNode *get_text_node();
180  INLINE static void set_text_node(TextNode *node);
181 
182  INLINE static PGItem *get_focus_item();
183 
184 protected:
185  void play_sound(const string &event);
186 
187  void reduce_region(LVecBase4 &clip, PGItem *obscurer) const;
188  void reduce_region(LVecBase4 &frame, PN_stdfloat px, PN_stdfloat py) const;
189  LVecBase4 get_relative_frame(PGItem *item) const;
190  LPoint3 mouse_to_local(const LPoint2 &mouse_point) const;
191 
192  virtual void frame_changed();
193 
194 private:
195  void slot_state_def(int state);
196  void update_frame(int state);
197  void mark_frames_stale();
198 
199  INLINE static PN_stdfloat compute_area(const LVecBase4 &frame);
200  INLINE static void compare_largest(const LVecBase4 *&largest,
201  PN_stdfloat &largest_area,
202  const LVecBase4 *new_frame);
203 
205  bool clip_frame(ClipPoints &source_points, const LPlane &plane) const;
206 
207 protected:
208  LightReMutex _lock;
209 
210 private:
211  PGItemNotify *_notify;
212 
213  bool _has_frame;
214  LVecBase4 _frame;
215  int _state;
216  enum Flags {
217  F_active = 0x01,
218  F_focus = 0x02,
219  F_background_focus = 0x04,
220  };
221  int _flags;
222 
223  PT(PGMouseWatcherRegion) _region;
224 
225  LMatrix4 _frame_inv_xform;
226 
227  class StateDef {
228  public:
229  INLINE StateDef();
230  NodePath _root;
231  PGFrameStyle _frame_style;
232  NodePath _frame;
233  bool _frame_stale;
234  };
236  StateDefs _state_defs;
237 
238 #ifdef HAVE_AUDIO
239  typedef pmap<string, PT(AudioSound) > Sounds;
240  Sounds _sounds;
241 #endif
242 
243  static PT(TextNode) _text_node;
244  static PGItem *_focus_item;
245 
247  static BackgroundFocus _background_focus;
248 
249 public:
250  static TypeHandle get_class_type() {
251  return _type_handle;
252  }
253  static void init_type() {
254  PandaNode::init_type();
255  register_type(_type_handle, "PGItem",
256  PandaNode::get_class_type());
257  }
258  virtual TypeHandle get_type() const {
259  return get_class_type();
260  }
261  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
262 
263 private:
264  static TypeHandle _type_handle;
265 };
266 
267 #include "pgItem.I"
268 
269 #endif
The &quot;top&quot; node of the new Panda GUI system.
Definition: pgTop.h:43
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
This is the base class for all the various kinds of gui widget objects.
Definition: pgItem.h:58
A lightweight reentrant mutex.
Definition: lightReMutex.h:34
This collects together the pieces of data that are accumulated for each node while walking the scene ...
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:604
This functions similarly to a LightAttrib.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
virtual void r_prepare_scene(GraphicsStateGuardianBase *gsg, const RenderState *node_state, GeomTransformer &transformer, Thread *current_thread)
The recursive implementation of prepare_scene().
Definition: pandaNode.cxx:2925
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this PandaNode by the indicated matrix, if it means anything to do so...
Definition: pandaNode.cxx:377
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
void set_state(const RenderState *state, Thread *current_thread=Thread::get_current_thread())
Sets the complete RenderState that will be applied to all nodes at this level and below...
Definition: pandaNode.cxx:1216
This is a specialization on MouseWatcherRegion, to add a bit more fields that are relevant to the PG ...
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
Definition: pandaNode.cxx:578
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A thread; that is, a lightweight process.
Definition: thread.h:51
The primary interface to this module.
Definition: textNode.h:52
This restricts rendering to within a rectangular region of the scene, without otherwise affecting the...
Definition: scissorAttrib.h:41
Objects that inherit from this class can receive specialized messages when PGItems change in certain ...
Definition: pgItemNotify.h:30
This is a two-component point in space.
Definition: lpoint2.h:92
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
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:165
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
Definition: pandaNode.cxx:477
An object specifically designed to transform the vertices of a Geom without disturbing indexing or af...