OpenTTD Source 20260704-master-gbf70c61fb8
sdl2_v.cpp File Reference

Implementation of the SDL2 video driver. More...

#include "../stdafx.h"
#include "../openttd.h"
#include "../gfx_func.h"
#include "../blitter/factory.hpp"
#include "../thread.h"
#include "../progress.h"
#include "../core/math_func.hpp"
#include "../core/geometry_func.hpp"
#include "../core/utf8.hpp"
#include "../fileio_func.h"
#include "../framerate_type.h"
#include "../window_func.h"
#include "sdl2_v.h"
#include <SDL.h>
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

struct  SDLVkMapping
 Mapping from keycodes in the SDL world to OpenTTD's world. More...

Functions

static void FindResolutions ()
 Find and store all possible resolutions into _resolutions.
static void GetAvailableVideoMode (uint *w, uint *h)
 Get the best resolution given the requested width and height.
static uint FindStartupDisplay (uint startup_display)
 Find the display we want to start OpenTTD on.
static uint ConvertSdlKeyIntoMy (SDL_Keysym *sym, char32_t *character)
 Convert the SDL key into our WindowKeyCode and the printable character (if any).
static uint ConvertSdlKeycodeIntoMy (SDL_Keycode kc)
 Convert a SDL_Keycode into our own key codes.
static std::optional< std::string_view > InitializeSDL ()
 Initialize the SDL backend if needed.

Variables

static const Dimension _default_resolutions []
 Set of common resolutions that can be used as default when none is provided by SDL.
static constexpr SDLVkMapping _vk_mapping []
 Mapping of SDL keycodes to WKC.

Detailed Description

Implementation of the SDL2 video driver.

Definition in file sdl2_v.cpp.

Function Documentation

◆ ConvertSdlKeycodeIntoMy()

uint ConvertSdlKeycodeIntoMy ( SDL_Keycode kc)
static

Convert a SDL_Keycode into our own key codes.

Parameters
kcThe SDL key code.
Returns
OpenTTD's internal key code.

Definition at line 398 of file sdl2_v.cpp.

References IsInsideBS().

Referenced by VideoDriver_SDL_Base::PollEvent().

◆ ConvertSdlKeyIntoMy()

uint ConvertSdlKeyIntoMy ( SDL_Keysym * sym,
char32_t * character )
static

Convert the SDL key into our WindowKeyCode and the printable character (if any).

Parameters
symThe keyboard event.
[out]characterThe pressed character (or '\0' when no character was pressed).
Returns
The pressed key.

Definition at line 358 of file sdl2_v.cpp.

References IsInsideBS().

Referenced by VideoDriver_SDL_Base::PollEvent().

◆ FindResolutions()

void FindResolutions ( )
static

Find and store all possible resolutions into _resolutions.

Definition at line 59 of file sdl2_v.cpp.

References _default_resolutions, and _resolutions.

Referenced by VideoDriver_SDL_Base::Initialize().

◆ FindStartupDisplay()

uint FindStartupDisplay ( uint startup_display)
static

Find the display we want to start OpenTTD on.

Parameters
startup_displayThe user preferred display, MAX_UINT32 when not given.
Returns
The best display to start OpenTTD on.

Definition at line 114 of file sdl2_v.cpp.

References Debug, and IsInsideBS().

Referenced by VideoDriver_SDL_Base::Start().

◆ GetAvailableVideoMode()

void GetAvailableVideoMode ( uint * w,
uint * h )
static

Get the best resolution given the requested width and height.

Parameters
[in,out]wThe requested width, updated with the best fit.
[in,out]hThe requested height, updated with the best fit.

Definition at line 87 of file sdl2_v.cpp.

References _resolutions, and Delta().

Referenced by VideoDriver_SDL_Base::CreateMainSurface().

◆ InitializeSDL()

std::optional< std::string_view > InitializeSDL ( )
static

Initialize the SDL backend if needed.

Returns
An optional with the error message upon failure.

Definition at line 573 of file sdl2_v.cpp.

Referenced by VideoDriver_SDL_Base::Initialize().

Variable Documentation

◆ _default_resolutions

const Dimension _default_resolutions[]
static
Initial value:
= {
{ 640, 480 },
{ 800, 600 },
{ 1024, 768 },
{ 1152, 864 },
{ 1280, 800 },
{ 1280, 960 },
{ 1280, 1024 },
{ 1400, 1050 },
{ 1600, 1200 },
{ 1680, 1050 },
{ 1920, 1200 }
}

Set of common resolutions that can be used as default when none is provided by SDL.

Definition at line 44 of file sdl2_v.cpp.

◆ _vk_mapping

SDLVkMapping _vk_mapping[]
staticconstexpr

Mapping of SDL keycodes to WKC.

Definition at line 299 of file sdl2_v.cpp.