mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-12 04:46:39 +00:00
(Nuklear) Cleanups
This commit is contained in:
parent
da5fb291a6
commit
7780162d53
@ -46,7 +46,9 @@ struct nk_image nk_common_image_load(const char *filename)
|
||||
int x,y,n;
|
||||
GLuint tex;
|
||||
unsigned char *data = stbi_load(filename, &x, &y, &n, 0);
|
||||
if (!data) printf("Failed to load image: %s\n", filename);
|
||||
|
||||
if (!data)
|
||||
printf("Failed to load image: %s\n", filename);
|
||||
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
glGenTextures(1, &tex);
|
||||
|
@ -1,102 +1,105 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2011-2016 - Daniel De Matteis
|
||||
* Copyright (C) 2014-2015 - Jean-André Santoni
|
||||
* Copyright (C) 2016 - Andrés Suárez
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nk_menu.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <file/file_path.h>
|
||||
#include <string/stdstring.h>
|
||||
#include <lists/string_list.h>
|
||||
#include <lists/dir_list.h>
|
||||
|
||||
#include "../../menu_driver.h"
|
||||
#include "../../menu_hash.h"
|
||||
#include "../../frontend/frontend_driver.h"
|
||||
|
||||
static bool assets_loaded;
|
||||
static char path[PATH_MAX_LENGTH];
|
||||
|
||||
struct icon_list {
|
||||
struct nk_image disk;
|
||||
struct nk_image folder;
|
||||
struct nk_image file;
|
||||
};
|
||||
struct icon_list icons;
|
||||
|
||||
void load_icons(nk_menu_handle_t *nk)
|
||||
{
|
||||
char buf[PATH_MAX_LENGTH];
|
||||
fill_pathname_join(buf, nk->assets_directory,
|
||||
"harddisk.png", sizeof(buf));
|
||||
icons.disk = nk_common_image_load(buf);
|
||||
fill_pathname_join(buf, nk->assets_directory,
|
||||
"folder.png", sizeof(buf));
|
||||
icons.folder = nk_common_image_load(buf);
|
||||
fill_pathname_join(buf, nk->assets_directory,
|
||||
"file.png", sizeof(buf));
|
||||
icons.file = nk_common_image_load(buf);
|
||||
|
||||
assets_loaded = true;
|
||||
}
|
||||
|
||||
void nk_wnd_file_picker(nk_menu_handle_t *nk)
|
||||
{
|
||||
struct nk_panel layout;
|
||||
struct nk_context *ctx = &nk->ctx;
|
||||
const int id = NK_WND_FILE_PICKER;
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
int i = 0;
|
||||
|
||||
static file_list_t *drives;
|
||||
static struct string_list *files;
|
||||
|
||||
if (!drives)
|
||||
{
|
||||
drives = (file_list_t*)calloc(1, sizeof(file_list_t));
|
||||
frontend_driver_parse_drive_list(drives);
|
||||
}
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2011-2016 - Daniel De Matteis
|
||||
* Copyright (C) 2014-2015 - Jean-André Santoni
|
||||
* Copyright (C) 2016 - Andrés Suárez
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <file/file_path.h>
|
||||
#include <string/stdstring.h>
|
||||
#include <lists/string_list.h>
|
||||
#include <lists/dir_list.h>
|
||||
#include <retro_stat.h>
|
||||
|
||||
#include "nk_menu.h"
|
||||
|
||||
#include "../../menu_driver.h"
|
||||
#include "../../menu_hash.h"
|
||||
#include "../../frontend/frontend_driver.h"
|
||||
|
||||
static bool assets_loaded;
|
||||
static char path[PATH_MAX_LENGTH];
|
||||
|
||||
struct icon_list
|
||||
{
|
||||
struct nk_image disk;
|
||||
struct nk_image folder;
|
||||
struct nk_image file;
|
||||
};
|
||||
|
||||
struct icon_list icons;
|
||||
|
||||
void load_icons(nk_menu_handle_t *nk)
|
||||
{
|
||||
char buf[PATH_MAX_LENGTH] = {0};
|
||||
|
||||
fill_pathname_join(buf, nk->assets_directory,
|
||||
"harddisk.png", sizeof(buf));
|
||||
icons.disk = nk_common_image_load(buf);
|
||||
fill_pathname_join(buf, nk->assets_directory,
|
||||
"folder.png", sizeof(buf));
|
||||
icons.folder = nk_common_image_load(buf);
|
||||
fill_pathname_join(buf, nk->assets_directory,
|
||||
"file.png", sizeof(buf));
|
||||
icons.file = nk_common_image_load(buf);
|
||||
|
||||
assets_loaded = true;
|
||||
}
|
||||
|
||||
void nk_wnd_file_picker(nk_menu_handle_t *nk)
|
||||
{
|
||||
struct nk_panel layout;
|
||||
struct nk_context *ctx = &nk->ctx;
|
||||
const int id = NK_WND_FILE_PICKER;
|
||||
int i = 0;
|
||||
static file_list_t *drives = NULL;
|
||||
static struct string_list *files = NULL;
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
if (!drives)
|
||||
{
|
||||
drives = (file_list_t*)calloc(1, sizeof(file_list_t));
|
||||
frontend_driver_parse_drive_list(drives);
|
||||
}
|
||||
|
||||
if (!assets_loaded)
|
||||
load_icons(nk);
|
||||
|
||||
if (nk_begin(ctx, &layout, "Select File", nk_rect(440, 10, 330, 400),
|
||||
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE|
|
||||
NK_WINDOW_BORDER))
|
||||
{
|
||||
nk_layout_row_dynamic(ctx, 30, 3);
|
||||
if (drives->size == 0)
|
||||
{
|
||||
if(nk_button_image_label(ctx, icons.disk, "/",
|
||||
NK_TEXT_CENTERED, NK_BUTTON_DEFAULT))
|
||||
{
|
||||
fill_pathname_join(path, "/",
|
||||
"", sizeof(path));
|
||||
files = dir_list_new(path, NULL, true, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < drives->size; i++)
|
||||
{
|
||||
|
||||
if (nk_begin(ctx, &layout, "Select File", nk_rect(440, 10, 330, 400),
|
||||
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE|
|
||||
NK_WINDOW_BORDER))
|
||||
{
|
||||
nk_layout_row_dynamic(ctx, 30, 3);
|
||||
|
||||
if (drives->size == 0)
|
||||
{
|
||||
if(nk_button_image_label(ctx, icons.disk, "/",
|
||||
NK_TEXT_CENTERED, NK_BUTTON_DEFAULT))
|
||||
{
|
||||
fill_pathname_join(path, "/",
|
||||
"", sizeof(path));
|
||||
files = dir_list_new(path, NULL, true, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < drives->size; i++)
|
||||
{
|
||||
if(nk_button_image_label(ctx, icons.disk, drives->list[i].path,
|
||||
NK_TEXT_CENTERED, NK_BUTTON_DEFAULT))
|
||||
{
|
||||
@ -126,6 +129,6 @@ void nk_wnd_file_picker(nk_menu_handle_t *nk)
|
||||
}
|
||||
}
|
||||
/* 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));
|
||||
nk_end(ctx);
|
||||
}
|
||||
nk_wnd_set_state(nk, id, nk_window_get_position(ctx), nk_window_get_size(ctx));
|
||||
nk_end(ctx);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user