diff --git a/src/frontend/mame/ui/menu.cpp b/src/frontend/mame/ui/menu.cpp index f3a95d81dca..78e0dd17285 100644 --- a/src/frontend/mame/ui/menu.cpp +++ b/src/frontend/mame/ui/menu.cpp @@ -82,12 +82,32 @@ bool menu::exclusive_input_pressed(int &iptkey, int key, int repeat) ***************************************************************************/ menu::global_state::global_state(running_machine &machine, ui_options const &options) - : widgets_manager(machine, options) + : widgets_manager(machine) , m_machine(machine) , m_cleanup_callbacks() + , m_bgrnd_bitmap() , m_stack() , m_free() { + render_manager &render(machine.render()); + auto const texture_free([&render](render_texture *texture) { render.texture_free(texture); }); + + // create a texture for main menu background + m_bgrnd_texture = texture_ptr(render.texture_alloc(render_texture::hq_scale), texture_free); + if (options.use_background_image() && (&machine.system() == &GAME_NAME(___empty))) + { + m_bgrnd_bitmap = std::make_unique(0, 0); + emu_file backgroundfile(".", OPEN_FLAG_READ); + render_load_jpeg(*m_bgrnd_bitmap, backgroundfile, nullptr, "background.jpg"); + + if (!m_bgrnd_bitmap->valid()) + render_load_png(*m_bgrnd_bitmap, backgroundfile, nullptr, "background.png"); + + if (m_bgrnd_bitmap->valid()) + m_bgrnd_texture->set_bitmap(*m_bgrnd_bitmap, m_bgrnd_bitmap->cliprect(), TEXFORMAT_ARGB32); + else + m_bgrnd_bitmap->reset(); + } } diff --git a/src/frontend/mame/ui/menu.h b/src/frontend/mame/ui/menu.h index d51cb470da4..ab9799371f0 100644 --- a/src/frontend/mame/ui/menu.h +++ b/src/frontend/mame/ui/menu.h @@ -266,6 +266,9 @@ private: void add_cleanup_callback(cleanup_callback &&callback); + bitmap_argb32 *bgrnd_bitmap() { return m_bgrnd_bitmap.get(); } + render_texture * bgrnd_texture() { return m_bgrnd_texture.get(); } + void reset_topmost(reset_options options) { if (m_stack) m_stack->reset(options); } template @@ -283,6 +286,9 @@ private: running_machine &m_machine; cleanup_callback_vector m_cleanup_callbacks; + bitmap_ptr m_bgrnd_bitmap; + texture_ptr m_bgrnd_texture; + std::unique_ptr m_stack; std::unique_ptr m_free; }; diff --git a/src/frontend/mame/ui/widgets.cpp b/src/frontend/mame/ui/widgets.cpp index 9b8c11a8897..3d92bd7c03a 100644 --- a/src/frontend/mame/ui/widgets.cpp +++ b/src/frontend/mame/ui/widgets.cpp @@ -21,12 +21,11 @@ namespace ui { // ctor //------------------------------------------------- -widgets_manager::widgets_manager(running_machine &machine, ui_options const &options) +widgets_manager::widgets_manager(running_machine &machine) : m_hilight_bitmap(std::make_unique(256, 1)) , m_hilight_texture() , m_hilight_main_bitmap(std::make_unique(1, 128)) , m_hilight_main_texture() - , m_bgrnd_bitmap() , m_bgrnd_texture() { render_manager &render(machine.render()); @@ -56,23 +55,6 @@ widgets_manager::widgets_manager(running_machine &machine, ui_options const &opt // create a texture for arrow icons m_arrow_texture = texture_ptr(render.texture_alloc(render_triangle), texture_free); - - // create a texture for main menu background - m_bgrnd_texture = texture_ptr(render.texture_alloc(render_texture::hq_scale), texture_free); - if (options.use_background_image() && (&machine.system() == &GAME_NAME(___empty))) - { - m_bgrnd_bitmap = std::make_unique(0, 0); - emu_file backgroundfile(".", OPEN_FLAG_READ); - render_load_jpeg(*m_bgrnd_bitmap, backgroundfile, nullptr, "background.jpg"); - - if (!m_bgrnd_bitmap->valid()) - render_load_png(*m_bgrnd_bitmap, backgroundfile, nullptr, "background.png"); - - if (m_bgrnd_bitmap->valid()) - m_bgrnd_texture->set_bitmap(*m_bgrnd_bitmap, m_bgrnd_bitmap->cliprect(), TEXFORMAT_ARGB32); - else - m_bgrnd_bitmap->reset(); - } } diff --git a/src/frontend/mame/ui/widgets.h b/src/frontend/mame/ui/widgets.h index 88c476de23d..5e9c79f78ba 100644 --- a/src/frontend/mame/ui/widgets.h +++ b/src/frontend/mame/ui/widgets.h @@ -28,12 +28,11 @@ TYPE DEFINITIONS class widgets_manager { public: - widgets_manager(running_machine &machine, ui_options const &options); + widgets_manager(running_machine &machine); render_texture *hilight_texture() { return m_hilight_texture.get(); } render_texture *hilight_main_texture() { return m_hilight_main_texture.get(); } render_texture *arrow_texture() { return m_arrow_texture.get(); } - bitmap_argb32 *bgrnd_bitmap() { return m_bgrnd_bitmap.get(); } render_texture * bgrnd_texture() { return m_bgrnd_texture.get(); } using bitmap_ptr = std::unique_ptr; @@ -45,7 +44,6 @@ private: bitmap_ptr m_hilight_main_bitmap; texture_ptr m_hilight_main_texture; texture_ptr m_arrow_texture; - bitmap_ptr m_bgrnd_bitmap; texture_ptr m_bgrnd_texture; static void render_triangle(bitmap_argb32 &dest, bitmap_argb32 &source, const rectangle &sbounds, void *param);