OXYGENHUB
◆ main openmsx / src / video / VisibleSurface.hh
3.3 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#ifndef VISIBLESURFACE_HH
2
#define VISIBLESURFACE_HH
3
4
#include "EventListener.hh"
5
#include "Observer.hh"
6
#include "OutputSurface.hh"
7
#include "RTSchedulable.hh"
8
#include "SDLSurfacePtr.hh"
9
10
#include <memory>
11
#include <optional>
12
13
namespace openmsx {
14
15
class CliComm;
16
class CommandConsole;
17
class Display;
18
class EventDistributor;
19
class ImGuiManager;
20
class InputEventGenerator;
21
class Layer;
22
class OSDGUI;
23
class Reactor;
24
class Setting;
25
class VideoSystem;
26
class BooleanSetting;
27
28
/** An OutputSurface which is visible to the user, such as a window or a
29
  * full screen display.
30
  */
31
class VisibleSurface final : public OutputSurface, public EventListener
32
                                , private Observer<Setting>, private RTSchedulable
33
{
34
public:
35
	VisibleSurface(Display& display,
36
	               RTScheduler& rtScheduler,
37
	               EventDistributor& eventDistributor,
38
	               InputEventGenerator& inputEventGenerator,
39
	               CliComm& cliComm,
40
	               VideoSystem& videoSystem,
41
		       BooleanSetting& pauseSetting);
42
	~VisibleSurface() override;
43
44
	[[nodiscard]] CliComm& getCliComm() const { return cliComm; }
45
	[[nodiscard]] Display& getDisplay() const { return display; }
46
47
	static void saveScreenshotGL(const OutputSurface& output,
48
	                             const std::string& filename);
49
50
	[[nodiscard]] std::optional<gl::ivec2> getMouseCoord() const;
51
	[[nodiscard]] gl::vec2 getMsxPixelSize() const;
52
	void updateWindowTitle();
53
	bool setFullScreen(bool fullscreen);
54
	void resize();
55
56
	/** When a complete frame is finished, call this method.
57
	  * It will 'actually' display it. E.g. when using double buffering
58
	  * it will swap the front and back buffer.
59
	  */
60
	void finish();
61
62
	[[nodiscard]] std::unique_ptr<Layer> createSnowLayer();
63
	[[nodiscard]] std::unique_ptr<Layer> createOSDGUILayer(OSDGUI& gui);
64
	[[nodiscard]] std::unique_ptr<Layer> createImGUILayer(ImGuiManager& manager);
65
66
	/** Create an off-screen OutputSurface which has similar properties
67
	  * as this VisibleSurface. E.g. used to re-render the current frame
68
	  * without OSD elements to take a screenshot.
69
	  */
70
	[[nodiscard]] std::unique_ptr<OutputSurface> createOffScreenSurface();
71
72
	void fullScreenUpdated(bool fullScreen);
73
74
	/** Returns x,y coordinates of top-left window corner,
75
	    or returns a nullopt when in fullscreen mode. */
76
	[[nodiscard]] std::optional<gl::ivec2> getWindowPosition() const;
77
	void setWindowPosition(gl::ivec2 pos);
78
79
	// OutputSurface
80
	void saveScreenshot(const std::string& filename) override;
81
82
	// Observer
83
	void update(const Setting& setting) noexcept override;
84
85
	// EventListener
86
	bool signalEvent(const Event& event) override;
87
88
	// RTSchedulable
89
	void executeRT() override;
90
91
private:
92
	void updateCursor();
93
	void createSurface(gl::ivec2 size, unsigned flags);
94
	void setViewPort(gl::ivec2 logicalSize, bool fullScreen);
95
96
private:
97
	Display& display;
98
	EventDistributor& eventDistributor;
99
	InputEventGenerator& inputEventGenerator;
100
	CliComm& cliComm;
101
	VideoSystem& videoSystem;
102
	BooleanSetting& pauseSetting;
103
104
	struct VSyncObserver : openmsx::Observer<Setting> {
105
		void update(const Setting& setting) noexcept override;
106
	} vSyncObserver;
107
108
	[[no_unique_address]] SDLSubSystemInitializer<SDL_INIT_VIDEO> videoSubSystem;
109
	SDLWindowPtr window;
110
	SDL_GLContext glContext;
111
112
	bool grab = false;
113
	bool guiActive = false;
114
115
	static int windowPosX;
116
	static int windowPosY;
117
};
118
119
} // namespace openmsx
120
121
#endif