Skip to content

Commit

Permalink
-osd: Better XInput and SDL game controller input enhancements:
Browse files Browse the repository at this point in the history
* Added initial support for XInput controller subtypes, starting with
  driving, arcade and flight controllers.
* Check XInput capabilities to ignore buttons and hats that aren't
  present.
* Added preliminary SDL Game Controller joystick provider.  Reconnection
  and mixed Game Controller/Joystick devices are unsupported.
* Show the input token for the highlighted control on input device
  menus.

-ui: Allow menus to set required space above and below menu when metrics
change.  Fixes the initial bad layout on the system selecton menu, or
bad layout after resizing windows.
  • Loading branch information
cuavas committed Jan 12, 2023
1 parent 9e8064c commit fee7047
Show file tree
Hide file tree
Showing 92 changed files with 1,881 additions and 658 deletions.
10 changes: 6 additions & 4 deletions docs/source/commandline/commandline-all.rst
Expand Up @@ -899,22 +899,24 @@ Example:
- dinput
- xinput
- none
- sdl
- sdljoy
- sdlgame
* - **SDL**
- auto [#JIPAutoSDL]_.
-
-
-
- none
- sdl
- sdljoy
- sdlgame
.. rubric:: Footnotes
.. [#JIPAutoWindows] On Windows, auto will default to ``dinput``.
.. [#JIPAutoSDL] On SDL, auto will default to ``sdl``.
.. [#JIPAutoSDL] On SDL, auto will default to ``sdljoy``.
.. Tip:: Note that Microsoft XBox 360 and XBox One controllers connected to
.. Tip:: Note that Microsoft Xbox 360 and Xbox One controllers connected to
Windows will work best with ``winhybrid`` or ``xinput``. The
``winhybrid`` option supports a mix of DirectInput and XInput
controllers at the same time.
Expand Down
5 changes: 3 additions & 2 deletions docs/source/commandline/sdlconfig.rst
Expand Up @@ -70,8 +70,9 @@ SDL Joystick Mapping

**-sixaxis**

Use special handling for PlayStation 3 SixAxis controllers. Default is OFF
(**-nosixaxis**)
Use special handling for PlayStation 3 SixAxis controllers. May cause
undesirable behaviour with other controllers. Only affects the ``sdljoy``
joystick provider. Default is OFF (**-nosixaxis**)


SDL Lightgun Mapping
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Expand Up @@ -63,9 +63,9 @@
# built documents.
#
# The short X.Y version.
version = '0.251'
version = '0.252'
# The full version, including alpha/beta/rc tags.
release = '0.251'
release = '0.252'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
6 changes: 3 additions & 3 deletions src/emu/render.cpp
Expand Up @@ -1013,9 +1013,9 @@ void render_target::set_bounds(s32 width, s32 height, float pixel_aspect)
m_width = width;
m_height = height;
m_bounds.x0 = m_bounds.y0 = 0;
m_bounds.x1 = (float)width;
m_bounds.y1 = (float)height;
m_pixel_aspect = pixel_aspect != 0.0? pixel_aspect : 1.0;
m_bounds.x1 = float(width);
m_bounds.y1 = float(height);
m_pixel_aspect = pixel_aspect != 0.0F ? pixel_aspect : 1.0F;
}


Expand Down
17 changes: 14 additions & 3 deletions src/frontend/mame/ui/about.cpp
Expand Up @@ -63,6 +63,19 @@ menu_about::~menu_about()
}


//-------------------------------------------------
// recompute metrics
//-------------------------------------------------

void menu_about::recompute_metrics(uint32_t width, uint32_t height, float aspect)
{
menu_textbox::recompute_metrics(width, height, aspect);

// make space for the title and revision
set_custom_space((line_height() * m_header.size()) + (tb_border() * 3.0F), 0.0F);
}


//-------------------------------------------------
// perform our special rendering
//-------------------------------------------------
Expand Down Expand Up @@ -103,10 +116,8 @@ void menu_about::populate_text(std::optional<text_layout> &layout, float &width,
// populate - populates the about modal
//-------------------------------------------------

void menu_about::populate(float &customtop, float &custombottom)
void menu_about::populate()
{
// make space for the title and revision
customtop = (line_height() * m_header.size()) + (tb_border() * 3.0f);
}


Expand Down
3 changes: 2 additions & 1 deletion src/frontend/mame/ui/about.h
Expand Up @@ -29,12 +29,13 @@ class menu_about : public menu_textbox
virtual ~menu_about() override;

protected:
virtual void recompute_metrics(uint32_t width, uint32_t height, float aspect) override;
virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override;

virtual void populate_text(std::optional<text_layout> &layout, float &width, int &lines) override;

private:
virtual void populate(float &customtop, float &custombottom) override;
virtual void populate() override;
virtual void handle(event const *ev) override;

std::vector<std::string> const m_header;
Expand Down
13 changes: 11 additions & 2 deletions src/frontend/mame/ui/analogipt.cpp
Expand Up @@ -66,6 +66,15 @@ menu_analog::~menu_analog()
}


void menu_analog::recompute_metrics(uint32_t width, uint32_t height, float aspect)
{
menu::recompute_metrics(width, height, aspect);

// space for live display
set_custom_space(0.0f, (line_height() * m_visible_fields) + (tb_border() * 3.0f));
}


void menu_analog::custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2)
{
// work out how much space to use for field names
Expand Down Expand Up @@ -331,7 +340,7 @@ void menu_analog::handle(event const *ev)
}


void menu_analog::populate(float &customtop, float &custombottom)
void menu_analog::populate()
{
// loop over input ports
if (m_item_data.empty())
Expand Down Expand Up @@ -401,7 +410,7 @@ void menu_analog::populate(float &customtop, float &custombottom)
item_append(menu_item_type::SEPARATOR);

// space for live display
custombottom = (line_height() * m_visible_fields) + (tb_border() * 3.0f);
set_custom_space(0.0f, (line_height() * m_visible_fields) + (tb_border() * 3.0f));
}


Expand Down
3 changes: 2 additions & 1 deletion src/frontend/mame/ui/analogipt.h
Expand Up @@ -27,6 +27,7 @@ class menu_analog : public menu
virtual ~menu_analog() override;

protected:
virtual void recompute_metrics(uint32_t width, uint32_t height, float aspect) override;
virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override;
virtual void menu_activated() override;

Expand Down Expand Up @@ -66,7 +67,7 @@ class menu_analog : public menu
using item_data_vector = std::vector<item_data>;
using field_data_vector = std::vector<field_data>;

virtual void populate(float &customtop, float &custombottom) override;
virtual void populate() override;
virtual void handle(event const *ev) override;

void find_fields();
Expand Down
15 changes: 11 additions & 4 deletions src/frontend/mame/ui/auditmenu.cpp
Expand Up @@ -74,6 +74,14 @@ menu_audit::~menu_audit()
}


