mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 12:32:52 +00:00
[nk] allow picking core and content on demo window
This commit is contained in:
parent
9777ea933f
commit
afe68b2a62
@ -48,34 +48,19 @@
|
||||
#include "../../verbosity.h"
|
||||
#include "../../tasks/tasks_internal.h"
|
||||
|
||||
/* this is the main control function, it opens and closes windows, */
|
||||
static void nk_menu_main(nk_menu_handle_t *nk)
|
||||
{
|
||||
|
||||
settings_t *settings = config_get_ptr();
|
||||
struct nk_context *ctx = &nk->ctx;
|
||||
|
||||
static char out[PATH_MAX_LENGTH];
|
||||
|
||||
if (nk->window[NK_WND_SETTINGS].open)
|
||||
nk_wnd_settings(nk);
|
||||
if (nk->window[NK_WND_FILE_PICKER].open)
|
||||
{
|
||||
if (nk_wnd_file_picker(nk, settings->directory.menu_content, out, ".zip"))
|
||||
{
|
||||
RARCH_LOG ("%s selected\n", out);
|
||||
nk_window_close(&nk->ctx, "Select File");
|
||||
}
|
||||
|
||||
}
|
||||
if (nk->window[NK_WND_SHADER_PARAMETERS].open)
|
||||
nk_wnd_shader_parameters(nk);
|
||||
if (nk->window[NK_WND_MAIN].open)
|
||||
nk_wnd_main(nk);
|
||||
|
||||
nk->window[NK_WND_SETTINGS].open = !nk_window_is_closed(ctx, "Settings");
|
||||
nk->window[NK_WND_FILE_PICKER].open = !nk_window_is_closed(ctx, "Select File");
|
||||
nk->window[NK_WND_SHADER_PARAMETERS].open = !nk_window_is_closed(ctx, "Shader Parameters");
|
||||
nk->window[NK_WND_MAIN].open = !nk_window_is_closed(ctx, "Main");
|
||||
nk_wnd_main(nk, "Demo");
|
||||
|
||||
nk_buffer_info(&nk->status, &nk->ctx.memory);
|
||||
}
|
||||
@ -311,7 +296,6 @@ static void *nk_menu_init(void **userdata)
|
||||
nk->window[i].open = true;
|
||||
#else
|
||||
nk->window[NK_WND_MAIN].open = true;
|
||||
nk->window[NK_WND_FILE_PICKER].open = true;
|
||||
#endif
|
||||
|
||||
return menu;
|
||||
|
@ -86,8 +86,8 @@ typedef struct nk_menu_handle
|
||||
} nk_menu_handle_t;
|
||||
|
||||
void nk_wnd_shader_parameters(nk_menu_handle_t *nk);
|
||||
void nk_wnd_main(nk_menu_handle_t *nk);
|
||||
bool nk_wnd_file_picker(nk_menu_handle_t *nk, const char* in, char* out, const char* filter);
|
||||
void nk_wnd_main(nk_menu_handle_t *nk, const char* title);
|
||||
bool nk_wnd_file_picker(nk_menu_handle_t *nk, char* title, char* in, char* out, char* filter);
|
||||
void nk_wnd_settings(nk_menu_handle_t *nk);
|
||||
void nk_wnd_set_state(nk_menu_handle_t *nk, const int id,
|
||||
struct nk_vec2 pos, struct nk_vec2 size);
|
||||
|
@ -61,7 +61,7 @@ void load_icons(nk_menu_handle_t *nk)
|
||||
assets_loaded = true;
|
||||
}
|
||||
|
||||
bool nk_wnd_file_picker(nk_menu_handle_t *nk, const char* in, char* out, const char* filter)
|
||||
bool nk_wnd_file_picker(nk_menu_handle_t *nk, char* title, char* in, char* out, char* filter)
|
||||
{
|
||||
struct nk_panel layout;
|
||||
struct nk_context *ctx = &nk->ctx;
|
||||
@ -80,7 +80,6 @@ bool nk_wnd_file_picker(nk_menu_handle_t *nk, const char* in, char* out, const c
|
||||
|
||||
if (!string_is_empty(in) && string_is_empty(path))
|
||||
{
|
||||
RARCH_LOG("beep\n");
|
||||
strlcpy(path, in, sizeof(path));
|
||||
files = dir_list_new(path, filter, true, true);
|
||||
}
|
||||
@ -88,7 +87,7 @@ bool nk_wnd_file_picker(nk_menu_handle_t *nk, const char* in, char* out, const c
|
||||
if (!assets_loaded)
|
||||
load_icons(nk);
|
||||
|
||||
if (nk_begin(ctx, &layout, "Select File", nk_rect(10, 10, 500, 400),
|
||||
if (nk_begin(ctx, &layout, title, nk_rect(10, 10, 500, 400),
|
||||
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE|
|
||||
NK_WINDOW_BORDER))
|
||||
{
|
||||
@ -136,7 +135,12 @@ bool nk_wnd_file_picker(nk_menu_handle_t *nk, const char* in, char* out, const c
|
||||
nk_layout_row_dynamic(ctx, 30, 1);
|
||||
{
|
||||
if (nk_button_text(ctx, "OK", 2, NK_BUTTON_DEFAULT))
|
||||
{
|
||||
ret = true;
|
||||
strlcpy(out, path, sizeof(path));
|
||||
nk->window[NK_WND_FILE_PICKER].open = false;
|
||||
path[0] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +148,6 @@ bool nk_wnd_file_picker(nk_menu_handle_t *nk, const char* in, char* out, const c
|
||||
dir_list_sort(files, true);
|
||||
|
||||
/* copy the path variable to out*/
|
||||
strlcpy(out, path, sizeof(path));
|
||||
|
||||
/* save position and size to restore after context reset */
|
||||
nk_wnd_set_state(nk, id, nk_window_get_position(ctx), nk_window_get_size(ctx));
|
||||
|
@ -29,19 +29,72 @@
|
||||
#include "../../menu_driver.h"
|
||||
#include "../../menu_hash.h"
|
||||
|
||||
void nk_wnd_main(nk_menu_handle_t *nk)
|
||||
static char* out;
|
||||
static char core[PATH_MAX_LENGTH] = {0};
|
||||
static char content[PATH_MAX_LENGTH] = {0};
|
||||
float ratio[] = {0.85f, 0.15f};
|
||||
|
||||
void nk_wnd_main(nk_menu_handle_t *nk, const char* title)
|
||||
{
|
||||
unsigned i;
|
||||
video_shader_ctx_t shader_info;
|
||||
struct nk_panel layout;
|
||||
struct nk_context *ctx = &nk->ctx;
|
||||
const int id = NK_WND_MAIN;
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
if (nk_begin(ctx, &layout, "Main", nk_rect(240, 10, 300, 400),
|
||||
static char picker_filter[PATH_MAX_LENGTH];
|
||||
static char picker_title[PATH_MAX_LENGTH];
|
||||
static char* picker_startup_dir;
|
||||
|
||||
int len_core, len_content = 0;
|
||||
|
||||
if (!out)
|
||||
out = &core;
|
||||
|
||||
if (!string_is_empty(core))
|
||||
len_core = strlen(path_basename(core));
|
||||
if (!string_is_empty(content))
|
||||
len_content = strlen(content);
|
||||
|
||||
if (nk->window[NK_WND_FILE_PICKER].open)
|
||||
{
|
||||
if (nk_wnd_file_picker(nk, picker_title, picker_startup_dir, out, picker_filter))
|
||||
{
|
||||
RARCH_LOG ("%s selected\n", out);
|
||||
nk_window_close(&nk->ctx, picker_title);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (nk_begin(ctx, &layout, title, nk_rect(240, 10, 600, 400),
|
||||
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE|
|
||||
NK_WINDOW_SCALABLE|NK_WINDOW_BORDER))
|
||||
{
|
||||
nk_layout_row_dynamic(ctx, 30, 1);
|
||||
nk_label(ctx,"Core:", NK_TEXT_LEFT);
|
||||
nk_layout_row(ctx, NK_DYNAMIC, 30, 3, ratio);
|
||||
nk_edit_string(ctx, NK_EDIT_SIMPLE, path_basename(core), &len_core, 64, nk_filter_default);
|
||||
if (nk_button_text(ctx, "...", 3, NK_BUTTON_DEFAULT))
|
||||
{
|
||||
out = &core;
|
||||
strlcpy(picker_title, "Select core", sizeof(picker_title));
|
||||
strlcpy(picker_filter, ".dll", sizeof(picker_filter));
|
||||
picker_startup_dir = settings->directory.libretro;
|
||||
nk->window[NK_WND_FILE_PICKER].open = true;
|
||||
}
|
||||
nk_layout_row_dynamic(ctx, 30, 1);
|
||||
nk_label(ctx,"Content:", NK_TEXT_LEFT);
|
||||
nk_layout_row(ctx, NK_DYNAMIC, 30, 3, ratio);
|
||||
nk_edit_string(ctx, NK_EDIT_SIMPLE, content, &len_content, 64, nk_filter_default);
|
||||
if (nk_button_text(ctx, "...", 3, NK_BUTTON_DEFAULT))
|
||||
{
|
||||
out = &content;
|
||||
strlcpy(picker_title, "Select content", sizeof(picker_title));
|
||||
strlcpy(picker_filter, ".zip", sizeof(picker_filter));
|
||||
picker_startup_dir = settings->directory.menu_content;
|
||||
nk->window[NK_WND_FILE_PICKER].open = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* save position and size to restore after context reset */
|
||||
|
Loading…
x
Reference in New Issue
Block a user