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
|
// license:BSD-3-Clause
// copyright-holders:Vas Crabb
/***************************************************************************
ui/keyboard.cpp
Keyboard mode menu.
***************************************************************************/
#include "emu.h"
#include "ui/keyboard.h"
#include "natkeyboard.h"
namespace ui {
namespace {
constexpr uintptr_t ITEM_KBMODE = 0x00000100;
constexpr uintptr_t ITEM_KBDEV_FIRST = 0x00000200;
} // anonymous namespace
menu_keyboard_mode::menu_keyboard_mode(mame_ui_manager &mui, render_container &container) : menu(mui, container)
{
}
void menu_keyboard_mode::populate(float &customtop, float &custombottom)
{
natural_keyboard &natkbd(machine().natkeyboard());
if (natkbd.can_post())
{
bool const natmode(natkbd.in_use());
item_append(
_("Keyboard Mode"),
natmode ? _("Natural") : _("Emulated"),
natmode ? FLAG_LEFT_ARROW : FLAG_RIGHT_ARROW,
reinterpret_cast<void *>(ITEM_KBMODE));
item_append(menu_item_type::SEPARATOR);
}
uintptr_t ref(ITEM_KBDEV_FIRST);
for (size_t i = 0; natkbd.keyboard_count() > i; ++i, ++ref)
{
device_t &kbddev(natkbd.keyboard_device(i));
bool const enabled(natkbd.keyboard_enabled(i));
item_append(
util::string_format(
kbddev.owner() ? _("%1$s [root%2$s]") : _("[root%2$s]"),
kbddev.type().fullname(),
kbddev.tag()),
enabled ? _("Enabled") : _("Disabled"),
enabled ? FLAG_LEFT_ARROW : FLAG_RIGHT_ARROW,
reinterpret_cast<void *>(ref));
}
item_append(menu_item_type::SEPARATOR);
}
menu_keyboard_mode::~menu_keyboard_mode()
{
}
void menu_keyboard_mode::handle(event const *ev)
{
if (ev && uintptr_t(ev->itemref))
{
natural_keyboard &natkbd(machine().natkeyboard());
uintptr_t const ref(uintptr_t(ev->itemref));
bool const left(IPT_UI_LEFT == ev->iptkey);
bool const right(IPT_UI_RIGHT == ev->iptkey);
if (ITEM_KBMODE == ref)
{
if ((left || right) && (natkbd.in_use() != right))
{
natkbd.set_in_use(right);
reset(reset_options::REMEMBER_REF);
}
}
else if (ITEM_KBDEV_FIRST <= ref)
{
if ((left || right) && (natkbd.keyboard_enabled(ref - ITEM_KBDEV_FIRST) != right))
{
if (right)
natkbd.enable_keyboard(ref - ITEM_KBDEV_FIRST);
else
natkbd.disable_keyboard(ref - ITEM_KBDEV_FIRST);
reset(reset_options::REMEMBER_REF);
}
}
}
}
} // namespace ui
|