OpenTTD Source 20261112-master-gbcbec5e63f
sdl3_v.cpp File Reference

Implementation of the SDL3 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 "sdl3_v.h"
#include <SDL3/SDL.h>
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_init.h>
#include <SDL3/SDL_video.h>
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

class  SDLRange< T >
 Helper to map some SDL functions to behave like a std::range. More...
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_KeyboardEvent *key_event, 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 SDL3 video driver.

Definition in file sdl3_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 431 of file sdl3_v.cpp.

References IsInsideBS().

Referenced by VideoDriver_SDL_Base::PollEvent().

◆ ConvertSdlKeyIntoMy()

uint ConvertSdlKeyIntoMy ( SDL_KeyboardEvent * key_event,
char32_t * character )
static

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

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

Definition at line 391 of file sdl3_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 104 of file sdl3_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 156 of file sdl3_v.cpp.

References Debug, Driver, Error, IsInsideBS(), and SDLRange< T >::size().

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 129 of file sdl3_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 627 of file sdl3_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 89 of file sdl3_v.cpp.

◆ _vk_mapping

SDLVkMapping _vk_mapping[]
staticconstexpr

Mapping of SDL keycodes to WKC.

Definition at line 332 of file sdl3_v.cpp.