diff options
Diffstat (limited to 'src/frontend/mame/ui/ui.h')
-rw-r--r-- | src/frontend/mame/ui/ui.h | 208 |
1 files changed, 88 insertions, 120 deletions
diff --git a/src/frontend/mame/ui/ui.h b/src/frontend/mame/ui/ui.h index af9ad03efcc..662d8d06fc1 100644 --- a/src/frontend/mame/ui/ui.h +++ b/src/frontend/mame/ui/ui.h @@ -21,9 +21,14 @@ #include "ui/slider.h" #include "ui/text.h" +#include <any> +#include <cassert> #include <ctime> -#include <functional> #include <set> +#include <string_view> +#include <typeindex> +#include <typeinfo> +#include <unordered_map> #include <utility> #include <vector> @@ -35,6 +40,8 @@ class machine_info; } // namespace ui +class laserdisc_device; + /*************************************************************************** CONSTANTS @@ -46,75 +53,15 @@ class machine_info; #define UI_LINE_WIDTH (1.0f / 500.0f) /* handy colors */ -#define UI_GREEN_COLOR rgb_t(0xef,0x10,0x60,0x10) -#define UI_YELLOW_COLOR rgb_t(0xef,0x60,0x60,0x10) -#define UI_RED_COLOR rgb_t(0xf0,0x60,0x10,0x10) - -/* cancel return value for a UI handler */ -#define UI_HANDLER_CANCEL ((uint32_t)~0) - -#define SLIDER_DEVICE_SPACING 0x0ff -#define SLIDER_SCREEN_SPACING 0x0f -#define SLIDER_INPUT_SPACING 0x0f - -enum -{ - SLIDER_ID_VOLUME = 0, - SLIDER_ID_MIXERVOL, - SLIDER_ID_MIXERVOL_LAST = SLIDER_ID_MIXERVOL + SLIDER_DEVICE_SPACING, - SLIDER_ID_ADJUSTER, - SLIDER_ID_ADJUSTER_LAST = SLIDER_ID_ADJUSTER + SLIDER_DEVICE_SPACING, - SLIDER_ID_OVERCLOCK, - SLIDER_ID_OVERCLOCK_LAST = SLIDER_ID_OVERCLOCK + SLIDER_DEVICE_SPACING, - SLIDER_ID_REFRESH, - SLIDER_ID_REFRESH_LAST = SLIDER_ID_REFRESH + SLIDER_SCREEN_SPACING, - SLIDER_ID_BRIGHTNESS, - SLIDER_ID_BRIGHTNESS_LAST = SLIDER_ID_BRIGHTNESS + SLIDER_SCREEN_SPACING, - SLIDER_ID_CONTRAST, - SLIDER_ID_CONTRAST_LAST = SLIDER_ID_CONTRAST + SLIDER_SCREEN_SPACING, - SLIDER_ID_GAMMA, - SLIDER_ID_GAMMA_LAST = SLIDER_ID_GAMMA + SLIDER_SCREEN_SPACING, - SLIDER_ID_XSCALE, - SLIDER_ID_XSCALE_LAST = SLIDER_ID_XSCALE + SLIDER_SCREEN_SPACING, - SLIDER_ID_YSCALE, - SLIDER_ID_YSCALE_LAST = SLIDER_ID_YSCALE + SLIDER_SCREEN_SPACING, - SLIDER_ID_XOFFSET, - SLIDER_ID_XOFFSET_LAST = SLIDER_ID_XOFFSET + SLIDER_SCREEN_SPACING, - SLIDER_ID_YOFFSET, - SLIDER_ID_YOFFSET_LAST = SLIDER_ID_YOFFSET + SLIDER_SCREEN_SPACING, - SLIDER_ID_OVERLAY_XSCALE, - SLIDER_ID_OVERLAY_XSCALE_LAST = SLIDER_ID_OVERLAY_XSCALE + SLIDER_SCREEN_SPACING, - SLIDER_ID_OVERLAY_YSCALE, - SLIDER_ID_OVERLAY_YSCALE_LAST = SLIDER_ID_OVERLAY_YSCALE + SLIDER_SCREEN_SPACING, - SLIDER_ID_OVERLAY_XOFFSET, - SLIDER_ID_OVERLAY_XOFFSET_LAST = SLIDER_ID_OVERLAY_XOFFSET + SLIDER_SCREEN_SPACING, - SLIDER_ID_OVERLAY_YOFFSET, - SLIDER_ID_OVERLAY_YOFFSET_LAST = SLIDER_ID_OVERLAY_YOFFSET + SLIDER_SCREEN_SPACING, - SLIDER_ID_FLICKER, - SLIDER_ID_FLICKER_LAST = SLIDER_ID_FLICKER + SLIDER_SCREEN_SPACING, - SLIDER_ID_BEAM_WIDTH_MIN, - SLIDER_ID_BEAM_WIDTH_MIN_LAST = SLIDER_ID_BEAM_WIDTH_MIN + SLIDER_SCREEN_SPACING, - SLIDER_ID_BEAM_WIDTH_MAX, - SLIDER_ID_BEAM_WIDTH_MAX_LAST = SLIDER_ID_BEAM_WIDTH_MAX + SLIDER_SCREEN_SPACING, - SLIDER_ID_BEAM_INTENSITY, - SLIDER_ID_BEAM_INTENSITY_LAST = SLIDER_ID_BEAM_INTENSITY + SLIDER_SCREEN_SPACING, - SLIDER_ID_BEAM_DOT_SIZE, - SLIDER_ID_BEAM_DOT_SIZE_LAST = SLIDER_ID_BEAM_DOT_SIZE + SLIDER_SCREEN_SPACING, - SLIDER_ID_CROSSHAIR_SCALE, - SLIDER_ID_CROSSHAIR_SCALE_LAST = SLIDER_ID_CROSSHAIR_SCALE + SLIDER_INPUT_SPACING, - SLIDER_ID_CROSSHAIR_OFFSET, - SLIDER_ID_CROSSHAIR_OFFSET_LAST = SLIDER_ID_CROSSHAIR_OFFSET + SLIDER_INPUT_SPACING, - - SLIDER_ID_CORE_LAST = SLIDER_ID_CROSSHAIR_OFFSET, - SLIDER_ID_CORE_COUNT -}; +#define UI_GREEN_COLOR rgb_t(0xef,0x0a,0x66,0x0a) +#define UI_YELLOW_COLOR rgb_t(0xef,0xcc,0x7a,0x28) +#define UI_RED_COLOR rgb_t(0xef,0xb2,0x00,0x00) /*************************************************************************** TYPE DEFINITIONS ***************************************************************************/ class mame_ui_manager; -typedef uint32_t (*ui_callback)(mame_ui_manager &, render_container &, uint32_t); enum class ui_callback_type { @@ -169,9 +116,15 @@ private: // ======================> mame_ui_manager -class mame_ui_manager : public ui_manager, public slider_changed_notifier +class mame_ui_manager : public ui_manager { public: + enum : uint32_t + { + HANDLER_UPDATE = 1U << 0, // force video update + HANDLER_CANCEL = 1U << 1 // return to in-game event handler + }; + enum draw_mode { NONE, @@ -199,22 +152,22 @@ public: void initialize(running_machine &machine); std::vector<ui::menu_item> slider_init(running_machine &machine); - void set_handler(ui_callback_type callback_type, const std::function<uint32_t (render_container &)> &&callback); - void display_startup_screens(bool first_time); virtual void set_startup_text(const char *text, bool force) override; - void update_and_render(render_container &container); + bool update_and_render(render_container &container); render_font *get_font(); - float get_line_height(); + float get_line_height(float scale = 1.0F); float get_char_width(char32_t ch); - float get_string_width(const char *s, float text_size = 1.0f); + float get_string_width(std::string_view s); + float get_string_width(std::string_view s, float text_size); void draw_outlined_box(render_container &container, float x0, float y0, float x1, float y1, rgb_t backcolor); void draw_outlined_box(render_container &container, float x0, float y0, float x1, float y1, rgb_t fgcolor, rgb_t bgcolor); - void draw_text(render_container &container, const char *buf, float x, float y); - void draw_text_full(render_container &container, const char *origs, float x, float y, float origwrapwidth, ui::text_layout::text_justify justify, ui::text_layout::word_wrapping wrap, draw_mode draw, rgb_t fgcolor, rgb_t bgcolor, float *totalwidth = nullptr, float *totalheight = nullptr, float text_size = 1.0f); - void draw_text_box(render_container &container, const char *text, ui::text_layout::text_justify justify, float xpos, float ypos, rgb_t backcolor); + void draw_text(render_container &container, std::string_view buf, float x, float y); + void draw_text_full(render_container &container, std::string_view origs, float x, float y, float origwrapwidth, ui::text_layout::text_justify justify, ui::text_layout::word_wrapping wrap, draw_mode draw, rgb_t fgcolor, rgb_t bgcolor, float *totalwidth = nullptr, float *totalheight = nullptr); + void draw_text_full(render_container &container, std::string_view origs, float x, float y, float origwrapwidth, ui::text_layout::text_justify justify, ui::text_layout::word_wrapping wrap, draw_mode draw, rgb_t fgcolor, rgb_t bgcolor, float *totalwidth, float *totalheight, float text_size); + void draw_text_box(render_container &container, std::string_view text, ui::text_layout::text_justify justify, float xpos, float ypos, rgb_t backcolor); void draw_text_box(render_container &container, ui::text_layout &layout, float xpos, float ypos, rgb_t backcolor); - void draw_message_window(render_container &container, const char *text); + void draw_message_window(render_container &container, std::string_view text); // load/save options to file void load_ui_options(); @@ -222,6 +175,8 @@ public: void save_main_option(); template <typename Format, typename... Params> void popup_time(int seconds, Format &&fmt, Params &&... args); + void set_ui_active(bool active) { m_ui_active = active; } + bool ui_active() const { return m_ui_active; } void show_fps_temp(double seconds); void set_show_fps(bool show); bool show_fps() const; @@ -238,14 +193,10 @@ public: void decrease_frameskip(); void request_quit(); void draw_fps_counter(render_container &container); - void draw_timecode_counter(render_container &container); - void draw_timecode_total(render_container &container); void draw_profiler(render_container &container); - void start_save_state(); - void start_load_state(); // slider controls - std::vector<ui::menu_item>& get_slider_list(void); + std::vector<ui::menu_item>& get_slider_list(); // metrics float target_font_height() const { return m_target_font_height; } @@ -255,10 +206,9 @@ public: // other void process_natural_keyboard(); - ui::text_layout create_layout(render_container &container, float width = 1.0, ui::text_layout::text_justify justify = ui::text_layout::LEFT, ui::text_layout::word_wrapping wrap = ui::text_layout::WORD); - - // word wrap - int wrap_text(render_container &container, const char *origs, float x, float y, float origwrapwidth, std::vector<int> &xstart, std::vector<int> &xend, float text_size = 1.0f); + ui::text_layout create_layout(render_container &container, float width = 1.0, ui::text_layout::text_justify justify = ui::text_layout::text_justify::LEFT, ui::text_layout::word_wrapping wrap = ui::text_layout::word_wrapping::WORD); + void set_image_display_enabled(bool image_display_enabled) { m_image_display_enabled = image_display_enabled; } + bool image_display_enabled() const { return m_image_display_enabled; } // draw an outlined box with given line color and filled with a texture void draw_textured_box(render_container &container, float x0, float y0, float x1, float y1, rgb_t backcolor, rgb_t linecolor, render_texture *texture = nullptr, uint32_t flags = PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); @@ -266,28 +216,50 @@ public: virtual void menu_reset() override; + template <typename Owner, typename Data, typename... Param> + Data &get_session_data(Param &&... args) + { + auto const ins(m_session_data.try_emplace(typeid(Owner))); + assert(!ins.first->second.has_value() == ins.second); + if (ins.second) + return ins.first->second.emplace<Data>(std::forward<Param>(args)...); + Data *const result(std::any_cast<Data>(&ins.first->second)); + assert(result); + return *result; + } + + // helper for getting a general input setting - used for instruction text + std::string get_general_input_setting(ioport_type type, int player = 0, input_seq_type seqtype = SEQ_TYPE_STANDARD); + private: - using handler_callback_func = std::function<uint32_t (render_container &)>; + using handler_callback_func = delegate<uint32_t (render_container &)>; using device_feature_set = std::set<std::pair<std::string, std::string> >; + using session_data_map = std::unordered_map<std::type_index, std::any>; // instance variables std::unique_ptr<render_font> m_font; handler_callback_func m_handler_callback; ui_callback_type m_handler_callback_type; - uint32_t m_handler_param; + bool m_ui_active; bool m_single_step; bool m_showfps; osd_ticks_t m_showfps_end; bool m_show_profiler; osd_ticks_t m_popup_text_end; std::unique_ptr<uint8_t []> m_non_char_keys_down; + bitmap_argb32 m_mouse_bitmap; render_texture * m_mouse_arrow_texture; bool m_mouse_show; + int m_mouse_target; + std::pair<float, float> m_mouse_position; + ui_options m_ui_options; ui_colors m_ui_colors; float m_target_font_height; bool m_has_warnings; + bool m_unthrottle_mute; + bool m_image_display_enabled; std::unique_ptr<ui::machine_info> m_machine_info; device_feature_set m_unemulated_features; @@ -295,56 +267,52 @@ private: std::time_t m_last_launch_time; std::time_t m_last_warning_time; + session_data_map m_session_data; + // static variables static std::string messagebox_text; static std::string messagebox_poptext; - static rgb_t messagebox_backcolor; static std::vector<ui::menu_item> slider_list; - static slider_state *slider_current; // UI handlers - uint32_t handler_messagebox(render_container &container); - uint32_t handler_messagebox_anykey(render_container &container); uint32_t handler_ingame(render_container &container); - uint32_t handler_load_save(render_container &container, uint32_t state); - uint32_t handler_confirm_quit(render_container &container); // private methods + void set_handler(ui_callback_type callback_type, handler_callback_func &&callback); void exit(); - void config_load(config_type cfg_type, util::xml::data_node const *parentnode); + void config_load(config_type cfg_type, config_level cfg_level, util::xml::data_node const *parentnode); void config_save(config_type cfg_type, util::xml::data_node *parentnode); - std::unique_ptr<slider_state> slider_alloc(int id, const char *title, int32_t minval, int32_t defval, int32_t maxval, int32_t incval, void *arg); + template <typename... Params> void slider_alloc(Params &&...args) { m_sliders.push_back(std::make_unique<slider_state>(std::forward<Params>(args)...)); } // slider controls - virtual int32_t slider_changed(running_machine &machine, void *arg, int id, std::string *str, int32_t newval) override; - - int32_t slider_volume(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_mixervol(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_adjuster(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_overclock(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_refresh(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_brightness(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_contrast(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_gamma(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_xscale(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_yscale(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_xoffset(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_yoffset(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_overxscale(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_overyscale(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_overxoffset(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_overyoffset(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_flicker(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_beam_width_min(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_beam_width_max(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_beam_dot_size(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_beam_intensity_weight(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); + int32_t slider_volume(std::string *str, int32_t newval); + int32_t slider_mixervol(int item, std::string *str, int32_t newval); + int32_t slider_panning(speaker_device &speaker, std::string *str, int32_t newval); + int32_t slider_adjuster(ioport_field &field, std::string *str, int32_t newval); + int32_t slider_overclock(device_t &device, std::string *str, int32_t newval); + int32_t slider_refresh(screen_device &screen, std::string *str, int32_t newval); + int32_t slider_brightness(screen_device &screen, std::string *str, int32_t newval); + int32_t slider_contrast(screen_device &screen, std::string *str, int32_t newval); + int32_t slider_gamma(screen_device &screen, std::string *str, int32_t newval); + int32_t slider_xscale(screen_device &screen, std::string *str, int32_t newval); + int32_t slider_yscale(screen_device &screen, std::string *str, int32_t newval); + int32_t slider_xoffset(screen_device &screen, std::string *str, int32_t newval); + int32_t slider_yoffset(screen_device &screen, std::string *str, int32_t newval); + int32_t slider_overxscale(laserdisc_device &laserdisc, std::string *str, int32_t newval); + int32_t slider_overyscale(laserdisc_device &laserdisc, std::string *str, int32_t newval); + int32_t slider_overxoffset(laserdisc_device &laserdisc, std::string *str, int32_t newval); + int32_t slider_overyoffset(laserdisc_device &laserdisc, std::string *str, int32_t newval); + int32_t slider_flicker(screen_device &screen, std::string *str, int32_t newval); + int32_t slider_beam_width_min(screen_device &screen, std::string *str, int32_t newval); + int32_t slider_beam_width_max(screen_device &screen, std::string *str, int32_t newval); + int32_t slider_beam_dot_size(screen_device &screen, std::string *str, int32_t newval); + int32_t slider_beam_intensity_weight(screen_device &screen, std::string *str, int32_t newval); std::string slider_get_screen_desc(screen_device &screen); - #ifdef MAME_DEBUG - int32_t slider_crossscale(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - int32_t slider_crossoffset(running_machine &machine, void *arg, int id, std::string *str, int32_t newval); - #endif +#ifdef MAME_DEBUG + int32_t slider_crossscale(ioport_field &field, std::string *str, int32_t newval); + int32_t slider_crossoffset(ioport_field &field, std::string *str, int32_t newval); +#endif std::vector<std::unique_ptr<slider_state>> m_sliders; }; |