summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/sdl/osdsdl.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/sdl/osdsdl.h')
-rw-r--r--src/osd/sdl/osdsdl.h220
1 files changed, 136 insertions, 84 deletions
diff --git a/src/osd/sdl/osdsdl.h b/src/osd/sdl/osdsdl.h
index 4a320319f44..74730f69df5 100644
--- a/src/osd/sdl/osdsdl.h
+++ b/src/osd/sdl/osdsdl.h
@@ -1,47 +1,31 @@
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert, R. Belmont
-#ifndef _osdsdl_h_
-#define _osdsdl_h_
+#ifndef MAME_OSD_SDL_OSDSDL_H
+#define MAME_OSD_SDL_OSDSDL_H
+
+#pragma once
+
+#include "sdlopts.h"
#include "modules/lib/osdobj_common.h"
#include "modules/osdmodule.h"
-#include "modules/font/font_module.h"
+
+#include <SDL2/SDL.h>
+
+#include <cassert>
+#include <chrono>
+#include <memory>
+#include <mutex>
+#include <unordered_map>
+#include <utility>
+#include <string>
+#include <vector>
+
//============================================================
// Defines
//============================================================
-#define SDLOPTION_INIPATH "inipath"
-#define SDLOPTION_SDLVIDEOFPS "sdlvideofps"
-#define SDLOPTION_USEALLHEADS "useallheads"
-#define SDLOPTION_CENTERH "centerh"
-#define SDLOPTION_CENTERV "centerv"
-
-#define SDLOPTION_SCALEMODE "scalemode"
-
-#define SDLOPTION_WAITVSYNC "waitvsync"
-#define SDLOPTION_SYNCREFRESH "syncrefresh"
-#define SDLOPTION_KEYMAP "keymap"
-#define SDLOPTION_KEYMAP_FILE "keymap_file"
-
-#define SDLOPTION_SIXAXIS "sixaxis"
-#define SDLOPTION_JOYINDEX "joy_idx"
-#define SDLOPTION_KEYBINDEX "keyb_idx"
-#define SDLOPTION_MOUSEINDEX "mouse_index"
-#if (USE_XINPUT)
-#define SDLOPTION_LIGHTGUNINDEX "lightgun_index"
-#endif
-
-#define SDLOPTION_AUDIODRIVER "audiodriver"
-#define SDLOPTION_VIDEODRIVER "videodriver"
-#define SDLOPTION_RENDERDRIVER "renderdriver"
-#define SDLOPTION_GL_LIB "gl_lib"
-
-#define SDLOPTVAL_OPENGL "opengl"
-#define SDLOPTVAL_SOFT "soft"
-#define SDLOPTVAL_SDL2ACCEL "accel"
-#define SDLOPTVAL_BGFX "bgfx"
-
#define SDLMAME_LED(x) "led" #x
// read by sdlmame
@@ -56,63 +40,103 @@
#define SDLENV_AUDIODRIVER "SDL_AUDIODRIVER"
#define SDLENV_RENDERDRIVER "SDL_VIDEO_RENDERER"
-#define SDLMAME_SOUND_LOG "sound.log"
-
-#ifdef SDLMAME_MACOSX
-/* Vas Crabb: Default GL-lib for MACOSX */
-#define SDLOPTVAL_GLLIB "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
-#else
-#define SDLOPTVAL_GLLIB OSDOPTVAL_AUTO
-#endif
-
//============================================================
// TYPE DEFINITIONS
//============================================================
-class sdl_options : public osd_options
+template <typename EventRecord, typename EventType>
+class event_subscription_manager
{
-public:
- // construction/destruction
- sdl_options();
-
- // performance options
- bool video_fps() const { return bool_value(SDLOPTION_SDLVIDEOFPS); }
+public: // need extra public section for forward declaration
+ class subscriber;
- // video options
- bool centerh() const { return bool_value(SDLOPTION_CENTERH); }
- bool centerv() const { return bool_value(SDLOPTION_CENTERV); }
- const char *scale_mode() const { return value(SDLOPTION_SCALEMODE); }
+private:
+ class impl
+ {
+ public:
+ std::mutex m_mutex;
+ std::unordered_multimap<EventType, subscriber *> m_subs;
+ };
- // full screen options
-#ifdef SDLMAME_X11
- bool use_all_heads() const { return bool_value(SDLOPTION_USEALLHEADS); }
-#endif
+ std::shared_ptr<impl> m_impl;
- // keyboard mapping
- bool keymap() const { return bool_value(SDLOPTION_KEYMAP); }
- const char *keymap_file() const { return value(SDLOPTION_KEYMAP_FILE); }
+protected:
+ event_subscription_manager() : m_impl(new impl)
+ {
+ }
- // joystick mapping
- const char *joy_index(int index) const { return value(string_format("%s%d", SDLOPTION_JOYINDEX, index).c_str()); }
- bool sixaxis() const { return bool_value(SDLOPTION_SIXAXIS); }
+ ~event_subscription_manager() = default;
- const char *mouse_index(int index) const { return value(string_format("%s%d", SDLOPTION_MOUSEINDEX, index).c_str()); }
- const char *keyboard_index(int index) const { return value(string_format("%s%d", SDLOPTION_KEYBINDEX, index).c_str()); }
+ std::mutex &subscription_mutex()
+ {
+ return m_impl->m_mutex;
+ }
- const char *video_driver() const { return value(SDLOPTION_VIDEODRIVER); }
- const char *render_driver() const { return value(SDLOPTION_RENDERDRIVER); }
- const char *audio_driver() const { return value(SDLOPTION_AUDIODRIVER); }
-#if USE_OPENGL
- const char *gl_lib() const { return value(SDLOPTION_GL_LIB); }
-#endif
+ void dispatch_event(EventType const &type, EventRecord const &event)
+ {
+ auto const matches = m_impl->m_subs.equal_range(type);
+ for (auto it = matches.first; matches.second != it; ++it)
+ it->second->handle_event(event);
+ }
-private:
- static const options_entry s_option_entries[];
+public:
+ class subscriber
+ {
+ public:
+ virtual void handle_event(EventRecord const &event) = 0;
+
+ protected:
+ subscriber() = default;
+
+ virtual ~subscriber()
+ {
+ unsubscribe();
+ }
+
+ template <typename T>
+ void subscribe(event_subscription_manager &host, T &&types)
+ {
+ assert(!m_host.lock());
+ assert(host.m_impl);
+
+ m_host = host.m_impl;
+
+ std::lock_guard<std::mutex> lock(host.m_impl->m_mutex);
+ for (auto const &t : types)
+ host.m_impl->m_subs.emplace(t, this);
+ }
+
+ void unsubscribe()
+ {
+ auto const host(m_host.lock());
+ m_host.reset();
+ if (host)
+ {
+ std::lock_guard<std::mutex> lock(host->m_mutex);
+ auto it = host->m_subs.begin();
+ while (host->m_subs.end() != it)
+ {
+ if (it->second == this)
+ it = host->m_subs.erase(it);
+ else
+ ++it;
+ }
+ }
+ }
+
+ private:
+ std::weak_ptr<impl> m_host;
+ };
};
-class sdl_osd_interface : public osd_common_t
+using sdl_event_manager = event_subscription_manager<SDL_Event, uint32_t>;
+
+
+class sdl_window_info;
+
+class sdl_osd_interface : public osd_common_t, public sdl_event_manager
{
public:
// construction/destruction
@@ -122,11 +146,11 @@ public:
// general overridables
virtual void init(running_machine &machine) override;
virtual void update(bool skip_redraw) override;
+ virtual void input_update(bool relative_reset) override;
+ virtual void check_osd_inputs() override;
// input overridables
- virtual void customize_input_type_list(simple_list<input_type_entry> &typelist) override;
-
- virtual void video_register() override;
+ virtual void customize_input_type_list(std::vector<input_type_entry> &typelist) override;
virtual bool video_init() override;
virtual bool window_init() override;
@@ -134,25 +158,53 @@ public:
virtual void video_exit() override;
virtual void window_exit() override;
- // sdl specific
- void poll_inputs(running_machine &machine);
+ // SDL-specific
+ virtual bool has_focus() const override { return bool(m_focus_window); }
void release_keys();
bool should_hide_mouse();
void process_events_buf();
virtual sdl_options &options() override { return m_options; }
-protected:
- virtual void build_slider_list() override;
- virtual void update_slider_list() override;
+ virtual void process_events() override;
private:
+ enum
+ {
+ MODIFIER_KEY_LCTRL = 0x01,
+ MODIFIER_KEY_RCTRL = 0x02,
+ MODIFIER_KEY_LSHIFT = 0x04,
+ MODIFIER_KEY_RSHIFT = 0x08,
+
+ MODIFIER_KEY_CTRL = MODIFIER_KEY_LCTRL | MODIFIER_KEY_RCTRL,
+ MODIFIER_KEY_SHIFT = MODIFIER_KEY_LSHIFT | MODIFIER_KEY_RSHIFT
+ };
+
virtual void osd_exit() override;
void extract_video_config();
void output_oslog(const char *buffer);
+ void process_window_event(SDL_Event const &event);
+ void process_textinput_event(SDL_Event const &event);
+
+ bool mouse_over_window() const { return m_mouse_over_window > 0; }
+ template <typename T> sdl_window_info *focus_window(T const &event) const;
+
+ unsigned map_pointer_device(SDL_TouchID device);
+
sdl_options &m_options;
+ sdl_window_info *m_focus_window;
+ int m_mouse_over_window;
+ uint8_t m_modifier_keys;
+
+ std::chrono::steady_clock::time_point m_last_click_time;
+ int m_last_click_x;
+ int m_last_click_y;
+
+ bool m_enable_touch;
+ unsigned m_next_ptrdev;
+ std::vector<std::pair<SDL_TouchID, unsigned> > m_ptrdev_map;
};
//============================================================
@@ -161,4 +213,4 @@ private:
extern int osd_num_processors;
-#endif
+#endif // MAME_OSD_SDL_OSDSDL_H