1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles
3 //============================================================
4 //
5 //  window.h - Win32 window handling
6 //
7 //============================================================
8 #ifndef MAME_OSD_WINDOWS_WINDOW_H
9 #define MAME_OSD_WINDOWS_WINDOW_H
10 
11 #pragma once
12 
13 #include "render.h"
14 
15 #include "modules/osdwindow.h"
16 #include "modules/lib/osdlib.h"
17 
18 #include <chrono>
19 #include <list>
20 #include <memory>
21 #include <mutex>
22 #include <utility>
23 #include <vector>
24 
25 // standard windows headers
26 #include <windows.h>
27 #include <windowsx.h>
28 #include <mmsystem.h>
29 
30 
31 //============================================================
32 //  CONSTANTS
33 //============================================================
34 
35 #define RESIZE_STATE_NORMAL     0
36 #define RESIZE_STATE_RESIZING   1
37 #define RESIZE_STATE_PENDING    2
38 
39 
40 
41 //============================================================
42 //  TYPE DEFINITIONS
43 //============================================================
44 
45 enum class win_window_focus
46 {
47 	NONE,       // neither this window nor this thread have focus
48 	THREAD,     // a window in this thread has focus
49 	WINDOW      // this window has focus directly
50 };
51 
52 
53 class win_window_info  : public osd_window_t<HWND>
54 {
55 public:
56 	win_window_info(running_machine &machine, int index, std::shared_ptr<osd_monitor_info> monitor, const osd_window_config *config);
57 
machine()58 	running_machine &machine() const override { return m_machine; }
59 
target()60 	virtual render_target *target() override { return m_target; }
fullscreen()61 	int fullscreen() const override { return m_fullscreen; }
attached_mode()62 	bool attached_mode() const { return m_attached_mode; }
63 	win_window_focus focus() const;
64 
65 	void update() override;
66 
win_has_menu()67 	virtual bool win_has_menu() override
68 	{
69 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
70 		return GetMenu(platform_window()) ? true : false;
71 #else
72 		return false;
73 #endif
74 	}
75 
get_size()76 	virtual osd_dim get_size() override
77 	{
78 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
79 		RECT client;
80 		GetClientRect(platform_window(), &client);
81 		return osd_dim(client.right - client.left, client.bottom - client.top);
82 #else
83 		throw ref new Platform::NotImplementedException();
84 #endif
85 	}
86 
87 	void capture_pointer() override;
88 	void release_pointer() override;
89 	void show_pointer() override;
90 	void hide_pointer() override;
91 
monitor()92 	virtual osd_monitor_info *monitor() const override { return m_monitor.get(); }
93 
94 	void destroy() override;
95 
96 	// static
97 
98 	static void create(running_machine &machine, int index, std::shared_ptr<osd_monitor_info> monitor, const osd_window_config *config);
99 
100 	// static callbacks
101 
102 	static LRESULT CALLBACK video_window_proc(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam);
103 
104 	// member variables
105 
106 	win_window_info *   m_next;
107 	volatile int        m_init_state;
108 
109 	// window handle and info
110 	char                m_title[256];
111 	RECT                m_non_fullscreen_bounds;
112 	int                 m_startmaximized;
113 	int                 m_isminimized;
114 	int                 m_ismaximized;
115 
116 	// monitor info
117 	std::shared_ptr<osd_monitor_info>  m_monitor;
118 	int                                m_fullscreen;
119 	int                                m_fullscreen_safe;
120 	float                              m_aspect;
121 
122 	// rendering info
123 	std::mutex          m_render_lock;
124 	render_target *     m_target;
125 	unsigned            m_targetview;
126 	int                 m_targetorient;
127 	render_layer_config m_targetlayerconfig;
128 	u32                 m_targetvismask;
129 
130 	// input info
131 	std::chrono::steady_clock::time_point  m_lastclicktime;
132 	int                                    m_lastclickx;
133 	int                                    m_lastclicky;
134 
135 private:
136 	void draw_video_contents(HDC dc, bool update);
137 	int complete_create();
138 	void set_starting_view(int index, const char *defview, const char *view);
139 	int wnd_extra_width();
140 	int wnd_extra_height();
141 	osd_rect constrain_to_aspect_ratio(const osd_rect &rect, int adjustment);
142 	osd_dim get_min_bounds(int constrain);
143 	osd_dim get_max_bounds(int constrain);
144 	void update_minmax_state();
145 	void minimize_window();
146 	void maximize_window();
147 	void adjust_window_position_after_major_change();
148 	void set_fullscreen(int fullscreen);
149 	std::shared_ptr<osd_monitor_info> monitor_from_rect(const osd_rect* proposed) const;
150 
151 	static POINT        s_saved_cursor_pos;
152 
153 #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
154 	static Windows::UI::Core::CoreCursor^ s_cursor;
155 #endif
156 
157 	running_machine &   m_machine;
158 	bool                m_attached_mode;
159 };
160 
161 struct osd_draw_callbacks
162 {
163 	osd_renderer *(*create)(osd_window *window);
164 	void (*exit)(void);
165 };
166 
167 
168 //============================================================
169 //  PROTOTYPES
170 //============================================================
171 
172 bool winwindow_has_focus(void);
173 void winwindow_update_cursor_state(running_machine &machine);
174 
175 extern LRESULT CALLBACK winwindow_video_window_proc_ui(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam);
176 
177 void winwindow_toggle_full_screen(void);
178 void winwindow_take_snap(void);
179 void winwindow_take_video(void);
180 void winwindow_toggle_fsfx(void);
181 
182 void winwindow_process_events_periodic(running_machine &machine);
183 void winwindow_process_events(running_machine &machine, bool ingame, bool nodispatch);
184 
185 void winwindow_ui_pause(running_machine &machine, int pause);
186 int winwindow_ui_is_paused(running_machine &machine);
187 
188 void winwindow_dispatch_message(running_machine &machine, MSG *message);
189 
190 extern int win_create_menu(running_machine &machine, HMENU *menus);
191 
192 
193 
194 //============================================================
195 //  rect_width / rect_height
196 //============================================================
197 
rect_width(const RECT * rect)198 static inline int rect_width(const RECT *rect)
199 {
200 	return rect->right - rect->left;
201 }
202 
203 
rect_height(const RECT * rect)204 static inline int rect_height(const RECT *rect)
205 {
206 	return rect->bottom - rect->top;
207 }
208 
209 #endif // MAME_OSD_WINDOWS_WINDOW_H
210