Mana
Loading...
Searching...
No Matches
video.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "graphics.h"
25
26#include <memory>
27#include <vector>
28
29static constexpr int defaultScreenWidth = 1280;
30static constexpr int defaultScreenHeight = 720;
31
32enum class WindowMode
33{
34 Windowed = 0,
36 Fullscreen = 2,
37};
38
40{
41 int width = 0;
42 int height = 0;
43};
44
46{
48 int width = defaultScreenWidth;
49 int height = defaultScreenHeight;
50 int display = 0;
51 int userScale = 0;
52 bool vsync = true;
53 bool openGL = false;
54
55 int scale() const;
56 int autoScale() const;
57 int maxScale() const;
58
59 bool operator==(const VideoSettings &other) const
60 {
61 return width == other.width &&
62 height == other.height &&
63 windowMode == other.windowMode &&
64 display == other.display &&
65 userScale == other.userScale &&
66 vsync == other.vsync &&
67 openGL == other.openGL;
68 }
69};
70
71class Video
72{
73public:
74 Video() = default;
75 ~Video();
76
77 const VideoSettings &settings() const { return mSettings; }
78 SDL_Window *window() const { return mWindow; }
79 Graphics *graphics() const { return mGraphics.get(); }
80
85
89 bool apply(const VideoSettings &settings);
90
94 void updateWindowSize();
95
99 void present();
100
102 {
103 return mDesktopDisplayMode;
104 }
105
106 const std::vector<DisplayMode> &displayModes() const
107 {
108 return mDisplayModes;
109 }
110
111private:
112 bool initDisplayModes();
113
116 std::vector<DisplayMode> mDisplayModes;
117 std::unique_ptr<Graphics> mGraphics;
118 SDL_Window *mWindow = nullptr;
119 bool mWindowShown = false;
120};
A central point of control for graphics.
Definition graphics.h:78
Definition video.h:72
VideoSettings mSettings
Definition video.h:114
SDL_Window * window() const
Definition video.h:78
void updateWindowSize()
Handles a change in window size, possibly adjusting the scale.
Definition video.cpp:250
bool apply(const VideoSettings &settings)
Try to apply the given video settings.
Definition video.cpp:174
const std::vector< DisplayMode > & displayModes() const
Definition video.h:106
void present()
Present the next frame.
Definition video.cpp:258
SDL_Window * mWindow
Definition video.h:118
Graphics * graphics() const
Definition video.h:79
DisplayMode mDesktopDisplayMode
Definition video.h:115
const VideoSettings & settings() const
Definition video.h:77
Graphics * initialize(const VideoSettings &settings)
Try to create a window with the given settings.
Definition video.cpp:66
std::vector< DisplayMode > mDisplayModes
Definition video.h:116
const DisplayMode & desktopDisplayMode() const
Definition video.h:101
std::unique_ptr< Graphics > mGraphics
Definition video.h:117
bool initDisplayModes()
Definition video.cpp:269
bool mWindowShown
Definition video.h:119
Video()=default
~Video()
Definition video.cpp:58
int height
Definition video.h:42
int width
Definition video.h:41
WindowMode windowMode
Definition video.h:47
bool vsync
Definition video.h:52
int height
Definition video.h:49
int scale() const
Definition video.cpp:37
bool openGL
Definition video.h:53
int maxScale() const
Definition video.cpp:51
int width
Definition video.h:48
int userScale
Definition video.h:51
int display
Definition video.h:50
int autoScale() const
Definition video.cpp:45
bool operator==(const VideoSettings &other) const
Definition video.h:59
WindowMode
Definition video.h:33
@ WindowedFullscreen