ScummVM API documentation
graphics_mode.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef AGS_ENGINE_MAIN_GRAPHICS_MODE_H
23 #define AGS_ENGINE_MAIN_GRAPHICS_MODE_H
24 
25 #include "ags/engine/gfx/gfx_defines.h"
26 #include "ags/shared/util/geometry.h"
27 #include "ags/shared/util/scaling.h"
28 #include "ags/shared/util/string.h"
29 
30 namespace AGS3 {
31 
32 using AGS::Shared::String;
33 using AGS::Engine::GraphicResolution;
34 using AGS::Engine::DisplayMode;
35 using AGS::Engine::WindowMode;
36 
37 Size get_desktop_size();
38 
39 namespace AGS {
40 namespace Engine {
41 class IGfxModeList;
42 } // namespace Engine
43 } // namespace AGS
44 
45 bool find_nearest_supported_mode(const AGS::Engine::IGfxModeList &modes, const Size &wanted_size,
46  const int color_depth, const Size *ratio_reference, const Size *upper_bound,
47  AGS::Engine::DisplayMode &dm, int *mode_index = nullptr);
48 
49 // Filter configuration
51  String ID; // internal filter ID
52  String UserRequest; // filter name, requested by user
53 };
54 
55 // Defines how game frame is scaled inside a larger window
56 enum FrameScaleDef {
57  kFrame_Undefined = -1,
58  kFrame_Round, // max round (integer) scaling factor
59  kFrame_Stretch, // resize to maximal possible inside the display box
60  kFrame_Proportional, // same as stretch, but keep game's aspect ratio
61  kNumFrameScaleDef
62 };
63 
64 // Configuration that is used to determine the size and style of the window
66 {
67  AGS3::Size Size; // explicit screen metrics
68  int Scale = 0; // explicit game scale factor
69  WindowMode Mode = AGS::Engine::kWnd_Windowed; // window mode
70 
71  WindowSetup() = default;
72  WindowSetup(const AGS3::Size &sz, WindowMode mode = AGS::Engine::kWnd_Windowed)
73  : Size(sz), Scale(0), Mode(mode) {}
74  WindowSetup(int scale, WindowMode mode = AGS::Engine::kWnd_Windowed)
75  : Scale(scale), Mode(mode) {}
76  WindowSetup(WindowMode mode) : Scale(0), Mode(mode) {}
77 };
78 
79 // Additional parameters for the display mode setup
81  int RefreshRate = 0; // gfx mode refresh rate
82  bool VSync = false; // vertical sync
83 };
84 
85 // Full graphics configuration, contains graphics driver selection,
86 // alternate settings for windowed and fullscreen modes and gfx filter setup.
88  String DriverID; // graphics driver ID
89 
90  // Definitions for the fullscreen and windowed modes and scaling methods.
91  // When the initial display mode is set, corresponding scaling method from this pair is used.
92  // The second method is meant to be saved and used if display mode is switched at runtime.
93  WindowSetup FsSetup; // definition of the fullscreen mode
94  WindowSetup WinSetup; // definition of the windowed mode
95  FrameScaleDef FsGameFrame = // how the game frame should be scaled/positioned in fullscreen mode
96  kFrame_Undefined;
97  FrameScaleDef WinGameFrame = // how the game frame should be scaled/positioned in windowed mode
98  kFrame_Undefined;
99 
100  bool Windowed = false; // initial mode
101  DisplaySetupEx Params;
102 
103  GfxFilterSetup Filter; // graphics filter definition
104 };
105 
106 // Display mode color depth variants suggested for the use
108  int Bits; // color depth value in bits
109  bool Forced; // whether the depth should be forced, or driver's recommendation used
110 
111  ColorDepthOption() : Bits(0), Forced(false) {
112  }
113  ColorDepthOption(int bits, bool forced = false) : Bits(bits), Forced(forced) {
114  }
115 };
116 
117 // ActiveDisplaySetting struct merges DisplayMode and FrameScaleDef,
118 // which is useful if you need to save active settings and reapply them later.
120  DisplayMode Dm;
121  FrameScaleDef Frame = kFrame_Undefined;
122 };
123 
124 // Initializes any possible gfx mode, using user config as a recommendation;
125 // may try all available renderers and modes before succeeding (or failing)
126 bool graphics_mode_init_any(const GraphicResolution &game_res, const DisplayModeSetup &setup, const ColorDepthOption &color_depth);
127 // Return last saved display mode of the given kind
128 ActiveDisplaySetting graphics_mode_get_last_setting(bool windowed);
129 // Creates graphics driver of given id
130 bool graphics_mode_create_renderer(const String &driver_id);
131 // Try to find and initialize compatible display mode as close to given setup as possible
132 bool graphics_mode_set_dm_any(const Size &game_size, const WindowSetup &ws,
133  const ColorDepthOption &color_depth,
134  const FrameScaleDef frame, const DisplaySetupEx &params);
135 // Set the display mode with given parameters
136 bool graphics_mode_set_dm(const AGS::Engine::DisplayMode &dm);
137 // Set the native image size
138 bool graphics_mode_set_native_res(const GraphicResolution &native_res);
139 // Get current render frame setup
140 FrameScaleDef graphics_mode_get_render_frame();
141 // Set the render frame position inside the window
142 bool graphics_mode_set_render_frame(const FrameScaleDef &frame_setup);
143 // Set requested graphics filter, or default filter if the requested one failed
144 bool graphics_mode_set_filter_any(const GfxFilterSetup &setup);
145 // Set the scaling filter with given ID
146 bool graphics_mode_set_filter(const String &filter_id);
147 // Update graphic renderer and render frame when window size changes
148 void graphics_mode_on_window_changed(const Size &sz);
149 // Releases current graphic mode and shuts down renderer
150 void graphics_mode_shutdown();
151 
152 } // namespace AGS3
153 
154 #endif
Definition: achievements_tables.h:27
Definition: graphics_mode.h:87
Definition: graphics_mode.h:50
Definition: graphics_mode.h:119
Definition: graphics_mode.h:80
Definition: gfx_defines.h:60
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: graphics_mode.h:65
Definition: graphics_mode.h:107
Definition: string.h:62
Definition: geometry.h:144
Definition: gfx_defines.h:33
Definition: engine.h:143
Definition: ags.h:40