summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/ui/filecreate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/mame/ui/filecreate.cpp')
-rw-r--r--src/frontend/mame/ui/filecreate.cpp173
1 files changed, 108 insertions, 65 deletions
diff --git a/src/frontend/mame/ui/filecreate.cpp b/src/frontend/mame/ui/filecreate.cpp
index 07f7f10ad16..75e78702567 100644
--- a/src/frontend/mame/ui/filecreate.cpp
+++ b/src/frontend/mame/ui/filecreate.cpp
@@ -12,19 +12,21 @@
***************************************************************************/
#include "emu.h"
-
#include "ui/filecreate.h"
+
#include "ui/ui.h"
#include "ui/utils.h"
-#include "imagedev/floppy.h"
+#include "formats/flopimg.h"
+#include "path.h"
#include "zippath.h"
#include <cstring>
namespace ui {
+
/***************************************************************************
CONSTANTS
***************************************************************************/
@@ -53,11 +55,11 @@ CONFIRM SAVE AS MENU
// ctor
//-------------------------------------------------
-menu_confirm_save_as::menu_confirm_save_as(mame_ui_manager &mui, render_container &container, bool *yes)
+menu_confirm_save_as::menu_confirm_save_as(mame_ui_manager &mui, render_container &container, bool &yes)
: menu(mui, container)
+ , m_yes(yes)
{
- m_yes = yes;
- *m_yes = false;
+ m_yes = false;
}
@@ -74,7 +76,7 @@ menu_confirm_save_as::~menu_confirm_save_as()
// populate
//-------------------------------------------------
-void menu_confirm_save_as::populate(float &customtop, float &custombottom)
+void menu_confirm_save_as::populate()
{
item_append(_("File Already Exists - Override?"), FLAG_DISABLE, nullptr);
item_append(menu_item_type::SEPARATOR);
@@ -86,20 +88,19 @@ void menu_confirm_save_as::populate(float &customtop, float &custombottom)
// handle - confirm save as menu
//-------------------------------------------------
-void menu_confirm_save_as::handle()
+bool menu_confirm_save_as::handle(event const *ev)
{
- // process the menu
- const event *event = process(0);
-
// process the event
- if ((event != nullptr) && (event->iptkey == IPT_UI_SELECT))
+ if (ev && (ev->iptkey == IPT_UI_SELECT))
{
- if (event->itemref == ITEMREF_YES)
- *m_yes = true;
+ if (ev->itemref == ITEMREF_YES)
+ m_yes = true;
// no matter what, pop out
stack_pop();
}
+
+ return false;
}
@@ -120,7 +121,7 @@ menu_file_create::menu_file_create(mame_ui_manager &mui, render_container &conta
, m_current_format(nullptr)
{
m_image = image;
- m_ok = true;
+ m_ok = false;
m_filename.reserve(1024);
m_filename = core_filename_extract_base(current_file);
@@ -137,14 +138,36 @@ menu_file_create::~menu_file_create()
//-------------------------------------------------
+// recompute_metrics - recompute metrics
+//-------------------------------------------------
+
+void menu_file_create::recompute_metrics(uint32_t width, uint32_t height, float aspect)
+{
+ menu::recompute_metrics(width, height, aspect);
+
+ set_custom_space(line_height() + 3.0F * tb_border(), 0.0F);
+}
+
+
+//-------------------------------------------------
// custom_render - perform our special rendering
//-------------------------------------------------
void menu_file_create::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
{
extra_text_render(top, bottom, origx1, origy1, origx2, origy2,
- m_current_directory,
- std::string_view());
+ m_current_directory,
+ std::string_view());
+}
+
+
+//-------------------------------------------------
+// custom_ui_back - override back handling
+//-------------------------------------------------
+
+bool menu_file_create::custom_ui_back()
+{
+ return (get_selection_ref() == ITEMREF_NEW_IMAGE_NAME) && !m_filename.empty();
}
@@ -152,10 +175,9 @@ void menu_file_create::custom_render(void *selectedref, float top, float bottom,
// populate - populates the file creator menu
//-------------------------------------------------
-void menu_file_create::populate(float &customtop, float &custombottom)
+void menu_file_create::populate()
{
std::string buffer;
- const image_device_format *format;
const std::string *new_image_name;
// append the "New Image Name" item
@@ -171,9 +193,10 @@ void menu_file_create::populate(float &customtop, float &custombottom)
item_append(_("New Image Name:"), *new_image_name, 0, ITEMREF_NEW_IMAGE_NAME);
// do we support multiple formats?
- if (ENABLE_FORMATS) format = m_image->formatlist().front().get();
- if (ENABLE_FORMATS && (format != nullptr))
+ image_device_format const *const format = ENABLE_FORMATS ? m_image->formatlist().front().get() : nullptr;
+ if (format)
{
+ // FIXME: is this in the right order? It reassigns m_current_format after reading it.
item_append(_("Image Format:"), m_current_format->description(), 0, ITEMREF_FORMAT);
m_current_format = format;
}
@@ -181,8 +204,6 @@ void menu_file_create::populate(float &customtop, float &custombottom)
// finish up the menu
item_append(menu_item_type::SEPARATOR);
item_append(_("Create"), 0, ITEMREF_CREATE);
-
- customtop = ui().get_line_height() + 3.0f * ui().box_tb_border();
}
@@ -190,43 +211,64 @@ void menu_file_create::populate(float &customtop, float &custombottom)
// handle - file creator menu
//-------------------------------------------------
-void menu_file_create::handle()
+bool menu_file_create::handle(event const *ev)
{
- // process the menu
- const event *event = process(0);
+ if (!ev)
+ return false;
- // process the event
- if (event)
+ // handle selections
+ switch (ev->iptkey)
{
- // handle selections
- switch (event->iptkey)
+ case IPT_UI_SELECT:
+ if ((ev->itemref == ITEMREF_CREATE) || (ev->itemref == ITEMREF_NEW_IMAGE_NAME))
{
- case IPT_UI_SELECT:
- if ((event->itemref == ITEMREF_CREATE) || (event->itemref == ITEMREF_NEW_IMAGE_NAME))
+ std::string tmp_file(m_filename);
+ if (tmp_file.find('.') != -1 && tmp_file.find('.') < tmp_file.length() - 1)
+ {
+ m_current_file = m_filename;
+ m_ok = true;
+ stack_pop();
+ }
+ else
{
- std::string tmp_file(m_filename);
- if (tmp_file.find('.') != -1 && tmp_file.find('.') < tmp_file.length() - 1)
- {
- m_current_file = m_filename;
- stack_pop();
- }
- else
- ui().popup_time(1, "%s", _("Please enter a file extension too"));
+ ui().popup_time(1, "%s", _("Please enter a file extension too"));
}
- break;
+ }
+ break;
- case IPT_SPECIAL:
- if (get_selection_ref() == ITEMREF_NEW_IMAGE_NAME)
+ case IPT_UI_PASTE:
+ if (ev->itemref == ITEMREF_NEW_IMAGE_NAME)
+ {
+ if (paste_text(m_filename, &osd_is_valid_filename_char))
{
- input_character(m_filename, event->unichar, &osd_is_valid_filename_char);
- reset(reset_options::REMEMBER_POSITION);
+ ev->item->set_subtext(m_filename + "_");
+ return true;
}
- break;
- case IPT_UI_CANCEL:
- m_ok = false;
- break;
}
+ break;
+
+ case IPT_SPECIAL:
+ if (ev->itemref == ITEMREF_NEW_IMAGE_NAME)
+ {
+ if (input_character(m_filename, ev->unichar, &osd_is_valid_filename_char))
+ {
+ ev->item->set_subtext(m_filename + "_");
+ return true;
+ }
+ }
+ break;
+
+ case IPT_UI_CANCEL:
+ if ((ev->itemref == ITEMREF_NEW_IMAGE_NAME) && !m_filename.empty())
+ {
+ m_filename.clear();
+ ev->item->set_subtext("_");
+ return true;
+ }
+ break;
}
+
+ return false;
}
@@ -238,12 +280,11 @@ SELECT FORMAT MENU
// ctor
//-------------------------------------------------
-menu_select_format::menu_select_format(mame_ui_manager &mui, render_container &container, floppy_image_format_t **formats, int ext_match, int total_usable, int *result)
+menu_select_format::menu_select_format(mame_ui_manager &mui, render_container &container, const std::vector<const floppy_image_format_t *> &formats, int ext_match, const floppy_image_format_t **result)
: menu(mui, container)
{
m_formats = formats;
m_ext_match = ext_match;
- m_total_usable = total_usable;
m_result = result;
}
@@ -261,16 +302,16 @@ menu_select_format::~menu_select_format()
// populate
//-------------------------------------------------
-void menu_select_format::populate(float &customtop, float &custombottom)
+void menu_select_format::populate()
{
item_append(_("Select image format"), FLAG_DISABLE, nullptr);
- for (int i = 0; i < m_total_usable; i++)
+ for (unsigned int i = 0; i != m_formats.size(); i++)
{
const floppy_image_format_t *fmt = m_formats[i];
if (i && i == m_ext_match)
item_append(menu_item_type::SEPARATOR);
- item_append(fmt->description(), fmt->name(), 0, (void *)(uintptr_t)i);
+ item_append(fmt->description(), fmt->name(), 0, const_cast<floppy_image_format_t *>(fmt));
}
}
@@ -279,15 +320,16 @@ void menu_select_format::populate(float &customtop, float &custombottom)
// handle
//-------------------------------------------------
-void menu_select_format::handle()
+bool menu_select_format::handle(event const *ev)
{
// process the menu
- const event *event = process(0);
- if (event != nullptr && event->iptkey == IPT_UI_SELECT)
+ if (ev && ev->iptkey == IPT_UI_SELECT)
{
- *m_result = int(uintptr_t(event->itemref));
+ *m_result = (floppy_image_format_t *)ev->itemref;
stack_pop();
}
+
+ return false;
}
@@ -299,9 +341,9 @@ SELECT FORMAT MENU
// ctor
//-------------------------------------------------
-menu_select_floppy_init::menu_select_floppy_init(mame_ui_manager &mui, render_container &container, const std::vector<floppy_image_device::fs_info> &fs, int *result)
+menu_select_floppy_init::menu_select_floppy_init(mame_ui_manager &mui, render_container &container, std::vector<std::reference_wrapper<const floppy_image_device::fs_info>> &&fs, int *result)
: menu(mui, container),
- m_fs(fs),
+ m_fs(std::move(fs)),
m_result(result)
{
@@ -321,11 +363,11 @@ menu_select_floppy_init::~menu_select_floppy_init()
// populate
//-------------------------------------------------
-void menu_select_floppy_init::populate(float &customtop, float &custombottom)
+void menu_select_floppy_init::populate()
{
item_append(_("Select initial contents"), FLAG_DISABLE, nullptr);
int id = 0;
- for (const auto &fmt : m_fs)
+ for (const floppy_image_device::fs_info &fmt : m_fs)
item_append(fmt.m_description, fmt.m_name, 0, (void *)(uintptr_t)(id++));
}
@@ -334,15 +376,16 @@ void menu_select_floppy_init::populate(float &customtop, float &custombottom)
// handle
//-------------------------------------------------
-void menu_select_floppy_init::handle()
+bool menu_select_floppy_init::handle(event const *ev)
{
// process the menu
- const event *event = process(0);
- if (event != nullptr && event->iptkey == IPT_UI_SELECT)
+ if (ev && ev->iptkey == IPT_UI_SELECT)
{
- *m_result = int(uintptr_t(event->itemref));
+ *m_result = int(uintptr_t(ev->itemref));
stack_pop();
}
+
+ return false;
}