void menu_audit::recompute_metrics(uint32_t width, uint32_t height, float aspect)
{
menu::recompute_metrics(width, height, aspect);

set_custom_space(0.0F, (line_height() * 1.0F) + (tb_border() * 3.0F));
}


void menu_audit::custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2)
{
switch (m_phase)
Expand Down Expand Up @@ -107,7 +115,7 @@ void menu_audit::custom_render(void *selectedref, float top, float bottom, float
container(),
std::move(text).str(),
text_layout::text_justify::CENTER,
0.5f, 0.5f,
0.5F, 0.5F,
ui().colors().background_color());
}
break;
Expand All @@ -120,7 +128,7 @@ void menu_audit::custom_render(void *selectedref, float top, float bottom, float
ui().get_general_input_setting(IPT_UI_SELECT),
ui().get_general_input_setting(IPT_UI_CANCEL)),
text_layout::text_justify::CENTER,
0.5f, 0.5f,
0.5F, 0.5F,
UI_RED_COLOR);
break;
}
Expand All @@ -133,13 +141,12 @@ bool menu_audit::custom_ui_cancel()
}


void menu_audit::populate(float &customtop, float &custombottom)
void menu_audit::populate()
{
if (m_unavailable && (m_availablesorted.size() != m_unavailable))
item_append(util::string_format(_("Audit media for %1$u systems marked unavailable"), m_unavailable), 0, ITEMREF_START_FAST);
item_append(util::string_format(_("Audit media for all %1$u systems"), m_availablesorted.size()), 0, ITEMREF_START_FULL);
item_append(menu_item_type::SEPARATOR, 0);
custombottom = (line_height() * 1.0f) + (tb_border() * 3.0f);
}

void menu_audit::handle(event const *ev)
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/mame/ui/auditmenu.h
Expand Up @@ -29,13 +29,14 @@ class menu_audit : public menu
virtual ~menu_audit() override;

protected:
virtual void recompute_metrics(uint32_t width, uint32_t height, float aspect) override;
virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override;
virtual bool custom_ui_cancel() override;

private:
enum class phase { CONFIRMATION, AUDIT, CANCELLATION };

virtual void populate(float &customtop, float &custombottom) override;
virtual void populate() override;
virtual void handle(event const *ev) override;

bool do_audit();
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/mame/ui/barcode.cpp
Expand Up @@ -54,7 +54,7 @@ menu_barcode_reader::~menu_barcode_reader()
// populate - populates the barcode input menu
//-------------------------------------------------

