summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/sdl/window.h
blob: 49fe452192fb682af7dddeb636f6c0738fc338a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert, R. Belmont
//============================================================
//
//  window.h - SDL window handling
//
//  SDLMAME by Olivier Galibert and R. Belmont
//
//============================================================

#ifndef MAME_OSD_SDL_WINDOW_H
#define MAME_OSD_SDL_WINDOW_H

#include "modules/osdwindow.h"
#include "osdsync.h"

#include <SDL2/SDL.h>

#include <chrono>
#include <cstdint>
#include <memory>
#include <vector>


//============================================================
//  TYPE DEFINITIONS
//============================================================

class render_target;

typedef uintptr_t HashT;

#define OSDWORK_CALLBACK(name)  void *name(void *param, int threadid)

class sdl_window_info : public osd_window_t<SDL_Window*>
{
public:
	sdl_window_info(
			running_machine &a_machine,
			render_module &renderprovider,
			int index,
			const std::shared_ptr<osd_monitor_info> &a_monitor,
			const osd_window_config *config);

	~sdl_window_info();

	int window_init();

	void update() override;
	void toggle_full_screen();
	void modify_prescale(int dir);
	void resize(int32_t width, int32_t height);
	void complete_destroy() override;

	void capture_pointer() override;
	void release_pointer() override;
	void show_pointer() override;
	void hide_pointer() override;

	void notify_changed();

	osd_dim get_size() override;

	int xy_to_render_target(int x, int y, int *xt, int *yt);

	void mouse_entered(unsigned device);
	void mouse_left(unsigned device);
	void mouse_down(unsigned device, int x, int y, unsigned button);
	void mouse_up(unsigned device, int x, int y, unsigned button);
	void mouse_moved(unsigned device, int x, int y);
	void mouse_wheel(unsigned device, int y);
	void finger_down(SDL_FingerID finger, unsigned device, int x, int y);
	void finger_up(SDL_FingerID finger, unsigned device, int x, int y);
	void finger_moved(SDL_FingerID finger, unsigned device, int x, int y);

private:
	struct sdl_pointer_info : public pointer_info
	{
		static constexpr bool compare(sdl_pointer_info const &info, SDL_FingerID finger) { return info.finger < finger; }

		sdl_pointer_info(sdl_pointer_info const &) = default;
		sdl_pointer_info(sdl_pointer_info &&) = default;
		sdl_pointer_info &operator=(sdl_pointer_info const &) = default;
		sdl_pointer_info &operator=(sdl_pointer_info &&) = default;

		sdl_pointer_info(SDL_FingerID, unsigned i, unsigned d);

		SDL_FingerID finger;
	};

	// returns 0 on success, else 1
	int complete_create();

	int wnd_extra_width();
	int wnd_extra_height();
	osd_rect constrain_to_aspect_ratio(const osd_rect &rect, int adjustment);
	osd_dim get_min_bounds(int constrain);
	osd_dim get_max_bounds(int constrain);
	void update_cursor_state();
	osd_dim pick_best_mode();
	void set_fullscreen(int afullscreen) { m_fullscreen = afullscreen; }

	void measure_fps(int update);

	std::vector<sdl_pointer_info>::iterator map_pointer(SDL_FingerID finger, unsigned device);

	// window handle and info
	int                 m_startmaximized;

	// dimensions
	osd_dim             m_minimum_dim;
	osd_dim             m_windowed_dim;

	// rendering info
	osd_event           m_rendered_event;

	// Original display_mode
	SDL_DisplayMode     m_original_mode;

	int                 m_extra_flags;

	// monitor info
	bool                m_mouse_captured;
	bool                m_mouse_hidden;

	// info on currently active pointers - 64 pointers ought to be enough for anyone
	uint64_t m_pointer_mask;
	unsigned m_next_pointer;
	bool m_mouse_inside;
	std::vector<pointer_dev_info> m_ptrdev_info;
	std::vector<sdl_pointer_info> m_active_pointers;
};

#endif // MAME_OSD_SDL_WINDOW_H