Standardize platform window pointer storage in osd_window.

Also encapsulate show/hide capture/release cursor functionality.
This commit is contained in:
Brad Hughes 2016-04-17 18:27:07 -04:00
parent 55d3e544e0
commit 870db16e99
21 changed files with 222 additions and 152 deletions

View File

@ -236,7 +236,7 @@ void debugger_windows::show_all()
void debugger_windows::hide_all() void debugger_windows::hide_all()
{ {
SetForegroundWindow(win_window_list->m_hwnd); SetForegroundWindow(win_window_list->platform_window<HWND>());
for (debugwin_info &info : m_window_list) for (debugwin_info &info : m_window_list)
info.hide(); info.hide();
} }

View File

@ -35,7 +35,7 @@ debugwin_info::debugwin_info(debugger_windows_interface &debugger, bool is_main_
register_window_class(); register_window_class();
m_wnd = win_create_window_ex_utf8(DEBUG_WINDOW_STYLE_EX, "MAMEDebugWindow", title, DEBUG_WINDOW_STYLE, m_wnd = win_create_window_ex_utf8(DEBUG_WINDOW_STYLE_EX, "MAMEDebugWindow", title, DEBUG_WINDOW_STYLE,
0, 0, 100, 100, win_window_list->m_hwnd, create_standard_menubar(), GetModuleHandleUni(), this); 0, 0, 100, 100, win_window_list->platform_window<HWND>(), create_standard_menubar(), GetModuleHandleUni(), this);
if (m_wnd == NULL) if (m_wnd == NULL)
return; return;

View File

@ -103,7 +103,7 @@ public:
} }
// set the cooperative level // set the cooperative level
result = devinfo->dinput.device->SetCooperativeLevel(win_window_list->m_hwnd, cooperative_level); result = devinfo->dinput.device->SetCooperativeLevel(win_window_list->platform_window<HWND>(), cooperative_level);
if (result != DI_OK) if (result != DI_OK)
goto error; goto error;

View File

@ -475,7 +475,7 @@ public:
registration.usUsagePage = usagepage(); registration.usUsagePage = usagepage();
registration.usUsage = usage(); registration.usUsage = usage();
registration.dwFlags = m_global_inputs_enabled ? 0x00000100 : 0; registration.dwFlags = m_global_inputs_enabled ? 0x00000100 : 0;
registration.hwndTarget = win_window_list->m_hwnd; registration.hwndTarget = win_window_list->platform_window<HWND>();
// register the device // register the device
register_rawinput_devices(&registration, 1, sizeof(registration)); register_rawinput_devices(&registration, 1, sizeof(registration));

View File

@ -43,7 +43,7 @@ static inline sdl_window_info * window_from_id(Uint32 windowID)
for (w = sdl_window_list; w != NULL; w = w->m_next) for (w = sdl_window_list; w != NULL; w = w->m_next)
{ {
//printf("w->window_id: %d\n", w->window_id); //printf("w->window_id: %d\n", w->window_id);
if (w->sdl_window() == window) if (w->platform_window<SDL_Window*>() == window)
{ {
return w; return w;
} }

View File

@ -152,7 +152,7 @@ public:
mouse.lY = (cursor_info.ptScreenPos.y - win32_mouse.last_point.y) * INPUT_RELATIVE_PER_PIXEL; mouse.lY = (cursor_info.ptScreenPos.y - win32_mouse.last_point.y) * INPUT_RELATIVE_PER_PIXEL;
RECT window_pos = {0}; RECT window_pos = {0};
GetWindowRect(win_window_list->m_hwnd, &window_pos); GetWindowRect(win_window_list->platform_window<HWND>(), &window_pos);
// We reset the cursor position to the middle of the window each frame // We reset the cursor position to the middle of the window each frame
win32_mouse.last_point.x = window_pos.left + (window_pos.right - window_pos.left) / 2; win32_mouse.last_point.x = window_pos.left + (window_pos.right - window_pos.left) / 2;
@ -274,8 +274,8 @@ public:
RECT client_rect; RECT client_rect;
// get the position relative to the window // get the position relative to the window
GetClientRect(win_window_list->m_hwnd, &client_rect); GetClientRect(win_window_list->platform_window<HWND>(), &client_rect);
ScreenToClient(win_window_list->m_hwnd, &mousepos); ScreenToClient(win_window_list->platform_window<HWND>(), &mousepos);
// convert to absolute coordinates // convert to absolute coordinates
xpos = normalize_absolute_axis(mousepos.x, client_rect.left, client_rect.right); xpos = normalize_absolute_axis(mousepos.x, client_rect.left, client_rect.right);
@ -335,10 +335,10 @@ private:
POINT mousepos; POINT mousepos;
// get the position relative to the window // get the position relative to the window
GetClientRect(win_window_list->m_hwnd, &client_rect); GetClientRect(win_window_list->platform_window<HWND>(), &client_rect);
mousepos.x = args.xpos; mousepos.x = args.xpos;
mousepos.y = args.ypos; mousepos.y = args.ypos;
ScreenToClient(win_window_list->m_hwnd, &mousepos); ScreenToClient(win_window_list->platform_window<HWND>(), &mousepos);
// convert to absolute coordinates // convert to absolute coordinates
mouse.lX = normalize_absolute_axis(mousepos.x, client_rect.left, client_rect.right); mouse.lX = normalize_absolute_axis(mousepos.x, client_rect.left, client_rect.right);

View File

@ -112,12 +112,13 @@ public:
osd_window() osd_window()
: :
#ifndef OSD_SDL #ifndef OSD_SDL
m_hwnd(0), m_dc(0), m_focus_hwnd(0), m_resize_state(0), m_dc(0), m_resize_state(0),
#endif #endif
m_primlist(nullptr), m_primlist(nullptr),
m_index(0), m_index(0),
m_main(nullptr), m_main(nullptr),
m_prescale(1) m_prescale(1),
m_platform_window(nullptr)
{} {}
virtual ~osd_window() { } virtual ~osd_window() { }
@ -142,19 +143,30 @@ public:
virtual osd_monitor_info *monitor() const = 0; virtual osd_monitor_info *monitor() const = 0;
#ifdef OSD_SDL template <class TWindow>
virtual SDL_Window *sdl_window() = 0; TWindow platform_window() const { return static_cast<TWindow>(m_platform_window); }
#else
void set_platform_window(void *window)
{
assert(window == nullptr || m_platform_window == nullptr);
m_platform_window = window;
}
// Clips the pointer to the bounds of this window
virtual void capture_pointer() = 0;
// Releases the pointer from a previously captured state
virtual void release_pointer() = 0;
virtual void show_pointer() = 0;
virtual void hide_pointer() = 0;
#ifndef OSD_SDL
virtual bool win_has_menu() = 0; virtual bool win_has_menu() = 0;
// FIXME: cann we replace winwindow_video_window_monitor(NULL) with monitor() ? // FIXME: cann we replace winwindow_video_window_monitor(NULL) with monitor() ?
virtual osd_monitor_info *winwindow_video_window_monitor(const osd_rect *proposed) = 0; virtual osd_monitor_info *winwindow_video_window_monitor(const osd_rect *proposed) = 0;
// window handle and info
HWND m_hwnd;
HDC m_dc; // only used by GDI renderer! HDC m_dc; // only used by GDI renderer!
// FIXME: this is the same as win_window_list->m_hwnd, i.e. first window.
// During modularization, this should be passed in differently
HWND m_focus_hwnd;
int m_resize_state; int m_resize_state;
#endif #endif
@ -165,6 +177,8 @@ public:
osd_window *m_main; osd_window *m_main;
protected: protected:
int m_prescale; int m_prescale;
private:
void *m_platform_window;
}; };
class osd_renderer class osd_renderer

