Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
viewport.h
1 /* * Copyright (c) 2011-2017 Luke Benstead https://simulant-engine.appspot.com
2  *
3  * This file is part of Simulant.
4  *
5  * Simulant is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Simulant is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with Simulant. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef SIMULANT_VIEWPORT_H
20 #define SIMULANT_VIEWPORT_H
21 
22 #include <memory>
23 #include <cstdint>
24 #include "generic/managed.h"
25 #include "interfaces.h"
26 #include "types.h"
27 
28 namespace smlt {
29 
30 enum ViewportType {
31  VIEWPORT_TYPE_FULL,
32  VIEWPORT_TYPE_BLACKBAR_4_BY_3,
33  VIEWPORT_TYPE_BLACKBAR_16_BY_9,
34  VIEWPORT_TYPE_BLACKBAR_16_BY_10,
35  VIEWPORT_TYPE_VERTICAL_SPLIT_LEFT,
36  VIEWPORT_TYPE_VERTICAL_SPLIT_RIGHT,
37  VIEWPORT_TYPE_HORIZONTAL_SPLIT_TOP,
38  VIEWPORT_TYPE_HORIZONTAL_SPLIT_BOTTOM,
39  VIEWPORT_TYPE_CUSTOM
40 };
41 
42 void calculate_ratios_from_viewport(ViewportType type, float& x, float& y, float& width, float& height);
43 
44 class Viewport : public RefCounted<Viewport> {
45 public:
46  Viewport();
47  Viewport(const Viewport& rhs) = default;
48  Viewport& operator=(const Viewport& rhs) = default;
49 
50  Viewport(ViewportType type, const Colour& colour=smlt::Colour::BLACK);
51  Viewport(Ratio x, Ratio y, Ratio width, Ratio height, const Colour& colour=smlt::Colour::BLACK);
52 
53  Ratio x() const { return x_; }
54  Ratio y() const { return y_; }
55  Ratio width() const { return width_; }
56  Ratio height() const { return height_; }
57 
58  void clear(const RenderTarget& target, uint32_t clear_flags);
59  void apply(const RenderTarget& target);
60 
61  uint32_t width_in_pixels(const RenderTarget& target) const;
62  uint32_t height_in_pixels(const RenderTarget& target) const;
63 
64  ViewportType type() const { return type_; }
65 
66  void set_colour(const smlt::Colour& colour);
67 private:
68  Ratio x_;
69  Ratio y_;
70  Ratio width_;
71  Ratio height_;
72 
73  ViewportType type_;
74  Colour colour_;
75 };
76 
77 }
78 
79 #endif
smlt::RefCounted
Definition: managed.h:65
smlt
Definition: animation.cpp:25
smlt::RenderTarget
Definition: interfaces.h:27
smlt::Colour
Definition: colour.h:29
smlt::Viewport
Definition: viewport.h:44