Panda3D
 All Classes Functions Variables Enumerations
pgVirtualFrame.cxx
1 // Filename: pgVirtualFrame.cxx
2 // Created by: drose (17Aug05)
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 #include "pgVirtualFrame.h"
16 #include "scissorEffect.h"
17 #include "sceneGraphReducer.h"
18 
19 TypeHandle PGVirtualFrame::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: PGVirtualFrame::Constructor
23 // Access: Published
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 PGVirtualFrame::
27 PGVirtualFrame(const string &name) : PGItem(name)
28 {
29  _has_clip_frame = false;
30  _clip_frame.set(0.0f, 0.0f, 0.0f, 0.0f);
31 
32  setup_child_nodes();
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: PGVirtualFrame::Destructor
37 // Access: Public, Virtual
38 // Description:
39 ////////////////////////////////////////////////////////////////////
40 PGVirtualFrame::
41 ~PGVirtualFrame() {
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: PGVirtualFrame::Copy Constructor
46 // Access: Protected
47 // Description:
48 ////////////////////////////////////////////////////////////////////
49 PGVirtualFrame::
50 PGVirtualFrame(const PGVirtualFrame &copy) :
51  PGItem(copy),
52  _has_clip_frame(copy._has_clip_frame),
53  _clip_frame(copy._clip_frame)
54 {
55  setup_child_nodes();
56 
57  // Reassign the clip planes according to the clip frame.
58  if (_has_clip_frame) {
59  set_clip_frame(_clip_frame);
60  } else {
61  clear_clip_frame();
62  }
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: PGVirtualFrame::make_copy
67 // Access: Public, Virtual
68 // Description: Returns a newly-allocated Node that is a shallow copy
69 // of this one. It will be a different Node pointer,
70 // but its internal data may or may not be shared with
71 // that of the original Node.
72 ////////////////////////////////////////////////////////////////////
73 PandaNode *PGVirtualFrame::
74 make_copy() const {
75  LightReMutexHolder holder(_lock);
76  return new PGVirtualFrame(*this);
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: PGVirtualFrame::r_copy_children
81 // Access: Protected, Virtual
82 // Description: This is called by r_copy_subgraph(); the copy has
83 // already been made of this particular node (and this
84 // is the copy); this function's job is to copy all of
85 // the children from the original.
86 //
87 // Note that it includes the parameter inst_map, which
88 // is a map type, and is not (and cannot be) exported
89 // from PANDA.DLL. Thus, any derivative of PandaNode
90 // that is not also a member of PANDA.DLL *cannot*
91 // access this map, and probably should not even
92 // override this function.
93 ////////////////////////////////////////////////////////////////////
94 void PGVirtualFrame::
95 r_copy_children(const PandaNode *from, PandaNode::InstanceMap &inst_map,
96  Thread *current_thread) {
97  LightReMutexHolder holder(_lock);
98  PandaNode::r_copy_children(from, inst_map, current_thread);
99 
100  // Reassign the canvas_node to point to the new copy, if it's there.
101  const PGVirtualFrame *from_frame = DCAST(PGVirtualFrame, from);
102  PandaNode *from_canvas_node = from_frame->get_canvas_node();
103  PandaNode *from_canvas_parent = from_frame->get_canvas_parent();
104 
105  InstanceMap::const_iterator ci;
106  ci = inst_map.find(from_canvas_node);
107  if (ci != inst_map.end()) {
108  remove_child(_canvas_node);
109  _canvas_node = DCAST(ModelNode, (*ci).second);
110  }
111 
112  ci = inst_map.find(from_canvas_parent);
113  if (ci != inst_map.end()) {
114  remove_child(_canvas_parent);
115  _canvas_parent = DCAST(ModelNode, (*ci).second);
116  }
117 
118  // Reassign the clip planes according to the clip frame.
119  if (_has_clip_frame) {
120  set_clip_frame(_clip_frame);
121  } else {
123  }
124 }
125 
126 ////////////////////////////////////////////////////////////////////
127 // Function: PGVirtualFrame::setup
128 // Access: Published
129 // Description: Creates a PGVirtualFrame with the indicated
130 // dimensions.
131 ////////////////////////////////////////////////////////////////////
132 void PGVirtualFrame::
133 setup(PN_stdfloat width, PN_stdfloat height) {
134  LightReMutexHolder holder(_lock);
135  set_state(0);
136  clear_state_def(0);
137 
138  set_frame(0, width, 0, height);
139 
140  PN_stdfloat bevel = 0.05f;
141 
142  PGFrameStyle style;
143  style.set_width(bevel, bevel);
144 
145  style.set_color(0.8f, 0.8f, 0.8f, 1.0f);
146  style.set_type(PGFrameStyle::T_bevel_out);
147  set_frame_style(0, style);
148 
149  set_clip_frame(bevel, width - 2 * bevel,
150  bevel, height - 2 * bevel);
151 }
152 
153 ////////////////////////////////////////////////////////////////////
154 // Function: PGVirtualFrame::set_clip_frame
155 // Access: Published
156 // Description: Sets the bounding rectangle of the clip frame.
157 // This is the size of the small window through which we
158 // can see the virtual canvas. Normally, this is the
159 // same size as the actual frame or smaller (typically
160 // it is smaller by the size of the bevel, or to make
161 // room for scroll bars).
162 ////////////////////////////////////////////////////////////////////
163 void PGVirtualFrame::
164 set_clip_frame(const LVecBase4 &frame) {
165  LightReMutexHolder holder(_lock);
166  if (!_has_clip_frame || _clip_frame != frame) {
167  _has_clip_frame = true;
168  _clip_frame = frame;
169 
170  CPT(RenderEffect) scissor_effect = ScissorEffect::make_node
171  (LPoint3(_clip_frame[0], _clip_frame[2], _clip_frame[2]),
172  LPoint3(_clip_frame[1], _clip_frame[2], _clip_frame[2]),
173  LPoint3(_clip_frame[1], _clip_frame[3], _clip_frame[3]),
174  LPoint3(_clip_frame[0], _clip_frame[3], _clip_frame[3]));
175 
176  _canvas_parent->set_effect(scissor_effect);
177  clip_frame_changed();
178  }
179 }
180 
181 ////////////////////////////////////////////////////////////////////
182 // Function: PGVirtualFrame::clear_clip_frame
183 // Access: Published
184 // Description: Removes the clip frame from the item. This
185 // disables clipping.
186 ////////////////////////////////////////////////////////////////////
187 void PGVirtualFrame::
189  LightReMutexHolder holder(_lock);
190  if (_has_clip_frame) {
191  _has_clip_frame = false;
192 
193  _canvas_parent->clear_effect(ScissorEffect::get_class_type());
194  clip_frame_changed();
195  }
196 }
197 
198 ////////////////////////////////////////////////////////////////////
199 // Function: PGVirtualFrame::clip_frame_changed
200 // Access: Protected, Virtual
201 // Description: Called when the user changes the clip_frame size.
202 ////////////////////////////////////////////////////////////////////
203 void PGVirtualFrame::
204 clip_frame_changed() {
205 }
206 
207 ////////////////////////////////////////////////////////////////////
208 // Function: PGVirtualFrame::setup_child_nodes
209 // Access: Private
210 // Description: Creates the special canvas_node and canvas_parent
211 // for this object.
212 ////////////////////////////////////////////////////////////////////
213 void PGVirtualFrame::
214 setup_child_nodes() {
215  _canvas_parent = new ModelNode("canvas_parent");
216  _canvas_parent->set_preserve_transform(ModelNode::PT_local);
217  add_child(_canvas_parent);
218 
219  _canvas_node = new ModelNode("canvas");
220  _canvas_node->set_preserve_transform(ModelNode::PT_local);
221  _canvas_parent->add_child(_canvas_node);
222 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
void set_width(PN_stdfloat x, PN_stdfloat y)
Sets the width parameter, which has meaning only for certain frame types.
Definition: pgFrameStyle.I:172
void remove_child(int child_index, Thread *current_thread=Thread::get_current_thread())
Removes the nth child from the node.
Definition: pandaNode.cxx:697
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
This represents a frame that is rendered as a window onto another (possibly much larger) canvas...
void set_clip_frame(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top)
Sets the bounding rectangle of the clip frame.
void set_type(Type type)
Sets the basic type of frame.
Definition: pgFrameStyle.I:76
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:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This is the base class for a number of special render effects that may be set on scene graph nodes to...
Definition: renderEffect.h:56
PandaNode * get_canvas_parent() const
Returns the parent node of the canvas_node.
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:1102
This node is placed at key points within the scene graph to indicate the roots of "models": subtrees ...
Definition: modelNode.h:34
void clear_clip_frame()
Removes the clip frame from the item.
void set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a)
Sets the dominant color of the frame.
Definition: pgFrameStyle.I:96
void setup(PN_stdfloat width, PN_stdfloat height)
Creates a PGVirtualFrame with the indicated dimensions.
Similar to MutexHolder, but for a light reentrant mutex.
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
void set_state(int state)
Sets the "state" of this particular PGItem.
Definition: pgItem.I:175
PandaNode * get_canvas_node() const
Returns the special node that holds all of the children that appear in the virtual canvas...
A thread; that is, a lightweight process.
Definition: thread.h:51
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:1021
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
void add_child(PandaNode *child_node, int sort=0, Thread *current_thread=Thread::get_current_thread())
Adds a new child to the node.
Definition: pandaNode.cxx:654