View File

@ -437,9 +437,9 @@ int renderer_sdl1::create()
} }
if (video_config.waitvsync) if (video_config.waitvsync)
m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); m_sdl_renderer = SDL_CreateRenderer(window().platform_window<SDL_Window*>(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
else else
m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_ACCELERATED); m_sdl_renderer = SDL_CreateRenderer(window().platform_window<SDL_Window*>(), -1, SDL_RENDERER_ACCELERATED);
if (!m_sdl_renderer) if (!m_sdl_renderer)
{ {

View File

@ -164,9 +164,9 @@ int renderer_bgfx::create()
bgfx::setPlatformData(blank_pd); bgfx::setPlatformData(blank_pd);
} }
#ifdef OSD_WINDOWS #ifdef OSD_WINDOWS
bgfx::winSetHwnd(window().m_hwnd); bgfx::winSetHwnd(window().platform_window<HWND>());
#else #else
bgfx::sdlSetWindow(window().sdl_window()); bgfx::sdlSetWindow(window().platform_window<SDL_Window*>());
#endif #endif
std::string backend(m_options.bgfx_backend()); std::string backend(m_options.bgfx_backend());
if (backend == "auto") if (backend == "auto")
@ -213,9 +213,9 @@ int renderer_bgfx::create()
if (window().m_index != 0) if (window().m_index != 0)
{ {
#ifdef OSD_WINDOWS #ifdef OSD_WINDOWS
m_framebuffer = m_targets->create_backbuffer(window().m_hwnd, m_width[window().m_index], m_height[window().m_index]); m_framebuffer = m_targets->create_backbuffer(window().platform_window<HWND>(), m_width[window().m_index], m_height[window().m_index]);
#else #else
m_framebuffer = m_targets->create_backbuffer(sdlNativeWindowHandle(window().sdl_window()), m_width[window().m_index], m_height[window().m_index]); m_framebuffer = m_targets->create_backbuffer(sdlNativeWindowHandle(window().platform_window<SDL_Window*>()), m_width[window().m_index], m_height[window().m_index]);
#endif #endif
bgfx::touch(window().m_index); bgfx::touch(window().m_index);
} }
@ -803,9 +803,9 @@ bool renderer_bgfx::update_dimensions()
delete m_framebuffer; delete m_framebuffer;
#ifdef OSD_WINDOWS #ifdef OSD_WINDOWS
m_framebuffer = m_targets->create_backbuffer(window().m_hwnd, width, height); m_framebuffer = m_targets->create_backbuffer(window().platform_window<HWND>(), width, height);
#else #else
m_framebuffer = m_targets->create_backbuffer(sdlNativeWindowHandle(window().sdl_window()), width, height); m_framebuffer = m_targets->create_backbuffer(sdlNativeWindowHandle(window().platform_window<SDL_Window*>()), width, height);
#endif #endif
bgfx::setViewFrameBuffer(s_current_view, m_framebuffer->target()); bgfx::setViewFrameBuffer(s_current_view, m_framebuffer->target());

View File

@ -200,7 +200,7 @@ render_primitive_list *renderer_d3d9::get_primitives()
{ {
RECT client; RECT client;
GetClientRectExceptMenu(window().m_hwnd, &client, window().fullscreen()); GetClientRectExceptMenu(window().platform_window<HWND>(), &client, window().fullscreen());
if (rect_width(&client) > 0 && rect_height(&client) > 0) if (rect_width(&client) > 0 && rect_height(&client) > 0)
{ {
window().target()->set_bounds(rect_width(&client), rect_height(&client), window().pixel_aspect()); window().target()->set_bounds(rect_width(&client), rect_height(&client), window().pixel_aspect());
@ -581,7 +581,7 @@ int renderer_d3d9::initialize()
} }
// create the device immediately for the full screen case (defer for window mode) // create the device immediately for the full screen case (defer for window mode)
if (window().fullscreen() && device_create(window().m_focus_hwnd)) if (window().fullscreen() && device_create(window().m_main->platform_window<HWND>()))
{ {
return false; return false;
} }
@ -827,7 +827,7 @@ try_again:
m_presentation.BackBufferCount = video_config.triplebuf ? 2 : 1; m_presentation.BackBufferCount = video_config.triplebuf ? 2 : 1;
m_presentation.MultiSampleType = D3DMULTISAMPLE_NONE; m_presentation.MultiSampleType = D3DMULTISAMPLE_NONE;
m_presentation.SwapEffect = D3DSWAPEFFECT_DISCARD; m_presentation.SwapEffect = D3DSWAPEFFECT_DISCARD;
m_presentation.hDeviceWindow = window().m_hwnd; m_presentation.hDeviceWindow = window().platform_window<HWND>();
m_presentation.Windowed = !window().fullscreen() || window().win_has_menu(); m_presentation.Windowed = !window().fullscreen() || window().win_has_menu();
m_presentation.EnableAutoDepthStencil = FALSE; m_presentation.EnableAutoDepthStencil = FALSE;
m_presentation.AutoDepthStencilFormat = D3DFMT_D16; m_presentation.AutoDepthStencilFormat = D3DFMT_D16;
@ -1200,7 +1200,7 @@ int renderer_d3d9::config_adapter_mode()
RECT client; RECT client;
// bounds are from the window client rect // bounds are from the window client rect
GetClientRectExceptMenu(window().m_hwnd, &client, window().fullscreen()); GetClientRectExceptMenu(window().platform_window<HWND>(), &client, window().fullscreen());
m_width = client.right - client.left; m_width = client.right - client.left;
m_height = client.bottom - client.top; m_height = client.bottom - client.top;
@ -1363,7 +1363,7 @@ int renderer_d3d9::update_window_size()
{ {
// get the current window bounds // get the current window bounds
RECT client; RECT client;
GetClientRectExceptMenu(window().m_hwnd, &client, window().fullscreen()); GetClientRectExceptMenu(window().platform_window<HWND>(), &client, window().fullscreen());
// if we have a device and matching width/height, nothing to do // if we have a device and matching width/height, nothing to do
if (m_device != nullptr && rect_width(&client) == m_width && rect_height(&client) == m_height) if (m_device != nullptr && rect_width(&client) == m_width && rect_height(&client) == m_height)
@ -1381,7 +1381,7 @@ int renderer_d3d9::update_window_size()
// set the new bounds and create the device again // set the new bounds and create the device again
m_width = rect_width(&client); m_width = rect_width(&client);
m_height = rect_height(&client); m_height = rect_height(&client);
if (device_create(window().m_focus_hwnd)) if (window().m_main != nullptr && device_create(window().m_main->platform_window<HWND>()))
return FALSE; return FALSE;
// reset the resize state to normal, and indicate we made a change // reset the resize state to normal, and indicate we made a change

View File

@ -46,7 +46,7 @@ int renderer_gdi::create()
render_primitive_list *renderer_gdi::get_primitives() render_primitive_list *renderer_gdi::get_primitives()
{ {
RECT client; RECT client;
GetClientRect(window().m_hwnd, &client); GetClientRect(window().platform_window<HWND>(), &client);
window().target()->set_bounds(rect_width(&client), rect_height(&client), window().pixel_aspect()); window().target()->set_bounds(rect_width(&client), rect_height(&client), window().pixel_aspect());
return &window().target()->get_primitives(); return &window().target()->get_primitives();
} }
@ -63,7 +63,7 @@ int renderer_gdi::draw(const int update)
// get the target bounds // get the target bounds
RECT bounds; RECT bounds;
GetClientRect(window().m_hwnd, &bounds); GetClientRect(window().platform_window<HWND>(), &bounds);
// compute width/height/pitch of target // compute width/height/pitch of target
int width = rect_width(&bounds); int width = rect_width(&bounds);

View File

@ -22,7 +22,7 @@
render_primitive_list *renderer_none::get_primitives() render_primitive_list *renderer_none::get_primitives()
{ {
RECT client; RECT client;
GetClientRect(window().m_hwnd, &client); GetClientRect(window().platform_window<HWND>(), &client);
window().target()->set_bounds(rect_width(&client), rect_height(&client), window().pixel_aspect()); window().target()->set_bounds(rect_width(&client), rect_height(&client), window().pixel_aspect());
return &window().target()->get_primitives(); return &window().target()->get_primitives();
} }

View File

@ -563,9 +563,9 @@ int renderer_ogl::create()
{ {
// create renderer // create renderer
#if defined(OSD_WINDOWS) #if defined(OSD_WINDOWS)
m_gl_context = global_alloc(win_gl_context(window().m_hwnd)); m_gl_context = global_alloc(win_gl_context(window().platform_window<HWND>()));
#else #else
m_gl_context = global_alloc(sdl_gl_context(window().sdl_window())); m_gl_context = global_alloc(sdl_gl_context(window().platform_window<SDL_Window*>()));
#endif #endif
if (m_gl_context->LastErrorMsg() != nullptr) if (m_gl_context->LastErrorMsg() != nullptr)
{ {

View File

@ -193,16 +193,16 @@ int renderer_sdl2::create()
if (video_config.waitvsync) if (video_config.waitvsync)
m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); m_sdl_renderer = SDL_CreateRenderer(window().platform_window<SDL_Window*>(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
else else
m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_ACCELERATED); m_sdl_renderer = SDL_CreateRenderer(window().platform_window<SDL_Window*>(), -1, SDL_RENDERER_ACCELERATED);
if (!m_sdl_renderer) if (!m_sdl_renderer)
{ {
if (video_config.waitvsync) if (video_config.waitvsync)
m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_SOFTWARE); m_sdl_renderer = SDL_CreateRenderer(window().platform_window<SDL_Window*>(), -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_SOFTWARE);
else else
m_sdl_renderer = SDL_CreateRenderer(window().sdl_window(), -1, SDL_RENDERER_SOFTWARE); m_sdl_renderer = SDL_CreateRenderer(window().platform_window<SDL_Window*>(), -1, SDL_RENDERER_SOFTWARE);
} }
if (!m_sdl_renderer) if (!m_sdl_renderer)

View File

@ -404,10 +404,10 @@ HRESULT sound_direct_sound::dsound_init()
#ifdef SDLMAME_WIN32 #ifdef SDLMAME_WIN32
SDL_SysWMinfo wminfo; SDL_SysWMinfo wminfo;
SDL_VERSION(&wminfo.version); SDL_VERSION(&wminfo.version);
SDL_GetWindowWMInfo(sdl_window_list->sdl_window(), &wminfo); SDL_GetWindowWMInfo(sdl_window_list->platform_window<SDL_Window*>(), &wminfo);
HWND const window = wminfo.info.win.window; HWND const window = wminfo.info.win.window;
#else // SDLMAME_WIN32 #else // SDLMAME_WIN32
HWND const window = win_window_list->m_hwnd; HWND const window = win_window_list->platform_window<HWND>();
#endif // SDLMAME_WIN32 #endif // SDLMAME_WIN32
result = m_dsound->SetCooperativeLevel(window, DSSCL_PRIORITY); result = m_dsound->SetCooperativeLevel(window, DSSCL_PRIORITY);
} }

View File

@ -377,6 +377,31 @@ void sdl_osd_interface::window_exit()
} }
void sdl_window_info::capture_pointer()
{
if (!SDL_GetWindowGrab(platform_window<SDL_Window*>()))
SDL_SetWindowGrab(platform_window<SDL_Window*>(), SDL_TRUE);
SDL_SetRelativeMouseMode(SDL_TRUE);
}
void sdl_window_info::release_pointer()
{
if (SDL_GetWindowGrab(platform_window<SDL_Window*>()))
SDL_SetWindowGrab(platform_window<SDL_Window*>(), SDL_FALSE);
SDL_SetRelativeMouseMode(SDL_FALSE);
}
void sdl_window_info::hide_pointer()
{
SDL_ShowCursor(SDL_DISABLE);
}
void sdl_window_info::show_pointer()
{
SDL_ShowCursor(SDL_ENABLE);
}
//============================================================ //============================================================
// sdlwindow_resize // sdlwindow_resize
@ -392,7 +417,7 @@ OSDWORK_CALLBACK( sdl_window_info::sdlwindow_resize_wt )
ASSERT_WINDOW_THREAD(); ASSERT_WINDOW_THREAD();
SDL_SetWindowSize(window->sdl_window(), width, height); SDL_SetWindowSize(window->platform_window<SDL_Window*>(), width, height);
window->renderer().notify_changed(); window->renderer().notify_changed();
osd_free(wp); osd_free(wp);
@ -475,11 +500,11 @@ OSDWORK_CALLBACK( sdl_window_info::sdlwindow_toggle_full_screen_wt )
#endif #endif
if (window->fullscreen() && (video_config.switchres || is_osx)) if (window->fullscreen() && (video_config.switchres || is_osx))
{ {
SDL_SetWindowFullscreen(window->sdl_window(), 0); // Try to set mode SDL_SetWindowFullscreen(window->platform_window<SDL_Window*>(), 0); // Try to set mode
SDL_SetWindowDisplayMode(window->sdl_window(), &window->m_original_mode->mode); // Try to set mode SDL_SetWindowDisplayMode(window->platform_window<SDL_Window*>(), &window->m_original_mode->mode); // Try to set mode
SDL_SetWindowFullscreen(window->sdl_window(), SDL_WINDOW_FULLSCREEN); // Try to set mode SDL_SetWindowFullscreen(window->platform_window<SDL_Window*>(), SDL_WINDOW_FULLSCREEN); // Try to set mode
} }
SDL_DestroyWindow(window->sdl_window()); SDL_DestroyWindow(window->platform_window<SDL_Window*>());
downcast<sdl_osd_interface &>(window->machine().osd()).release_keys(); downcast<sdl_osd_interface &>(window->machine().osd()).release_keys();
@ -555,18 +580,15 @@ void sdl_window_info::update_cursor_state()
if (!fullscreen() && !should_hide_mouse) if (!fullscreen() && !should_hide_mouse)
{ {
SDL_ShowCursor(SDL_ENABLE); show_pointer();
if (SDL_GetWindowGrab(sdl_window() )) release_pointer();
SDL_SetWindowGrab(sdl_window(), SDL_FALSE);
SDL_SetRelativeMouseMode(SDL_FALSE);
} }
else else
{ {
SDL_ShowCursor(SDL_DISABLE); hide_pointer();
if (!SDL_GetWindowGrab(sdl_window())) capture_pointer();
SDL_SetWindowGrab(sdl_window(), SDL_TRUE);
SDL_SetRelativeMouseMode(SDL_TRUE);
} }
SDL_SetCursor(nullptr); // Force an update in case the underlying driver has changed visibility SDL_SetCursor(nullptr); // Force an update in case the underlying driver has changed visibility
} }
#endif #endif
@ -657,11 +679,11 @@ OSDWORK_CALLBACK( sdl_window_info::sdlwindow_video_window_destroy_wt )
if (window->fullscreen() && video_config.switchres) if (window->fullscreen() && video_config.switchres)
{ {
SDL_SetWindowFullscreen(window->sdl_window(), 0); // Try to set mode SDL_SetWindowFullscreen(window->platform_window<SDL_Window*>(), 0); // Try to set mode
SDL_SetWindowDisplayMode(window->sdl_window(), &window->m_original_mode->mode); // Try to set mode SDL_SetWindowDisplayMode(window->platform_window<SDL_Window*>(), &window->m_original_mode->mode); // Try to set mode
SDL_SetWindowFullscreen(window->sdl_window(), SDL_WINDOW_FULLSCREEN); // Try to set mode SDL_SetWindowFullscreen(window->platform_window<SDL_Window*>(), SDL_WINDOW_FULLSCREEN); // Try to set mode
} }
SDL_DestroyWindow(window->sdl_window()); SDL_DestroyWindow(window->platform_window<SDL_Window*>());
// release all keys ... // release all keys ...
downcast<sdl_osd_interface &>(window->machine().osd()).release_keys(); downcast<sdl_osd_interface &>(window->machine().osd()).release_keys();
@ -928,14 +950,14 @@ OSDWORK_CALLBACK( sdl_window_info::complete_create_wt )
osd_rect work = window->monitor()->usuable_position_size(); osd_rect work = window->monitor()->usuable_position_size();
// create the SDL window // create the SDL window
window->m_sdl_window = SDL_CreateWindow(window->m_title, auto sdlwindow = SDL_CreateWindow(window->m_title,
work.left() + (work.width() - temp.width()) / 2, work.left() + (work.width() - temp.width()) / 2,
work.top() + (work.height() - temp.height()) / 2, work.top() + (work.height() - temp.height()) / 2,
temp.width(), temp.height(), window->m_extra_flags); temp.width(), temp.height(), window->m_extra_flags);
//window().sdl_window() = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, //window().sdl_window() = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
// width, height, m_extra_flags); // width, height, m_extra_flags);
if ( window->m_sdl_window == nullptr ) if (sdlwindow == nullptr )
{ {
if (window->renderer().has_flags(osd_renderer::FLAG_NEEDS_OPENGL)) if (window->renderer().has_flags(osd_renderer::FLAG_NEEDS_OPENGL))
osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError());
@ -944,18 +966,20 @@ OSDWORK_CALLBACK( sdl_window_info::complete_create_wt )
return (void *) &result[1]; return (void *) &result[1];
} }
window->set_platform_window(sdlwindow);
if (window->fullscreen() && video_config.switchres) if (window->fullscreen() && video_config.switchres)
{ {
SDL_DisplayMode mode; SDL_DisplayMode mode;
//SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode); //SDL_GetCurrentDisplayMode(window().monitor()->handle, &mode);
SDL_GetWindowDisplayMode(window->sdl_window(), &mode); SDL_GetWindowDisplayMode(window->platform_window<SDL_Window*>(), &mode);
window->m_original_mode->mode = mode; window->m_original_mode->mode = mode;
mode.w = temp.width(); mode.w = temp.width();
mode.h = temp.height(); mode.h = temp.height();
if (window->m_win_config.refresh) if (window->m_win_config.refresh)
mode.refresh_rate = window->m_win_config.refresh; mode.refresh_rate = window->m_win_config.refresh;
SDL_SetWindowDisplayMode(window->sdl_window(), &mode); // Try to set mode SDL_SetWindowDisplayMode(window->platform_window<SDL_Window*>(), &mode); // Try to set mode
#ifndef SDLMAME_WIN32 #ifndef SDLMAME_WIN32
/* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution
* is in place after the mode switch - which will most likely be the case * is in place after the mode switch - which will most likely be the case
@ -971,14 +995,14 @@ OSDWORK_CALLBACK( sdl_window_info::complete_create_wt )
// show window // show window
SDL_ShowWindow(window->sdl_window()); SDL_ShowWindow(window->platform_window<SDL_Window*>());
//SDL_SetWindowFullscreen(window->sdl_window(), 0); //SDL_SetWindowFullscreen(window->sdl_window(), 0);
//SDL_SetWindowFullscreen(window->sdl_window(), window->fullscreen()); //SDL_SetWindowFullscreen(window->sdl_window(), window->fullscreen());
SDL_RaiseWindow(window->sdl_window()); SDL_RaiseWindow(window->platform_window<SDL_Window*>());
#ifdef SDLMAME_WIN32 #ifdef SDLMAME_WIN32
if (window->fullscreen()) if (window->fullscreen())
SDL_SetWindowGrab(window->sdl_window(), SDL_TRUE); SDL_SetWindowGrab(window->platform_window<SDL_Window*>(), SDL_TRUE);
#endif #endif
// set main window // set main window
@ -1308,7 +1332,7 @@ osd_dim sdl_window_info::get_min_bounds(int constrain)
osd_dim sdl_window_info::get_size() osd_dim sdl_window_info::get_size()
{ {
int w=0; int h=0; int w=0; int h=0;
SDL_GetWindowSize(m_sdl_window, &w, &h); SDL_GetWindowSize(platform_window<SDL_Window*>(), &w, &h);
return osd_dim(w,h); return osd_dim(w,h);
} }
@ -1368,7 +1392,6 @@ sdl_window_info::sdl_window_info(running_machine &a_machine, int index, osd_moni
m_minimum_dim(0,0), m_minimum_dim(0,0),
m_windowed_dim(0,0), m_windowed_dim(0,0),
m_rendered_event(0, 1), m_target(0), m_rendered_event(0, 1), m_target(0),
m_sdl_window(NULL),
m_machine(a_machine), m_monitor(a_monitor), m_fullscreen(0) m_machine(a_machine), m_monitor(a_monitor), m_fullscreen(0)
{ {
m_win_config = *config; m_win_config = *config;

View File

@ -47,6 +47,11 @@ public:
void resize(INT32 width, INT32 height); void resize(INT32 width, INT32 height);
void destroy(); void destroy();
void capture_pointer() override;
void release_pointer() override;
void show_pointer() override;
void hide_pointer() override;
void notify_changed(); void notify_changed();
osd_dim get_size() override; osd_dim get_size() override;
@ -58,7 +63,6 @@ public:
int fullscreen() const override { return m_fullscreen; } int fullscreen() const override { return m_fullscreen; }
render_target *target() override { return m_target; } render_target *target() override { return m_target; }
SDL_Window *sdl_window() override { return m_sdl_window; }
int prescale() const { return m_prescale; } int prescale() const { return m_prescale; }
osd_renderer &renderer() const { return *m_renderer; } osd_renderer &renderer() const { return *m_renderer; }
@ -84,8 +88,6 @@ private:
osd_event m_rendered_event; osd_event m_rendered_event;
render_target * m_target; render_target * m_target;
// Needs to be here as well so we can identify window
SDL_Window *m_sdl_window;
// Original display_mode // Original display_mode
SDL_DM_Wrapper *m_original_mode; SDL_DM_Wrapper *m_original_mode;

View File

@ -81,7 +81,7 @@ bool windows_osd_interface::video_init()
} }
if (video_config.mode != VIDEO_MODE_NONE) if (video_config.mode != VIDEO_MODE_NONE)
SetForegroundWindow(win_window_list->m_hwnd); SetForegroundWindow(win_window_list->platform_window<HWND>());
return true; return true;
} }

View File

@ -304,6 +304,9 @@ void windows_osd_interface::window_exit()
{ {
assert(GetCurrentThreadId() == main_threadid); assert(GetCurrentThreadId() == main_threadid);
// if we hid the cursor during the emulation, show it
win_window_list->show_pointer();
// free all the windows // free all the windows
while (win_window_list != nullptr) while (win_window_list != nullptr)
{ {
@ -343,9 +346,6 @@ void windows_osd_interface::window_exit()
// kill the window thread ready event // kill the window thread ready event
if (window_thread_ready_event) if (window_thread_ready_event)
CloseHandle(window_thread_ready_event); CloseHandle(window_thread_ready_event);
// if we hid the cursor during the emulation, show it
while (ShowCursor(TRUE) < 0) ;
} }
win_window_info::win_window_info(running_machine &machine) win_window_info::win_window_info(running_machine &machine)
@ -383,6 +383,41 @@ win_window_info::~win_window_info()
} }
} }
POINT win_window_info::s_saved_cursor_pos = { -1, -1 };
void win_window_info::capture_pointer()
{
RECT bounds;
GetClientRect(platform_window<HWND>(), &bounds);
ClientToScreen(platform_window<HWND>(), &reinterpret_cast<POINT *>(&bounds)[0]);
ClientToScreen(platform_window<HWND>(), &reinterpret_cast<POINT *>(&bounds)[1]);
ClipCursor(&bounds);
}
void win_window_info::release_pointer()
{
ClipCursor(nullptr);
}
void win_window_info::hide_pointer()
{
GetCursorPos(&s_saved_cursor_pos);
while (ShowCursor(FALSE) >= -1) {};
ShowCursor(TRUE);
}
void win_window_info::show_pointer()
{
if (s_saved_cursor_pos.x != -1 || s_saved_cursor_pos.y != -1)
{
SetCursorPos(s_saved_cursor_pos.x, s_saved_cursor_pos.y);
s_saved_cursor_pos.x = s_saved_cursor_pos.y = -1;
}
while (ShowCursor(TRUE) < 1) {};
ShowCursor(FALSE);
}
//============================================================ //============================================================
// winwindow_process_events_periodic // winwindow_process_events_periodic
@ -410,7 +445,7 @@ void winwindow_process_events_periodic(running_machine &machine)
static BOOL is_mame_window(HWND hwnd) static BOOL is_mame_window(HWND hwnd)
{ {
for (win_window_info *window = win_window_list; window != nullptr; window = window->m_next) for (win_window_info *window = win_window_list; window != nullptr; window = window->m_next)
if (window->m_hwnd == hwnd) if (window->platform_window<HWND>() == hwnd)
return TRUE; return TRUE;
return FALSE; return FALSE;
@ -658,8 +693,8 @@ void winwindow_toggle_full_screen(void)
// iterate over windows and toggle their fullscreen state // iterate over windows and toggle their fullscreen state
for (window = win_window_list; window != nullptr; window = window->m_next) for (window = win_window_list; window != nullptr; window = window->m_next)
SendMessage(window->m_hwnd, WM_USER_SET_FULLSCREEN, !video_config.windowed, 0); SendMessage(window->platform_window<HWND>(), WM_USER_SET_FULLSCREEN, !video_config.windowed, 0);
SetForegroundWindow(win_window_list->m_hwnd); SetForegroundWindow(win_window_list->platform_window<HWND>());
} }
@ -676,7 +711,7 @@ BOOL winwindow_has_focus(void)
// see if one of the video windows has focus // see if one of the video windows has focus
for (window = win_window_list; window != nullptr; window = window->m_next) for (window = win_window_list; window != nullptr; window = window->m_next)
if (focuswnd == window->m_hwnd) if (focuswnd == window->platform_window<HWND>())
return TRUE; return TRUE;
return FALSE; return FALSE;
@ -690,10 +725,10 @@ BOOL winwindow_has_focus(void)
void winwindow_update_cursor_state(running_machine &machine) void winwindow_update_cursor_state(running_machine &machine)
{ {
static POINT saved_cursor_pos = { -1, -1 };
assert(GetCurrentThreadId() == main_threadid); assert(GetCurrentThreadId() == main_threadid);
win_window_info *window = win_window_list;
// if we should hide the mouse cursor, then do it // if we should hide the mouse cursor, then do it
// rules are: // rules are:
// 1. we must have focus before hiding the cursor // 1. we must have focus before hiding the cursor
@ -702,35 +737,19 @@ void winwindow_update_cursor_state(running_machine &machine)
// the input system requests it // the input system requests it
if (winwindow_has_focus() && ((!video_config.windowed && !win_window_list->win_has_menu()) || (!machine.paused() && downcast<windows_osd_interface&>(machine.osd()).should_hide_mouse()))) if (winwindow_has_focus() && ((!video_config.windowed && !win_window_list->win_has_menu()) || (!machine.paused() && downcast<windows_osd_interface&>(machine.osd()).should_hide_mouse())))
{ {
win_window_info *window = win_window_list;
RECT bounds;
// hide cursor // hide cursor
while (ShowCursor(FALSE) >= -1) { }; window->hide_pointer();
ShowCursor(TRUE);
// store the cursor position // clip pointer to game video window
GetCursorPos(&saved_cursor_pos); window->capture_pointer();
// clip cursor to game video window
GetClientRect(window->m_hwnd, &bounds);
ClientToScreen(window->m_hwnd, &((POINT *)&bounds)[0]);
ClientToScreen(window->m_hwnd, &((POINT *)&bounds)[1]);
ClipCursor(&bounds);
} }
else else
{ {
// show cursor // show cursor
while (ShowCursor(TRUE) < 1) { }; window->show_pointer();
ShowCursor(FALSE);
// allow cursor to move freely // allow cursor to move freely
ClipCursor(nullptr); window->release_pointer();
if (saved_cursor_pos.x != -1 || saved_cursor_pos.y != -1)
{
SetCursorPos(saved_cursor_pos.x, saved_cursor_pos.y);
saved_cursor_pos.x = saved_cursor_pos.y = -1;
}
} }
} }
@ -766,6 +785,12 @@ void win_window_info::create(running_machine &machine, int index, osd_monitor_in
} }
} }
} }
else
{
// Give the main window a reference to itself
window->m_main = window;
}
// see if we are safe for fullscreen // see if we are safe for fullscreen
window->m_fullscreen_safe = TRUE; window->m_fullscreen_safe = TRUE;
for (win = win_window_list; win != nullptr; win = win->m_next) for (win = win_window_list; win != nullptr; win = win->m_next)
@ -828,8 +853,8 @@ void win_window_info::destroy()
} }
// destroy the window // destroy the window
if (m_hwnd != nullptr) if (platform_window<HWND>() != nullptr)
SendMessage(m_hwnd, WM_USER_SELF_TERMINATE, 0, 0); SendMessage(platform_window<HWND>(), WM_USER_SELF_TERMINATE, 0, 0);
// free the render target // free the render target
machine().render().target_free(m_target); machine().render().target_free(m_target);
@ -865,14 +890,14 @@ void win_window_info::update()
if (!m_fullscreen) if (!m_fullscreen)
{ {
if (m_isminimized) if (m_isminimized)
SendMessage(m_hwnd, WM_USER_SET_MINSIZE, 0, 0); SendMessage(platform_window<HWND>(), WM_USER_SET_MINSIZE, 0, 0);
if (m_ismaximized) if (m_ismaximized)
SendMessage(m_hwnd, WM_USER_SET_MAXSIZE, 0, 0); SendMessage(platform_window<HWND>(), WM_USER_SET_MAXSIZE, 0, 0);
} }
} }
// if we're visible and running and not in the middle of a resize, draw // if we're visible and running and not in the middle of a resize, draw
if (m_hwnd != nullptr && m_target != nullptr && m_renderer != nullptr) if (platform_window<HWND>() != nullptr && m_target != nullptr && m_renderer != nullptr)
{ {
bool got_lock = true; bool got_lock = true;
@ -900,7 +925,7 @@ void win_window_info::update()
// post a redraw request with the primitive list as a parameter // post a redraw request with the primitive list as a parameter
last_update_time = timeGetTime(); last_update_time = timeGetTime();
mtlog_add("winwindow_video_window_update: PostMessage start"); mtlog_add("winwindow_video_window_update: PostMessage start");
SendMessage(m_hwnd, WM_USER_REDRAW, 0, (LPARAM)primlist); SendMessage(platform_window<HWND>(), WM_USER_REDRAW, 0, (LPARAM)primlist);
mtlog_add("winwindow_video_window_update: PostMessage end"); mtlog_add("winwindow_video_window_update: PostMessage end");
} }
} }
@ -932,7 +957,7 @@ osd_monitor_info *win_window_info::winwindow_video_window_monitor(const osd_rect
monitor = win_monitor_info::monitor_from_handle(MonitorFromRect(&p, MONITOR_DEFAULTTONEAREST)); monitor = win_monitor_info::monitor_from_handle(MonitorFromRect(&p, MONITOR_DEFAULTTONEAREST));
} }
else else
monitor = win_monitor_info::monitor_from_handle(MonitorFromWindow(m_hwnd, MONITOR_DEFAULTTONEAREST)); monitor = win_monitor_info::monitor_from_handle(MonitorFromWindow(platform_window<HWND>(), MONITOR_DEFAULTTONEAREST));
} }
// in full screen, just use the configured monitor // in full screen, just use the configured monitor
@ -1238,7 +1263,7 @@ int win_window_info::complete_create()
} }
// create the window, but don't show it yet // create the window, but don't show it yet
m_hwnd = win_create_window_ex_utf8( HWND hwnd = win_create_window_ex_utf8(
m_fullscreen ? FULLSCREEN_STYLE_EX : WINDOW_STYLE_EX, m_fullscreen ? FULLSCREEN_STYLE_EX : WINDOW_STYLE_EX,
"MAME", "MAME",
m_title, m_title,
@ -1249,14 +1274,14 @@ int win_window_info::complete_create()
menu, menu,
GetModuleHandleUni(), GetModuleHandleUni(),
nullptr); nullptr);
if (m_hwnd == nullptr)
if (hwnd == nullptr)
return 1; return 1;
// set window #0 as the focus window for all windows, required for D3D & multimonitor set_platform_window(hwnd);
m_focus_hwnd = win_window_list->m_hwnd;
// set a pointer back to us // set a pointer back to us
SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)this); SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)this);
// skip the positioning stuff for -video none */ // skip the positioning stuff for -video none */
if (video_config.mode == VIDEO_MODE_NONE) if (video_config.mode == VIDEO_MODE_NONE)
@ -1265,7 +1290,7 @@ int win_window_info::complete_create()
// adjust the window position to the initial width/height // adjust the window position to the initial width/height
tempwidth = (m_win_config.width != 0) ? m_win_config.width : 640; tempwidth = (m_win_config.width != 0) ? m_win_config.width : 640;
tempheight = (m_win_config.height != 0) ? m_win_config.height : 480; tempheight = (m_win_config.height != 0) ? m_win_config.height : 480;
SetWindowPos(m_hwnd, nullptr, monitorbounds.left() + 20, monitorbounds.top() + 20, SetWindowPos(platform_window<HWND>(), nullptr, monitorbounds.left() + 20, monitorbounds.top() + 20,
monitorbounds.left() + tempwidth + wnd_extra_width(), monitorbounds.left() + tempwidth + wnd_extra_width(),
monitorbounds.top() + tempheight + wnd_extra_height(), monitorbounds.top() + tempheight + wnd_extra_height(),
SWP_NOZORDER); SWP_NOZORDER);
@ -1289,14 +1314,14 @@ int win_window_info::complete_create()
if (m_renderer->create()) if (m_renderer->create())
return 1; return 1;
ShowWindow(m_hwnd, SW_SHOW); ShowWindow(platform_window<HWND>(), SW_SHOW);
} }
// clear the window // clear the window
dc = GetDC(m_hwnd); dc = GetDC(platform_window<HWND>());
GetClientRect(m_hwnd, &client); GetClientRect(platform_window<HWND>(), &client);
FillRect(dc, &client, (HBRUSH)GetStockObject(BLACK_BRUSH)); FillRect(dc, &client, (HBRUSH)GetStockObject(BLACK_BRUSH));
ReleaseDC(m_hwnd, dc); ReleaseDC(platform_window<HWND>(), dc);
return 0; return 0;
} }
@ -1329,7 +1354,7 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
HDC hdc = BeginPaint(wnd, &pstruct); HDC hdc = BeginPaint(wnd, &pstruct);
window->draw_video_contents(hdc, TRUE); window->draw_video_contents(hdc, TRUE);
if (window->win_has_menu()) if (window->win_has_menu())
DrawMenuBar(window->m_hwnd); DrawMenuBar(window->platform_window<HWND>());
EndPaint(wnd, &pstruct); EndPaint(wnd, &pstruct);
break; break;
} }
@ -1484,7 +1509,7 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
case WM_DESTROY: case WM_DESTROY:
global_free(window->m_renderer); global_free(window->m_renderer);
window->m_renderer = nullptr; window->m_renderer = nullptr;
window->m_hwnd = nullptr; window->set_platform_window(nullptr);
return DefWindowProc(wnd, message, wparam, lparam); return DefWindowProc(wnd, message, wparam, lparam);
// self redraw: draw ourself in a non-painty way // self redraw: draw ourself in a non-painty way
@ -1503,7 +1528,7 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
// self destruct // self destruct
case WM_USER_SELF_TERMINATE: case WM_USER_SELF_TERMINATE:
DestroyWindow(window->m_hwnd); DestroyWindow(window->platform_window<HWND>());
break; break;
// fullscreen set // fullscreen set
@ -1566,13 +1591,13 @@ void win_window_info::draw_video_contents(HDC dc, int update)
mtlog_add("draw_video_contents: render lock acquired"); mtlog_add("draw_video_contents: render lock acquired");
// if we're iconic, don't bother // if we're iconic, don't bother
if (m_hwnd != nullptr && !IsIconic(m_hwnd)) if (platform_window<HWND>() != nullptr && !IsIconic(platform_window<HWND>()))
{ {
// if no bitmap, just fill // if no bitmap, just fill
if (m_primlist == nullptr) if (m_primlist == nullptr)
{ {
RECT fill; RECT fill;
GetClientRect(m_hwnd, &fill); GetClientRect(platform_window<HWND>(), &fill);
FillRect(dc, &fill, (HBRUSH)GetStockObject(BLACK_BRUSH)); FillRect(dc, &fill, (HBRUSH)GetStockObject(BLACK_BRUSH));
} }
@ -1820,7 +1845,7 @@ void win_window_info::update_minmax_state()
// compare the maximum bounds versus the current bounds // compare the maximum bounds versus the current bounds
osd_dim minbounds = get_min_bounds(video_config.keepaspect); osd_dim minbounds = get_min_bounds(video_config.keepaspect);
osd_dim maxbounds = get_max_bounds(video_config.keepaspect); osd_dim maxbounds = get_max_bounds(video_config.keepaspect);
GetWindowRect(m_hwnd, &bounds); GetWindowRect(platform_window<HWND>(), &bounds);
// if either the width or height matches, we were maximized // if either the width or height matches, we were maximized
m_isminimized = (rect_width(&bounds) == minbounds.width()) || m_isminimized = (rect_width(&bounds) == minbounds.width()) ||
@ -1850,12 +1875,12 @@ void win_window_info::minimize_window()
// get the window rect // get the window rect
RECT bounds; RECT bounds;
GetWindowRect(m_hwnd, &bounds); GetWindowRect(platform_window<HWND>(), &bounds);
osd_rect newrect(bounds.left, bounds.top, newsize ); osd_rect newrect(bounds.left, bounds.top, newsize );
SetWindowPos(m_hwnd, nullptr, newrect.left(), newrect.top(), newrect.width(), newrect.height(), SWP_NOZORDER); SetWindowPos(platform_window<HWND>(), nullptr, newrect.left(), newrect.top(), newrect.width(), newrect.height(), SWP_NOZORDER);
} }
@ -1877,7 +1902,7 @@ void win_window_info::maximize_window()
work.top() + (work.height() - newsize.height()) / 2, work.top() + (work.height() - newsize.height()) / 2,
newsize); newsize);
SetWindowPos(m_hwnd, nullptr, newrect.left(), newrect.top(), newrect.width(), newrect.height(), SWP_NOZORDER); SetWindowPos(platform_window<HWND>(), nullptr, newrect.left(), newrect.top(), newrect.width(), newrect.height(), SWP_NOZORDER);
} }
@ -1894,7 +1919,7 @@ void win_window_info::adjust_window_position_after_major_change()
assert(GetCurrentThreadId() == window_threadid); assert(GetCurrentThreadId() == window_threadid);
// get the current size // get the current size
GetWindowRect(m_hwnd, &oldrect); GetWindowRect(platform_window<HWND>(), &oldrect);
osd_rect newrect = RECT_to_osd_rect(oldrect); osd_rect newrect = RECT_to_osd_rect(oldrect);
// adjust the window size so the client area is what we want // adjust the window size so the client area is what we want
@ -1915,7 +1940,7 @@ void win_window_info::adjust_window_position_after_major_change()
// adjust the position if different // adjust the position if different
if (oldrect.left != newrect.left() || oldrect.top != newrect.top() || if (oldrect.left != newrect.left() || oldrect.top != newrect.top() ||
oldrect.right != newrect.right() || oldrect.bottom != newrect.bottom()) oldrect.right != newrect.right() || oldrect.bottom != newrect.bottom())
SetWindowPos(m_hwnd, m_fullscreen ? HWND_TOPMOST : HWND_TOP, SetWindowPos(platform_window<HWND>(), m_fullscreen ? HWND_TOPMOST : HWND_TOP,
newrect.left(), newrect.top(), newrect.left(), newrect.top(),
newrect.width(), newrect.height(), 0); newrect.width(), newrect.height(), 0);
@ -1948,24 +1973,24 @@ void win_window_info::set_fullscreen(int fullscreen)
m_renderer = nullptr; m_renderer = nullptr;
// hide ourself // hide ourself
ShowWindow(m_hwnd, SW_HIDE); ShowWindow(platform_window<HWND>(), SW_HIDE);
// configure the window if non-fullscreen // configure the window if non-fullscreen
if (!fullscreen) if (!fullscreen)
{ {
// adjust the style // adjust the style
SetWindowLong(m_hwnd, GWL_STYLE, WINDOW_STYLE); SetWindowLong(platform_window<HWND>(), GWL_STYLE, WINDOW_STYLE);
SetWindowLong(m_hwnd, GWL_EXSTYLE, WINDOW_STYLE_EX); SetWindowLong(platform_window<HWND>(), GWL_EXSTYLE, WINDOW_STYLE_EX);
SetWindowPos(m_hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); SetWindowPos(platform_window<HWND>(), 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
// force to the bottom, then back on top // force to the bottom, then back on top
SetWindowPos(m_hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); SetWindowPos(platform_window<HWND>(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
SetWindowPos(m_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); SetWindowPos(platform_window<HWND>(), HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
// if we have previous non-fullscreen bounds, use those // if we have previous non-fullscreen bounds, use those
if (m_non_fullscreen_bounds.right != m_non_fullscreen_bounds.left) if (m_non_fullscreen_bounds.right != m_non_fullscreen_bounds.left)
{ {
SetWindowPos(m_hwnd, HWND_TOP, m_non_fullscreen_bounds.left, m_non_fullscreen_bounds.top, SetWindowPos(platform_window<HWND>(), HWND_TOP, m_non_fullscreen_bounds.left, m_non_fullscreen_bounds.top,
rect_width(&m_non_fullscreen_bounds), rect_height(&m_non_fullscreen_bounds), rect_width(&m_non_fullscreen_bounds), rect_height(&m_non_fullscreen_bounds),
SWP_NOZORDER); SWP_NOZORDER);
} }
@ -1973,7 +1998,7 @@ void win_window_info::set_fullscreen(int fullscreen)
// otherwise, set a small size and maximize from there // otherwise, set a small size and maximize from there
else else
{ {
SetWindowPos(m_hwnd, HWND_TOP, 0, 0, MIN_WINDOW_DIM, MIN_WINDOW_DIM, SWP_NOZORDER); SetWindowPos(platform_window<HWND>(), HWND_TOP, 0, 0, MIN_WINDOW_DIM, MIN_WINDOW_DIM, SWP_NOZORDER);
maximize_window(); maximize_window();
} }
} }
@ -1982,15 +2007,15 @@ void win_window_info::set_fullscreen(int fullscreen)
else else
{ {
// save the bounds // save the bounds
GetWindowRect(m_hwnd, &m_non_fullscreen_bounds); GetWindowRect(platform_window<HWND>(), &m_non_fullscreen_bounds);
// adjust the style // adjust the style
SetWindowLong(m_hwnd, GWL_STYLE, FULLSCREEN_STYLE); SetWindowLong(platform_window<HWND>(), GWL_STYLE, FULLSCREEN_STYLE);
SetWindowLong(m_hwnd, GWL_EXSTYLE, FULLSCREEN_STYLE_EX); SetWindowLong(platform_window<HWND>(), GWL_EXSTYLE, FULLSCREEN_STYLE_EX);
SetWindowPos(m_hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); SetWindowPos(platform_window<HWND>(), 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
// set topmost // set topmost
SetWindowPos(m_hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); SetWindowPos(platform_window<HWND>(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
} }
// adjust the window to compensate for the change // adjust the window to compensate for the change
@ -2000,7 +2025,7 @@ void win_window_info::set_fullscreen(int fullscreen)
if (!m_fullscreen || m_fullscreen_safe) if (!m_fullscreen || m_fullscreen_safe)
{ {
if (video_config.mode != VIDEO_MODE_NONE) if (video_config.mode != VIDEO_MODE_NONE)
ShowWindow(m_hwnd, SW_SHOW); ShowWindow(platform_window<HWND>(), SW_SHOW);
m_renderer = reinterpret_cast<osd_renderer *>(osd_renderer::make_for_type(video_config.mode, reinterpret_cast<osd_window *>(this))); m_renderer = reinterpret_cast<osd_renderer *>(osd_renderer::make_for_type(video_config.mode, reinterpret_cast<osd_window *>(this)));
if (m_renderer->create()) if (m_renderer->create())

View File

@ -59,7 +59,7 @@ public:
virtual bool win_has_menu() override virtual bool win_has_menu() override
{ {
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
return GetMenu(m_hwnd) ? true : false; return GetMenu(platform_window<HWND>()) ? true : false;
#else #else
return false; return false;
#endif #endif
@ -69,13 +69,18 @@ public:
{ {
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
RECT client; RECT client;
GetClientRect(m_hwnd, &client); GetClientRect(platform_window<HWND>(), &client);
return osd_dim(client.right - client.left, client.bottom - client.top); return osd_dim(client.right - client.left, client.bottom - client.top);
#else #else
throw ref new Platform::NotImplementedException(); throw ref new Platform::NotImplementedException();
#endif #endif
} }
void capture_pointer() override;
void release_pointer() override;
void show_pointer() override;
void hide_pointer() override;
virtual osd_monitor_info *monitor() const override { return m_monitor; } virtual osd_monitor_info *monitor() const override { return m_monitor; }
void destroy(); void destroy();
@ -137,6 +142,7 @@ private:
void adjust_window_position_after_major_change(); void adjust_window_position_after_major_change();
void set_fullscreen(int fullscreen); void set_fullscreen(int fullscreen);
static POINT s_saved_cursor_pos;
running_machine & m_machine; running_machine & m_machine;
}; };

View File

@ -73,7 +73,7 @@ public:
winwindow_toggle_full_screen(); winwindow_toggle_full_screen();
vsnprintf(buffer, ARRAY_LENGTH(buffer), msg, args); vsnprintf(buffer, ARRAY_LENGTH(buffer), msg, args);
win_message_box_utf8(win_window_list ? win_window_list->m_hwnd : nullptr, buffer, emulator_info::get_appname(), MB_OK); win_message_box_utf8(win_window_list ? win_window_list->platform_window<HWND>() : nullptr, buffer, emulator_info::get_appname(), MB_OK);
} }
else else
chain_output(channel, msg, args); chain_output(channel, msg, args);