Debian Codegraph @

lib/database/src/so/elements/SoViewportRegionElement.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1990,91 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.1.1.1 $
44 |
45 | Classes:
46 | SoViewportRegionElement
47 |
48 | Author(s) : Paul S. Strauss
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54 #include <Inventor/elements/SoViewportRegionElement.h>
55
56 SbViewportRegion *SoViewportRegionElement::emptyViewportRegion;
57
58 SO_ELEMENT_SOURCE(SoViewportRegionElement);
59
60 ////////////////////////////////////////////////////////////////////////
61 //
62 // Description:
63 // Destructor.
64 //
65 // Use: private
66
67 SoViewportRegionElement::~SoViewportRegionElement()
68 //
69 ////////////////////////////////////////////////////////////////////////
70 {
71 }
72
73 ////////////////////////////////////////////////////////////////////////
74 //
75 // Description:
76 // Initializes element
77 //
78 // Use: public
79
80 void
81 SoViewportRegionElement::init(SoState *)
82 //
83 ////////////////////////////////////////////////////////////////////////
84 {
85 // Choose a reasonable default window size
86 viewportRegion.setWindowSize(100, 100);
87 }
88
89 ////////////////////////////////////////////////////////////////////////
90 //
91 // Description:
92 // Sets viewport region to given matrix in element accessed from state.
93 //
94 // Use: public, static
95
96 void
97 SoViewportRegionElement::set(SoState *state,
98 const SbViewportRegion &vpReg)
99 //
100 ////////////////////////////////////////////////////////////////////////
101 {
102 SoViewportRegionElement *elt;
103
104 // Get an instance we can change (pushing if necessary)
105 elt = (SoViewportRegionElement *) getElement(state, classStackIndex);
106
107 if (elt != NULL)
108 elt->setElt(vpReg);
109 }
110
111 ////////////////////////////////////////////////////////////////////////
112 //
113 // Description:
114 // Returns viewport region from state.
115 //
116 // Use: public, static
117
118 const SbViewportRegion &
119 SoViewportRegionElement::get(SoState *state)
120 //
121 ////////////////////////////////////////////////////////////////////////
122 {
123 const SoViewportRegionElement *elt;
124
125 elt = (const SoViewportRegionElement *)
126 getConstElement(state, classStackIndex);
127 if (elt != NULL )
128 return elt->viewportRegion;
129 else
130 return *emptyViewportRegion;
131 }
132
133 ////////////////////////////////////////////////////////////////////////
134 //
135 // Description:
136 // Returns TRUE if viewport regions are the same -- if they have
137 // the same size and origin.
138 //
139 // Use: public
140
141 SbBool
142 SoViewportRegionElement::matches(const SoElement *elt) const
143 //
144 ////////////////////////////////////////////////////////////////////////
145 {
146 return (viewportRegion ==
147 ((const SoViewportRegionElement *) elt)->viewportRegion);
148 }
149
150 ////////////////////////////////////////////////////////////////////////
151 //
152 // Description:
153 // Create a copy of this instance suitable for calling matches()
154 // on.
155 //
156 // Use: protected
157
158 SoElement *
159 SoViewportRegionElement::copyMatchInfo() const
160 //
161 ////////////////////////////////////////////////////////////////////////
162 {
163 SoViewportRegionElement *result =
164 (SoViewportRegionElement *)getTypeId().createInstance();
165
166 result->viewportRegion = viewportRegion;
167
168 return result;
169 }
170
171 ////////////////////////////////////////////////////////////////////////
172 //
173 // Description:
174 // Prints element for debugging.
175 //
176 // Use: public
177 //
178 ////////////////////////////////////////////////////////////////////////
179
180 #ifdef DEBUG
181 void
182 SoViewportRegionElement::print(FILE *fp) const
183 {
184 SoElement::print(fp);
185
186 fprintf(fp, "\tViewport Region:\n");
187
188 const SbVec2s &winSize = viewportRegion.getWindowSize();
189 const SbVec2f &vpOrig = viewportRegion.getViewportOrigin();
190 const SbVec2f &vpSize = viewportRegion.getViewportSize();
191
192 fprintf(fp, "\t\tWindow size = %d, %d\n", winSize[0], winSize[1]);
193 fprintf(fp, "\t\tViewport origin = %g, %g\n", vpOrig[0], vpOrig[1]);
194 fprintf(fp, "\t\tViewport size = %g, %g\n", vpSize[0], vpSize[1]);
195 }
196 #else /* DEBUG */
197 void
198 SoViewportRegionElement::print(FILE *) const
199 {
200 }
201 #endif /* DEBUG */
202
203 ////////////////////////////////////////////////////////////////////////
204 //
205 // Description:
206 // Sets viewport region in element to given viewport region.
207 //
208 // Use: protected, virtual
209
210 void
211 SoViewportRegionElement::setElt(const SbViewportRegion &vpReg)
212 //
213 ////////////////////////////////////////////////////////////////////////
214 {
215 viewportRegion = vpReg;
216 }