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 33 /** The size of the viewport in window coordinates */ get_rect() const34 Rect get_rect() const { return m_rect; } 35 36 /** The amount by which the content of the viewport is scaled */ get_scale() const37 Vector get_scale() const { return m_scale; } 38 39 /** The width of the resulting logical screen */ 40 int get_screen_width() const; 41 42 /** The height of the resulting logical screen */ 43 int get_screen_height() const; 44 45 /** The size of the resulting logical screen */ 46 Size get_screen_size() const; 47 48 /** Converts window coordinates into logical screen coordinates */ 49 Vector to_logical(int physical_x, int physical_y) const; 50 51 /** True if the logical screen doens't cover the whole window */ 52 bool needs_clear_screen() const; 53 54 private: 55 /** The minimum logical screen size that is allowed */ 56 static const Size s_max_size; 57 58 /** The maximum logical screen size that is allowed */ 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 */ 69