MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / MakeWindow

Method MakeWindow

src/video/win32_v.cpp:149–248  ·  view source on GitHub ↗

* Instantiate a new window. * @param full_screen Whether to make a full screen window or not. * @param resize Whether to change window size. * @return True if the window could be created. */

Source from the content-addressed store, hash-verified

147 * @return True if the window could be created.
148 */
149bool VideoDriver_Win32Base::MakeWindow(bool full_screen, bool resize)
150{
151 /* full_screen is whether the new window should be fullscreen,
152 * _wnd.fullscreen is whether the current window is. */
153 _fullscreen = full_screen;
154
155 /* recreate window? */
156 if ((full_screen != this->fullscreen) && this->main_wnd) {
157 DestroyWindow(this->main_wnd);
158 this->main_wnd = 0;
159 }
160
161 if (full_screen) {
162 DEVMODE settings{};
163 settings.dmSize = sizeof(settings);
164 settings.dmFields =
165 DM_BITSPERPEL |
166 DM_PELSWIDTH |
167 DM_PELSHEIGHT;
168 settings.dmBitsPerPel = this->GetFullscreenBpp();
169 settings.dmPelsWidth = this->width_org;
170 settings.dmPelsHeight = this->height_org;
171
172 /* Check for 8 bpp support. */
173 if (settings.dmBitsPerPel == 8 && ChangeDisplaySettings(&settings, CDS_FULLSCREEN | CDS_TEST) != DISP_CHANGE_SUCCESSFUL) {
174 settings.dmBitsPerPel = 32;
175 }
176
177 /* Test fullscreen with current resolution, if it fails use desktop resolution. */
178 if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN | CDS_TEST) != DISP_CHANGE_SUCCESSFUL) {
179 RECT r;
180 GetWindowRect(GetDesktopWindow(), &r);
181 /* Guard against recursion. If we already failed here once, just fall through to
182 * the next ChangeDisplaySettings call which will fail and error out appropriately. */
183 if ((int)settings.dmPelsWidth != r.right - r.left || (int)settings.dmPelsHeight != r.bottom - r.top) {
184 return this->ChangeResolution(r.right - r.left, r.bottom - r.top);
185 }
186 }
187
188 if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
189 this->MakeWindow(false, resize); // don't care about the result
190 return false; // the request failed
191 }
192 } else if (this->fullscreen) {
193 /* restore display? */
194 ChangeDisplaySettings(nullptr, 0);
195 /* restore the resolution */
196 this->width = _bck_resolution.width;
197 this->height = _bck_resolution.height;
198 }
199
200 {
201 RECT r;
202 DWORD style, showstyle;
203 int w, h;
204
205 showstyle = SW_SHOWNORMAL;
206 this->fullscreen = full_screen;

Callers 5

ChangeResolutionMethod · 0.95
ToggleFullscreenMethod · 0.95
WndProcGdiFunction · 0.80
StartMethod · 0.80
AfterBlitterChangeMethod · 0.80

Calls 6

GetFullscreenBppMethod · 0.95
ChangeResolutionMethod · 0.95
GameSizeChangedFunction · 0.85
PostResizeMethod · 0.80
OTTD2FSFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected