Open Inventor Reference
SbViewportRegion.h
Go to the documentation of this file.
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 /*
39  * Copyright (C) 1990,91 Silicon Graphics, Inc.
40  *
41  _______________________________________________________________________
42  ______________ S I L I C O N G R A P H I C S I N C . ____________
43  |
44  | $Revision: 1.1.1.1 $
45  |
46  | Description:
47  | This file contains the SbViewportRegion class definition.
48  |
49  | Author(s) : Paul S. Strauss
50  |
51  ______________ S I L I C O N G R A P H I C S I N C . ____________
52  _______________________________________________________________________
53  */
54 
55 #ifndef _SB_VIEWPORT_REGION_
56 #define _SB_VIEWPORT_REGION_
57 
59 
60 
61 #include <Inventor/SbLinear.h>
62 
65 
81 
83  public:
84 
87 
89  SbViewportRegion(short width, short height);
90 
93 
96 
98  void setWindowSize(short width, short height)
99  { setWindowSize(SbVec2s(width, height)); }
100 
103  void setWindowSize(SbVec2s winSize);
104 
107  void setViewport(float left, float bottom,
108  float width, float height)
109  { setViewport(SbVec2f(left, bottom), SbVec2f(width, height)); }
110 
113  void setViewport(SbVec2f origin, SbVec2f size);
114 
117  void setViewportPixels(short left, short bottom,
118  short width, short height)
119  { setViewportPixels(SbVec2s(left, bottom), SbVec2s(width, height)); }
120 
123  void setViewportPixels(SbVec2s origin, SbVec2s size);
124 
126  const SbVec2s & getWindowSize() const { return windowSize; }
127 
129  const SbVec2f & getViewportOrigin() const { return vpOrigin; }
130 
132  const SbVec2s & getViewportOriginPixels() const { return vpOriginPix; }
133 
135  const SbVec2f & getViewportSize() const { return vpSize; }
136 
138  const SbVec2s & getViewportSizePixels() const { return vpSizePix;}
139 
142  { return (vpSizePix[1] == 0 ? 1.0f :
143  (float) vpSizePix[0] / (float) vpSizePix[1]); }
144 
148  void scaleWidth(float ratio);
152  void scaleHeight(float ratio);
153 
157  void setPixelsPerInch(float ppi) { pixelsPerInch = ppi; }
158  float getPixelsPerInch() const { return pixelsPerInch; }
159 
161  float getPixelsPerPoint() const
162  { return pixelsPerInch / 72.0f; }
163 
165  friend bool operator ==(const SbViewportRegion &reg1,
166  const SbViewportRegion &reg2);
167 
168  private:
169  SbVec2s windowSize;
170  SbVec2f vpOrigin;
171  SbVec2s vpOriginPix;
172  SbVec2f vpSize;
173  SbVec2s vpSizePix;
174  bool vpSet;
175  float pixelsPerInch;
176 
178  void setFullViewport();
179 
181  void adjustViewport();
182 };
183 
184 #endif /* _SB_VIEWPORT_REGION_ */
INVENTOR_API bool operator==(const SbBox3f &b1, const SbBox3f &b2)
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition: SbSystem.h:81
2D vector class.
Definition: SbLinear.h:246
2D vector class.
Definition: SbLinear.h:354
Class for representing a viewport.
const SbVec2f & getViewportOrigin() const
Returns viewport origin in normalized coordinates.
SbViewportRegion()
Constructors of various kinds.
void setWindowSize(short width, short height)
Changes window size to given width and height in pixels.
void scaleWidth(float ratio)
Scales viewport within window to be the given ratio of its current width, leaving the resulting viewp...
void setPixelsPerInch(float ppi)
Sets/returns the pixel-per-inch ratio for the display device the viewport is part of.
float getPixelsPerPoint() const
Convenience function that returns number of pixels per printer's point.
void setViewportPixels(short left, short bottom, short width, short height)
Sets viewport to given region, specified as pixel coordinates in window: (0,0) is the lower-left corn...
float getPixelsPerInch() const
const SbVec2f & getViewportSize() const
Returns viewport size in normalized coordinates.
void setWindowSize(SbVec2s winSize)
Changes window size to given width and height in pixels, given as SbVec2s.
SbViewportRegion(const SbViewportRegion &vpReg)
Constructors of various kinds.
SbViewportRegion(SbVec2s winSize)
Constructors of various kinds.
void setViewportPixels(SbVec2s origin, SbVec2s size)
Sets viewport to region with given origin (lower-left corner) and size, given as pixel coordinates.
const SbVec2s & getViewportOriginPixels() const
Returns viewport origin in pixels.
const SbVec2s & getViewportSizePixels() const
Returns viewport size in pixels.
void scaleHeight(float ratio)
Scales viewport within window to be the given ratio of its current height, leaving the resulting view...
const SbVec2s & getWindowSize() const
Returns window size in pixels.
float getViewportAspectRatio() const
Returns aspect ratio (width/height) of viewport.
void setViewport(SbVec2f origin, SbVec2f size)
Sets viewport to region with given origin (lower-left corner) and size, given as normalized coordinat...
void setViewport(float left, float bottom, float width, float height)
Sets viewport to given region, specified as normalized window coordinates: (0,0) is the lower-left co...
SbViewportRegion(short width, short height)
Constructors of various kinds.