Panda3D
Loading...
Searching...
No Matches
pgVirtualFrame.cxx
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 pgVirtualFrame.cxx
10 * @author drose
11 * @date 2005-08-17
12 */
13
14#include "pgVirtualFrame.h"
15#include "scissorEffect.h"
16#include "sceneGraphReducer.h"
17
18TypeHandle PGVirtualFrame::_type_handle;
19
20/**
21 *
22 */
23PGVirtualFrame::
24PGVirtualFrame(const std::string &name) : PGItem(name)
25{
26 _has_clip_frame = false;
27 _clip_frame.set(0.0f, 0.0f, 0.0f, 0.0f);
28
29 setup_child_nodes();
30}
31
32/**
33 *
34 */
35PGVirtualFrame::
36~PGVirtualFrame() {
37}
38
39/**
40 *
41 */
42PGVirtualFrame::
43PGVirtualFrame(const PGVirtualFrame &copy) :
44 PGItem(copy),
45 _has_clip_frame(copy._has_clip_frame),
46 _clip_frame(copy._clip_frame)
47{
48 setup_child_nodes();
49
50 // Reassign the clip planes according to the clip frame.
51 if (_has_clip_frame) {
52 set_clip_frame(_clip_frame);
53 } else {
54 clear_clip_frame();
55 }
56}
57
58/**
59 * Returns a newly-allocated Node that is a shallow copy of this one. It will
60 * be a different Node pointer, but its internal data may or may not be shared
61 * with that of the original Node.
62 */
63PandaNode *PGVirtualFrame::
64make_copy() const {
65 LightReMutexHolder holder(_lock);
66 return new PGVirtualFrame(*this);
67}
68
69/**
70 * This is called by r_copy_subgraph(); the copy has already been made of this
71 * particular node (and this is the copy); this function's job is to copy all
72 * of the children from the original.
73 *
74 * Note that it includes the parameter inst_map, which is a map type, and is
75 * not (and cannot be) exported from PANDA.DLL. Thus, any derivative of
76 * PandaNode that is not also a member of PANDA.DLL *cannot* access this map,
77 * and probably should not even override this function.
78 */
79void PGVirtualFrame::
80r_copy_children(const PandaNode *from, PandaNode::InstanceMap &inst_map,
81 Thread *current_thread) {
82 LightReMutexHolder holder(_lock);
83 PandaNode::r_copy_children(from, inst_map, current_thread);
84
85 // Reassign the canvas_node to point to the new copy, if it's there.
86 const PGVirtualFrame *from_frame = DCAST(PGVirtualFrame, from);
87 PandaNode *from_canvas_node = from_frame->get_canvas_node();
88 PandaNode *from_canvas_parent = from_frame->get_canvas_parent();
89
90 InstanceMap::const_iterator ci;
91 ci = inst_map.find(from_canvas_node);
92 if (ci != inst_map.end()) {
93 remove_child(_canvas_node);
94 _canvas_node = DCAST(ModelNode, (*ci).second);
95 }
96
97 ci = inst_map.find(from_canvas_parent);
98 if (ci != inst_map.end()) {
99 remove_child(_canvas_parent);
100 _canvas_parent = DCAST(ModelNode, (*ci).second);
101 }
102
103 // Reassign the clip planes according to the clip frame.
104 if (_has_clip_frame) {
105 set_clip_frame(_clip_frame);
106 } else {
108 }
109}
110
111/**
112 * Creates a PGVirtualFrame with the indicated dimensions.
113 */
115setup(PN_stdfloat width, PN_stdfloat height) {
116 LightReMutexHolder holder(_lock);
117 set_state(0);
119
120 set_frame(0, width, 0, height);
121
122 PN_stdfloat bevel = 0.05f;
123
124 PGFrameStyle style;
125 style.set_width(bevel, bevel);
126
127 style.set_color(0.8f, 0.8f, 0.8f, 1.0f);
128 style.set_type(PGFrameStyle::T_bevel_out);
129 set_frame_style(0, style);
130
131 set_clip_frame(bevel, width - 2 * bevel,
132 bevel, height - 2 * bevel);
133}
134
135/**
136 * Sets the bounding rectangle of the clip frame. This is the size of the
137 * small window through which we can see the virtual canvas. Normally, this
138 * is the same size as the actual frame or smaller (typically it is smaller by
139 * the size of the bevel, or to make room for scroll bars).
140 */
142set_clip_frame(const LVecBase4 &frame) {
143 LightReMutexHolder holder(_lock);
144 if (!_has_clip_frame || _clip_frame != frame) {
145 _has_clip_frame = true;
146 _clip_frame = frame;
147
148 CPT(RenderEffect) scissor_effect = ScissorEffect::make_node
149 (LPoint3(_clip_frame[0], _clip_frame[2], _clip_frame[2]),
150 LPoint3(_clip_frame[1], _clip_frame[2], _clip_frame[2]),
151 LPoint3(_clip_frame[1], _clip_frame[3], _clip_frame[3]),
152 LPoint3(_clip_frame[0], _clip_frame[3], _clip_frame[3]));
153
154 _canvas_parent->set_effect(scissor_effect);
155 clip_frame_changed();
156 }
157}
158
159/**
160 * Removes the clip frame from the item. This disables clipping.
161 */
164 LightReMutexHolder holder(_lock);
165 if (_has_clip_frame) {
166 _has_clip_frame = false;
167
168 _canvas_parent->clear_effect(ScissorEffect::get_class_type());
169 clip_frame_changed();
170 }
171}
172
173/**
174 * Called when the user changes the clip_frame size.
175 */
176void PGVirtualFrame::
177clip_frame_changed() {
178}
179
180/**
181 * Creates the special canvas_node and canvas_parent for this object.
182 */
183void PGVirtualFrame::
184setup_child_nodes() {
185 _canvas_parent = new ModelNode("canvas_parent");
186 _canvas_parent->set_preserve_transform(ModelNode::PT_local);
187 add_child(_canvas_parent);
188
189 _canvas_node = new ModelNode("canvas");
190 _canvas_node->set_preserve_transform(ModelNode::PT_local);
191 _canvas_parent->add_child(_canvas_node);
192}
Similar to MutexHolder, but for a light reentrant mutex.
This node is placed at key points within the scene graph to indicate the roots of "models": subtrees ...
Definition modelNode.h:31
void set_type(Type type)
Sets the basic type of frame.
void set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a)
Sets the dominant color of the frame.
void set_width(PN_stdfloat x, PN_stdfloat y)
Sets the width parameter, which has meaning only for certain frame types.
This is the base class for all the various kinds of gui widget objects.
Definition pgItem.h:53
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:1007
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:953
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
This represents a frame that is rendered as a window onto another (possibly much larger) canvas.
PandaNode * get_canvas_parent() const
Returns the parent node of the canvas_node.
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 clear_clip_frame()
Removes the clip frame from the item.
PandaNode * get_canvas_node() const
Returns the special node that holds all of the children that appear in the virtual canvas.
void setup(PN_stdfloat width, PN_stdfloat height)
Creates a PGVirtualFrame with the indicated dimensions.
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
void remove_child(int child_index, Thread *current_thread=Thread::get_current_thread())
Removes the nth child from the node.
set_state
Sets the complete RenderState that will be applied to all nodes at this level and below.
Definition pandaNode.h:173
This is the base class for a number of special render effects that may be set on scene graph nodes to...
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.