OpenTTD Source 20261112-master-gbcbec5e63f
sdl3_v.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef VIDEO_SDL_H
11#define VIDEO_SDL_H
12
13#include "video_driver.hpp"
14
17public:
24
25 std::optional<std::string_view> Start(const StringList &param) override;
26
27 void Stop() override;
28
29 void MakeDirty(int left, int top, int width, int height) override;
30
31 void MainLoop() override;
32
33 bool ChangeResolution(int w, int h) override;
34
35 bool ToggleFullscreen(bool fullscreen) override;
36
37 bool AfterBlitterChange() override;
38
39 void ClaimMousePointer() override;
40
41 void EditBoxGainedFocus() override;
42
43 void EditBoxLostFocus() override;
44
45 std::vector<int> GetListOfMonitorRefreshRates() override;
46
47 std::string_view GetInfoString() const override { return this->driver_info; }
48
49 void SetScreensaverInhibited(bool inhibited) override;
50
51protected:
52 struct SDL_Window *sdl_window = nullptr;
53 Palette local_palette{};
54 bool buffer_locked = false;
56 std::string driver_info{};
57
58 Dimension GetScreenSize() const override;
59 void InputLoop() override;
60 bool LockVideoBuffer() override;
61 void UnlockVideoBuffer() override;
62 void CheckPaletteAnim() override;
63 bool PollEvent() override;
64
65 void ClientSizeChanged(int w, int h, bool force);
66
74 virtual bool AllocateBackingStore(int w, int h, bool force = false) = 0;
75
80 virtual void *GetVideoPointer() = 0;
81
83 virtual void ReleaseVideoPointer() = 0;
84
92 virtual bool CreateMainWindow(uint w, uint h, uint flags = 0);
93
94private:
95 void LoopOnce();
96 bool CreateMainSurface(uint w, uint h, bool resize);
97 std::optional<std::string_view> Initialize();
98
99#ifdef __EMSCRIPTEN__
100 /* Convert a constant pointer back to a non-constant pointer to a member function. */
101 static void EmscriptenLoop(void *self) { ((VideoDriver_SDL_Base *)self)->LoopOnce(); }
102#endif
103
107 bool edit_box_focused = false;
108
110};
111
112#endif /* VIDEO_SDL_H */
std::optional< std::string_view > Start(const StringList &param) override
Start this driver.
Definition sdl3_v.cpp:657
bool buffer_locked
Video buffer was locked by the main thread.
Definition sdl3_v.h:54
Dimension GetScreenSize() const override
Get the resolution of the main screen.
Definition sdl3_v.cpp:828
bool PollEvent() override
Process a single system event.
Definition sdl3_v.cpp:450
void EditBoxLostFocus() override
This is called to indicate that an edit box has lost focus, text input mode should be disabled.
Definition sdl3_v.cpp:278
std::string_view GetInfoString() const override
Get some information about the selected driver/backend to be shown to the user.
Definition sdl3_v.h:47
virtual void ReleaseVideoPointer()=0
Hand video buffer back to the painting backend.
void ClaimMousePointer() override
Claim the exclusive rights for the mouse pointer.
Definition sdl3_v.cpp:256
virtual void * GetVideoPointer()=0
Get a pointer to the video buffer.
void LoopOnce()
Run a single tick of the game/main loop.
Definition sdl3_v.cpp:733
bool AfterBlitterChange() override
Callback invoked after the blitter was changed.
Definition sdl3_v.cpp:820
virtual bool AllocateBackingStore(int w, int h, bool force=false)=0
(Re-)create the backing store.
void InputLoop() override
Handle input logic, is CTRL pressed, should we fast-forward, etc.
Definition sdl3_v.cpp:709
Palette local_palette
Current palette to use for drawing.
Definition sdl3_v.h:53
void MainLoop() override
Perform the actual drawing.
Definition sdl3_v.cpp:769
std::optional< std::string_view > Initialize()
Initialize the driver.
Definition sdl3_v.cpp:644
std::string driver_info
Information string about selected driver.
Definition sdl3_v.h:56
void UnlockVideoBuffer() override
Unlock a previously locked video buffer.
Definition sdl3_v.cpp:847
VideoDriver_SDL_Base(bool uses_hardware_acceleration=false, bool supports_animation_buffer=false)
Create the video driver.
Definition sdl3_v.h:23
void ClientSizeChanged(int w, int h, bool force)
Indicate to the driver the client-size might have changed.
Definition sdl3_v.cpp:183
int startup_display
The display to show OpenTTD on when starting.
Definition sdl3_v.h:109
void MakeDirty(int left, int top, int width, int height) override
Mark a particular area dirty.
Definition sdl3_v.cpp:34
virtual bool CreateMainWindow(uint w, uint h, uint flags=0)
Create the main window.
Definition sdl3_v.cpp:195
std::vector< int > GetListOfMonitorRefreshRates() override
Get a list of refresh rates of each available monitor.
Definition sdl3_v.cpp:286
void SetScreensaverInhibited(bool inhibited) override
Prevents the system from going to sleep.
Definition sdl3_v.cpp:858
bool edit_box_focused
This is true to indicate that keyboard input is in text input mode, and SDL_TEXTINPUT events are enab...
Definition sdl3_v.h:107
bool ChangeResolution(int w, int h) override
Change the resolution of the window.
Definition sdl3_v.cpp:785
void Stop() override
Stop this driver.
Definition sdl3_v.cpp:701
bool CreateMainSurface(uint w, uint h, bool resize)
Create/update the surfaces to draw OpenTTD on.
Definition sdl3_v.cpp:239
bool LockVideoBuffer() override
Make sure the video buffer is ready for drawing.
Definition sdl3_v.cpp:836
void EditBoxGainedFocus() override
This is called to indicate that an edit box has gained focus, text input mode should be enabled.
Definition sdl3_v.cpp:267
Rect dirty_rect
Rectangle encompassing the dirty area of the video buffer.
Definition sdl3_v.h:55
void CheckPaletteAnim() override
Process any pending palette animation.
Definition sdl3_v.cpp:40
struct SDL_Window * sdl_window
Main SDL window.
Definition sdl3_v.h:52
bool ToggleFullscreen(bool fullscreen) override
Change the full screen setting.
Definition sdl3_v.cpp:790
const bool supports_animation_buffer
Whether this driver supports hardware accelerated animation.
VideoDriver(bool uses_hardware_acceleration=false, bool supports_animation_buffer=false)
Create the video driver.
const bool uses_hardware_acceleration
Whether hardware acceleration is used or not.
#define Rect
Macro that prevents name conflicts between included headers.
std::vector< std::string > StringList
Type for a list of strings.
Definition string_type.h:61
Dimensions (a width and height) of a rectangle in 2D.
Base of all video drivers.