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
|
// license:BSD-3-Clause
// copyright-holders:Nathan Woods
/***************************************************************************
ui/devctrl.h
Device specific control menu
This source provides a base class for any device which need a specific
submenu and which can occur multiple times in the same driver (at the
moment, cassette tapes and barcode readers, in future possibly other like
printers)
The base class contains calls to get the total number of devices of
the same kind connected to the driver, and shortcuts to switch current
device to next one or previous one attached. This allows, for instance,
users to pass from a device to another one by simply pressing left/right
and the menu is rebuilt accordingly, without the need of a preliminary
submenu listing available devices of the same kind.
***************************************************************************/
#ifndef MAME_FRONTEND_UI_DEVCTRL_H
#define MAME_FRONTEND_UI_DEVCTRL_H
#pragma once
#include "ui/menu.h"
namespace ui {
template<class DeviceType>
class menu_device_control : public menu
{
public:
menu_device_control(mame_ui_manager &mui, render_container &container, DeviceType *device);
protected:
DeviceType *current_device() { return m_device; }
int count() { return m_count; }
int current_index();
void previous();
void next();
std::string current_display_name();
uint32_t current_display_flags();
private:
// device enumerator
typedef device_type_enumerator<DeviceType> enumerator;
DeviceType * m_device;
int m_count;
};
//-------------------------------------------------
// ctor
//-------------------------------------------------
template<class DeviceType>
menu_device_control<DeviceType>::menu_device_control(mame_ui_manager &mui, render_container &container, DeviceType *device)
: menu(mui, container)
{
enumerator iter(mui.machine().root_device());
m_count = iter.count();
m_device = device ? device : iter.first();
}
//-------------------------------------------------
// current_index
//-------------------------------------------------
template<class DeviceType>
int menu_device_control<DeviceType>::current_index()
{
enumerator iter(machine().root_device());
return iter.indexof(*m_device);
}
//-------------------------------------------------
// previous
//-------------------------------------------------
template<class DeviceType>
void menu_device_control<DeviceType>::previous()
{
// left arrow - rotate left through devices
if (m_device && (1 < m_count))
{
enumerator iter(machine().root_device());
int index = iter.indexof(*m_device);
if (index > 0)
index--;
else
index = m_count - 1;
m_device = iter.byindex(index);
reset(reset_options::REMEMBER_POSITION);
}
}
//-------------------------------------------------
// next
//-------------------------------------------------
template<class DeviceType>
void menu_device_control<DeviceType>::next()
{
// right arrow - rotate right through cassette devices
if (m_device && (1 < m_count))
{
enumerator iter(machine().root_device());
int index = iter.indexof(*m_device);
if (index < m_count - 1)
index++;
else
index = 0;
m_device = iter.byindex(index);
reset(reset_options::REMEMBER_POSITION);
}
}
//-------------------------------------------------
// current_display_name
//-------------------------------------------------
template<class DeviceType>
std::string menu_device_control<DeviceType>::current_display_name()
{
std::string display_name;
display_name.assign(current_device()->name());
if (count() > 1)
display_name.append(string_format(" %d", current_index() + 1));
return display_name;
}
//-------------------------------------------------
// current_display_flags
//-------------------------------------------------
template<class DeviceType>
uint32_t menu_device_control<DeviceType>::current_display_flags()
{
uint32_t flags = 0;
if (count() > 1)
{
if (current_index() > 0)
flags |= FLAG_LEFT_ARROW;
if (current_index() < count() - 1)
flags |= FLAG_RIGHT_ARROW;
}
return flags;
}
} // namespace ui
#endif // MAME_FRONTEND_UI_DEVCTRL_H
|