summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/ui/confswitch.h
blob: cdbc0e63ff6a6d9784667ac8efcf78d76e82e76b (plain) (blame)
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:Nicola Salmoria, Aaron Giles, Nathan Woods, Vas Crabb
/***************************************************************************

    ui/confswitch.h

    Configuration/DIP switches menu.

***************************************************************************/
#ifndef MAME_FRONTEND_UI_CONFSWITCH_H
#define MAME_FRONTEND_UI_CONFSWITCH_H

#include "ui/menu.h"

#include <functional>
#include <vector>


namespace ui {

class menu_confswitch : public menu
{
public:
	virtual ~menu_confswitch() override;

protected:
	struct field_descriptor
	{
		field_descriptor(ioport_field &f) noexcept;

		std::reference_wrapper<ioport_field> field;
	};

	struct switch_group_descriptor
	{
		switch_group_descriptor(ioport_field const &f, ioport_diplocation const &loc) noexcept;

		bool matches(ioport_field const &f, ioport_diplocation const &loc) const noexcept;
		unsigned switch_count() const noexcept;

		char const *name;
		std::reference_wrapper<device_t> owner;
		uint32_t mask;
		uint32_t state;
	};

	using field_vector = std::vector<field_descriptor>;
	using switch_group_vector = std::vector<switch_group_descriptor>;

	menu_confswitch(mame_ui_manager &mui, render_container &container, uint32_t type);

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

	field_vector const &fields() { return m_fields; }
	switch_group_vector const &switch_groups() { return m_switch_groups; }
	unsigned active_switch_groups() const { return m_active_switch_groups; }

	int m_dipcount;

private:
	virtual void handle() override;

	void find_fields();

	field_vector m_fields;
	switch_group_vector m_switch_groups;
	unsigned m_active_switch_groups;
	int const m_type;
};


class menu_settings_dip_switches : public menu_confswitch
{
public:
	menu_settings_dip_switches(mame_ui_manager &mui, render_container &container);
	virtual ~menu_settings_dip_switches() override;

protected:
	virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override;

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

	unsigned m_visible_switch_groups;
};


class menu_settings_machine_config : public menu_confswitch
{
public:
	menu_settings_machine_config(mame_ui_manager &mui, render_container &container);
	virtual ~menu_settings_machine_config();
};

} // namespace ui

#endif // MAME_FRONTEND_UI_CONFSWITCH_H