summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/input/input_win32.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/modules/input/input_win32.cpp')
-rw-r--r--src/osd/modules/input/input_win32.cpp622
1 files changed, 377 insertions, 245 deletions
diff --git a/src/osd/modules/input/input_win32.cpp b/src/osd/modules/input/input_win32.cpp
index c07a1c681d8..921c902ad31 100644
--- a/src/osd/modules/input/input_win32.cpp
+++ b/src/osd/modules/input/input_win32.cpp
@@ -7,25 +7,28 @@
//============================================================
#include "input_module.h"
-#include "modules/osdmodule.h"
#if defined(OSD_WINDOWS)
+#include "input_windows.h"
+
+#include "input_wincommon.h"
+
+// osd/windows
+#include "window.h"
+
+// emu
+#include "inpttype.h"
+
+#include "strconv.h"
+
// standard windows headers
-#include <windows.h>
#include <tchar.h>
-#undef interface
-// MAME headers
-#include "emu.h"
-#include "strconv.h"
-// MAMEOS headers
-#include "winmain.h"
-#include "window.h"
+namespace osd {
-#include "input_common.h"
-#include "input_windows.h"
+namespace {
//============================================================
// win32_keyboard_device
@@ -35,117 +38,118 @@
class win32_keyboard_device : public event_based_device<KeyPressEventArgs>
{
public:
- keyboard_state keyboard;
+ win32_keyboard_device(std::string &&name, std::string &&id, input_module &module) :
+ event_based_device(std::move(name), std::move(id), module),
+ m_keyboard({{0}})
+ {
+ }
- win32_keyboard_device(running_machine& machine, const char *name, const char *id, input_module &module)
- : event_based_device(machine, name, id, DEVICE_CLASS_KEYBOARD, module),
- keyboard({{0}})
+ virtual void reset() override
{
+ event_based_device::reset();
+ memset(&m_keyboard, 0, sizeof(m_keyboard));
}
- void reset() override
+ virtual void configure(input_device &device) override
{
- memset(&keyboard, 0, sizeof(keyboard));
+ keyboard_trans_table const &table = keyboard_trans_table::instance();
+
+ for (int keynum = 0; keynum < MAX_KEYS; keynum++)
+ {
+ input_item_id itemid = table.map_di_scancode_to_itemid(keynum);
+ TCHAR keyname[100];
+
+ // generate the name
+ // FIXME: GetKeyNameText gives bogus names for media keys and various other things
+ // in many cases it ignores the "extended" bit and returns the key name corresponding to the scan code alone
+ if (GetKeyNameText(((keynum & 0x7f) << 16) | ((keynum & 0x80) << 17), keyname, std::size(keyname)) == 0)
+ _sntprintf(keyname, std::size(keyname), TEXT("Scan%03d"), keynum);
+ std::string name = text::from_tstring(keyname);
+
+ // add the item to the device
+ device.add_item(
+ name,
+ util::string_format("SCAN%03d", keynum),
+ itemid,
+ generic_button_get_state<std::uint8_t>,
+ &m_keyboard.state[keynum]);
+ }
}
protected:
- void process_event(KeyPressEventArgs &args) override
+ virtual void process_event(KeyPressEventArgs const &args) override
{
- keyboard.state[args.scancode] = args.event_id == INPUT_EVENT_KEYDOWN ? 0x80 : 0x00;
+ m_keyboard.state[args.scancode] = args.event_id == INPUT_EVENT_KEYDOWN ? 0x80 : 0x00;
}
+
+private:
+ keyboard_state m_keyboard;
};
+
//============================================================
// keyboard_input_win32 - win32 keyboard input module
//============================================================
-class keyboard_input_win32 : public wininput_module
+class keyboard_input_win32 : public wininput_module<win32_keyboard_device>
{
-private:
-
public:
- keyboard_input_win32()
- : wininput_module(OSD_KEYBOARDINPUT_PROVIDER, "win32")
+ keyboard_input_win32() : wininput_module<win32_keyboard_device>(OSD_KEYBOARDINPUT_PROVIDER, "win32")
{
}
virtual void input_init(running_machine &machine) override
{
- // Add a single win32 keyboard device that we'll monitor using Win32
- win32_keyboard_device *devinfo = devicelist()->create_device<win32_keyboard_device>(machine, "Win32 Keyboard 1", "Win32 Keyboard 1", *this);
-
- keyboard_trans_table &table = keyboard_trans_table::instance();
-
- // populate it
- for (int keynum = 0; keynum < MAX_KEYS; keynum++)
- {
- input_item_id itemid = table.map_di_scancode_to_itemid(keynum);
- TCHAR keyname[100];
-
- // generate the name
- if (GetKeyNameText(((keynum & 0x7f) << 16) | ((keynum & 0x80) << 17), keyname, ARRAY_LENGTH(keyname)) == 0)
- _sntprintf(keyname, ARRAY_LENGTH(keyname), TEXT("Scan%03d"), keynum);
- std::string name = osd::text::from_tstring(keyname);
+ wininput_module<win32_keyboard_device>::input_init(machine);
- // add the item to the device
- devinfo->device()->add_item(name.c_str(), itemid, generic_button_get_state<std::uint8_t>, &devinfo->keyboard.state[keynum]);
- }
+ // Add a single win32 keyboard device that we'll monitor using Win32
+ create_device<win32_keyboard_device>(DEVICE_CLASS_KEYBOARD, "Win32 Keyboard 1", "Win32 Keyboard 1");
}
- bool handle_input_event(input_event eventid, void *eventdata) override
+ virtual bool handle_input_event(input_event eventid, void const *eventdata) override
{
- if (!input_enabled())
- return false;
-
- KeyPressEventArgs *args;
-
switch (eventid)
{
- case INPUT_EVENT_KEYDOWN:
- case INPUT_EVENT_KEYUP:
- args = static_cast<KeyPressEventArgs*>(eventdata);
- devicelist()->for_each_device([args](auto device)
- {
- auto keyboard = dynamic_cast<win32_keyboard_device*>(device);
- if (keyboard != nullptr)
- keyboard->queue_events(args, 1);
- });
-
- return true;
-
- default:
- return false;
+ case INPUT_EVENT_KEYDOWN:
+ case INPUT_EVENT_KEYUP:
+ devicelist().for_each_device(
+ [args = reinterpret_cast<KeyPressEventArgs const *>(eventdata)] (auto &device)
+ {
+ device.queue_events(args, 1);
+ });
+ return false; // we still want text input events to be generated
+
+ default:
+ return false;
}
}
};
+
//============================================================
// win32_mouse_device
//============================================================
-struct win32_mouse_state
-{
- POINT last_point;
-};
-
-class win32_mouse_device : public event_based_device<MouseButtonEventArgs>
+class win32_mouse_device : public event_based_device<MouseUpdateEventArgs>
{
public:
- mouse_state mouse;
- win32_mouse_state win32_mouse;
-
- win32_mouse_device(running_machine& machine, const char *name, const char *id, input_module &module)
- : event_based_device(machine, name, id, DEVICE_CLASS_MOUSE, module),
- mouse({0}),
- win32_mouse({{0}})
+ win32_mouse_device(std::string &&name, std::string &&id, input_module &module) :
+ event_based_device(std::move(name), std::move(id), module),
+ m_mouse({0}),
+ m_win32_mouse({{0}}),
+ m_vscroll(0),
+ m_hscroll(0)
{
}
- void poll() override
+ virtual void poll(bool relative_reset) override
{
- event_based_device::poll();
+ event_based_device::poll(relative_reset);
- CURSORINFO cursor_info = {0};
+ if (!relative_reset)
+ return;
+
+ CURSORINFO cursor_info = { 0 };
cursor_info.cbSize = sizeof(CURSORINFO);
GetCursorInfo(&cursor_info);
@@ -154,145 +158,228 @@ public:
if (!(cursor_info.flags & CURSOR_SHOWING))
{
// We measure the position change from the previously set center position
- mouse.lX = (cursor_info.ptScreenPos.x - win32_mouse.last_point.x) * INPUT_RELATIVE_PER_PIXEL;
- mouse.lY = (cursor_info.ptScreenPos.y - win32_mouse.last_point.y) * INPUT_RELATIVE_PER_PIXEL;
+ m_mouse.lX = (cursor_info.ptScreenPos.x - m_win32_mouse.last_point.x) * input_device::RELATIVE_PER_PIXEL;
+ m_mouse.lY = (cursor_info.ptScreenPos.y - m_win32_mouse.last_point.y) * input_device::RELATIVE_PER_PIXEL;
RECT window_pos = {0};
- GetWindowRect(std::static_pointer_cast<win_window_info>(osd_common_t::s_window_list.front())->platform_window(), &window_pos);
+ GetWindowRect(
+ dynamic_cast<win_window_info &>(*osd_common_t::window_list().front()).platform_window(),
+ &window_pos);
// We reset the cursor position to the middle of the window each frame
- win32_mouse.last_point.x = window_pos.left + (window_pos.right - window_pos.left) / 2;
- win32_mouse.last_point.y = window_pos.top + (window_pos.bottom - window_pos.top) / 2;
+ m_win32_mouse.last_point.x = window_pos.left + (window_pos.right - window_pos.left) / 2;
+ m_win32_mouse.last_point.y = window_pos.top + (window_pos.bottom - window_pos.top) / 2;
- SetCursorPos(win32_mouse.last_point.x, win32_mouse.last_point.y);
+ SetCursorPos(m_win32_mouse.last_point.x, m_win32_mouse.last_point.y);
}
+
+ // update scroll axes
+ m_mouse.lV = std::exchange(m_vscroll, 0) * input_device::RELATIVE_PER_PIXEL;
+ m_mouse.lH = std::exchange(m_hscroll, 0) * input_device::RELATIVE_PER_PIXEL;
}
- void reset() override
+ virtual void configure(input_device &device) override
{
- memset(&mouse, 0, sizeof(mouse));
- memset(&win32_mouse, 0, sizeof(win32_mouse));
+ // populate the axes
+ device.add_item(
+ "X",
+ std::string_view(),
+ ITEM_ID_XAXIS,
+ generic_axis_get_state<LONG>,
+ &m_mouse.lX);
+ device.add_item(
+ "Y",
+ std::string_view(),
+ ITEM_ID_YAXIS,
+ generic_axis_get_state<LONG>,
+ &m_mouse.lY);
+ device.add_item(
+ "Scroll V",
+ std::string_view(),
+ ITEM_ID_ZAXIS,
+ generic_axis_get_state<LONG>,
+ &m_mouse.lV);
+ device.add_item(
+ "Scroll H",
+ std::string_view(),
+ ITEM_ID_RZAXIS,
+ generic_axis_get_state<LONG>,
+ &m_mouse.lH);
+
+ // populate the buttons
+ for (int butnum = 0; butnum < 5; butnum++)
+ {
+ device.add_item(
+ default_button_name(butnum),
+ std::string_view(),
+ input_item_id(ITEM_ID_BUTTON1 + butnum),
+ generic_button_get_state<BYTE>,
+ &m_mouse.rgbButtons[butnum]);
+ }
+ }
+
+ virtual void reset() override
+ {
+ event_based_device::reset();
+ memset(&m_mouse, 0, sizeof(m_mouse));
+ memset(&m_win32_mouse, 0, sizeof(m_win32_mouse));
+ m_vscroll = m_hscroll = 0;
}
protected:
- void process_event(MouseButtonEventArgs &args) override
+ virtual void process_event(MouseUpdateEventArgs const &args) override
{
// set the button state
- mouse.rgbButtons[args.button] = args.keydown ? 0x80 : 0x00;
+ assert(!(args.pressed & args.released));
+ for (unsigned i = 0; 5 > i; ++i)
+ {
+ if (BIT(args.pressed, i))
+ m_mouse.rgbButtons[i] = 0x80;
+ else if (BIT(args.released, i))
+ m_mouse.rgbButtons[i] = 0x00;
+ }
- // Make sure we have a fresh mouse position on button down
- if (args.keydown)
- module().poll_if_necessary(machine());
+ // accumulate scroll delta
+ m_vscroll += args.vdelta;
+ m_hscroll += args.hdelta;
}
+
+private:
+ struct win32_mouse_state
+ {
+ POINT last_point;
+ };
+
+ mouse_state m_mouse;
+ win32_mouse_state m_win32_mouse;
+ long m_vscroll, m_hscroll;
};
+
//============================================================
// mouse_input_win32 - win32 mouse input module
//============================================================
-class mouse_input_win32 : public wininput_module
+class mouse_input_win32 : public wininput_module<win32_mouse_device>
{
public:
- mouse_input_win32()
- : wininput_module(OSD_MOUSEINPUT_PROVIDER, "win32")
+ mouse_input_win32() : wininput_module<win32_mouse_device>(OSD_MOUSEINPUT_PROVIDER, "win32")
{
}
virtual void input_init(running_machine &machine) override
{
- win32_mouse_device *devinfo;
- int axisnum, butnum;
+ wininput_module<win32_mouse_device>::input_init(machine);
- if (!input_enabled() || !mouse_enabled())
+ if (!options()->mouse())
return;
// allocate a device
- devinfo = devicelist()->create_device<win32_mouse_device>(machine, "Win32 Mouse 1", "Win32 Mouse 1", *this);
- if (devinfo == nullptr)
- return;
+ create_device<win32_mouse_device>(DEVICE_CLASS_MOUSE, "Win32 Mouse 1", "Win32 Mouse 1");
+ }
- // populate the axes
- for (axisnum = 0; axisnum < 2; axisnum++)
+ virtual bool handle_input_event(input_event eventid, void const *eventdata) override
+ {
+ if (manager().class_enabled(DEVICE_CLASS_MOUSE))
{
- devinfo->device()->add_item(
- default_axis_name[axisnum],
- static_cast<input_item_id>(ITEM_ID_XAXIS + axisnum),
- generic_axis_get_state<LONG>,
- &devinfo->mouse.lX + axisnum);
+ if ((eventid == INPUT_EVENT_MOUSE_BUTTON) || (eventid == INPUT_EVENT_MOUSE_WHEEL))
+ {
+ auto const *const args = reinterpret_cast<MouseUpdateEventArgs const *>(eventdata);
+ devicelist().for_each_device(
+ [args] (auto &device) { device.queue_events(args, 1); });
+ return true;
+ }
}
- // populate the buttons
- for (butnum = 0; butnum < 2; butnum++)
- {
- devinfo->device()->add_item(
- default_button_name(butnum),
- static_cast<input_item_id>(ITEM_ID_BUTTON1 + butnum),
- generic_button_get_state<BYTE>,
- &devinfo->mouse.rgbButtons[butnum]);
- }
+ return false;
}
+};
+
+
+//============================================================
+// win32_lightgun_device_base
+//============================================================
- bool handle_input_event(input_event eventid, void *eventdata) override
+class win32_lightgun_device_base : public event_based_device<MouseUpdateEventArgs>
+{
+public:
+ virtual void reset() override
{
- if (!input_enabled() || !mouse_enabled() || eventid != INPUT_EVENT_MOUSE_BUTTON)
- return false;
+ event_based_device::reset();
+ memset(&m_mouse, 0, sizeof(m_mouse));
+ }
- auto args = static_cast<MouseButtonEventArgs*>(eventdata);
- devicelist()->for_each_device([args](auto device)
+protected:
+ win32_lightgun_device_base(
+ std::string &&name,
+ std::string &&id,
+ input_module &module) :
+ event_based_device(std::move(name), std::move(id), module),
+ m_mouse({ 0 })
+ {
+ }
+
+ void do_configure(input_device &device, unsigned buttons)
+ {
+ // populate the axes
+ for (int axisnum = 0; axisnum < 2; axisnum++)
{
- auto mouse = dynamic_cast<win32_mouse_device*>(device);
- if (mouse != nullptr)
- mouse->queue_events(args, 1);
- });
+ device.add_item(
+ default_axis_name[axisnum],
+ std::string_view(),
+ input_item_id(ITEM_ID_XAXIS + axisnum),
+ generic_axis_get_state<LONG>,
+ &m_mouse.lX + axisnum);
+ }
- return true;
+ // populate the buttons
+ for (int butnum = 0; butnum < buttons; butnum++)
+ {
+ device.add_item(
+ default_button_name(butnum),
+ std::string_view(),
+ input_item_id(ITEM_ID_BUTTON1 + butnum),
+ generic_button_get_state<BYTE>,
+ &m_mouse.rgbButtons[butnum]);
+ }
}
+
+ mouse_state m_mouse;
};
+
+
//============================================================
// win32_lightgun_device
//============================================================
-class win32_lightgun_device : public event_based_device<MouseButtonEventArgs>
+class win32_lightgun_device : public win32_lightgun_device_base
{
-private:
- BOOL m_lightgun_shared_axis_mode;
- int m_gun_index;
-
public:
- mouse_state mouse;
-
- win32_lightgun_device(running_machine& machine, const char *name, const char *id, input_module &module)
- : event_based_device(machine, name, id, DEVICE_CLASS_LIGHTGUN, module),
- m_lightgun_shared_axis_mode(FALSE),
- m_gun_index(0),
- mouse({0})
+ win32_lightgun_device(
+ std::string &&name,
+ std::string &&id,
+ input_module &module) :
+ win32_lightgun_device_base(std::move(name), std::move(id), module),
+ m_vscroll(0),
+ m_hscroll(0)
{
- m_lightgun_shared_axis_mode = downcast<windows_options &>(machine.options()).dual_lightgun();
-
- // Since we are about to be added to the list, the current size is the zero-based index of where we will be
- m_gun_index = downcast<wininput_module&>(module).devicelist()->size();
}
- void poll() override
+ virtual void poll(bool relative_reset) override
{
- event_based_device::poll();
+ event_based_device::poll(relative_reset);
int32_t xpos = 0, ypos = 0;
- POINT mousepos;
-
- // if we are using the shared axis hack, the data is updated via Windows messages only
- if (m_lightgun_shared_axis_mode)
- return;
// get the cursor position and transform into final results
+ POINT mousepos;
GetCursorPos(&mousepos);
- if (!osd_common_t::s_window_list.empty())
+ if (!osd_common_t::window_list().empty())
{
- RECT client_rect;
-
// get the position relative to the window
- HWND hwnd = std::static_pointer_cast<win_window_info>(osd_common_t::s_window_list.front())->platform_window();
+ HWND const hwnd = dynamic_cast<win_window_info &>(*osd_common_t::window_list().front()).platform_window();
+ RECT client_rect;
GetClientRect(hwnd, &client_rect);
ScreenToClient(hwnd, &mousepos);
@@ -302,149 +389,194 @@ public:
}
// update the X/Y positions
- mouse.lX = xpos;
- mouse.lY = ypos;
+ m_mouse.lX = xpos;
+ m_mouse.lY = ypos;
+
+ // update the scroll axes if appropriate
+ if (relative_reset)
+ {
+ m_mouse.lV = std::exchange(m_vscroll, 0) * input_device::RELATIVE_PER_PIXEL;
+ m_mouse.lH = std::exchange(m_hscroll, 0) * input_device::RELATIVE_PER_PIXEL;
+ }
+ }
+
+ virtual void configure(input_device &device) override
+ {
+ do_configure(device, 5);
+
+ // add scroll axes
+ device.add_item(
+ "Scroll V",
+ std::string_view(),
+ ITEM_ID_ADD_RELATIVE1,
+ generic_axis_get_state<LONG>,
+ &m_mouse.lV);
+ device.add_item(
+ "Scroll H",
+ std::string_view(),
+ ITEM_ID_ADD_RELATIVE2,
+ generic_axis_get_state<LONG>,
+ &m_mouse.lH);
}
- void reset() override
+ virtual void reset() override
{
- memset(&mouse, 0, sizeof(mouse));
+ win32_lightgun_device_base::reset();
+ m_vscroll = m_hscroll = 0;
}
protected:
- void process_event(MouseButtonEventArgs &args) override
+ virtual void process_event(MouseUpdateEventArgs const &args) override
{
- // Are we in shared axis mode?
- if (m_lightgun_shared_axis_mode)
- {
- handle_shared_axis_mode(args);
- }
- else
+ // In non-shared axis mode, just update the button state
+ assert(!(args.pressed & args.released));
+ for (unsigned i = 0; 5 > i; ++i)
{
- // In non-shared axis mode, just update the button state
- mouse.rgbButtons[args.button] = args.keydown ? 0x80 : 0x00;
+ if (BIT(args.pressed, i))
+ m_mouse.rgbButtons[i] = 0x80;
+ else if (BIT(args.released, i))
+ m_mouse.rgbButtons[i] = 0x00;
}
+
+ // accumulate scroll delta
+ m_vscroll += args.vdelta;
+ m_hscroll += args.hdelta;
}
private:
- void handle_shared_axis_mode(MouseButtonEventArgs &args)
- {
- int button = args.button;
+ long m_vscroll, m_hscroll;
+};
- // We only handle the first four buttons in shared axis mode
- if (button > 3)
- return;
- // First gun doesn't handle buttons 2 & 3
- if (button >= 2 && m_gun_index == 0)
- return;
+//============================================================
+// win32_dual_lightgun_device
+//============================================================
- // Second gun doesn't handle buttons 0 & 1
- if (button < 2 && m_gun_index == 1)
- return;
+class win32_dual_lightgun_device : public win32_lightgun_device_base
+{
+public:
+ win32_dual_lightgun_device(
+ std::string &&name,
+ std::string &&id,
+ input_module &module,
+ int index) :
+ win32_lightgun_device_base(std::move(name), std::move(id), module),
+ m_gun_index(index)
+ {
+ }
- // Adjust the button if we're the second lightgun
- int logical_button = m_gun_index == 1 ? button - 2 : button;
+ virtual void configure(input_device &device) override
+ {
+ do_configure(device, 2);
+ }
- // set the button state
- mouse.rgbButtons[logical_button] = args.keydown ? 0x80 : 0x00;
- if (args.keydown)
+protected:
+ virtual void process_event(MouseUpdateEventArgs const &args) override
+ {
+ // We only handle the first four buttons in shared axis mode
+ assert(!(args.pressed & args.released));
+ for (unsigned i = 0; 2 > i; ++i)
{
- RECT client_rect;
- POINT mousepos;
+ // Adjust the button if we're the second lightgun
+ unsigned const bit = i + ((1 == m_gun_index) ? 2 : 0);
+ if (BIT(args.pressed, bit))
+ {
+ m_mouse.rgbButtons[i] = 0x80;
- // get the position relative to the window
- HWND hwnd = std::static_pointer_cast<win_window_info>(osd_common_t::s_window_list.front())->platform_window();
- GetClientRect(hwnd, &client_rect);
- mousepos.x = args.xpos;
- mousepos.y = args.ypos;
- ScreenToClient(hwnd, &mousepos);
+ // get the position relative to the window
+ HWND const hwnd = dynamic_cast<win_window_info &>(*osd_common_t::window_list().front()).platform_window();
+ RECT client_rect;
+ GetClientRect(hwnd, &client_rect);
- // convert to absolute coordinates
- mouse.lX = normalize_absolute_axis(mousepos.x, client_rect.left, client_rect.right);
- mouse.lY = normalize_absolute_axis(mousepos.y, client_rect.top, client_rect.bottom);
+ POINT mousepos;
+ mousepos.x = args.xpos;
+ mousepos.y = args.ypos;
+ ScreenToClient(hwnd, &mousepos);
+
+ // convert to absolute coordinates
+ m_mouse.lX = normalize_absolute_axis(mousepos.x, client_rect.left, client_rect.right);
+ m_mouse.lY = normalize_absolute_axis(mousepos.y, client_rect.top, client_rect.bottom);
+ }
+ else if (BIT(args.released, bit))
+ {
+ m_mouse.rgbButtons[i] = 0x00;
+ }
}
}
+
+private:
+ int const m_gun_index;
};
+
//============================================================
// lightgun_input_win32 - win32 lightgun input module
//============================================================
-class lightgun_input_win32 : public wininput_module
+class lightgun_input_win32 : public wininput_module<win32_lightgun_device_base>
{
public:
- lightgun_input_win32()
- : wininput_module(OSD_LIGHTGUNINPUT_PROVIDER, "win32")
- {
- }
-
- int init_internal() override
+ lightgun_input_win32() : wininput_module<win32_lightgun_device_base>(OSD_LIGHTGUNINPUT_PROVIDER, "win32")
{
- return 0;
}
virtual void input_init(running_machine &machine) override
{
- int max_guns = downcast<windows_options&>(machine.options()).dual_lightgun() ? 2 : 1;
+ wininput_module<win32_lightgun_device_base>::input_init(machine);
+
+ bool const shared_axis_mode = dynamic_cast<windows_options const &>(*options()).dual_lightgun();
+ int const max_guns = shared_axis_mode ? 2 : 1;
// allocate the lightgun devices
for (int gunnum = 0; gunnum < max_guns; gunnum++)
{
static const char *const gun_names[] = { "Win32 Gun 1", "Win32 Gun 2" };
- win32_lightgun_device *devinfo;
- int axisnum, butnum;
// allocate a device
- devinfo = devicelist()->create_device<win32_lightgun_device>(machine, gun_names[gunnum], gun_names[gunnum], *this);
- if (devinfo == nullptr)
- break;
-
- // populate the axes
- for (axisnum = 0; axisnum < 2; axisnum++)
- {
- devinfo->device()->add_item(
- default_axis_name[axisnum],
- static_cast<input_item_id>(ITEM_ID_XAXIS + axisnum),
- generic_axis_get_state<LONG>,
- &devinfo->mouse.lX + axisnum);
- }
-
- // populate the buttons
- for (butnum = 0; butnum < 2; butnum++)
- {
- devinfo->device()->add_item(
- default_button_name(butnum),
- static_cast<input_item_id>(ITEM_ID_BUTTON1 + butnum),
- generic_button_get_state<BYTE>,
- &devinfo->mouse.rgbButtons[butnum]);
- }
+ if (shared_axis_mode)
+ create_device<win32_dual_lightgun_device>(DEVICE_CLASS_LIGHTGUN, gun_names[gunnum], gun_names[gunnum], gunnum);
+ else
+ create_device<win32_lightgun_device>(DEVICE_CLASS_LIGHTGUN, gun_names[gunnum], gun_names[gunnum]);
}
}
- bool handle_input_event(input_event eventid, void* eventdata) override
+ virtual bool handle_input_event(input_event eventid, void const *eventdata) override
{
- if (!input_enabled() || !lightgun_enabled() || eventid != INPUT_EVENT_MOUSE_BUTTON)
- return false;
-
- auto args = static_cast<MouseButtonEventArgs*>(eventdata);
- devicelist()->for_each_device([args](auto device)
+ if (manager().class_enabled(DEVICE_CLASS_LIGHTGUN))
{
- auto lightgun = dynamic_cast<win32_lightgun_device*>(device);
- if (lightgun != nullptr)
- lightgun->queue_events(args, 1);
- });
+ if ((eventid == INPUT_EVENT_MOUSE_BUTTON) || (eventid == INPUT_EVENT_MOUSE_WHEEL))
+ {
+ auto const *const args = reinterpret_cast<MouseUpdateEventArgs const *>(eventdata);
+ devicelist().for_each_device(
+ [args] (auto &device) { device.queue_events(args, 1); });
+ return true;
+ }
+ }
- return true;
+ return false;
}
};
-#else
+} // anonymous namespace
+
+} // namespace osd
+
+#else // defined(OSD_WINDOWS)
+
+namespace osd {
+
+namespace {
+
MODULE_NOT_SUPPORTED(keyboard_input_win32, OSD_KEYBOARDINPUT_PROVIDER, "win32")
MODULE_NOT_SUPPORTED(mouse_input_win32, OSD_MOUSEINPUT_PROVIDER, "win32")
MODULE_NOT_SUPPORTED(lightgun_input_win32, OSD_LIGHTGUNINPUT_PROVIDER, "win32")
-#endif
-MODULE_DEFINITION(KEYBOARDINPUT_WIN32, keyboard_input_win32)
-MODULE_DEFINITION(MOUSEINPUT_WIN32, mouse_input_win32)
-MODULE_DEFINITION(LIGHTGUNINPUT_WIN32, lightgun_input_win32)
+} // anonymous namespace
+
+} // namespace osd
+
+#endif // defined(OSD_WINDOWS)
+
+MODULE_DEFINITION(KEYBOARDINPUT_WIN32, osd::keyboard_input_win32)
+MODULE_DEFINITION(MOUSEINPUT_WIN32, osd::mouse_input_win32)
+MODULE_DEFINITION(LIGHTGUNINPUT_WIN32, osd::lightgun_input_win32)