void menu_barcode_reader::populate(float &customtop, float &custombottom)
void menu_barcode_reader::populate()
{
if (current_device())
{
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/mame/ui/barcode.h
Expand Up @@ -24,7 +24,7 @@ class menu_barcode_reader : public menu_device_control<barcode_reader_device> {
virtual ~menu_barcode_reader() override;

private:
virtual void populate(float &customtop, float &custombottom) override;
virtual void populate() override;
virtual void handle(event const *ev) override;

std::string m_barcode_buffer;
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/mame/ui/cheatopt.cpp
Expand Up @@ -111,7 +111,7 @@ menu_cheat::menu_cheat(mame_ui_manager &mui, render_container &container) : menu
set_process_flags(PROCESS_LR_REPEAT);
}

void menu_cheat::populate(float &customtop, float &custombottom)
void menu_cheat::populate()
{
/* iterate over cheats */
std::string text;
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/mame/ui/cheatopt.h
Expand Up @@ -24,7 +24,7 @@ class menu_cheat : public menu
virtual ~menu_cheat() override;

private:
virtual void populate(float &customtop, float &custombottom) override;
virtual void populate() override;
virtual void handle(event const *ev) override;
};

Expand Down
22 changes: 17 additions & 5 deletions src/frontend/mame/ui/confswitch.cpp
Expand Up @@ -89,7 +89,7 @@ void menu_confswitch::menu_activated()
}


void menu_confswitch::populate(float &customtop, float &custombottom)
void menu_confswitch::populate()
{
// locate relevant fields if necessary
if (m_fields.empty())
Expand Down Expand Up @@ -320,6 +320,18 @@ menu_settings_dip_switches::~menu_settings_dip_switches()
}


void menu_settings_dip_switches::recompute_metrics(uint32_t width, uint32_t height, float aspect)
{
menu_confswitch::recompute_metrics(width, height, aspect);

set_custom_space(
0.0f,
m_visible_switch_groups
? ((m_visible_switch_groups * (DIP_SWITCH_HEIGHT * line_height())) + ((m_visible_switch_groups - 1) * (DIP_SWITCH_SPACING * line_height())) + (tb_border() * 3.0f))
: 0.0f);
}


void menu_settings_dip_switches::custom_render(void *selectedref, float top, float bottom, float x1, float y1, float x2, float y2)
{
// catch if no DIP locations have to be drawn
Expand Down Expand Up @@ -470,10 +482,10 @@ bool menu_settings_dip_switches::custom_mouse_down()
}


void menu_settings_dip_switches::populate(float &customtop, float &custombottom)
void menu_settings_dip_switches::populate()
{
// let the base class add items
menu_confswitch::populate(customtop, custombottom);
menu_confswitch::populate();

// use up to about 70% of height for DIP switch display
if (active_switch_groups())
Expand All @@ -485,12 +497,12 @@ void menu_settings_dip_switches::populate(float &customtop, float &custombottom)
m_visible_switch_groups = unsigned(0.7f / (groupheight + groupspacing));
else
m_visible_switch_groups = active_switch_groups();
custombottom = (m_visible_switch_groups * groupheight) + ((m_visible_switch_groups - 1) * groupspacing) + (tb_border() * 3.0f);
set_custom_space(0.0f, (m_visible_switch_groups * groupheight) + ((m_visible_switch_groups - 1) * groupspacing) + (tb_border() * 3.0f));
}
else
{
m_visible_switch_groups = 0U;
custombottom = 0.0f;
set_custom_space(0.0f, 0.0f);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/frontend/mame/ui/confswitch.h
Expand Up @@ -57,7 +57,7 @@ class menu_confswitch : public menu
menu_confswitch(mame_ui_manager &mui, render_container &container, uint32_t type);

virtual void menu_activated() override;
virtual void populate(float &customtop, float &custombottom) override;
virtual void populate() override;

field_vector const &fields() { return m_fields; }
switch_group_vector const &switch_groups() { return m_switch_groups; }
Expand All @@ -82,11 +82,12 @@ class menu_settings_dip_switches : public menu_confswitch
virtual ~menu_settings_dip_switches() override;

protected:
virtual void recompute_metrics(uint32_t width, uint32_t height, float aspect) override;
virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override;
virtual bool custom_mouse_down() override;

private:
virtual void populate(float &customtop, float &custombottom) override;
virtual void populate() override;

std::vector<float> m_switch_group_y;
unsigned m_visible_switch_groups;
Expand Down

1 comment on commit fee7047

@cuavas
Copy link
Member Author

@cuavas cuavas commented on fee7047 Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d appreciate some help testing with exotic controllers If you want to help out, I’d appreciate if you head over to this discussion and post some info.

If you can make an OSD=windows build (default on Windows):

  • OS version, types of controllers
  • Output of mame -joystickprovider winhybrid -verbose – filter for lines containing “XInput”
  • Screenshots of the input device menus
  • Check that the input codes look sane for each control, note any missing controls or anything surprising

If you can make an OSD=sdl build (Windows, macOS or Linux):

  • OS, SDL version, types of controllers
  • Output of mame -joystickprovider sdlgame -verbose – filter for lines starting with “Game Controller:”
  • Screenshots of the input device menus
  • Check that the input codes look sane for each control, note any missing controls or anything surprising

I’ll post examples of what I’m looking for.

Please sign in to comment.