Line data Source code
1 :
2 : /* Copyright (c) 2009-2016, 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 : #include <eq/fabric/vmmlib.h>
24 :
25 : namespace eq
26 : {
27 : namespace fabric
28 : {
29 : /**
30 : * A zoom specification with methods for manipulation.
31 : *
32 : * The x, y paramenters determine the factor by which the channel's rendering is
33 : * zoomed.
34 : */
35 7238 : class Zoom : public Vector2f
36 : {
37 : public:
38 : /** Construct a new zoom specification set to 1, 1. @version 1.0 */
39 21915 : Zoom() : Vector2f( 1.f, 1.f ) {}
40 :
41 : /** Construct a new zoom specification with default values. @version 1.0 */
42 2784 : Zoom( const float x_, const float y_ ) : Vector2f( x_, y_ ) {}
43 : //@}
44 :
45 : /** @internal @return true if this zoom defines a valid zoom factor. */
46 2419 : bool isValid() const { return ( x() != 0.f && y() != 0.f ); }
47 :
48 : /** @internal Enforce the zoom to be valid. */
49 4 : void validate()
50 : {
51 4 : if( x() == 0.f ) x() = 1.f;
52 4 : if( y() == 0.f ) y() = 1.f;
53 4 : }
54 :
55 : /** @internal Make the zoom factor invalid. */
56 : void invalidate() { x() = y() = 0.f; }
57 :
58 : /** @internal Apply an additional zoom factor to this zoom. */
59 126 : void apply( const Zoom& rhs )
60 : {
61 126 : x() *= rhs.x();
62 126 : y() *= rhs.y();
63 126 : }
64 :
65 : /** The zoom NONE (1,1) value. */
66 : EQFABRIC_API static const Zoom NONE;
67 : };
68 :
69 1 : inline std::ostream& operator << ( std::ostream& os, const Zoom& zoom )
70 : {
71 1 : if( zoom.isValid( ))
72 1 : os << "zoom [ " << zoom.x() << ' ' << zoom.y() << " ]";
73 1 : return os;
74 : }
75 : }
76 : }
77 : namespace lunchbox
78 : {
79 0 : template<> inline void byteswap( eq::fabric::Zoom& value )
80 0 : { byteswap< eq::fabric::Vector2f >( value ); }
81 : }
82 : #endif // EQFABRIC_ZOOM_H
|