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!)
switch (evt.event_type)
{
case ui_event::MOUSE_MOVE:
case ui_event::type::MOUSE_MOVE:
m_current_mouse_target = evt.target;
m_current_mouse_x = evt.mouse_x;
m_current_mouse_y = evt.mouse_y;
break;
case ui_event::MOUSE_LEAVE:
case ui_event::type::MOUSE_LEAVE:
if (m_current_mouse_target == evt.target)
{
m_current_mouse_target = nullptr;
@ -124,11 +124,11 @@ bool ui_input_manager::push_event(ui_event evt)
}
break;
case ui_event::MOUSE_DOWN:
case ui_event::type::MOUSE_DOWN:
m_current_mouse_down = true;
break;
case ui_event::MOUSE_UP:
case ui_event::type::MOUSE_UP:
m_current_mouse_down = false;
break;
@ -301,8 +301,8 @@ g_profiler.stop();
void ui_input_manager::push_mouse_move_event(render_target* target, s32 x, s32 y)
{
ui_event event = { ui_event::NONE };
event.event_type = ui_event::MOUSE_MOVE;
ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::type::MOUSE_MOVE;
event.target = target;
event.mouse_x = x;
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)
{
ui_event event = { ui_event::NONE };
event.event_type = ui_event::MOUSE_LEAVE;
ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::type::MOUSE_LEAVE;
event.target = target;
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)
{
ui_event event = { ui_event::NONE };
event.event_type = ui_event::MOUSE_DOWN;
ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::type::MOUSE_DOWN;
event.target = target;
event.mouse_x = x;
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)
{
ui_event event = { ui_event::NONE };
event.event_type = ui_event::MOUSE_UP;
ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::type::MOUSE_UP;
event.target = target;
event.mouse_x = x;
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)
{
ui_event event = { ui_event::NONE };
event.event_type = ui_event::MOUSE_RDOWN;
ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::type::MOUSE_RDOWN;
event.target = target;
event.mouse_x = x;
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)
{
ui_event event = { ui_event::NONE };
event.event_type = ui_event::MOUSE_RUP;
ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::type::MOUSE_RUP;
event.target = target;
event.mouse_x = x;
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)
{
ui_event event = { ui_event::NONE };
event.event_type = ui_event::MOUSE_DOUBLE_CLICK;
ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::type::MOUSE_DOUBLE_CLICK;
event.target = target;
event.mouse_x = x;
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)
{
ui_event event = { ui_event::NONE };
event.event_type = ui_event::IME_CHAR;
ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::type::IME_CHAR;
event.target = target;
event.ch = ch;
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)
{
ui_event event = { ui_event::NONE };
event.event_type = ui_event::MOUSE_WHEEL;
ui_event event = { ui_event::type::NONE };
event.event_type = ui_event::type::MOUSE_WHEEL;
event.target = target;
event.mouse_x = x;
event.mouse_y = y;

View File

@ -26,7 +26,7 @@
struct ui_event
{
enum type
enum class type
{
NONE,
MOUSE_MOVE,
@ -60,37 +60,36 @@ public:
void frame_update();
/* pushes a single event onto the queue */
// pushes a single event onto the queue
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);
/* 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; }
// 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::type::NONE; }
/* clears all outstanding events */
// clears all outstanding events
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;
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);
// enable/disable UI key presses
bool presses_enabled() const { return m_presses_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
autorepeat at the given speed is triggered */
// return true if a key down for the given user interface sequence is detected, or if autorepeat at the given speed is triggered
bool pressed_repeat(int code, int speed);
// getters
running_machine &machine() const { return m_machine; }
// queueing events
void push_mouse_move_event(render_target* target, s32 x, s32 y);
void push_mouse_leave_event(render_target* target);
void push_mouse_down_event(render_target* target, s32 x, s32 y);
@ -108,19 +107,19 @@ private:
// internal state
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;
osd_ticks_t m_next_repeat[IPT_COUNT];
u8 m_seqpressed[IPT_COUNT];
/* mouse position/info */
// mouse position/info
render_target * m_current_mouse_target;
s32 m_current_mouse_x;
s32 m_current_mouse_y;
bool m_current_mouse_down;
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];
int m_events_start;
int m_events_end;

View File

@ -912,7 +912,7 @@ void menu::handle_events(uint32_t flags, event &ev)
switch (local_menu_event.event_type)
{
// 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())
return;
@ -948,7 +948,7 @@ void menu::handle_events(uint32_t flags, event &ev)
break;
// 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 (!(flags & PROCESS_ONLYCHAR) && m_hover >= 0 && m_hover < m_items.size())
{
m_selected = m_hover;
@ -963,7 +963,7 @@ void menu::handle_events(uint32_t flags, event &ev)
break;
// caught scroll event
case ui_event::MOUSE_WHEEL:
case ui_event::type::MOUSE_WHEEL:
if (!(flags & PROCESS_ONLYCHAR))
{
if (local_menu_event.zdelta > 0)
@ -1006,7 +1006,7 @@ void menu::handle_events(uint32_t flags, event &ev)
break;
// translate CHAR events into specials
case ui_event::IME_CHAR:
case ui_event::type::IME_CHAR:
ev.iptkey = IPT_SPECIAL;
ev.unichar = local_menu_event.ch;
stop = true;

View File

@ -1661,7 +1661,7 @@ void menu_select_launch::handle_events(uint32_t flags, event &ev)
switch (local_menu_event.event_type)
{
// 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)
{
ev.iptkey = IPT_OTHER;
@ -1761,7 +1761,7 @@ void menu_select_launch::handle_events(uint32_t flags, event &ev)
break;
// 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())
{
set_selected_index(hover());
@ -1777,7 +1777,7 @@ void menu_select_launch::handle_events(uint32_t flags, event &ev)
break;
// 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 (local_menu_event.zdelta > 0)
@ -1807,7 +1807,7 @@ void menu_select_launch::handle_events(uint32_t flags, event &ev)
break;
// 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))
{
stop = true;
@ -1824,7 +1824,7 @@ void menu_select_launch::handle_events(uint32_t flags, event &ev)
}
break;
case ui_event::MOUSE_RDOWN:
case ui_event::type::MOUSE_RDOWN:
if (hover() >= 0 && hover() < item_count() - skip_main_items - 1)
{
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())
{
case ui_event::MOUSE_DOWN:
case ui_event::MOUSE_RDOWN:
case ui_event::MOUSE_DOUBLE_CLICK:
case ui_event::MOUSE_WHEEL:
case ui_event::type::MOUSE_DOWN:
case ui_event::type::MOUSE_RDOWN:
case ui_event::type::MOUSE_DOUBLE_CLICK:
case ui_event::type::MOUSE_WHEEL:
stop = true;
break;
case ui_event::NONE:
case ui_event::MOUSE_MOVE:
case ui_event::MOUSE_LEAVE:
case ui_event::MOUSE_UP:
case ui_event::MOUSE_RUP:
case ui_event::IME_CHAR:
case ui_event::type::NONE:
case ui_event::type::MOUSE_MOVE:
case ui_event::type::MOUSE_LEAVE:
case ui_event::type::MOUSE_UP:
case ui_event::type::MOUSE_RUP:
case ui_event::type::IME_CHAR:
break;
}
}

View File

@ -1004,7 +1004,7 @@ void mame_ui_manager::process_natural_keyboard()
while (machine().ui_input().pop_event(&event))
{
// 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);
}

View File

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

View File

@ -14,11 +14,9 @@
// standard C headers
#include <process.h>
#include <algorithm>
#include <atomic>
#include <cstring>
#include <chrono>
#include <list>
#include <memory>
// MAME headers
#include "emu.h"
@ -96,7 +94,7 @@ static DWORD main_threadid;
//============================================================
// 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_was_paused;
@ -295,29 +293,31 @@ void windows_osd_interface::window_exit()
CloseHandle(ui_pause_event);
}
win_window_info::win_window_info(
running_machine &machine,
int index,
std::shared_ptr<osd_monitor_info> monitor,
const osd_window_config *config) : osd_window_t(*config),
m_next(nullptr),
m_init_state(0),
m_startmaximized(0),
m_isminimized(0),
m_ismaximized(0),
m_monitor(monitor),
m_fullscreen(!video_config.windowed),
m_fullscreen_safe(0),
m_aspect(0),
m_target(nullptr),
m_targetview(0),
m_targetorient(0),
m_targetvismask(0),
m_lastclicktime(std::chrono::system_clock::time_point::min()),
m_lastclickx(0),
m_lastclicky(0),
m_machine(machine),
m_attached_mode(false)
const osd_window_config *config)
: osd_window_t(*config)
, m_next(nullptr)
, m_init_state(0)
, m_startmaximized(0)
, m_isminimized(0)
, m_ismaximized(0)
, m_monitor(monitor)
, m_fullscreen(!video_config.windowed)
, m_fullscreen_safe(0)
, m_aspect(0)
, m_target(nullptr)
, m_targetview(0)
, m_targetorient(0)
, m_targetvismask(0)
, m_lastclicktime(std::chrono::steady_clock::time_point::min())
, m_lastclickx(0)
, m_lastclicky(0)
, m_machine(machine)
, m_attached_mode(false)
{
memset(m_title,0,sizeof(m_title));
m_non_fullscreen_bounds.left = 0;
@ -350,7 +350,7 @@ void win_window_info::hide_pointer()
{
GetCursorPos(&s_saved_cursor_pos);
while (ShowCursor(FALSE) >= -1) {};
while (ShowCursor(FALSE) >= -1) { }
ShowCursor(TRUE);
}
@ -402,7 +402,7 @@ void win_window_info::show_pointer()
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);
@ -465,7 +465,7 @@ void winwindow_process_events(running_machine &machine, bool ingame, bool nodisp
assert(GetCurrentThreadId() == main_threadid);
// remember the last time we did this
last_event_check = std::chrono::system_clock::now();
last_event_check = std::chrono::steady_clock::now();
do
{
@ -1185,7 +1185,7 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
auto *window = (win_window_info *)ptr;
// we may get called before SetWindowLongPtr is called
if (window != nullptr)
if (window)
{
assert(GetCurrentThreadId() == window_threadid);
window->update_minmax_state();
@ -1203,8 +1203,8 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
if (window->win_has_menu())
DrawMenuBar(window->platform_window());
EndPaint(wnd, &pstruct);
break;
}
break;
// non-client paint: punt if full screen
case WM_NCPAINT:
@ -1233,7 +1233,7 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
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));
// 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_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));
}
else
@ -1250,8 +1250,8 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
window->m_lastclickx = GET_X_LPARAM(lparam);
window->m_lastclicky = GET_Y_LPARAM(lparam);
}
break;
}
break;
case WM_LBUTTONUP:
window->machine().ui_input().push_mouse_up_event(window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
@ -1300,6 +1300,7 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
minmax->ptMinTrackSize.y = MIN_WINDOW_DIMY;
break;
}
break;
// sizing: constrain to the aspect ratio unless control key is held down
case WM_SIZING:
@ -1314,8 +1315,8 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
rect->right = r.right();
}
InvalidateRect(wnd, nullptr, FALSE);
break;
}
break;
// syscommands: catch win_start_maximized
case WM_SYSCOMMAND:
@ -1339,8 +1340,8 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
window->maximize_window();
break;
}
return DefWindowProc(wnd, message, wparam, lparam);
}
return DefWindowProc(wnd, message, wparam, lparam);
// close: cause MAME to exit
case WM_CLOSE:
@ -1362,8 +1363,8 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
window->draw_video_contents(hdc, false);
ReleaseDC(wnd, hdc);
break;
}
break;
// fullscreen set
case WM_USER_SET_FULLSCREEN:

View File

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