summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/uiinput.h
blob: d5f85e2ff0241ec23b3d04ac7495d245a49c6601 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// license:BSD-3-Clause
// copyright-holders:Nicola Salmoria
/***************************************************************************

    uiinput.h

    Internal MAME user interface input state.
***************************************************************************/

#pragma once

#ifndef __UIINPUT_H__
#define __UIINPUT_H__

#include "render.h"


/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

enum ui_event_type
{
	UI_EVENT_NONE,
	UI_EVENT_MOUSE_MOVE,
	UI_EVENT_MOUSE_LEAVE,
	UI_EVENT_MOUSE_DOWN,
	UI_EVENT_MOUSE_UP,
	UI_EVENT_MOUSE_DOUBLE_CLICK,
	UI_EVENT_CHAR
};


struct ui_event
{
	ui_event_type       event_type;
	render_target *     target;
	INT32               mouse_x;
	INT32               mouse_y;
	input_item_id       key;
	unicode_char        ch;
};



/***************************************************************************
    FUNCTION PROTOTYPES
***************************************************************************/


/* ----- core system management ----- */

/* initialization */
void ui_input_init(running_machine &machine);



/* ----- event handling ----- */

void ui_input_frame_update(running_machine &machine);

/* pushes a single event onto the queue */
bool ui_input_push_event(running_machine &machine, ui_event event);

/* pops an event off of the queue */
bool ui_input_pop_event(running_machine &machine, ui_event *event);

/* clears all outstanding events */
void ui_input_reset(running_machine &machine);

/* retrieves the current location of the mouse */
render_target *ui_input_find_mouse(running_machine &machine, INT32 *x, INT32 *y, bool *button);



/* ----- user interface sequence reading ----- */

/* return TRUE if a key down for the given user interface sequence is detected */
bool ui_input_pressed(running_machine &machine, int code);

/* return TRUE if a key down for the given user interface sequence is detected, or if
   autorepeat at the given speed is triggered */
bool ui_input_pressed_repeat(running_machine &machine, int code, int speed);



/***************************************************************************
    INLINE FUNCTIONS
***************************************************************************/

/*-------------------------------------------------
    ui_input_push_mouse_move_event - pushes a mouse
    move event to the specified render_target
-------------------------------------------------*/

INLINE void ui_input_push_mouse_move_event(running_machine &machine, render_target *target, INT32 x, INT32 y)
{
	ui_event event = { UI_EVENT_NONE };
	event.event_type = UI_EVENT_MOUSE_MOVE;
	event.target = target;
	event.mouse_x = x;
	event.mouse_y = y;
	ui_input_push_event(machine, event);
}


/*-------------------------------------------------
    ui_input_push_mouse_leave_event - pushes a
    mouse leave event to the specified render_target
-------------------------------------------------*/

INLINE void ui_input_push_mouse_leave_event(running_machine &machine, render_target *target)
{
	ui_event event = { UI_EVENT_NONE };
	event.event_type = UI_EVENT_MOUSE_LEAVE;
	event.target = target;
	ui_input_push_event(machine, event);
}


/*-------------------------------------------------
    ui_input_push_mouse_down_event - pushes a mouse
    down event to the specified render_target
-------------------------------------------------*/

INLINE void ui_input_push_mouse_down_event(running_machine &machine, render_target *target, INT32 x, INT32 y)
{
	ui_event event = { UI_EVENT_NONE };
	event.event_type = UI_EVENT_MOUSE_DOWN;
	event.target = target;
	event.mouse_x = x;
	event.mouse_y = y;
	ui_input_push_event(machine, event);
}


/*-------------------------------------------------
    ui_input_push_mouse_down_event - pushes a mouse
    down event to the specified render_target
-------------------------------------------------*/

INLINE void ui_input_push_mouse_up_event(running_machine &machine, render_target *target, INT32 x, INT32 y)
{
	ui_event event = { UI_EVENT_NONE };
	event.event_type = UI_EVENT_MOUSE_UP;
	event.target = target;
	event.mouse_x = x;
	event.mouse_y = y;
	ui_input_push_event(machine, event);
}


/*-------------------------------------------------
    ui_input_push_mouse_double_click_event - pushes
    a mouse double-click event to the specified
    render_target
-------------------------------------------------*/

INLINE void ui_input_push_mouse_double_click_event(running_machine &machine, render_target *target, INT32 x, INT32 y)
{
	ui_event event = { UI_EVENT_NONE };
	event.event_type = UI_EVENT_MOUSE_DOUBLE_CLICK;
	event.target = target;
	event.mouse_x = x;
	event.mouse_y = y;
	ui_input_push_event(machine, event);
}


/*-------------------------------------------------
    ui_input_push_char_event - pushes a char event
    to the specified render_target
-------------------------------------------------*/

INLINE void ui_input_push_char_event(running_machine &machine, render_target *target, unicode_char ch)
{
	ui_event event = { UI_EVENT_NONE };
	event.event_type = UI_EVENT_CHAR;
	event.target = target;
	event.ch = ch;
	ui_input_push_event(machine, event);
}


#endif  /* __UIINPUT_H__ */