summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/ui/ui.h
blob: 757d0deb437f78e1db3a72bcee7c17af1eea75e8 (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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/***************************************************************************

    ui.h

    Functions used to handle MAME's crude user interface.

    Copyright Nicola Salmoria and the MAME Team.
    Visit http://mamedev.org for licensing and usage restrictions.

***************************************************************************/

#pragma once

#ifndef __USRINTRF_H__
#define __USRINTRF_H__

#include "render.h"


/***************************************************************************
    CONSTANTS
***************************************************************************/

/* preferred font height; use ui_get_line_height() to get actual height */
#define UI_TARGET_FONT_ROWS     (25)
#define UI_TARGET_FONT_HEIGHT   (1.0f / (float)UI_TARGET_FONT_ROWS)
#define UI_MAX_FONT_HEIGHT      (1.0f / 15.0f)

/* width of lines drawn in the UI */
#define UI_LINE_WIDTH           (1.0f / 500.0f)

/* border between outlines and inner text on left/right and top/bottom sides */
#define UI_BOX_LR_BORDER        (UI_TARGET_FONT_HEIGHT * 0.25f)
#define UI_BOX_TB_BORDER        (UI_TARGET_FONT_HEIGHT * 0.25f)

/* handy colors */
#define ARGB_WHITE              rgb_t(0xff,0xff,0xff,0xff)
#define ARGB_BLACK              rgb_t(0xff,0x00,0x00,0x00)
#define UI_BORDER_COLOR         rgb_t(0xff,0xff,0xff,0xff)
#define UI_BACKGROUND_COLOR     rgb_t(0xef,0x10,0x10,0x30)
#define UI_GFXVIEWER_BG_COLOR   rgb_t(0xef,0x10,0x10,0x30)
#define UI_GREEN_COLOR          rgb_t(0xef,0x10,0x60,0x10)
#define UI_YELLOW_COLOR         rgb_t(0xef,0x60,0x60,0x10)
#define UI_RED_COLOR            rgb_t(0xf0,0x60,0x10,0x10)
#define UI_UNAVAILABLE_COLOR    rgb_t(0xff,0x40,0x40,0x40)
#define UI_TEXT_COLOR           rgb_t(0xff,0xff,0xff,0xff)
#define UI_TEXT_BG_COLOR        rgb_t(0xef,0x00,0x00,0x00)
#define UI_SUBITEM_COLOR        rgb_t(0xff,0xff,0xff,0xff)
#define UI_CLONE_COLOR          rgb_t(0xff,0x80,0x80,0x80)
#define UI_SELECTED_COLOR       rgb_t(0xff,0xff,0xff,0x00)
#define UI_SELECTED_BG_COLOR    rgb_t(0xef,0x80,0x80,0x00)
#define UI_MOUSEOVER_COLOR      rgb_t(0xff,0xff,0xff,0x80)
#define UI_MOUSEOVER_BG_COLOR   rgb_t(0x70,0x40,0x40,0x00)
#define UI_MOUSEDOWN_COLOR      rgb_t(0xff,0xff,0xff,0x80)
#define UI_MOUSEDOWN_BG_COLOR   rgb_t(0xb0,0x60,0x60,0x00)
#define UI_DIPSW_COLOR          rgb_t(0xff,0xff,0xff,0x00)
#define UI_SLIDER_COLOR         rgb_t(0xff,0xff,0xff,0xff)

/* cancel return value for a UI handler */
#define UI_HANDLER_CANCEL       ((UINT32)~0)

/* justification options for ui_draw_text_full */
enum
{
	JUSTIFY_LEFT = 0,
	JUSTIFY_CENTER,
	JUSTIFY_RIGHT
};

/* word wrapping options for ui_draw_text_full */
enum
{
	WRAP_NEVER,
	WRAP_TRUNCATE,
	WRAP_WORD
};

/* drawing options for ui_draw_text_full */
enum
{
	DRAW_NONE,
	DRAW_NORMAL,
	DRAW_OPAQUE
};

#define SLIDER_NOCHANGE     0x12345678



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

typedef UINT32 (*ui_callback)(running_machine &, render_container *, UINT32);

typedef INT32 (*slider_update)(running_machine &machine, void *arg, astring *string, INT32 newval);

struct slider_state
{
	slider_state *  next;               /* pointer to next slider */
	slider_update   update;             /* callback */
	void *          arg;                /* argument */
	INT32           minval;             /* minimum value */
	INT32           defval;             /* default value */
	INT32           maxval;             /* maximum value */
	INT32           incval;             /* increment value */
	char            description[1];     /* textual description */
};


// ======================> ui_manager

class ui_manager
{
public:
	// construction/destruction
	ui_manager(running_machine &machine);

	// getters
	running_machine &machine() const { return m_machine; }
	bool single_step() const { return m_single_step; }

	// setters
	void set_single_step(bool single_step) { m_single_step = single_step; }

	// methods
	void initialize(running_machine &machine);
	UINT32 set_handler(ui_callback callback, UINT32 param);
	void display_startup_screens(bool first_time, bool show_disclaimer);
	void set_startup_text(const char *text, bool force);
	void update_and_render(render_container *container);
	render_font *get_font();
	float get_line_height();
	float get_char_width(unicode_char ch);
	float get_string_width(const char *s);
	void draw_outlined_box(render_container *container, float x0, float y0, float x1, float y1, rgb_t backcolor);
	void draw_outlined_box(render_container *container, float x0, float y0, float x1, float y1, rgb_t fgcolor, rgb_t bgcolor);
	void draw_text(render_container *container, const char *buf, float x, float y);
	void draw_text_full(render_container *container, const char *origs, float x, float y, float origwrapwidth, int justify, int wrap, int draw, rgb_t fgcolor, rgb_t bgcolor, float *totalwidth = NULL, float *totalheight = NULL);
	void draw_text_box(render_container *container, const char *text, int justify, float xpos, float ypos, rgb_t backcolor);
	void draw_message_window(render_container *container, const char *text);

	void CLIB_DECL popup_time(int seconds, const char *text, ...);
	void show_fps_temp(double seconds);
	void set_show_fps(bool show);
	bool show_fps() const;
	bool show_fps_counter();
	void set_show_profiler(bool show);
	bool show_profiler() const;
	void show_menu();
	void show_mouse(bool status);
	bool is_menu_active();
	bool can_paste();
	void paste();
	bool use_natural_keyboard() const;
	void set_use_natural_keyboard(bool use_natural_keyboard);
	void image_handler_ingame();
	void increase_frameskip();
	void decrease_frameskip();

	// print the game info string into a buffer
	astring &game_info_astring(astring &string);

	// slider controls
	const slider_state *get_slider_list(void);

	// other
	void process_natural_keyboard();

private:
	// instance variables
	running_machine &		m_machine;
	render_font *			m_font;
	ui_callback				m_handler_callback;
	UINT32					m_handler_param;
	bool					m_single_step;
	bool					m_showfps;
	osd_ticks_t				m_showfps_end;
	bool					m_show_profiler;
	osd_ticks_t				m_popup_text_end;
	bool					m_use_natural_keyboard;
	UINT8 *					m_non_char_keys_down;
	render_texture *		m_mouse_arrow_texture;
	bool					m_mouse_show;

	// text generators 
	astring &disclaimer_string(astring &buffer);
	astring &warnings_string(astring &buffer);

	// UI handlers 
	static UINT32 handler_messagebox(running_machine &machine, render_container *container, UINT32 state);
	static UINT32 handler_messagebox_ok(running_machine &machine, render_container *container, UINT32 state);
	static UINT32 handler_messagebox_anykey(running_machine &machine, render_container *container, UINT32 state);
	static UINT32 handler_ingame(running_machine &machine, render_container *container, UINT32 state);
	static UINT32 handler_load_save(running_machine &machine, render_container *container, UINT32 state);
	static UINT32 handler_confirm_quit(running_machine &machine, render_container *container, UINT32 state);

	// private methods
	void exit();
};


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

#endif  /* __USRINTRF_H__ */