Line data Source code
1 :
2 : /* Copyright (c) 2009-2017, 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 6478 : class Zoom : public Vector2f
36 : {
37 : public:
38 : /** Construct a new zoom specification set to 1, 1. @version 1.0 */
39 15686 : Zoom()
40 15686 : : Vector2f(1.f, 1.f)
41 : {
42 15686 : }
43 :
44 : /** Construct a new zoom specification with default values. @version 1.0 */
45 2776 : Zoom(const float x_, const float y_)
46 2776 : : Vector2f(x_, y_)
47 : {
48 2776 : }
49 : //@}
50 :
51 : /** @internal @return true if this zoom defines a valid zoom factor. */
52 2595 : bool isValid() const { return (x() != 0.f && y() != 0.f); }
53 : /** @internal Enforce the zoom to be valid. */
54 660 : void validate()
55 : {
56 660 : if (x() == 0.f)
57 0 : x() = 1.f;
58 660 : if (y() == 0.f)
59 0 : y() = 1.f;
60 660 : }
61 :
62 : /** @internal Make the zoom factor invalid. */
63 : void invalidate() { x() = y() = 0.f; }
64 : /** @internal Apply an additional zoom factor to this zoom. */
65 128 : void apply(const Zoom& rhs)
66 : {
67 128 : x() *= rhs.x();
68 128 : y() *= rhs.y();
69 128 : }
70 :
71 : /** The zoom NONE (1,1) value. */
72 : EQFABRIC_API static const Zoom NONE;
73 : };
74 :
75 1 : inline std::ostream& operator<<(std::ostream& os, const Zoom& zoom)
76 : {
77 1 : if (zoom.isValid())
78 1 : os << "zoom [ " << zoom.x() << ' ' << zoom.y() << " ]";
79 1 : return os;
80 : }
81 : }
82 : }
83 :
84 : #endif // EQFABRIC_ZOOM_H
|