supertux
viewport.hpp
1 // SuperTux
2 // Copyright (C) 2016 Ingo Ruhnke <grumbel@gmail.com>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_VIDEO_VIEWPORT_HPP
18 #define HEADER_SUPERTUX_VIDEO_VIEWPORT_HPP
19 
20 #include "math/rect.hpp"
21 #include "math/vector.hpp"
22 
23 class Viewport final
24 {
25 private:
26 public:
27  static Viewport from_size(const Size& target_size, const Size& desktop_size);
28 
29 public:
30  Viewport();
31  Viewport(const Rect& rect, const Vector& scale);
32 
34  Rect get_rect() const { return m_rect; }
35 
37  Vector get_scale() const { return m_scale; }
38 
40  int get_screen_width() const;
41 
43  int get_screen_height() const;
44 
46  Size get_screen_size() const;
47 
49  Vector to_logical(int physical_x, int physical_y) const;
50 
52  bool needs_clear_screen() const;
53 
54 private:
56  static const Size s_max_size;
57 
59  static const Size s_min_size;
60 
61 private:
62  Rect m_rect;
63  Vector m_scale;
64 };
65 
66 #endif
67 
68 /* EOF */
int get_screen_height() const
The height of the resulting logical screen.
Definition: viewport.cpp:198
Vector to_logical(int physical_x, int physical_y) const
Converts window coordinates into logical screen coordinates.
Definition: viewport.cpp:210
Definition: rect.hpp:30
Definition: size.hpp:24
bool needs_clear_screen() const
True if the logical screen doens&#39;t cover the whole window.
Definition: viewport.cpp:217
Size get_screen_size() const
The size of the resulting logical screen.
Definition: viewport.cpp:204
Rect get_rect() const
The size of the viewport in window coordinates.
Definition: viewport.hpp:34
Definition: viewport.hpp:23
int get_screen_width() const
The width of the resulting logical screen.
Definition: viewport.cpp:192
Vector get_scale() const
The amount by which the content of the viewport is scaled.
Definition: viewport.hpp:37