Miscellaneous cleanup:

* osd/windows: Use steady clock for timing double-clicks.
* emu/uiinput.cpp: Made the event type a scoped enum.
This commit is contained in:
Vas Crabb 2020-10-10 03:11:01 +11:00
parent 7ae53fff26
commit d822e7ec4a
8 changed files with 298 additions and 298 deletions

View File

@ -109,13 +109,13 @@ bool ui_input_manager::push_event(ui_event evt)
// some pre-processing (this is an icky place to do this stuff!) // some pre-processing (this is an icky place to do this stuff!)
switch (evt.event_type) switch (evt.event_type)
{ {
case ui_event::MOUSE_MOVE: case ui_event::type::MOUSE_MOVE:
m_current_mouse_target = evt.target; m_current_mouse_target = evt.target;
m_current_mouse_x = evt.mouse_x; m_current_mouse_x = evt.mouse_x;
m_current_mouse_y = evt.mouse_y; m_current_mouse_y = evt.mouse_y;
break; break;
case ui_event::MOUSE_LEAVE: case ui_event::type::MOUSE_LEAVE:
if (m_current_mouse_target == evt.target) if (m_current_mouse_target == evt.target)
{ {
m_current_mouse_target = nullptr; m_current_mouse_target = nullptr;
@ -124,11 +124,11 @@ bool ui_input_manager::push_event(ui_event evt)
} }
break; break;
case ui_event::MOUSE_DOWN: case ui_event::type::MOUSE_DOWN:
m_current_mouse_down = true; m_current_mouse_down = true;
break; break;
case ui_event::MOUSE_UP: case ui_event::type::MOUSE_UP:
m_current_mouse_down = false; m_current_mouse_down = false;
break; break;
@ -301,8 +301,8 @@ g_profiler.stop();
void ui_input_manager::push_mouse_move_event(render_target* target, s32 x, s32 y) void ui_input_manager::push_mouse_move_event(render_target* target, s32 x, s32 y)
{ {
ui_event event = { ui_event::NONE }; ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::MOUSE_MOVE; event.event_type = ui_event::type::MOUSE_MOVE;
event.target = target; event.target = target;
event.mouse_x = x; event.mouse_x = x;
event.mouse_y = y; event.mouse_y = y;
@ -316,8 +316,8 @@ void ui_input_manager::push_mouse_move_event(render_target* target, s32 x, s32 y
void ui_input_manager::push_mouse_leave_event(render_target* target) void ui_input_manager::push_mouse_leave_event(render_target* target)
{ {
ui_event event = { ui_event::NONE }; ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::MOUSE_LEAVE; event.event_type = ui_event::type::MOUSE_LEAVE;
event.target = target; event.target = target;
push_event(event); push_event(event);
} }
@ -329,8 +329,8 @@ void ui_input_manager::push_mouse_leave_event(render_target* target)
void ui_input_manager::push_mouse_down_event(render_target* target, s32 x, s32 y) void ui_input_manager::push_mouse_down_event(render_target* target, s32 x, s32 y)
{ {
ui_event event = { ui_event::NONE }; ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::MOUSE_DOWN; event.event_type = ui_event::type::MOUSE_DOWN;
event.target = target; event.target = target;
event.mouse_x = x; event.mouse_x = x;
event.mouse_y = y; event.mouse_y = y;
@ -344,8 +344,8 @@ void ui_input_manager::push_mouse_down_event(render_target* target, s32 x, s32 y
void ui_input_manager::push_mouse_up_event(render_target* target, s32 x, s32 y) void ui_input_manager::push_mouse_up_event(render_target* target, s32 x, s32 y)
{ {
ui_event event = { ui_event::NONE }; ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::MOUSE_UP; event.event_type = ui_event::type::MOUSE_UP;
event.target = target; event.target = target;
event.mouse_x = x; event.mouse_x = x;
event.mouse_y = y; event.mouse_y = y;
@ -359,8 +359,8 @@ down event to the specified render_target
void ui_input_manager::push_mouse_rdown_event(render_target* target, s32 x, s32 y) void ui_input_manager::push_mouse_rdown_event(render_target* target, s32 x, s32 y)
{ {
ui_event event = { ui_event::NONE }; ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::MOUSE_RDOWN; event.event_type = ui_event::type::MOUSE_RDOWN;
event.target = target; event.target = target;
event.mouse_x = x; event.mouse_x = x;
event.mouse_y = y; event.mouse_y = y;
@ -374,8 +374,8 @@ down event to the specified render_target
void ui_input_manager::push_mouse_rup_event(render_target* target, s32 x, s32 y) void ui_input_manager::push_mouse_rup_event(render_target* target, s32 x, s32 y)
{ {
ui_event event = { ui_event::NONE }; ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::MOUSE_RUP; event.event_type = ui_event::type::MOUSE_RUP;
event.target = target; event.target = target;
event.mouse_x = x; event.mouse_x = x;
event.mouse_y = y; event.mouse_y = y;
@ -389,8 +389,8 @@ void ui_input_manager::push_mouse_rup_event(render_target* target, s32 x, s32 y)
-------------------------------------------------*/ -------------------------------------------------*/
void ui_input_manager::push_mouse_double_click_event(render_target* target, s32 x, s32 y) void ui_input_manager::push_mouse_double_click_event(render_target* target, s32 x, s32 y)
{ {
ui_event event = { ui_event::NONE }; ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::MOUSE_DOUBLE_CLICK; event.event_type = ui_event::type::MOUSE_DOUBLE_CLICK;
event.target = target; event.target = target;
event.mouse_x = x; event.mouse_x = x;
event.mouse_y = y; event.mouse_y = y;
@ -403,8 +403,8 @@ void ui_input_manager::push_mouse_double_click_event(render_target* target, s32
-------------------------------------------------*/ -------------------------------------------------*/
void ui_input_manager::push_char_event(render_target* target, char32_t ch) void ui_input_manager::push_char_event(render_target* target, char32_t ch)
{ {
ui_event event = { ui_event::NONE }; ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::IME_CHAR; event.event_type = ui_event::type::IME_CHAR;
event.target = target; event.target = target;
event.ch = ch; event.ch = ch;
push_event(event); push_event(event);
@ -417,8 +417,8 @@ void ui_input_manager::push_char_event(render_target* target, char32_t ch)
void ui_input_manager::push_mouse_wheel_event(render_target *target, s32 x, s32 y, short delta, int ucNumLines) void ui_input_manager::push_mouse_wheel_event(render_target *target, s32 x, s32 y, short delta, int ucNumLines)
{ {
ui_event event = { ui_event::NONE }; ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::MOUSE_WHEEL; event.event_type = ui_event::type::MOUSE_WHEEL;
event.target = target; event.target = target;
event.mouse_x = x; event.mouse_x = x;
event.mouse_y = y; event.mouse_y = y;

View File

@ -26,7 +26,7 @@
struct ui_event struct ui_event
{ {
enum type enum class type
{ {
NONE, NONE,
MOUSE_MOVE, MOUSE_MOVE,
@ -60,37 +60,36 @@ public:
void frame_update(); void frame_update();
/* pushes a single event onto the queue */ // pushes a single event onto the queue
bool push_event(ui_event event); bool push_event(ui_event event);
/* pops an event off of the queue */ // pops an event off of the queue
bool pop_event(ui_event *event); bool pop_event(ui_event *event);
/* check the next event type without removing it */ // check the next event type without removing it
ui_event::type peek_event_type() const { return (m_events_start != m_events_end) ? m_events[m_events_start].event_type : ui_event::NONE; } ui_event::type peek_event_type() const { return (m_events_start != m_events_end) ? m_events[m_events_start].event_type : ui_event::type::NONE; }
/* clears all outstanding events */ // clears all outstanding events
void reset(); void reset();
/* retrieves the current location of the mouse */ // retrieves the current location of the mouse
render_target *find_mouse(s32 *x, s32 *y, bool *button) const; render_target *find_mouse(s32 *x, s32 *y, bool *button) const;
ioport_field *find_mouse_field() const; ioport_field *find_mouse_field() const;
/* return true if a key down for the given user interface sequence is detected */ // return true if a key down for the given user interface sequence is detected
bool pressed(int code); bool pressed(int code);
// enable/disable UI key presses // enable/disable UI key presses
bool presses_enabled() const { return m_presses_enabled; } bool presses_enabled() const { return m_presses_enabled; }
void set_presses_enabled(bool enabled) { m_presses_enabled = enabled; } void set_presses_enabled(bool enabled) { m_presses_enabled = enabled; }
/* return true if a key down for the given user interface sequence is detected, or if // return true if a key down for the given user interface sequence is detected, or if autorepeat at the given speed is triggered
autorepeat at the given speed is triggered */
bool pressed_repeat(int code, int speed); bool pressed_repeat(int code, int speed);
// getters // getters
running_machine &machine() const { return m_machine; } running_machine &machine() const { return m_machine; }
// queueing events
void push_mouse_move_event(render_target* target, s32 x, s32 y); void push_mouse_move_event(render_target* target, s32 x, s32 y);
void push_mouse_leave_event(render_target* target); void push_mouse_leave_event(render_target* target);
void push_mouse_down_event(render_target* target, s32 x, s32 y); void push_mouse_down_event(render_target* target, s32 x, s32 y);
@ -108,19 +107,19 @@ private:
// internal state // internal state
running_machine & m_machine; // reference to our machine running_machine & m_machine; // reference to our machine
/* pressed states; retrieved with ui_input_pressed() */ // pressed states; retrieved with ui_input_pressed()
bool m_presses_enabled; bool m_presses_enabled;
osd_ticks_t m_next_repeat[IPT_COUNT]; osd_ticks_t m_next_repeat[IPT_COUNT];
u8 m_seqpressed[IPT_COUNT]; u8 m_seqpressed[IPT_COUNT];
/* mouse position/info */ // mouse position/info
render_target * m_current_mouse_target; render_target * m_current_mouse_target;
s32 m_current_mouse_x; s32 m_current_mouse_x;
s32 m_current_mouse_y; s32 m_current_mouse_y;
bool m_current_mouse_down; bool m_current_mouse_down;
ioport_field * m_current_mouse_field; ioport_field * m_current_mouse_field;
/* popped states; ring buffer of ui_events */ // popped states; ring buffer of ui_events
ui_event m_events[EVENT_QUEUE_SIZE]; ui_event m_events[EVENT_QUEUE_SIZE];
int m_events_start; int m_events_start;
int m_events_end; int m_events_end;

View File

@ -911,110 +911,110 @@ void menu::handle_events(uint32_t flags, event &ev)
{ {
switch (local_menu_event.event_type) switch (local_menu_event.event_type)
{ {
// if we are hovering over a valid item, select it with a single click // if we are hovering over a valid item, select it with a single click
case ui_event::MOUSE_DOWN: case ui_event::type::MOUSE_DOWN:
if (custom_mouse_down()) if (custom_mouse_down())
return; return;
if ((flags & PROCESS_ONLYCHAR) == 0) if ((flags & PROCESS_ONLYCHAR) == 0)
{ {
if (m_hover >= 0 && m_hover < m_items.size()) if (m_hover >= 0 && m_hover < m_items.size())
m_selected = m_hover;
else if (m_hover == HOVER_ARROW_UP)
{
if ((flags & FLAG_UI_DATS) != 0)
{
top_line -= m_visible_items - (last_item_visible() ? 1 : 0);
return;
}
m_selected -= m_visible_items;
if (m_selected < 0)
m_selected = 0;
top_line -= m_visible_items - (last_item_visible() ? 1 : 0);
}
else if (m_hover == HOVER_ARROW_DOWN)
{
if ((flags & FLAG_UI_DATS) != 0)
{
top_line += m_visible_lines - 2;
return;
}
m_selected += m_visible_lines - 2 + is_first_selected();
if (m_selected > m_items.size() - 1)
m_selected = m_items.size() - 1;
top_line += m_visible_lines - 2;
}
}
break;
// if we are hovering over a valid item, fake a UI_SELECT with a double-click
case ui_event::MOUSE_DOUBLE_CLICK:
if (!(flags & PROCESS_ONLYCHAR) && m_hover >= 0 && m_hover < m_items.size())
{
m_selected = m_hover; m_selected = m_hover;
ev.iptkey = IPT_UI_SELECT; else if (m_hover == HOVER_ARROW_UP)
if (is_last_selected())
{
ev.iptkey = IPT_UI_CANCEL;
stack_pop();
}
stop = true;
}
break;
// caught scroll event
case ui_event::MOUSE_WHEEL:
if (!(flags & PROCESS_ONLYCHAR))
{ {
if (local_menu_event.zdelta > 0) if ((flags & FLAG_UI_DATS) != 0)
{ {
if ((flags & FLAG_UI_DATS) != 0) top_line -= m_visible_items - (last_item_visible() ? 1 : 0);
{ return;
top_line -= local_menu_event.num_lines;
return;
}
if (is_first_selected())
select_last_item();
else
{
m_selected -= local_menu_event.num_lines;
validate_selection(-1);
}
top_line -= (m_selected <= top_line && top_line != 0);
if (m_selected <= top_line && m_visible_items != m_visible_lines)
top_line -= local_menu_event.num_lines;
} }
m_selected -= m_visible_items;
if (m_selected < 0)
m_selected = 0;
top_line -= m_visible_items - (last_item_visible() ? 1 : 0);
}
else if (m_hover == HOVER_ARROW_DOWN)
{
if ((flags & FLAG_UI_DATS) != 0)
{
top_line += m_visible_lines - 2;
return;
}
m_selected += m_visible_lines - 2 + is_first_selected();
if (m_selected > m_items.size() - 1)
m_selected = m_items.size() - 1;
top_line += m_visible_lines - 2;
}
}
break;
// if we are hovering over a valid item, fake a UI_SELECT with a double-click
case ui_event::type::MOUSE_DOUBLE_CLICK:
if (!(flags & PROCESS_ONLYCHAR) && m_hover >= 0 && m_hover < m_items.size())
{
m_selected = m_hover;
ev.iptkey = IPT_UI_SELECT;
if (is_last_selected())
{
ev.iptkey = IPT_UI_CANCEL;
stack_pop();
}
stop = true;
}
break;
// caught scroll event
case ui_event::type::MOUSE_WHEEL:
if (!(flags & PROCESS_ONLYCHAR))
{
if (local_menu_event.zdelta > 0)
{
if ((flags & FLAG_UI_DATS) != 0)
{
top_line -= local_menu_event.num_lines;
return;
}
if (is_first_selected())
select_last_item();
else else
{ {
if ((flags & FLAG_UI_DATS)) m_selected -= local_menu_event.num_lines;
{ validate_selection(-1);
top_line += local_menu_event.num_lines;
return;
}
if (is_last_selected())
select_first_item();
else
{
m_selected += local_menu_event.num_lines;
validate_selection(1);
}
top_line += (m_selected >= top_line + m_visible_items + (top_line != 0));
if (m_selected >= (top_line + m_visible_items + (top_line != 0)))
top_line += local_menu_event.num_lines;
} }
top_line -= (m_selected <= top_line && top_line != 0);
if (m_selected <= top_line && m_visible_items != m_visible_lines)
top_line -= local_menu_event.num_lines;
} }
break; else
{
if ((flags & FLAG_UI_DATS))
{
top_line += local_menu_event.num_lines;
return;
}
if (is_last_selected())
select_first_item();
else
{
m_selected += local_menu_event.num_lines;
validate_selection(1);
}
top_line += (m_selected >= top_line + m_visible_items + (top_line != 0));
if (m_selected >= (top_line + m_visible_items + (top_line != 0)))
top_line += local_menu_event.num_lines;
}
}
break;
// translate CHAR events into specials // translate CHAR events into specials
case ui_event::IME_CHAR: case ui_event::type::IME_CHAR:
ev.iptkey = IPT_SPECIAL; ev.iptkey = IPT_SPECIAL;
ev.unichar = local_menu_event.ch; ev.unichar = local_menu_event.ch;
stop = true; stop = true;
break; break;
// ignore everything else // ignore everything else
default: default:
break; break;
} }
} }
} }

View File

@ -1661,7 +1661,7 @@ void menu_select_launch::handle_events(uint32_t flags, event &ev)
switch (local_menu_event.event_type) switch (local_menu_event.event_type)
{ {
// if we are hovering over a valid item, select it with a single click // if we are hovering over a valid item, select it with a single click
case ui_event::MOUSE_DOWN: case ui_event::type::MOUSE_DOWN:
if (m_ui_error) if (m_ui_error)
{ {
ev.iptkey = IPT_OTHER; ev.iptkey = IPT_OTHER;
@ -1761,7 +1761,7 @@ void menu_select_launch::handle_events(uint32_t flags, event &ev)
break; break;
// if we are hovering over a valid item, fake a UI_SELECT with a double-click // if we are hovering over a valid item, fake a UI_SELECT with a double-click
case ui_event::MOUSE_DOUBLE_CLICK: case ui_event::type::MOUSE_DOUBLE_CLICK:
if (hover() >= 0 && hover() < item_count()) if (hover() >= 0 && hover() < item_count())
{ {
set_selected_index(hover()); set_selected_index(hover());
@ -1777,7 +1777,7 @@ void menu_select_launch::handle_events(uint32_t flags, event &ev)
break; break;
// caught scroll event // caught scroll event
case ui_event::MOUSE_WHEEL: case ui_event::type::MOUSE_WHEEL:
if (hover() >= 0 && hover() < item_count() - skip_main_items - 1) if (hover() >= 0 && hover() < item_count() - skip_main_items - 1)
{ {
if (local_menu_event.zdelta > 0) if (local_menu_event.zdelta > 0)
@ -1807,7 +1807,7 @@ void menu_select_launch::handle_events(uint32_t flags, event &ev)
break; break;
// translate CHAR events into specials // translate CHAR events into specials
case ui_event::IME_CHAR: case ui_event::type::IME_CHAR:
if (exclusive_input_pressed(ev.iptkey, IPT_UI_FOCUS_NEXT, 0) || exclusive_input_pressed(ev.iptkey, IPT_UI_FOCUS_PREV, 0)) if (exclusive_input_pressed(ev.iptkey, IPT_UI_FOCUS_NEXT, 0) || exclusive_input_pressed(ev.iptkey, IPT_UI_FOCUS_PREV, 0))
{ {
stop = true; stop = true;
@ -1824,7 +1824,7 @@ void menu_select_launch::handle_events(uint32_t flags, event &ev)
} }
break; break;
case ui_event::MOUSE_RDOWN: case ui_event::type::MOUSE_RDOWN:
if (hover() >= 0 && hover() < item_count() - skip_main_items - 1) if (hover() >= 0 && hover() < item_count() - skip_main_items - 1)
{ {
set_selected_index(hover()); set_selected_index(hover());
@ -1847,18 +1847,18 @@ void menu_select_launch::handle_events(uint32_t flags, event &ev)
{ {
switch (machine().ui_input().peek_event_type()) switch (machine().ui_input().peek_event_type())
{ {
case ui_event::MOUSE_DOWN: case ui_event::type::MOUSE_DOWN:
case ui_event::MOUSE_RDOWN: case ui_event::type::MOUSE_RDOWN:
case ui_event::MOUSE_DOUBLE_CLICK: case ui_event::type::MOUSE_DOUBLE_CLICK:
case ui_event::MOUSE_WHEEL: case ui_event::type::MOUSE_WHEEL:
stop = true; stop = true;
break; break;
case ui_event::NONE: case ui_event::type::NONE:
case ui_event::MOUSE_MOVE: case ui_event::type::MOUSE_MOVE:
case ui_event::MOUSE_LEAVE: case ui_event::type::MOUSE_LEAVE:
case ui_event::MOUSE_UP: case ui_event::type::MOUSE_UP:
case ui_event::MOUSE_RUP: case ui_event::type::MOUSE_RUP:
case ui_event::IME_CHAR: case ui_event::type::IME_CHAR:
break; break;
} }
} }

View File

@ -1004,7 +1004,7 @@ void mame_ui_manager::process_natural_keyboard()
while (machine().ui_input().pop_event(&event)) while (machine().ui_input().pop_event(&event))
{ {
// if this was a UI_EVENT_CHAR event, post it // if this was a UI_EVENT_CHAR event, post it
if (event.event_type == ui_event::IME_CHAR) if (event.event_type == ui_event::type::IME_CHAR)
machine().ioport().natkeyboard().post_char(event.ch); machine().ioport().natkeyboard().post_char(event.ch);
} }

View File

@ -353,7 +353,7 @@ void debug_imgui::handle_keys()
{ {
switch (event.event_type) switch (event.event_type)
{ {
case ui_event::IME_CHAR: case ui_event::type::IME_CHAR:
m_key_char = event.ch; m_key_char = event.ch;
if(focus_view != nullptr) if(focus_view != nullptr)
focus_view->view->process_char(m_key_char); focus_view->view->process_char(m_key_char);

View File

@ -14,11 +14,9 @@
// standard C headers // standard C headers
#include <process.h> #include <process.h>
#include <algorithm>
#include <atomic> #include <atomic>
#include <cstring> #include <cstring>
#include <chrono>
#include <list>
#include <memory>
// MAME headers // MAME headers
#include "emu.h" #include "emu.h"
@ -96,7 +94,7 @@ static DWORD main_threadid;
//============================================================ //============================================================
// event handling // event handling
static std::chrono::system_clock::time_point last_event_check; static std::chrono::steady_clock::time_point last_event_check;
static int ui_temp_pause; static int ui_temp_pause;
static int ui_temp_was_paused; static int ui_temp_was_paused;
@ -295,29 +293,31 @@ void windows_osd_interface::window_exit()
CloseHandle(ui_pause_event); CloseHandle(ui_pause_event);
} }
win_window_info::win_window_info( win_window_info::win_window_info(
running_machine &machine, running_machine &machine,
int index, int index,
std::shared_ptr<osd_monitor_info> monitor, std::shared_ptr<osd_monitor_info> monitor,
const osd_window_config *config) : osd_window_t(*config), const osd_window_config *config)
m_next(nullptr), : osd_window_t(*config)
m_init_state(0), , m_next(nullptr)
m_startmaximized(0), , m_init_state(0)
m_isminimized(0), , m_startmaximized(0)
m_ismaximized(0), , m_isminimized(0)
m_monitor(monitor), , m_ismaximized(0)
m_fullscreen(!video_config.windowed), , m_monitor(monitor)
m_fullscreen_safe(0), , m_fullscreen(!video_config.windowed)
m_aspect(0), , m_fullscreen_safe(0)
m_target(nullptr), , m_aspect(0)
m_targetview(0), , m_target(nullptr)
m_targetorient(0), , m_targetview(0)
m_targetvismask(0), , m_targetorient(0)
m_lastclicktime(std::chrono::system_clock::time_point::min()), , m_targetvismask(0)
m_lastclickx(0), , m_lastclicktime(std::chrono::steady_clock::time_point::min())
m_lastclicky(0), , m_lastclickx(0)
m_machine(machine), , m_lastclicky(0)
m_attached_mode(false) , m_machine(machine)
, m_attached_mode(false)
{ {
memset(m_title,0,sizeof(m_title)); memset(m_title,0,sizeof(m_title));
m_non_fullscreen_bounds.left = 0; m_non_fullscreen_bounds.left = 0;
@ -350,7 +350,7 @@ void win_window_info::hide_pointer()
{ {
GetCursorPos(&s_saved_cursor_pos); GetCursorPos(&s_saved_cursor_pos);
while (ShowCursor(FALSE) >= -1) {}; while (ShowCursor(FALSE) >= -1) { }
ShowCursor(TRUE); ShowCursor(TRUE);
} }
@ -402,7 +402,7 @@ void win_window_info::show_pointer()
void winwindow_process_events_periodic(running_machine &machine) void winwindow_process_events_periodic(running_machine &machine)
{ {
auto currticks = std::chrono::system_clock::now(); auto currticks = std::chrono::steady_clock::now();
assert(GetCurrentThreadId() == main_threadid); assert(GetCurrentThreadId() == main_threadid);
@ -465,7 +465,7 @@ void winwindow_process_events(running_machine &machine, bool ingame, bool nodisp
assert(GetCurrentThreadId() == main_threadid); assert(GetCurrentThreadId() == main_threadid);
// remember the last time we did this // remember the last time we did this
last_event_check = std::chrono::system_clock::now(); last_event_check = std::chrono::steady_clock::now();
do do
{ {
@ -1185,7 +1185,7 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
auto *window = (win_window_info *)ptr; auto *window = (win_window_info *)ptr;
// we may get called before SetWindowLongPtr is called // we may get called before SetWindowLongPtr is called
if (window != nullptr) if (window)
{ {
assert(GetCurrentThreadId() == window_threadid); assert(GetCurrentThreadId() == window_threadid);
window->update_minmax_state(); window->update_minmax_state();
@ -1194,8 +1194,8 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
// handle a few messages // handle a few messages
switch (message) switch (message)
{ {
// paint: redraw the last bitmap // paint: redraw the last bitmap
case WM_PAINT: case WM_PAINT:
{ {
PAINTSTRUCT pstruct; PAINTSTRUCT pstruct;
HDC hdc = BeginPaint(wnd, &pstruct); HDC hdc = BeginPaint(wnd, &pstruct);
@ -1203,37 +1203,37 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
if (window->win_has_menu()) if (window->win_has_menu())
DrawMenuBar(window->platform_window()); DrawMenuBar(window->platform_window());
EndPaint(wnd, &pstruct); EndPaint(wnd, &pstruct);
break;
} }
break;
// non-client paint: punt if full screen // non-client paint: punt if full screen
case WM_NCPAINT: case WM_NCPAINT:
if (!window->fullscreen() || window->win_has_menu()) if (!window->fullscreen() || window->win_has_menu())
return DefWindowProc(wnd, message, wparam, lparam); return DefWindowProc(wnd, message, wparam, lparam);
break; break;
// input: handle the raw input // input: handle the raw input
case WM_INPUT: case WM_INPUT:
downcast<windows_osd_interface&>(window->machine().osd()).handle_input_event(INPUT_EVENT_RAWINPUT, &lparam); downcast<windows_osd_interface&>(window->machine().osd()).handle_input_event(INPUT_EVENT_RAWINPUT, &lparam);
break; break;
// syskeys - ignore // syskeys - ignore
case WM_SYSKEYUP: case WM_SYSKEYUP:
case WM_SYSKEYDOWN: case WM_SYSKEYDOWN:
break; break;
// input events // input events
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
window->machine().ui_input().push_mouse_move_event(window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); window->machine().ui_input().push_mouse_move_event(window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
break; break;
case WM_MOUSELEAVE: case WM_MOUSELEAVE:
window->machine().ui_input().push_mouse_leave_event(window->m_target); window->machine().ui_input().push_mouse_leave_event(window->m_target);
break; break;
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
{ {
auto ticks = std::chrono::system_clock::now(); auto const ticks = std::chrono::steady_clock::now();
window->machine().ui_input().push_mouse_down_event(window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); window->machine().ui_input().push_mouse_down_event(window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
// check for a double-click // check for a double-click
@ -1241,7 +1241,7 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
GET_X_LPARAM(lparam) >= window->m_lastclickx - 4 && GET_X_LPARAM(lparam) <= window->m_lastclickx + 4 && GET_X_LPARAM(lparam) >= window->m_lastclickx - 4 && GET_X_LPARAM(lparam) <= window->m_lastclickx + 4 &&
GET_Y_LPARAM(lparam) >= window->m_lastclicky - 4 && GET_Y_LPARAM(lparam) <= window->m_lastclicky + 4) GET_Y_LPARAM(lparam) >= window->m_lastclicky - 4 && GET_Y_LPARAM(lparam) <= window->m_lastclicky + 4)
{ {
window->m_lastclicktime = std::chrono::system_clock::time_point::min(); window->m_lastclicktime = std::chrono::steady_clock::time_point::min();
window->machine().ui_input().push_mouse_double_click_event(window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); window->machine().ui_input().push_mouse_double_click_event(window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
} }
else else
@ -1250,26 +1250,26 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
window->m_lastclickx = GET_X_LPARAM(lparam); window->m_lastclickx = GET_X_LPARAM(lparam);
window->m_lastclicky = GET_Y_LPARAM(lparam); window->m_lastclicky = GET_Y_LPARAM(lparam);
} }
break;
} }
break;
case WM_LBUTTONUP: case WM_LBUTTONUP:
window->machine().ui_input().push_mouse_up_event(window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); window->machine().ui_input().push_mouse_up_event(window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
break; break;
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
window->machine().ui_input().push_mouse_rdown_event(window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); window->machine().ui_input().push_mouse_rdown_event(window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
break; break;
case WM_RBUTTONUP: case WM_RBUTTONUP:
window->machine().ui_input().push_mouse_rup_event(window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); window->machine().ui_input().push_mouse_rup_event(window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
break; break;
case WM_CHAR: case WM_CHAR:
window->machine().ui_input().push_char_event(window->m_target, (char32_t) wparam); window->machine().ui_input().push_char_event(window->m_target, (char32_t) wparam);
break; break;
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
{ {
UINT ucNumLines = 3; // default UINT ucNumLines = 3; // default
SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &ucNumLines, 0); SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &ucNumLines, 0);
@ -1277,32 +1277,33 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
break; break;
} }
// pause the system when we start a menu or resize // pause the system when we start a menu or resize
case WM_ENTERSIZEMOVE: case WM_ENTERSIZEMOVE:
window->m_resize_state = RESIZE_STATE_RESIZING; window->m_resize_state = RESIZE_STATE_RESIZING;
case WM_ENTERMENULOOP: case WM_ENTERMENULOOP:
winwindow_ui_pause(window->machine(), TRUE); winwindow_ui_pause(window->machine(), TRUE);
break; break;
// unpause the system when we stop a menu or resize and force a redraw // unpause the system when we stop a menu or resize and force a redraw
case WM_EXITSIZEMOVE: case WM_EXITSIZEMOVE:
window->m_resize_state = RESIZE_STATE_PENDING; window->m_resize_state = RESIZE_STATE_PENDING;
case WM_EXITMENULOOP: case WM_EXITMENULOOP:
winwindow_ui_pause(window->machine(), FALSE); winwindow_ui_pause(window->machine(), FALSE);
InvalidateRect(wnd, nullptr, FALSE); InvalidateRect(wnd, nullptr, FALSE);
break; break;
// get min/max info: set the minimum window size // get min/max info: set the minimum window size
case WM_GETMINMAXINFO: case WM_GETMINMAXINFO:
{ {
auto *minmax = (MINMAXINFO *)lparam; auto *minmax = (MINMAXINFO *)lparam;
minmax->ptMinTrackSize.x = MIN_WINDOW_DIMX; minmax->ptMinTrackSize.x = MIN_WINDOW_DIMX;
minmax->ptMinTrackSize.y = MIN_WINDOW_DIMY; minmax->ptMinTrackSize.y = MIN_WINDOW_DIMY;
break; break;
} }
break;
// sizing: constrain to the aspect ratio unless control key is held down // sizing: constrain to the aspect ratio unless control key is held down
case WM_SIZING: case WM_SIZING:
{ {
RECT *rect = (RECT *)lparam; RECT *rect = (RECT *)lparam;
if (video_config.keepaspect && !(GetAsyncKeyState(VK_CONTROL) & 0x8000)) if (video_config.keepaspect && !(GetAsyncKeyState(VK_CONTROL) & 0x8000))
@ -1314,11 +1315,11 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
rect->right = r.right(); rect->right = r.right();
} }
InvalidateRect(wnd, nullptr, FALSE); InvalidateRect(wnd, nullptr, FALSE);
break;
} }
break;
// syscommands: catch win_start_maximized // syscommands: catch win_start_maximized
case WM_SYSCOMMAND: case WM_SYSCOMMAND:
{ {
uint16_t cmd = wparam & 0xfff0; uint16_t cmd = wparam & 0xfff0;
@ -1339,22 +1340,22 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
window->maximize_window(); window->maximize_window();
break; break;
} }
return DefWindowProc(wnd, message, wparam, lparam);
} }
return DefWindowProc(wnd, message, wparam, lparam);
// close: cause MAME to exit // close: cause MAME to exit
case WM_CLOSE: case WM_CLOSE:
window->machine().schedule_exit(); window->machine().schedule_exit();
break; break;
// destroy: clean up all attached rendering bits and nullptr out our hwnd // destroy: clean up all attached rendering bits and nullptr out our hwnd
case WM_DESTROY: case WM_DESTROY:
window->renderer_reset(); window->renderer_reset();
window->set_platform_window(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
case WM_USER_REDRAW: case WM_USER_REDRAW:
{ {
HDC hdc = GetDC(wnd); HDC hdc = GetDC(wnd);
@ -1362,46 +1363,46 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
window->draw_video_contents(hdc, false); window->draw_video_contents(hdc, false);
ReleaseDC(wnd, hdc); ReleaseDC(wnd, hdc);
break;
} }
break;
// fullscreen set // fullscreen set
case WM_USER_SET_FULLSCREEN: case WM_USER_SET_FULLSCREEN:
window->set_fullscreen(wparam); window->set_fullscreen(wparam);
break; break;
// minimum size set // minimum size set
case WM_USER_SET_MINSIZE: case WM_USER_SET_MINSIZE:
window->minimize_window(); window->minimize_window();
break; break;
// maximum size set // maximum size set
case WM_USER_SET_MAXSIZE: case WM_USER_SET_MAXSIZE:
window->maximize_window(); window->maximize_window();
break; break;
// maximum size set // maximum size set
case WM_DISPLAYCHANGE: case WM_DISPLAYCHANGE:
/* FIXME: The current codebase has an issue with setting aspect /* FIXME: The current codebase has an issue with setting aspect
* ratios correctly after display change. set_aspect should * ratios correctly after display change. set_aspect should
* be set_forced_aspect and on a refresh this forced aspect should * be set_forced_aspect and on a refresh this forced aspect should
* be preserved if set. If not, the standard aspect calculation * be preserved if set. If not, the standard aspect calculation
* should be used. * should be used.
*/ */
window->m_monitor->refresh(); window->m_monitor->refresh();
window->m_monitor->update_resolution(LOWORD(lparam), HIWORD(lparam)); window->m_monitor->update_resolution(LOWORD(lparam), HIWORD(lparam));
break; break;
// set focus: if we're not the primary window, switch back // set focus: if we're not the primary window, switch back
// commented out ATM because this prevents us from resizing secondary windows // commented out ATM because this prevents us from resizing secondary windows
// case WM_SETFOCUS: // case WM_SETFOCUS:
// if (window != osd_common_t::s_window_list && osd_common_t::s_window_list != nullptr) // if (window != osd_common_t::s_window_list && osd_common_t::s_window_list != nullptr)
// SetFocus(osd_common_t::s_window_list->m_hwnd); // SetFocus(osd_common_t::s_window_list->m_hwnd);
// break; // break;
// everything else: defaults // everything else: defaults
default: default:
return DefWindowProc(wnd, message, wparam, lparam); return DefWindowProc(wnd, message, wparam, lparam);
} }
return 0; return 0;

View File

@ -5,28 +5,28 @@
// window.h - Win32 window handling // window.h - Win32 window handling
// //
//============================================================ //============================================================
#ifndef MAME_OSD_WINDOWS_WINDOW_H
#define MAME_OSD_WINDOWS_WINDOW_H
#ifndef __WIN_WINDOW__ #pragma once
#define __WIN_WINDOW__
#include "render.h"
#include "modules/osdwindow.h"
#include "modules/lib/osdlib.h"
#include <chrono>
#include <list>
#include <memory>
#include <mutex>
#include <utility>
#include <vector>
// standard windows headers // standard windows headers
#include <windows.h> #include <windows.h>
#include <windowsx.h> #include <windowsx.h>
#include <mmsystem.h> #include <mmsystem.h>
#include <chrono>
#include <mutex>
#include <memory>
#include <list>
#include "render.h"
#include "modules/osdwindow.h"
//============================================================
// PARAMETERS
//============================================================
//============================================================ //============================================================
// CONSTANTS // CONSTANTS
@ -128,7 +128,7 @@ public:
u32 m_targetvismask; u32 m_targetvismask;
// input info // input info
std::chrono::system_clock::time_point m_lastclicktime; std::chrono::steady_clock::time_point m_lastclicktime;
int m_lastclickx; int m_lastclickx;
int m_lastclicky; int m_lastclicky;
@ -206,4 +206,4 @@ static inline int rect_height(const RECT *rect)
return rect->bottom - rect->top; return rect->bottom - rect->top;
} }
#endif #endif // MAME_OSD_WINDOWS_WINDOW_H