Line data Source code
1 :
2 : /* Copyright (c) 2009-2012, Stefan Eilemann <eile@equalizergraphics.com>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #ifndef EQFABRIC_ZOOM_H
19 : #define EQFABRIC_ZOOM_H
20 :
21 : #include <eq/fabric/api.h>
22 : #include <eq/fabric/types.h>
23 :
24 : namespace eq
25 : {
26 : namespace fabric
27 : {
28 : /**
29 : * A zoom specification with methods for manipulation.
30 : *
31 : * The x, y paramenters determine the factor by which the channel's
32 : * rendering is zoomed.
33 : */
34 4975 : class Zoom : public Vector2f
35 : {
36 : public:
37 : /** Construct a new zoom specification set to 1, 1. @version 1.0 */
38 19972 : Zoom() : Vector2f( 1.f, 1.f ) {}
39 :
40 : /**
41 : * Construct a new zoom specification with default values.
42 : * @version 1.0
43 : */
44 2926 : Zoom( const float x_, const float y_ ) : Vector2f( x_, y_ ) {}
45 : //@}
46 :
47 : /** @return true if this zoom defines a valid zoom factor. @internal */
48 3611 : bool isValid() const { return ( x() != 0.f && y() != 0.f ); }
49 :
50 : /** Enforce the zoom to be valid. @internal */
51 1363 : void validate()
52 : {
53 1363 : if( x() == 0.f ) x() = 1.f;
54 1363 : if( y() == 0.f ) y() = 1.f;
55 1363 : }
56 :
57 : /** Make the zoom factor invalid. @internal */
58 : void invalidate() { x() = y() = 0.f; }
59 :
60 : /** Apply an additional zoom factor to this zoom. @internal */
61 4 : void apply( const Zoom& rhs )
62 : {
63 4 : x() *= rhs.x();
64 4 : y() *= rhs.y();
65 4 : }
66 :
67 : /** The zoom NONE (1,1) value. */
68 : EQFABRIC_API static const Zoom NONE;
69 : };
70 :
71 1 : inline std::ostream& operator << ( std::ostream& os, const Zoom& zoom )
72 : {
73 1 : if( zoom.isValid( ))
74 1 : os << "zoom [ " << zoom.x() << ' ' << zoom.y() << " ]";
75 1 : return os;
76 : }
77 : }
78 : }
79 : namespace lunchbox
80 : {
81 0 : template<> inline void byteswap( eq::fabric::Zoom& value )
82 0 : { byteswap< eq::fabric::Vector2f >( value ); }
83 : }
84 : #endif // EQFABRIC_ZOOM_H
|