2019-09-19 15:18:50 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file sdl2_v.h Base of the SDL2 video driver. */
|
|
|
|
|
|
|
|
#ifndef VIDEO_SDL_H
|
|
|
|
#define VIDEO_SDL_H
|
|
|
|
|
2021-02-11 09:00:40 +00:00
|
|
|
#include <condition_variable>
|
2021-03-02 11:59:03 +00:00
|
|
|
#if defined(__MINGW32__)
|
|
|
|
#include "../3rdparty/mingw-std-threads/mingw.condition_variable.h"
|
|
|
|
#endif
|
2021-02-11 09:00:40 +00:00
|
|
|
|
2019-09-19 15:18:50 +00:00
|
|
|
#include "video_driver.hpp"
|
|
|
|
|
|
|
|
/** The SDL video driver. */
|
2021-02-11 20:03:18 +00:00
|
|
|
class VideoDriver_SDL_Base : public VideoDriver {
|
2019-09-19 15:18:50 +00:00
|
|
|
public:
|
2023-01-06 17:31:29 +00:00
|
|
|
VideoDriver_SDL_Base() : sdl_window(nullptr), buffer_locked(false) {}
|
2021-02-11 09:00:40 +00:00
|
|
|
|
2020-05-17 21:32:08 +00:00
|
|
|
const char *Start(const StringList ¶m) override;
|
2019-09-19 15:18:50 +00:00
|
|
|
|
|
|
|
void Stop() override;
|
|
|
|
|
|
|
|
void MakeDirty(int left, int top, int width, int height) override;
|
|
|
|
|
|
|
|
void MainLoop() override;
|
|
|
|
|
|
|
|
bool ChangeResolution(int w, int h) override;
|
|
|
|
|
|
|
|
bool ToggleFullscreen(bool fullscreen) override;
|
|
|
|
|
|
|
|
bool AfterBlitterChange() override;
|
|
|
|
|
|
|
|
bool ClaimMousePointer() override;
|
|
|
|
|
2019-11-04 18:16:34 +00:00
|
|
|
void EditBoxGainedFocus() override;
|
|
|
|
|
|
|
|
void EditBoxLostFocus() override;
|
|
|
|
|
2021-03-09 09:22:52 +00:00
|
|
|
std::vector<int> GetListOfMonitorRefreshRates() override;
|
|
|
|
|
2022-04-30 12:52:39 +00:00
|
|
|
const char *GetInfoString() const override { return this->driver_info.c_str(); }
|
|
|
|
|
2021-01-14 20:53:06 +00:00
|
|
|
protected:
|
2021-02-11 09:00:40 +00:00
|
|
|
struct SDL_Window *sdl_window; ///< Main SDL window.
|
|
|
|
Palette local_palette; ///< Copy of _cur_palette.
|
2021-02-11 09:08:04 +00:00
|
|
|
bool buffer_locked; ///< Video buffer was locked by the main thread.
|
2021-02-21 18:16:18 +00:00
|
|
|
Rect dirty_rect; ///< Rectangle encompassing the dirty area of the video buffer.
|
2022-04-30 12:52:39 +00:00
|
|
|
std::string driver_info; ///< Information string about selected driver.
|
2021-02-11 09:00:40 +00:00
|
|
|
|
2021-01-14 20:53:06 +00:00
|
|
|
Dimension GetScreenSize() const override;
|
2021-02-19 10:01:49 +00:00
|
|
|
void InputLoop() override;
|
2021-02-20 09:49:27 +00:00
|
|
|
bool LockVideoBuffer() override;
|
|
|
|
void UnlockVideoBuffer() override;
|
2021-02-20 21:14:26 +00:00
|
|
|
void CheckPaletteAnim() override;
|
2021-02-24 13:45:10 +00:00
|
|
|
bool PollEvent() override;
|
2021-01-14 20:53:06 +00:00
|
|
|
|
2021-02-11 09:08:04 +00:00
|
|
|
/** Indicate to the driver the client-side might have changed. */
|
|
|
|
void ClientSizeChanged(int w, int h, bool force);
|
|
|
|
|
2021-02-11 09:00:40 +00:00
|
|
|
/** (Re-)create the backing store. */
|
2021-02-11 20:03:18 +00:00
|
|
|
virtual bool AllocateBackingStore(int w, int h, bool force = false) = 0;
|
2021-02-11 09:08:04 +00:00
|
|
|
/** Get a pointer to the video buffer. */
|
2021-02-11 20:03:18 +00:00
|
|
|
virtual void *GetVideoPointer() = 0;
|
2021-02-11 09:08:04 +00:00
|
|
|
/** Hand video buffer back to the painting backend. */
|
2021-02-11 20:03:18 +00:00
|
|
|
virtual void ReleaseVideoPointer() = 0;
|
2021-02-11 09:08:04 +00:00
|
|
|
/** Create the main window. */
|
|
|
|
virtual bool CreateMainWindow(uint w, uint h, uint flags = 0);
|
2021-01-14 20:53:06 +00:00
|
|
|
|
2019-09-19 15:18:50 +00:00
|
|
|
private:
|
2020-12-06 19:38:34 +00:00
|
|
|
void LoopOnce();
|
|
|
|
void MainLoopCleanup();
|
2019-09-19 15:18:50 +00:00
|
|
|
bool CreateMainSurface(uint w, uint h, bool resize);
|
2021-01-16 14:26:37 +00:00
|
|
|
const char *Initialize();
|
2019-11-04 18:16:34 +00:00
|
|
|
|
2020-12-05 20:57:47 +00:00
|
|
|
#ifdef __EMSCRIPTEN__
|
|
|
|
/* Convert a constant pointer back to a non-constant pointer to a member function. */
|
2021-02-11 20:03:18 +00:00
|
|
|
static void EmscriptenLoop(void *self) { ((VideoDriver_SDL_Base *)self)->LoopOnce(); }
|
2020-12-05 20:57:47 +00:00
|
|
|
#endif
|
|
|
|
|
2019-11-04 18:16:34 +00:00
|
|
|
/**
|
|
|
|
* This is true to indicate that keyboard input is in text input mode, and SDL_TEXTINPUT events are enabled.
|
|
|
|
*/
|
|
|
|
bool edit_box_focused;
|
2020-12-06 19:38:34 +00:00
|
|
|
|
2021-01-14 22:29:29 +00:00
|
|
|
int startup_display;
|
2019-09-19 15:18:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* VIDEO_SDL_H */
|