RetroArch/frontend/menu/rgui.c

2980 lines
101 KiB
C
Raw Normal View History

2012-05-06 02:04:33 +00:00
/* RetroArch - A frontend for libretro.
2013-01-01 00:37:37 +00:00
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
2013-03-11 06:13:11 +00:00
* Copyright (C) 2011-2013 - Daniel De Matteis
* Copyright (C) 2012-2013 - Michael Lelli
2012-05-06 02:04:33 +00:00
*
* 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 <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "rgui.h"
#include "utils/file_list.h"
2013-03-09 14:33:44 +00:00
#include "../../general.h"
#include "../../file_ext.h"
#include "../../gfx/gfx_common.h"
2013-03-16 08:55:08 +00:00
#include "../../config.def.h"
#include "../../file.h"
2013-03-17 20:18:56 +00:00
#include "../../dynamic.h"
#include "../../compat/posix_string.h"
#include "../../gfx/shader_parse.h"
#include "../../performance.h"
2013-03-09 14:33:44 +00:00
#ifdef HAVE_OPENGL
#include "../../gfx/gl_common.h"
#endif
#include "../../gfx/fonts/bitmap.h"
#include "../../screenshot.h"
2012-05-06 02:04:33 +00:00
#define TERM_START_X 15
#define TERM_START_Y 27
#define TERM_WIDTH (((RGUI_WIDTH - TERM_START_X - 15) / (FONT_WIDTH_STRIDE)))
2012-08-12 05:32:22 +00:00
#define TERM_HEIGHT (((RGUI_HEIGHT - TERM_START_Y - 15) / (FONT_HEIGHT_STRIDE)) - 1)
2012-05-06 02:04:33 +00:00
#ifdef GEKKO
enum
{
GX_RESOLUTIONS_512_192 = 0,
GX_RESOLUTIONS_598_200,
GX_RESOLUTIONS_640_200,
2013-01-06 17:09:56 +00:00
GX_RESOLUTIONS_384_224,
GX_RESOLUTIONS_448_224,
GX_RESOLUTIONS_480_224,
GX_RESOLUTIONS_512_224,
GX_RESOLUTIONS_340_232,
GX_RESOLUTIONS_512_232,
GX_RESOLUTIONS_512_236,
GX_RESOLUTIONS_336_240,
GX_RESOLUTIONS_384_240,
GX_RESOLUTIONS_512_240,
GX_RESOLUTIONS_576_224,
GX_RESOLUTIONS_608_224,
2013-01-06 17:09:56 +00:00
GX_RESOLUTIONS_640_224,
GX_RESOLUTIONS_530_240,
GX_RESOLUTIONS_640_240,
GX_RESOLUTIONS_512_448,
GX_RESOLUTIONS_640_448,
2013-01-06 17:09:56 +00:00
GX_RESOLUTIONS_640_480,
GX_RESOLUTIONS_LAST,
};
unsigned rgui_gx_resolutions[GX_RESOLUTIONS_LAST][2] = {
{ 512, 192 },
{ 598, 200 },
{ 640, 200 },
{ 384, 224 },
{ 448, 224 },
{ 480, 224 },
{ 512, 224 },
{ 340, 232 },
{ 512, 232 },
{ 512, 236 },
{ 336, 240 },
{ 384, 240 },
{ 512, 240 },
{ 576, 224 },
{ 608, 224 },
2013-01-06 17:09:56 +00:00
{ 640, 224 },
{ 530, 240 },
{ 640, 240 },
{ 512, 448 },
{ 640, 448 },
2013-01-06 17:09:56 +00:00
{ 640, 480 },
};
unsigned rgui_current_gx_resolution = GX_RESOLUTIONS_640_480;
#endif
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_HLSL)
#define HAVE_SHADER_MANAGER
#endif
unsigned RGUI_WIDTH = 320;
unsigned RGUI_HEIGHT = 240;
2013-03-09 14:33:44 +00:00
uint16_t menu_framebuf[400 * 240];
2013-05-08 23:12:18 +00:00
#ifdef HAVE_SHADER_MANAGER
static int shader_manager_toggle_setting(rgui_handle_t *rgui, unsigned setting, rgui_action_t action);
2013-05-08 23:12:18 +00:00
#endif
static int video_option_toggle_setting(rgui_handle_t *rgui, unsigned setting, rgui_action_t action);
static const unsigned rgui_controller_lut[] = {
RETRO_DEVICE_ID_JOYPAD_UP,
RETRO_DEVICE_ID_JOYPAD_DOWN,
RETRO_DEVICE_ID_JOYPAD_LEFT,
RETRO_DEVICE_ID_JOYPAD_RIGHT,
RETRO_DEVICE_ID_JOYPAD_A,
RETRO_DEVICE_ID_JOYPAD_B,
RETRO_DEVICE_ID_JOYPAD_X,
RETRO_DEVICE_ID_JOYPAD_Y,
RETRO_DEVICE_ID_JOYPAD_START,
RETRO_DEVICE_ID_JOYPAD_SELECT,
RETRO_DEVICE_ID_JOYPAD_L,
RETRO_DEVICE_ID_JOYPAD_R,
RETRO_DEVICE_ID_JOYPAD_L2,
RETRO_DEVICE_ID_JOYPAD_R2,
RETRO_DEVICE_ID_JOYPAD_L3,
RETRO_DEVICE_ID_JOYPAD_R3,
};
static void rgui_copy_glyph(uint8_t *glyph, const uint8_t *buf)
2012-05-06 02:04:33 +00:00
{
for (int y = 0; y < FONT_HEIGHT; y++)
{
for (int x = 0; x < FONT_WIDTH; x++)
{
uint32_t col =
((uint32_t)buf[3 * (-y * 256 + x) + 0] << 0) |
((uint32_t)buf[3 * (-y * 256 + x) + 1] << 8) |
((uint32_t)buf[3 * (-y * 256 + x) + 2] << 16);
uint8_t rem = 1 << ((x + y * FONT_WIDTH) & 7);
unsigned offset = (x + y * FONT_WIDTH) >> 3;
if (col != 0xff)
glyph[offset] |= rem;
2012-05-06 02:04:33 +00:00
}
}
}
static void init_font(rgui_handle_t *rgui, const uint8_t *font_bmp_buf)
2012-05-06 02:04:33 +00:00
{
uint8_t *font = (uint8_t *) calloc(1, FONT_OFFSET(256));
2012-08-27 18:48:00 +00:00
rgui->alloc_font = true;
2012-05-06 02:04:33 +00:00
for (unsigned i = 0; i < 256; i++)
{
unsigned y = i / 16;
unsigned x = i % 16;
rgui_copy_glyph(&font[FONT_OFFSET(i)],
font_bmp_buf + 54 + 3 * (256 * (255 - 16 * y) + 16 * x));
2012-05-06 02:04:33 +00:00
}
rgui->font = font;
2012-05-06 02:04:33 +00:00
}
static void rgui_flush_menu_stack_type(rgui_handle_t *rgui, unsigned final_type)
{
rgui->need_refresh = true;
unsigned type = 0;
rgui_list_get_last(rgui->menu_stack, NULL, &type);
while (type != final_type)
{
rgui_list_pop(rgui->menu_stack, &rgui->selection_ptr);
rgui_list_get_last(rgui->menu_stack, NULL, &type);
}
}
static void rgui_flush_menu_stack(rgui_handle_t *rgui)
{
rgui_flush_menu_stack_type(rgui, RGUI_SETTINGS);
}
static bool menu_type_is_settings(unsigned type)
{
return type == RGUI_SETTINGS ||
type == RGUI_SETTINGS_CORE_OPTIONS ||
type == RGUI_SETTINGS_VIDEO_OPTIONS ||
2013-05-05 22:53:53 +00:00
#ifdef HAVE_SHADER_MANAGER
type == RGUI_SETTINGS_SHADER_OPTIONS ||
2013-05-05 22:53:53 +00:00
#endif
type == RGUI_SETTINGS_AUDIO_OPTIONS ||
type == RGUI_SETTINGS_DISK_OPTIONS ||
type == RGUI_SETTINGS_PATH_OPTIONS ||
2013-05-05 20:02:30 +00:00
type == RGUI_SETTINGS_OPTIONS ||
(type == RGUI_SETTINGS_INPUT_OPTIONS);
}
#ifdef HAVE_SHADER_MANAGER
static bool menu_type_is_shader_browser(unsigned type)
{
2013-04-13 23:27:13 +00:00
return (type >= RGUI_SETTINGS_SHADER_0 &&
type <= RGUI_SETTINGS_SHADER_LAST &&
2013-04-13 23:27:13 +00:00
((type - RGUI_SETTINGS_SHADER_0) % 3) == 0) ||
type == RGUI_SETTINGS_SHADER_PRESET;
}
#endif
2013-05-21 02:17:26 +00:00
static bool menu_type_is_directory_browser(unsigned type)
{
return type == RGUI_BROWSER_DIR_PATH ||
#ifdef HAVE_SHADER_MANAGER
type == RGUI_SHADER_DIR_PATH ||
#endif
type == RGUI_SAVESTATE_DIR_PATH ||
2013-09-15 21:09:23 +00:00
#ifdef HAVE_DYNAMIC
type == RGUI_LIBRETRO_DIR_PATH ||
2013-09-15 21:09:23 +00:00
#endif
2013-05-21 02:17:26 +00:00
type == RGUI_SAVEFILE_DIR_PATH ||
#ifdef HAVE_OVERLAY
type == RGUI_OVERLAY_DIR_PATH ||
#endif
#ifdef HAVE_SCREENSHOTS
type == RGUI_SCREENSHOT_DIR_PATH ||
#endif
2013-05-21 02:17:26 +00:00
type == RGUI_SYSTEM_DIR_PATH;
}
2013-04-18 21:00:27 +00:00
static void rgui_settings_populate_entries(rgui_handle_t *rgui);
rgui_handle_t *rgui_init(void)
2012-05-06 02:04:33 +00:00
{
uint16_t *framebuf = menu_framebuf;
size_t framebuf_pitch = RGUI_WIDTH * sizeof(uint16_t);
const uint8_t *font_bmp_buf = NULL;
const uint8_t *font_bin_buf = bitmap_bin;
2012-05-06 02:04:33 +00:00
rgui_handle_t *rgui = (rgui_handle_t*)calloc(1, sizeof(*rgui));
rgui->frame_buf = framebuf;
rgui->frame_buf_pitch = framebuf_pitch;
2012-05-06 02:04:33 +00:00
if (font_bmp_buf)
init_font(rgui, font_bmp_buf);
else if (font_bin_buf)
2012-08-27 18:48:00 +00:00
rgui->font = font_bin_buf;
else
{
RARCH_ERR("no font bmp or bin, abort");
/* TODO - should be refactored - perhaps don't do rarch_fail but instead
* exit program */
2013-05-05 13:20:45 +00:00
g_extern.lifecycle_mode_state &= ~((1ULL << MODE_MENU) | (1ULL << MODE_GAME));
return NULL;
}
2012-05-06 02:04:33 +00:00
strlcpy(rgui->base_path, g_settings.rgui_browser_directory, sizeof(rgui->base_path));
rgui->menu_stack = (rgui_list_t*)calloc(1, sizeof(rgui_list_t));
rgui->selection_buf = (rgui_list_t*)calloc(1, sizeof(rgui_list_t));
rgui_list_push(rgui->menu_stack, "", RGUI_SETTINGS, 0);
2013-04-18 21:00:27 +00:00
rgui->selection_ptr = 0;
rgui_settings_populate_entries(rgui);
// Make sure that custom viewport is something sane incase we use it
// before it's configured.
rarch_viewport_t *custom = &g_extern.console.screen.viewports.custom_vp;
if (driver.video_data && (!custom->width || !custom->height))
{
driver.video->viewport_info(driver.video_data, custom);
aspectratio_lut[ASPECT_RATIO_CUSTOM].value =
(float)custom->width / custom->height;
}
else if (DEFAULT_ASPECT_RATIO > 0.0f)
aspectratio_lut[ASPECT_RATIO_CUSTOM].value = DEFAULT_ASPECT_RATIO;
else
aspectratio_lut[ASPECT_RATIO_CUSTOM].value = 4.0f / 3.0f; // Something arbitrary
2012-05-06 02:04:33 +00:00
return rgui;
}
void rgui_free(rgui_handle_t *rgui)
2012-05-06 02:04:33 +00:00
{
2012-08-27 18:48:00 +00:00
if (rgui->alloc_font)
2013-04-27 22:35:20 +00:00
free((uint8_t*)rgui->font);
2013-03-17 20:18:56 +00:00
#ifdef HAVE_DYNAMIC
libretro_free_system_info(&rgui->info);
#endif
rgui_list_free(rgui->menu_stack);
rgui_list_free(rgui->selection_buf);
2012-05-06 02:04:33 +00:00
}
2012-08-25 01:29:05 +00:00
static uint16_t gray_filler(unsigned x, unsigned y)
2012-05-06 02:04:33 +00:00
{
x >>= 1;
y >>= 1;
unsigned col = ((x + y) & 1) + 1;
#ifdef GEKKO
2012-08-25 01:29:05 +00:00
return (6 << 12) | (col << 8) | (col << 4) | (col << 0);
#else
return (col << 13) | (col << 9) | (col << 5) | (12 << 0);
#endif
2012-05-06 02:04:33 +00:00
}
2012-08-25 01:29:05 +00:00
static uint16_t green_filler(unsigned x, unsigned y)
2012-05-06 02:04:33 +00:00
{
x >>= 1;
y >>= 1;
unsigned col = ((x + y) & 1) + 1;
#ifdef GEKKO
2012-08-25 01:29:05 +00:00
return (6 << 12) | (col << 8) | (col << 5) | (col << 0);
#else
return (col << 13) | (col << 10) | (col << 5) | (12 << 0);
#endif
2012-05-06 02:04:33 +00:00
}
2012-08-25 01:29:05 +00:00
static void fill_rect(uint16_t *buf, unsigned pitch,
2012-05-06 02:04:33 +00:00
unsigned x, unsigned y,
unsigned width, unsigned height,
2012-08-25 01:29:05 +00:00
uint16_t (*col)(unsigned x, unsigned y))
2012-05-06 02:04:33 +00:00
{
for (unsigned j = y; j < y + height; j++)
for (unsigned i = x; i < x + width; i++)
buf[j * (pitch >> 1) + i] = col(i, j);
2012-05-06 02:04:33 +00:00
}
static void blit_line(rgui_handle_t *rgui,
int x, int y, const char *message, bool green)
2012-05-06 02:04:33 +00:00
{
while (*message)
{
for (int j = 0; j < FONT_HEIGHT; j++)
2012-05-06 02:04:33 +00:00
{
for (int i = 0; i < FONT_WIDTH; i++)
2012-05-06 02:04:33 +00:00
{
uint8_t rem = 1 << ((i + j * FONT_WIDTH) & 7);
int offset = (i + j * FONT_WIDTH) >> 3;
2012-08-27 18:48:00 +00:00
bool col = (rgui->font[FONT_OFFSET((unsigned char)*message) + offset] & rem);
2012-05-06 02:04:33 +00:00
if (col)
{
rgui->frame_buf[(y + j) * (rgui->frame_buf_pitch >> 1) + (x + i)] = green ?
#ifdef GEKKO
(3 << 0) | (10 << 4) | (3 << 8) | (7 << 12) : 0x7FFF;
#else
(15 << 0) | (7 << 4) | (15 << 8) | (7 << 12) : 0xFFFF;
#endif
}
2012-05-06 02:04:33 +00:00
}
}
x += FONT_WIDTH_STRIDE;
message++;
}
}
2012-07-16 21:57:43 +00:00
static void render_background(rgui_handle_t *rgui)
2012-05-06 02:04:33 +00:00
{
fill_rect(rgui->frame_buf, rgui->frame_buf_pitch,
0, 0, RGUI_WIDTH, RGUI_HEIGHT, gray_filler);
fill_rect(rgui->frame_buf, rgui->frame_buf_pitch,
5, 5, RGUI_WIDTH - 10, 5, green_filler);
fill_rect(rgui->frame_buf, rgui->frame_buf_pitch,
5, RGUI_HEIGHT - 10, RGUI_WIDTH - 10, 5, green_filler);
fill_rect(rgui->frame_buf, rgui->frame_buf_pitch,
5, 5, 5, RGUI_HEIGHT - 10, green_filler);
fill_rect(rgui->frame_buf, rgui->frame_buf_pitch,
RGUI_WIDTH - 10, 5, 5, RGUI_HEIGHT - 10, green_filler);
2012-07-16 21:57:43 +00:00
}
static void render_messagebox(rgui_handle_t *rgui, const char *message)
{
if (!message || !*message)
return;
char *msg = strdup(message);
if (strlen(msg) > TERM_WIDTH)
{
msg[TERM_WIDTH - 2] = '.';
msg[TERM_WIDTH - 1] = '.';
msg[TERM_WIDTH - 0] = '.';
msg[TERM_WIDTH + 1] = '\0';
}
unsigned width = strlen(msg) * FONT_WIDTH_STRIDE - 1 + 6 + 10;
unsigned height = FONT_HEIGHT + 6 + 10;
int x = (RGUI_WIDTH - width) / 2;
int y = (RGUI_HEIGHT - height) / 2;
fill_rect(rgui->frame_buf, rgui->frame_buf_pitch,
x + 5, y + 5, width - 10, height - 10, gray_filler);
fill_rect(rgui->frame_buf, rgui->frame_buf_pitch,
x, y, width - 5, 5, green_filler);
fill_rect(rgui->frame_buf, rgui->frame_buf_pitch,
x + width - 5, y, 5, height - 5, green_filler);
fill_rect(rgui->frame_buf, rgui->frame_buf_pitch,
x + 5, y + height - 5, width - 5, 5, green_filler);
fill_rect(rgui->frame_buf, rgui->frame_buf_pitch,
x, y + 5, 5, height - 5, green_filler);
blit_line(rgui, x + 8, y + 8, msg, false);
free(msg);
}
static void render_text(rgui_handle_t *rgui)
2012-07-16 21:57:43 +00:00
{
if (rgui->need_refresh &&
(g_extern.lifecycle_mode_state & (1ULL << MODE_MENU))
&& !rgui->msg_force)
return;
size_t begin = rgui->selection_ptr >= TERM_HEIGHT / 2 ?
rgui->selection_ptr - TERM_HEIGHT / 2 : 0;
size_t end = rgui->selection_ptr + TERM_HEIGHT <= rgui->selection_buf->size ?
rgui->selection_ptr + TERM_HEIGHT : rgui->selection_buf->size;
// Do not scroll if all items are visible.
if (rgui->selection_buf->size <= TERM_HEIGHT)
begin = 0;
if (end - begin > TERM_HEIGHT)
end = begin + TERM_HEIGHT;
2012-07-16 21:57:43 +00:00
render_background(rgui);
2012-05-06 02:04:33 +00:00
char title[256];
const char *dir = NULL;
unsigned menu_type = 0;
rgui_list_get_last(rgui->menu_stack, &dir, &menu_type);
if (menu_type == RGUI_SETTINGS_CORE)
snprintf(title, sizeof(title), "CORE SELECTION %s", dir);
2013-04-27 13:14:59 +00:00
else if (menu_type == RGUI_SETTINGS_DISK_APPEND)
snprintf(title, sizeof(title), "DISK APPEND %s", dir);
else if (menu_type == RGUI_SETTINGS_VIDEO_OPTIONS)
strlcpy(title, "VIDEO OPTIONS", sizeof(title));
2013-05-05 22:53:53 +00:00
#ifdef HAVE_SHADER_MANAGER
else if (menu_type == RGUI_SETTINGS_SHADER_OPTIONS)
strlcpy(title, "SHADER OPTIONS", sizeof(title));
2013-05-05 22:53:53 +00:00
#endif
else if (menu_type == RGUI_SETTINGS_AUDIO_OPTIONS)
strlcpy(title, "AUDIO OPTIONS", sizeof(title));
else if (menu_type == RGUI_SETTINGS_DISK_OPTIONS)
strlcpy(title, "DISK OPTIONS", sizeof(title));
else if (menu_type == RGUI_SETTINGS_CORE_OPTIONS)
strlcpy(title, "CORE OPTIONS", sizeof(title));
#ifdef HAVE_SHADER_MANAGER
else if (menu_type_is_shader_browser(menu_type))
snprintf(title, sizeof(title), "SHADER %s", dir);
#endif
else if ((menu_type == RGUI_SETTINGS_INPUT_OPTIONS) ||
(menu_type == RGUI_SETTINGS_PATH_OPTIONS) ||
2013-05-05 20:02:30 +00:00
(menu_type == RGUI_SETTINGS_OPTIONS) ||
(menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT || menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT_2) ||
menu_type == RGUI_SETTINGS)
snprintf(title, sizeof(title), "MENU %s", dir);
2013-04-27 23:35:31 +00:00
else if (menu_type == RGUI_SETTINGS_OPEN_HISTORY)
strlcpy(title, "LOAD HISTORY", sizeof(title));
#ifdef HAVE_OVERLAY
else if (menu_type == RGUI_SETTINGS_OVERLAY_PRESET)
snprintf(title, sizeof(title), "OVERLAY %s", dir);
#endif
2013-05-21 02:17:26 +00:00
else if (menu_type == RGUI_BROWSER_DIR_PATH)
snprintf(title, sizeof(title), "BROWSER DIR %s", dir);
#ifdef HAVE_SCREENSHOTS
else if (menu_type == RGUI_SCREENSHOT_DIR_PATH)
snprintf(title, sizeof(title), "SCREENSHOT DIR %s", dir);
#endif
2013-05-21 02:17:26 +00:00
else if (menu_type == RGUI_SHADER_DIR_PATH)
snprintf(title, sizeof(title), "SHADER DIR %s", dir);
else if (menu_type == RGUI_SAVESTATE_DIR_PATH)
snprintf(title, sizeof(title), "SAVESTATE DIR %s", dir);
2013-09-15 21:09:23 +00:00
#ifdef HAVE_DYNAMIC
else if (menu_type == RGUI_LIBRETRO_DIR_PATH)
snprintf(title, sizeof(title), "LIBRETRO DIR %s", dir);
2013-09-15 21:09:23 +00:00
#endif
2013-05-21 02:17:26 +00:00
else if (menu_type == RGUI_SAVEFILE_DIR_PATH)
snprintf(title, sizeof(title), "SAVEFILE DIR %s", dir);
#ifdef HAVE_OVERLAY
else if (menu_type == RGUI_OVERLAY_DIR_PATH)
snprintf(title, sizeof(title), "OVERLAY DIR %s", dir);
#endif
2013-05-21 02:17:26 +00:00
else if (menu_type == RGUI_SYSTEM_DIR_PATH)
snprintf(title, sizeof(title), "SYSTEM DIR %s", dir);
2012-07-16 21:57:43 +00:00
else
{
const char *core_name = rgui->info.library_name;
if (!core_name)
core_name = g_extern.system.info.library_name;
if (!core_name)
core_name = "No Core";
snprintf(title, sizeof(title), "GAME (%s) %s", core_name, dir);
}
2013-05-05 09:31:43 +00:00
char title_buf[256];
menu_ticker_line(title_buf, TERM_WIDTH - 3, g_extern.frame_count / 15, title, true);
2013-05-05 09:31:43 +00:00
blit_line(rgui, TERM_START_X + 15, 15, title_buf, true);
char title_msg[64];
const char *core_name = rgui->info.library_name;
if (!core_name)
core_name = g_extern.system.info.library_name;
if (!core_name)
core_name = "No Core";
2013-04-22 18:16:26 +00:00
const char *core_version = rgui->info.library_version;
if (!core_version)
core_version = g_extern.system.info.library_version;
if (!core_version)
core_version = "";
snprintf(title_msg, sizeof(title_msg), "%s - %s %s", PACKAGE_VERSION, core_name, core_version);
blit_line(rgui, TERM_START_X + 15, (TERM_HEIGHT * FONT_HEIGHT_STRIDE) + TERM_START_Y + 2, title_msg, true);
2012-08-12 05:32:22 +00:00
2012-05-06 02:04:33 +00:00
unsigned x = TERM_START_X;
unsigned y = TERM_START_Y;
for (size_t i = begin; i < end; i++, y += FONT_HEIGHT_STRIDE)
{
2012-07-28 19:36:03 +00:00
const char *path = 0;
unsigned type = 0;
rgui_list_get_at_offset(rgui->selection_buf, i, &path, &type);
char message[256];
char type_str[256];
unsigned w = (menu_type == RGUI_SETTINGS_INPUT_OPTIONS || menu_type == RGUI_SETTINGS_PATH_OPTIONS) ? 24 : 19;
unsigned port = rgui->current_pad;
#ifdef HAVE_SHADER_MANAGER
if (type >= RGUI_SETTINGS_SHADER_FILTER &&
type <= RGUI_SETTINGS_SHADER_LAST)
{
// HACK. Work around that we're using the menu_type as dir type to propagate state correctly.
if (menu_type_is_shader_browser(menu_type) && menu_type_is_shader_browser(type))
{
type = RGUI_FILE_DIRECTORY;
strlcpy(type_str, "(DIR)", sizeof(type_str));
w = 5;
}
else if (type == RGUI_SETTINGS_SHADER_OPTIONS || type == RGUI_SETTINGS_SHADER_PRESET)
strlcpy(type_str, "...", sizeof(type_str));
2013-04-13 23:45:33 +00:00
else if (type == RGUI_SETTINGS_SHADER_FILTER)
snprintf(type_str, sizeof(type_str), "%s",
g_settings.video.smooth ? "Linear" : "Nearest");
else
shader_manager_get_str(&rgui->shader, type_str, sizeof(type_str), type);
}
else
#endif
if (menu_type == RGUI_SETTINGS_CORE ||
#ifdef HAVE_OVERLAY
menu_type == RGUI_SETTINGS_OVERLAY_PRESET ||
#endif
2013-05-21 02:17:26 +00:00
menu_type == RGUI_SETTINGS_DISK_APPEND ||
menu_type_is_directory_browser(menu_type))
{
if (type == RGUI_FILE_PLAIN)
{
strlcpy(type_str, "(FILE)", sizeof(type_str));
w = 6;
}
2013-05-21 02:17:26 +00:00
else if (type == RGUI_FILE_USE_DIRECTORY)
{
*type_str = '\0';
w = 0;
}
else
{
strlcpy(type_str, "(DIR)", sizeof(type_str));
type = RGUI_FILE_DIRECTORY;
w = 5;
}
}
2013-04-27 23:43:37 +00:00
else if (menu_type == RGUI_SETTINGS_OPEN_HISTORY)
{
*type_str = '\0';
w = 0;
}
else if (type >= RGUI_SETTINGS_CORE_OPTION_START)
strlcpy(type_str, core_option_get_val(g_extern.system.core_options, type - RGUI_SETTINGS_CORE_OPTION_START), sizeof(type_str));
else
{
switch (type)
{
case RGUI_SETTINGS_VIDEO_ROTATION:
strlcpy(type_str, rotation_lut[g_extern.console.screen.orientation],
sizeof(type_str));
break;
case RGUI_SETTINGS_VIDEO_SOFT_FILTER:
snprintf(type_str, sizeof(type_str),
(g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE)) ? "ON" : "OFF");
break;
case RGUI_SETTINGS_VIDEO_FILTER:
if (g_settings.video.smooth)
strlcpy(type_str, "Bilinear filtering", sizeof(type_str));
else
strlcpy(type_str, "Point filtering", sizeof(type_str));
break;
case RGUI_SETTINGS_VIDEO_GAMMA:
snprintf(type_str, sizeof(type_str), "%d", g_extern.console.screen.gamma_correction);
break;
case RGUI_SETTINGS_VIDEO_VSYNC:
strlcpy(type_str, g_settings.video.vsync ? "ON" : "OFF", sizeof(type_str));
break;
case RGUI_SETTINGS_VIDEO_HARD_SYNC:
strlcpy(type_str, g_settings.video.hard_sync ? "ON" : "OFF", sizeof(type_str));
break;
case RGUI_SETTINGS_VIDEO_BLACK_FRAME_INSERTION:
strlcpy(type_str, g_settings.video.black_frame_insertion ? "ON" : "OFF", sizeof(type_str));
break;
case RGUI_SETTINGS_VIDEO_SWAP_INTERVAL:
snprintf(type_str, sizeof(type_str), "%u", g_settings.video.swap_interval);
break;
case RGUI_SETTINGS_VIDEO_WINDOW_SCALE_X:
snprintf(type_str, sizeof(type_str), "%.1fx", g_settings.video.xscale);
break;
case RGUI_SETTINGS_VIDEO_WINDOW_SCALE_Y:
snprintf(type_str, sizeof(type_str), "%.1fx", g_settings.video.yscale);
break;
case RGUI_SETTINGS_VIDEO_CROP_OVERSCAN:
strlcpy(type_str, g_settings.video.crop_overscan ? "ON" : "OFF", sizeof(type_str));
break;
case RGUI_SETTINGS_VIDEO_HARD_SYNC_FRAMES:
snprintf(type_str, sizeof(type_str), "%u", g_settings.video.hard_sync_frames);
break;
case RGUI_SETTINGS_VIDEO_REFRESH_RATE_AUTO:
{
double refresh_rate = 0.0;
double deviation = 0.0;
unsigned sample_points = 0;
if (driver_monitor_fps_statistics(&refresh_rate, &deviation, &sample_points))
snprintf(type_str, sizeof(type_str), "%.3f Hz (%.1f%% dev, %u samples)", refresh_rate, 100.0 * deviation, sample_points);
else
strlcpy(type_str, "N/A", sizeof(type_str));
break;
}
case RGUI_SETTINGS_VIDEO_INTEGER_SCALE:
strlcpy(type_str, g_settings.video.scale_integer ? "ON" : "OFF", sizeof(type_str));
break;
case RGUI_SETTINGS_VIDEO_ASPECT_RATIO:
strlcpy(type_str, aspectratio_lut[g_settings.video.aspect_ratio_idx].name, sizeof(type_str));
break;
#ifdef GEKKO
case RGUI_SETTINGS_VIDEO_RESOLUTION:
strlcpy(type_str, gx_get_video_mode(), sizeof(type_str));
break;
#endif
case RGUI_FILE_PLAIN:
strlcpy(type_str, "(FILE)", sizeof(type_str));
w = 6;
break;
case RGUI_FILE_DIRECTORY:
strlcpy(type_str, "(DIR)", sizeof(type_str));
w = 5;
break;
case RGUI_SETTINGS_REWIND_ENABLE:
strlcpy(type_str, g_settings.rewind_enable ? "ON" : "OFF", sizeof(type_str));
break;
2013-09-16 21:10:15 +00:00
#ifdef HAVE_SCREENSHOTS
case RGUI_SETTINGS_GPU_SCREENSHOT:
strlcpy(type_str, g_settings.video.gpu_screenshot ? "ON" : "OFF", sizeof(type_str));
break;
#endif
case RGUI_SETTINGS_REWIND_GRANULARITY:
2013-04-29 13:56:49 +00:00
snprintf(type_str, sizeof(type_str), "%u", g_settings.rewind_granularity);
break;
2013-05-22 13:35:28 +00:00
case RGUI_SETTINGS_CONFIG_SAVE_ON_EXIT:
strlcpy(type_str, g_extern.config_save_on_exit ? "ON" : "OFF", sizeof(type_str));
break;
2013-04-29 13:56:49 +00:00
case RGUI_SETTINGS_SRAM_AUTOSAVE:
strlcpy(type_str, g_settings.autosave_interval ? "ON" : "OFF", sizeof(type_str));
break;
case RGUI_SETTINGS_SAVESTATE_SAVE:
case RGUI_SETTINGS_SAVESTATE_LOAD:
snprintf(type_str, sizeof(type_str), "%d", g_extern.state_slot);
break;
case RGUI_SETTINGS_AUDIO_MUTE:
strlcpy(type_str, g_extern.audio_data.mute ? "ON" : "OFF", sizeof(type_str));
break;
case RGUI_SETTINGS_AUDIO_CONTROL_RATE_DELTA:
snprintf(type_str, sizeof(type_str), "%.3f", g_settings.audio.rate_control_delta);
break;
case RGUI_SETTINGS_DEBUG_TEXT:
snprintf(type_str, sizeof(type_str), (g_extern.lifecycle_mode_state & (1ULL << MODE_FPS_DRAW)) ? "ON" : "OFF");
break;
case RGUI_BROWSER_DIR_PATH:
strlcpy(type_str, *g_settings.rgui_browser_directory ? g_settings.rgui_browser_directory : "<default>", sizeof(type_str));
break;
#ifdef HAVE_SCREENSHOTS
case RGUI_SCREENSHOT_DIR_PATH:
strlcpy(type_str, *g_settings.screenshot_directory ? g_settings.screenshot_directory : "<ROM dir>", sizeof(type_str));
break;
#endif
case RGUI_SAVEFILE_DIR_PATH:
strlcpy(type_str, *g_extern.savefile_dir ? g_extern.savefile_dir : "<ROM dir>", sizeof(type_str));
break;
#ifdef HAVE_OVERLAY
case RGUI_OVERLAY_DIR_PATH:
strlcpy(type_str, *g_extern.overlay_dir ? g_extern.overlay_dir : "<default>", sizeof(type_str));
break;
#endif
case RGUI_SAVESTATE_DIR_PATH:
strlcpy(type_str, *g_extern.savestate_dir ? g_extern.savestate_dir : "<ROM dir>", sizeof(type_str));
break;
2013-09-15 21:09:23 +00:00
#ifdef HAVE_DYNAMIC
case RGUI_LIBRETRO_DIR_PATH:
strlcpy(type_str, *rgui->libretro_dir ? rgui->libretro_dir : "<None>", sizeof(type_str));
break;
2013-09-15 21:09:23 +00:00
#endif
2013-05-04 20:29:22 +00:00
case RGUI_SHADER_DIR_PATH:
strlcpy(type_str, *g_settings.video.shader_dir ? g_settings.video.shader_dir : "<default>", sizeof(type_str));
2013-05-04 20:29:22 +00:00
break;
case RGUI_SYSTEM_DIR_PATH:
strlcpy(type_str, *g_settings.system_directory ? g_settings.system_directory : "<ROM dir>", sizeof(type_str));
break;
2013-04-27 11:29:01 +00:00
case RGUI_SETTINGS_DISK_INDEX:
{
const struct retro_disk_control_callback *control = &g_extern.system.disk_control;
unsigned images = control->get_num_images();
unsigned current = control->get_image_index();
if (current >= images)
strlcpy(type_str, "No Disk", sizeof(type_str));
else
snprintf(type_str, sizeof(type_str), "%u", current + 1);
break;
}
case RGUI_SETTINGS_OPEN_FILEBROWSER:
2013-04-27 23:35:31 +00:00
case RGUI_SETTINGS_OPEN_HISTORY:
case RGUI_SETTINGS_CORE_OPTIONS:
case RGUI_SETTINGS_CUSTOM_VIEWPORT:
case RGUI_SETTINGS_TOGGLE_FULLSCREEN:
case RGUI_SETTINGS_VIDEO_OPTIONS:
case RGUI_SETTINGS_AUDIO_OPTIONS:
case RGUI_SETTINGS_DISK_OPTIONS:
#ifdef HAVE_SHADER_MANAGER
2013-05-05 22:53:53 +00:00
case RGUI_SETTINGS_SHADER_OPTIONS:
2013-04-13 23:27:13 +00:00
case RGUI_SETTINGS_SHADER_PRESET:
#endif
case RGUI_SETTINGS_CORE:
2013-04-27 13:14:59 +00:00
case RGUI_SETTINGS_DISK_APPEND:
case RGUI_SETTINGS_INPUT_OPTIONS:
case RGUI_SETTINGS_PATH_OPTIONS:
2013-05-05 20:02:30 +00:00
case RGUI_SETTINGS_OPTIONS:
strlcpy(type_str, "...", sizeof(type_str));
break;
2013-05-17 21:26:11 +00:00
#ifdef HAVE_OVERLAY
case RGUI_SETTINGS_OVERLAY_PRESET:
strlcpy(type_str, path_basename(g_settings.input.overlay), sizeof(type_str));
break;
2013-05-17 21:26:11 +00:00
case RGUI_SETTINGS_OVERLAY_OPACITY:
{
snprintf(type_str, sizeof(type_str), "%.2f", g_settings.input.overlay_opacity);
2013-05-17 21:26:11 +00:00
break;
}
case RGUI_SETTINGS_OVERLAY_SCALE:
{
snprintf(type_str, sizeof(type_str), "%.2f", g_settings.input.overlay_scale);
break;
}
2013-05-17 21:26:11 +00:00
#endif
case RGUI_SETTINGS_BIND_PLAYER:
{
snprintf(type_str, sizeof(type_str), "#%d", port + 1);
break;
}
case RGUI_SETTINGS_BIND_DEVICE:
2013-04-25 22:22:12 +00:00
{
int map = g_settings.input.joypad_map[port];
if (map >= 0 && map < MAX_PLAYERS)
{
const char *device_name = g_settings.input.device_names[map];
if (*device_name)
strlcpy(type_str, device_name, sizeof(type_str));
else
snprintf(type_str, sizeof(type_str), "N/A (port #%u)", map);
}
else
strlcpy(type_str, "Disabled", sizeof(type_str));
break;
2013-04-25 22:22:12 +00:00
}
case RGUI_SETTINGS_BIND_DEVICE_TYPE:
{
const char *name;
switch (g_extern.libretro_device[port])
{
case RETRO_DEVICE_NONE: name = "None"; break;
case RETRO_DEVICE_JOYPAD: name = "Joypad"; break;
case RETRO_DEVICE_ANALOG: name = "Joypad w/ Analog"; break;
case RETRO_DEVICE_JOYPAD_MULTITAP: name = "Multitap"; break;
case RETRO_DEVICE_MOUSE: name = "Mouse"; break;
case RETRO_DEVICE_LIGHTGUN_JUSTIFIER: name = "Justifier"; break;
case RETRO_DEVICE_LIGHTGUN_JUSTIFIERS: name = "Justifiers"; break;
case RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE: name = "SuperScope"; break;
default: name = "Unknown"; break;
}
strlcpy(type_str, name, sizeof(type_str));
break;
}
case RGUI_SETTINGS_BIND_DPAD_EMULATION:
2013-04-25 22:22:12 +00:00
switch (g_settings.input.dpad_emulation[port])
{
case ANALOG_DPAD_NONE:
strlcpy(type_str, "None", sizeof(type_str));
break;
case ANALOG_DPAD_LSTICK:
strlcpy(type_str, "Left Stick", sizeof(type_str));
break;
2013-07-31 18:19:53 +00:00
case ANALOG_DPAD_DUALANALOG:
strlcpy(type_str, "Dual Analog", sizeof(type_str));
break;
case ANALOG_DPAD_RSTICK:
strlcpy(type_str, "Right Stick", sizeof(type_str));
break;
}
break;
case RGUI_SETTINGS_BIND_UP:
case RGUI_SETTINGS_BIND_DOWN:
case RGUI_SETTINGS_BIND_LEFT:
case RGUI_SETTINGS_BIND_RIGHT:
case RGUI_SETTINGS_BIND_A:
case RGUI_SETTINGS_BIND_B:
case RGUI_SETTINGS_BIND_X:
case RGUI_SETTINGS_BIND_Y:
case RGUI_SETTINGS_BIND_START:
case RGUI_SETTINGS_BIND_SELECT:
case RGUI_SETTINGS_BIND_L:
case RGUI_SETTINGS_BIND_R:
case RGUI_SETTINGS_BIND_L2:
case RGUI_SETTINGS_BIND_R2:
case RGUI_SETTINGS_BIND_L3:
case RGUI_SETTINGS_BIND_R3:
{
unsigned id = rgui_controller_lut[type - RGUI_SETTINGS_BIND_UP];
struct platform_bind key_label;
strlcpy(key_label.desc, "Unknown", sizeof(key_label.desc));
key_label.joykey = g_settings.input.binds[port][id].joykey;
if (driver.input->set_keybinds)
driver.input->set_keybinds(&key_label, 0, 0, 0, (1ULL << KEYBINDS_ACTION_GET_BIND_LABEL));
strlcpy(type_str, key_label.desc, sizeof(type_str));
}
break;
default:
type_str[0] = 0;
w = 0;
break;
}
}
char entry_title_buf[256];
char type_str_buf[64];
bool selected = i == rgui->selection_ptr;
strlcpy(entry_title_buf, path, sizeof(entry_title_buf));
strlcpy(type_str_buf, type_str, sizeof(type_str_buf));
if ((type == RGUI_FILE_PLAIN || type == RGUI_FILE_DIRECTORY))
menu_ticker_line(entry_title_buf, TERM_WIDTH - (w + 1 + 2), g_extern.frame_count / 15, path, selected);
else
menu_ticker_line(type_str_buf, w, g_extern.frame_count / 15, type_str, selected);
snprintf(message, sizeof(message), "%c %-*.*s %-*s",
selected ? '>' : ' ',
TERM_WIDTH - (w + 1 + 2), TERM_WIDTH - (w + 1 + 2),
entry_title_buf,
2012-07-16 21:57:43 +00:00
w,
type_str_buf);
2012-05-06 02:04:33 +00:00
blit_line(rgui, x, y, message, selected);
2012-05-06 02:04:33 +00:00
}
#ifdef GEKKO
2013-03-06 17:19:56 +00:00
const char *message_queue;
if (rgui->msg_force)
{
message_queue = msg_queue_pull(g_extern.msg_queue);
rgui->msg_force = false;
}
else
message_queue = driver.current_msg;
render_messagebox(rgui, message_queue);
2013-03-06 17:19:56 +00:00
#endif
}
#ifdef GEKKO
#define MAX_GAMMA_SETTING 2
#else
#define MAX_GAMMA_SETTING 1
#endif
2013-04-04 20:08:23 +00:00
static int rgui_core_setting_toggle(unsigned setting, rgui_action_t action)
{
unsigned index = setting - RGUI_SETTINGS_CORE_OPTION_START;
switch (action)
{
case RGUI_ACTION_LEFT:
core_option_prev(g_extern.system.core_options, index);
break;
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
core_option_next(g_extern.system.core_options, index);
break;
case RGUI_ACTION_START:
core_option_set_default(g_extern.system.core_options, index);
break;
default:
break;
}
return 0;
}
static int rgui_settings_toggle_setting(rgui_handle_t *rgui, unsigned setting, rgui_action_t action, unsigned menu_type)
2012-07-16 21:57:43 +00:00
{
unsigned port = rgui->current_pad;
if (setting >= RGUI_SETTINGS_VIDEO_OPTIONS_FIRST && setting <= RGUI_SETTINGS_VIDEO_OPTIONS_LAST)
return video_option_toggle_setting(rgui, setting, action);
#ifdef HAVE_SHADER_MANAGER
else if (setting >= RGUI_SETTINGS_SHADER_FILTER && setting <= RGUI_SETTINGS_SHADER_LAST)
return shader_manager_toggle_setting(rgui, setting, action);
#endif
2013-04-04 20:08:23 +00:00
if (setting >= RGUI_SETTINGS_CORE_OPTION_START)
return rgui_core_setting_toggle(setting, action);
2012-07-16 21:57:43 +00:00
switch (setting)
{
2013-01-18 14:22:03 +00:00
case RGUI_SETTINGS_REWIND_ENABLE:
2013-03-16 13:28:10 +00:00
if (action == RGUI_ACTION_OK ||
action == RGUI_ACTION_LEFT ||
action == RGUI_ACTION_RIGHT)
2013-01-18 14:22:03 +00:00
{
2013-04-07 13:15:16 +00:00
settings_set(1ULL << S_REWIND);
2013-03-16 13:28:10 +00:00
if (g_settings.rewind_enable)
rarch_init_rewind();
2013-04-07 13:15:16 +00:00
else
rarch_deinit_rewind();
2013-01-18 14:22:03 +00:00
}
else if (action == RGUI_ACTION_START)
2013-03-16 13:28:10 +00:00
{
2013-01-18 14:22:03 +00:00
g_settings.rewind_enable = false;
2013-03-16 13:28:10 +00:00
rarch_deinit_rewind();
}
2013-01-18 14:22:03 +00:00
break;
2013-09-16 21:10:15 +00:00
#ifdef HAVE_SCREENSHOTS
case RGUI_SETTINGS_GPU_SCREENSHOT:
if (action == RGUI_ACTION_OK ||
action == RGUI_ACTION_LEFT ||
action == RGUI_ACTION_RIGHT)
g_settings.video.gpu_screenshot = !g_settings.video.gpu_screenshot;
else if (action == RGUI_ACTION_START)
g_settings.video.gpu_screenshot = true;
break;
#endif
2013-01-18 14:22:03 +00:00
case RGUI_SETTINGS_REWIND_GRANULARITY:
if (action == RGUI_ACTION_OK || action == RGUI_ACTION_RIGHT)
settings_set(1ULL << S_REWIND_GRANULARITY_INCREMENT);
2013-01-18 14:22:03 +00:00
else if (action == RGUI_ACTION_LEFT)
settings_set(1ULL << S_REWIND_GRANULARITY_DECREMENT);
2013-01-18 14:22:03 +00:00
else if (action == RGUI_ACTION_START)
settings_set(1ULL << S_DEF_REWIND_GRANULARITY);
2013-01-18 14:22:03 +00:00
break;
2013-05-22 13:35:28 +00:00
case RGUI_SETTINGS_CONFIG_SAVE_ON_EXIT:
if (action == RGUI_ACTION_OK || action == RGUI_ACTION_RIGHT
|| action == RGUI_ACTION_LEFT)
{
g_extern.config_save_on_exit = !g_extern.config_save_on_exit;
}
else if (action == RGUI_ACTION_START)
g_extern.config_save_on_exit = true;
break;
2013-04-29 13:56:49 +00:00
#if defined(HAVE_THREADS) && !defined(RARCH_CONSOLE)
case RGUI_SETTINGS_SRAM_AUTOSAVE:
if (action == RGUI_ACTION_OK || action == RGUI_ACTION_RIGHT || action == RGUI_ACTION_LEFT)
{
rarch_deinit_autosave();
g_settings.autosave_interval = (!g_settings.autosave_interval) * 10;
if (g_settings.autosave_interval)
rarch_init_autosave();
}
else if (action == RGUI_ACTION_START)
{
rarch_deinit_autosave();
g_settings.autosave_interval = 0;
}
break;
#endif
2012-08-12 07:38:23 +00:00
case RGUI_SETTINGS_SAVESTATE_SAVE:
case RGUI_SETTINGS_SAVESTATE_LOAD:
if (action == RGUI_ACTION_OK)
{
if (setting == RGUI_SETTINGS_SAVESTATE_SAVE)
rarch_save_state();
else
rarch_load_state();
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
2013-01-11 03:36:40 +00:00
return -1;
2012-08-12 07:38:23 +00:00
}
else if (action == RGUI_ACTION_START)
settings_set(1ULL << S_DEF_SAVE_STATE);
else if (action == RGUI_ACTION_LEFT)
settings_set(1ULL << S_SAVESTATE_DECREMENT);
else if (action == RGUI_ACTION_RIGHT)
settings_set(1ULL << S_SAVESTATE_INCREMENT);
2012-08-12 07:38:23 +00:00
break;
2013-03-10 21:54:46 +00:00
#ifdef HAVE_SCREENSHOTS
case RGUI_SETTINGS_SCREENSHOT:
if (action == RGUI_ACTION_OK)
rarch_take_screenshot();
break;
2013-03-10 21:54:46 +00:00
#endif
case RGUI_SETTINGS_RESTART_GAME:
if (action == RGUI_ACTION_OK)
{
rarch_game_reset();
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
2013-01-11 03:36:40 +00:00
return -1;
}
break;
case RGUI_SETTINGS_AUDIO_MUTE:
if (action == RGUI_ACTION_START)
settings_set(1ULL << S_DEF_AUDIO_MUTE);
else
settings_set(1ULL << S_AUDIO_MUTE);
break;
case RGUI_SETTINGS_AUDIO_CONTROL_RATE_DELTA:
if (action == RGUI_ACTION_START)
settings_set(1ULL << S_DEF_AUDIO_CONTROL_RATE);
else if (action == RGUI_ACTION_LEFT)
settings_set(1ULL << S_AUDIO_CONTROL_RATE_DECREMENT);
else if (action == RGUI_ACTION_RIGHT)
settings_set(1ULL << S_AUDIO_CONTROL_RATE_INCREMENT);
2012-07-16 21:57:43 +00:00
break;
2012-08-27 20:09:53 +00:00
case RGUI_SETTINGS_DEBUG_TEXT:
if (action == RGUI_ACTION_START || action == RGUI_ACTION_LEFT)
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_FPS_DRAW);
2012-08-27 20:09:53 +00:00
else if (action == RGUI_ACTION_RIGHT)
g_extern.lifecycle_mode_state |= (1ULL << MODE_FPS_DRAW);
2012-08-27 20:09:53 +00:00
break;
2013-04-27 11:29:01 +00:00
case RGUI_SETTINGS_DISK_INDEX:
{
const struct retro_disk_control_callback *control = &g_extern.system.disk_control;
unsigned num_disks = control->get_num_images();
unsigned current = control->get_image_index();
int step = 0;
if (action == RGUI_ACTION_RIGHT || action == RGUI_ACTION_OK)
step = 1;
else if (action == RGUI_ACTION_LEFT)
step = -1;
if (step)
{
unsigned next_index = (current + num_disks + 1 + step) % (num_disks + 1);
rarch_disk_control_set_eject(true, false);
rarch_disk_control_set_index(next_index);
rarch_disk_control_set_eject(false, false);
}
break;
}
case RGUI_SETTINGS_RESTART_EMULATOR:
if (action == RGUI_ACTION_OK)
{
2013-05-21 22:29:48 +00:00
#if defined(GEKKO) && defined(HW_RVL)
fill_pathname_join(g_extern.fullpath, default_paths.core_dir, SALAMANDER_FILE,
sizeof(g_extern.fullpath));
#endif
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME);
g_extern.lifecycle_mode_state |= (1ULL << MODE_EXITSPAWN);
2013-01-11 03:36:40 +00:00
return -1;
}
2012-07-31 03:00:20 +00:00
break;
2013-03-24 05:32:22 +00:00
case RGUI_SETTINGS_RESUME_GAME:
if (action == RGUI_ACTION_OK && (g_extern.main_is_init))
{
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
return -1;
}
break;
case RGUI_SETTINGS_QUIT_RARCH:
if (action == RGUI_ACTION_OK)
{
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME);
2013-01-11 03:36:40 +00:00
return -1;
}
break;
#ifdef HAVE_OVERLAY
case RGUI_SETTINGS_OVERLAY_PRESET:
switch (action)
{
case RGUI_ACTION_OK:
rgui_list_push(rgui->menu_stack, g_extern.overlay_dir, setting, rgui->selection_ptr);
rgui->selection_ptr = 0;
rgui->need_refresh = true;
break;
#ifndef __QNX__ // FIXME: Why ifndef QNX?
case RGUI_ACTION_START:
if (driver.overlay)
input_overlay_free(driver.overlay);
driver.overlay = NULL;
*g_settings.input.overlay = '\0';
break;
#endif
default:
break;
}
break;
2013-05-17 21:26:11 +00:00
case RGUI_SETTINGS_OVERLAY_OPACITY:
{
bool changed = true;
switch (action)
2013-05-17 21:26:11 +00:00
{
case RGUI_ACTION_LEFT:
settings_set(1ULL << S_INPUT_OVERLAY_OPACITY_DECREMENT);
break;
2013-05-17 21:26:11 +00:00
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
settings_set(1ULL << S_INPUT_OVERLAY_OPACITY_INCREMENT);
break;
case RGUI_ACTION_START:
settings_set(1ULL << S_DEF_INPUT_OVERLAY_OPACITY);
break;
2013-05-17 21:26:11 +00:00
default:
changed = false;
break;
2013-05-17 21:26:11 +00:00
}
if (changed && driver.overlay)
input_overlay_set_alpha_mod(driver.overlay,
g_settings.input.overlay_opacity);
2013-05-17 21:26:11 +00:00
break;
}
case RGUI_SETTINGS_OVERLAY_SCALE:
{
bool changed = true;
switch (action)
{
case RGUI_ACTION_LEFT:
settings_set(1ULL << S_INPUT_OVERLAY_SCALE_DECREMENT);
break;
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
settings_set(1ULL << S_INPUT_OVERLAY_SCALE_INCREMENT);
break;
case RGUI_ACTION_START:
settings_set(1ULL << S_DEF_INPUT_OVERLAY_SCALE);
break;
default:
changed = false;
break;
}
if (changed && driver.overlay)
input_overlay_set_scale_factor(driver.overlay,
g_settings.input.overlay_scale);
break;
}
#endif
// controllers
case RGUI_SETTINGS_BIND_PLAYER:
if (action == RGUI_ACTION_START)
rgui->current_pad = 0;
else if (action == RGUI_ACTION_LEFT)
{
if (rgui->current_pad != 0)
rgui->current_pad--;
}
else if (action == RGUI_ACTION_RIGHT)
{
if (rgui->current_pad < MAX_PLAYERS - 1)
rgui->current_pad++;
}
port = rgui->current_pad;
break;
case RGUI_SETTINGS_BIND_DEVICE:
// If set_keybinds is supported, we do it more fancy, and scroll through
// a list of supported devices directly.
if (driver.input->set_keybinds)
{
g_settings.input.device[port] += DEVICE_LAST;
if (action == RGUI_ACTION_START)
g_settings.input.device[port] = 0;
else if (action == RGUI_ACTION_LEFT)
g_settings.input.device[port]--;
else if (action == RGUI_ACTION_RIGHT)
g_settings.input.device[port]++;
// DEVICE_LAST can be 0, avoid modulo.
if (g_settings.input.device[port] >= DEVICE_LAST)
g_settings.input.device[port] -= DEVICE_LAST;
unsigned keybind_action = (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BINDS);
switch (g_settings.input.dpad_emulation[port])
{
case ANALOG_DPAD_LSTICK:
keybind_action |= (1ULL << KEYBINDS_ACTION_SET_ANALOG_DPAD_LSTICK);
break;
case ANALOG_DPAD_RSTICK:
keybind_action |= (1ULL << KEYBINDS_ACTION_SET_ANALOG_DPAD_RSTICK);
break;
case ANALOG_DPAD_NONE:
keybind_action |= (1ULL << KEYBINDS_ACTION_SET_ANALOG_DPAD_NONE);
break;
default:
break;
}
driver.input->set_keybinds(driver.input_data, g_settings.input.device[port], port, 0,
keybind_action);
}
else
{
// When only straight g_settings.input.joypad_map[] style
// mapping is supported.
int *p = &g_settings.input.joypad_map[port];
if (action == RGUI_ACTION_START)
*p = port;
else if (action == RGUI_ACTION_LEFT)
(*p)--;
else if (action == RGUI_ACTION_RIGHT)
(*p)++;
if (*p < -1)
*p = -1;
else if (*p >= MAX_PLAYERS)
*p = MAX_PLAYERS - 1;
}
break;
2013-04-27 10:57:34 +00:00
case RGUI_SETTINGS_BIND_DEVICE_TYPE:
{
static const unsigned device_types[] = {
RETRO_DEVICE_NONE,
RETRO_DEVICE_JOYPAD,
RETRO_DEVICE_ANALOG,
RETRO_DEVICE_MOUSE,
RETRO_DEVICE_JOYPAD_MULTITAP,
RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE,
RETRO_DEVICE_LIGHTGUN_JUSTIFIER,
RETRO_DEVICE_LIGHTGUN_JUSTIFIERS,
};
unsigned current_device = g_extern.libretro_device[port];
unsigned current_index = 0;
for (unsigned i = 0; i < ARRAY_SIZE(device_types); i++)
{
if (current_device == device_types[i])
{
current_index = i;
break;
}
}
bool updated = true;
switch (action)
{
case RGUI_ACTION_START:
current_device = RETRO_DEVICE_JOYPAD;
break;
case RGUI_ACTION_LEFT:
current_device = device_types[(current_index + ARRAY_SIZE(device_types) - 1) % ARRAY_SIZE(device_types)];
break;
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
2013-04-27 11:29:01 +00:00
current_device = device_types[(current_index + 1) % ARRAY_SIZE(device_types)];
2013-04-27 10:57:34 +00:00
break;
default:
updated = false;
}
if (updated)
{
g_extern.libretro_device[port] = current_device;
pretro_set_controller_port_device(port, current_device);
}
break;
}
case RGUI_SETTINGS_BIND_DPAD_EMULATION:
g_settings.input.dpad_emulation[port] += ANALOG_DPAD_LAST;
if (action == RGUI_ACTION_START)
g_settings.input.dpad_emulation[port] = ANALOG_DPAD_LSTICK;
else if (action == RGUI_ACTION_LEFT)
g_settings.input.dpad_emulation[port]--;
else if (action == RGUI_ACTION_RIGHT)
g_settings.input.dpad_emulation[port]++;
g_settings.input.dpad_emulation[port] %= ANALOG_DPAD_LAST;
if (driver.input->set_keybinds)
{
unsigned keybind_action = 0;
switch (g_settings.input.dpad_emulation[port])
{
case ANALOG_DPAD_LSTICK:
keybind_action = (1ULL << KEYBINDS_ACTION_SET_ANALOG_DPAD_LSTICK);
break;
case ANALOG_DPAD_RSTICK:
keybind_action = (1ULL << KEYBINDS_ACTION_SET_ANALOG_DPAD_RSTICK);
break;
case ANALOG_DPAD_NONE:
keybind_action = (1ULL << KEYBINDS_ACTION_SET_ANALOG_DPAD_NONE);
break;
default:
break;
}
if (keybind_action)
driver.input->set_keybinds(driver.input_data, g_settings.input.device[port], port, 0,
keybind_action);
}
break;
case RGUI_SETTINGS_BIND_UP:
case RGUI_SETTINGS_BIND_DOWN:
case RGUI_SETTINGS_BIND_LEFT:
case RGUI_SETTINGS_BIND_RIGHT:
case RGUI_SETTINGS_BIND_A:
case RGUI_SETTINGS_BIND_B:
case RGUI_SETTINGS_BIND_X:
case RGUI_SETTINGS_BIND_Y:
case RGUI_SETTINGS_BIND_START:
case RGUI_SETTINGS_BIND_SELECT:
case RGUI_SETTINGS_BIND_L:
case RGUI_SETTINGS_BIND_R:
case RGUI_SETTINGS_BIND_L2:
case RGUI_SETTINGS_BIND_R2:
case RGUI_SETTINGS_BIND_L3:
case RGUI_SETTINGS_BIND_R3:
if (driver.input->set_keybinds)
{
unsigned keybind_action = KEYBINDS_ACTION_NONE;
2012-07-28 00:39:49 +00:00
if (action == RGUI_ACTION_START)
keybind_action = (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BIND);
else if (action == RGUI_ACTION_LEFT)
keybind_action = (1ULL << KEYBINDS_ACTION_DECREMENT_BIND);
else if (action == RGUI_ACTION_RIGHT)
keybind_action = (1ULL << KEYBINDS_ACTION_INCREMENT_BIND);
if (keybind_action != KEYBINDS_ACTION_NONE)
driver.input->set_keybinds(driver.input_data, g_settings.input.device[setting - RGUI_SETTINGS_BIND_UP], port,
rgui_controller_lut[setting - RGUI_SETTINGS_BIND_UP], keybind_action);
}
2013-05-21 02:17:26 +00:00
case RGUI_BROWSER_DIR_PATH:
if (action == RGUI_ACTION_START)
{
2013-05-21 06:46:51 +00:00
*g_settings.rgui_browser_directory = '\0';
*rgui->base_path = '\0';
2013-05-21 02:17:26 +00:00
}
break;
#ifdef HAVE_SCREENSHOTS
case RGUI_SCREENSHOT_DIR_PATH:
if (action == RGUI_ACTION_START)
*g_settings.screenshot_directory = '\0';
break;
#endif
2013-05-21 02:17:26 +00:00
case RGUI_SAVEFILE_DIR_PATH:
if (action == RGUI_ACTION_START)
2013-05-21 06:46:51 +00:00
*g_extern.savefile_dir = '\0';
2013-05-21 02:17:26 +00:00
break;
#ifdef HAVE_OVERLAY
case RGUI_OVERLAY_DIR_PATH:
if (action == RGUI_ACTION_START)
*g_extern.overlay_dir = '\0';
break;
#endif
2013-05-21 02:17:26 +00:00
case RGUI_SAVESTATE_DIR_PATH:
if (action == RGUI_ACTION_START)
2013-05-21 06:46:51 +00:00
*g_extern.savestate_dir = '\0';
2013-05-21 02:17:26 +00:00
break;
2013-09-15 21:09:23 +00:00
#ifdef HAVE_DYNAMIC
case RGUI_LIBRETRO_DIR_PATH:
if (action == RGUI_ACTION_START)
*rgui->libretro_dir = '\0';
break;
2013-09-15 21:09:23 +00:00
#endif
2013-05-21 02:17:26 +00:00
case RGUI_SHADER_DIR_PATH:
if (action == RGUI_ACTION_START)
2013-05-21 06:46:51 +00:00
*g_settings.video.shader_dir = '\0';
2013-05-21 02:17:26 +00:00
break;
case RGUI_SYSTEM_DIR_PATH:
if (action == RGUI_ACTION_START)
2013-05-21 06:46:51 +00:00
*g_settings.system_directory = '\0';
2013-05-21 02:17:26 +00:00
break;
2012-07-16 21:57:43 +00:00
default:
break;
}
2013-01-11 03:36:40 +00:00
return 0;
2012-07-16 21:57:43 +00:00
}
static void rgui_settings_audio_options_populate_entries(rgui_handle_t *rgui)
{
rgui_list_clear(rgui->selection_buf);
rgui_list_push(rgui->selection_buf, "Mute Audio", RGUI_SETTINGS_AUDIO_MUTE, 0);
rgui_list_push(rgui->selection_buf, "Rate Control Delta", RGUI_SETTINGS_AUDIO_CONTROL_RATE_DELTA, 0);
}
static void rgui_settings_disc_options_populate_entries(rgui_handle_t *rgui)
{
rgui_list_clear(rgui->selection_buf);
rgui_list_push(rgui->selection_buf, "Disk Index", RGUI_SETTINGS_DISK_INDEX, 0);
rgui_list_push(rgui->selection_buf, "Disk Image Append", RGUI_SETTINGS_DISK_APPEND, 0);
}
2013-05-05 20:02:30 +00:00
static void rgui_settings_options_populate_entries(rgui_handle_t *rgui)
{
rgui_list_clear(rgui->selection_buf);
rgui_list_push(rgui->selection_buf, "Rewind", RGUI_SETTINGS_REWIND_ENABLE, 0);
rgui_list_push(rgui->selection_buf, "Rewind Granularity", RGUI_SETTINGS_REWIND_GRANULARITY, 0);
2013-09-16 21:10:15 +00:00
#ifdef HAVE_SCREENSHOTS
rgui_list_push(rgui->selection_buf, "GPU Screenshots", RGUI_SETTINGS_GPU_SCREENSHOT, 0);
#endif
2013-05-22 13:35:28 +00:00
rgui_list_push(rgui->selection_buf, "Config Save On Exit", RGUI_SETTINGS_CONFIG_SAVE_ON_EXIT, 0);
#if defined(HAVE_THREADS) && !defined(RARCH_CONSOLE)
rgui_list_push(rgui->selection_buf, "SRAM Autosave", RGUI_SETTINGS_SRAM_AUTOSAVE, 0);
#endif
2013-05-05 20:02:30 +00:00
rgui_list_push(rgui->selection_buf, "Debug Info Messages", RGUI_SETTINGS_DEBUG_TEXT, 0);
}
2012-07-16 21:57:43 +00:00
static void rgui_settings_populate_entries(rgui_handle_t *rgui)
{
rgui_list_clear(rgui->selection_buf);
2012-07-28 00:39:49 +00:00
2013-04-07 23:51:18 +00:00
#if defined(HAVE_DYNAMIC) || defined(HAVE_LIBRETRO_MANAGEMENT)
2013-03-17 20:23:28 +00:00
rgui_list_push(rgui->selection_buf, "Core", RGUI_SETTINGS_CORE, 0);
#endif
if (rgui->history)
rgui_list_push(rgui->selection_buf, "Load Game (History)", RGUI_SETTINGS_OPEN_HISTORY, 0);
rgui_list_push(rgui->selection_buf, "Load Game", RGUI_SETTINGS_OPEN_FILEBROWSER, 0);
rgui_list_push(rgui->selection_buf, "Core Options", RGUI_SETTINGS_CORE_OPTIONS, 0);
rgui_list_push(rgui->selection_buf, "Video Options", RGUI_SETTINGS_VIDEO_OPTIONS, 0);
rgui_list_push(rgui->selection_buf, "Audio Options", RGUI_SETTINGS_AUDIO_OPTIONS, 0);
rgui_list_push(rgui->selection_buf, "Input Options", RGUI_SETTINGS_INPUT_OPTIONS, 0);
rgui_list_push(rgui->selection_buf, "Path Options", RGUI_SETTINGS_PATH_OPTIONS, 0);
2013-05-05 20:02:30 +00:00
rgui_list_push(rgui->selection_buf, "Settings", RGUI_SETTINGS_OPTIONS, 0);
if (g_extern.main_is_init && !g_extern.libretro_dummy)
2012-08-12 07:38:23 +00:00
{
if (g_extern.system.disk_control.get_num_images)
rgui_list_push(rgui->selection_buf, "Disk Options", RGUI_SETTINGS_DISK_OPTIONS, 0);
rgui_list_push(rgui->selection_buf, "Save State", RGUI_SETTINGS_SAVESTATE_SAVE, 0);
rgui_list_push(rgui->selection_buf, "Load State", RGUI_SETTINGS_SAVESTATE_LOAD, 0);
2013-03-10 21:54:46 +00:00
#ifdef HAVE_SCREENSHOTS
rgui_list_push(rgui->selection_buf, "Take Screenshot", RGUI_SETTINGS_SCREENSHOT, 0);
2013-03-10 21:54:46 +00:00
#endif
rgui_list_push(rgui->selection_buf, "Resume Game", RGUI_SETTINGS_RESUME_GAME, 0);
rgui_list_push(rgui->selection_buf, "Restart Game", RGUI_SETTINGS_RESTART_GAME, 0);
2013-04-27 11:29:01 +00:00
2012-08-12 07:38:23 +00:00
}
#ifndef HAVE_DYNAMIC
rgui_list_push(rgui->selection_buf, "Restart RetroArch", RGUI_SETTINGS_RESTART_EMULATOR, 0);
#endif
2013-03-24 05:32:22 +00:00
rgui_list_push(rgui->selection_buf, "Quit RetroArch", RGUI_SETTINGS_QUIT_RARCH, 0);
2012-07-16 21:57:43 +00:00
}
static void rgui_settings_core_options_populate_entries(rgui_handle_t *rgui)
{
rgui_list_clear(rgui->selection_buf);
2013-04-04 20:08:23 +00:00
if (g_extern.system.core_options)
{
size_t opts = core_option_size(g_extern.system.core_options);
for (size_t i = 0; i < opts; i++)
rgui_list_push(rgui->selection_buf,
core_option_get_desc(g_extern.system.core_options, i), RGUI_SETTINGS_CORE_OPTION_START + i, 0);
}
else
rgui_list_push(rgui->selection_buf, "No options available.", RGUI_SETTINGS_CORE_OPTION_NONE, 0);
}
static void rgui_settings_video_options_populate_entries(rgui_handle_t *rgui)
{
rgui_list_clear(rgui->selection_buf);
#ifdef HAVE_SHADER_MANAGER
rgui_list_push(rgui->selection_buf, "Shader Options", RGUI_SETTINGS_SHADER_OPTIONS, 0);
#endif
#ifdef GEKKO
rgui_list_push(rgui->selection_buf, "Screen Resolution", RGUI_SETTINGS_VIDEO_RESOLUTION, 0);
#endif
2013-04-27 23:52:58 +00:00
#ifndef HAVE_SHADER_MANAGER
rgui_list_push(rgui->selection_buf, "Default Filter", RGUI_SETTINGS_VIDEO_FILTER, 0);
#endif
#ifdef HW_RVL
rgui_list_push(rgui->selection_buf, "VI Trap filtering", RGUI_SETTINGS_VIDEO_SOFT_FILTER, 0);
rgui_list_push(rgui->selection_buf, "Gamma", RGUI_SETTINGS_VIDEO_GAMMA, 0);
#endif
rgui_list_push(rgui->selection_buf, "Integer Scale", RGUI_SETTINGS_VIDEO_INTEGER_SCALE, 0);
rgui_list_push(rgui->selection_buf, "Aspect Ratio", RGUI_SETTINGS_VIDEO_ASPECT_RATIO, 0);
rgui_list_push(rgui->selection_buf, "Custom Ratio", RGUI_SETTINGS_CUSTOM_VIEWPORT, 0);
#if !defined(RARCH_CONSOLE) && !defined(RARCH_MOBILE)
rgui_list_push(rgui->selection_buf, "Toggle Fullscreen", RGUI_SETTINGS_TOGGLE_FULLSCREEN, 0);
#endif
rgui_list_push(rgui->selection_buf, "Rotation", RGUI_SETTINGS_VIDEO_ROTATION, 0);
rgui_list_push(rgui->selection_buf, "VSync", RGUI_SETTINGS_VIDEO_VSYNC, 0);
rgui_list_push(rgui->selection_buf, "Hard GPU Sync", RGUI_SETTINGS_VIDEO_HARD_SYNC, 0);
rgui_list_push(rgui->selection_buf, "Hard GPU Sync Frames", RGUI_SETTINGS_VIDEO_HARD_SYNC_FRAMES, 0);
rgui_list_push(rgui->selection_buf, "Black Frame Insertion", RGUI_SETTINGS_VIDEO_BLACK_FRAME_INSERTION, 0);
rgui_list_push(rgui->selection_buf, "VSync Swap Interval", RGUI_SETTINGS_VIDEO_SWAP_INTERVAL, 0);
#if !defined(RARCH_CONSOLE) && !defined(RARCH_MOBILE)
rgui_list_push(rgui->selection_buf, "Windowed Scale (X)", RGUI_SETTINGS_VIDEO_WINDOW_SCALE_X, 0);
rgui_list_push(rgui->selection_buf, "Windowed Scale (Y)", RGUI_SETTINGS_VIDEO_WINDOW_SCALE_Y, 0);
#endif
rgui_list_push(rgui->selection_buf, "Crop Overscan (reload)", RGUI_SETTINGS_VIDEO_CROP_OVERSCAN, 0);
rgui_list_push(rgui->selection_buf, "Estimated Monitor FPS", RGUI_SETTINGS_VIDEO_REFRESH_RATE_AUTO, 0);
}
#ifdef HAVE_SHADER_MANAGER
static void rgui_settings_shader_manager_populate_entries(rgui_handle_t *rgui)
{
rgui_list_clear(rgui->selection_buf);
2013-04-27 23:52:58 +00:00
rgui_list_push(rgui->selection_buf, "Apply Shader Changes",
RGUI_SETTINGS_SHADER_APPLY, 0);
2013-04-27 23:52:58 +00:00
rgui_list_push(rgui->selection_buf, "Default Filter", RGUI_SETTINGS_SHADER_FILTER, 0);
rgui_list_push(rgui->selection_buf, "Load Shader Preset",
2013-04-13 23:27:13 +00:00
RGUI_SETTINGS_SHADER_PRESET, 0);
2013-04-29 20:02:20 +00:00
rgui_list_push(rgui->selection_buf, "Shader Passes",
RGUI_SETTINGS_SHADER_PASSES, 0);
for (unsigned i = 0; i < rgui->shader.passes; i++)
{
char buf[64];
snprintf(buf, sizeof(buf), "Shader #%u", i);
rgui_list_push(rgui->selection_buf, buf,
RGUI_SETTINGS_SHADER_0 + 3 * i, 0);
2013-04-27 23:52:58 +00:00
snprintf(buf, sizeof(buf), "Shader #%u Filter", i);
rgui_list_push(rgui->selection_buf, buf,
RGUI_SETTINGS_SHADER_0_FILTER + 3 * i, 0);
2013-04-27 23:52:58 +00:00
snprintf(buf, sizeof(buf), "Shader #%u Scale", i);
rgui_list_push(rgui->selection_buf, buf,
RGUI_SETTINGS_SHADER_0_SCALE + 3 * i, 0);
}
}
2013-04-11 14:01:42 +00:00
static enum rarch_shader_type shader_manager_get_type(const struct gfx_shader *shader)
{
// All shader types must be the same, or we cannot use it.
enum rarch_shader_type type = RARCH_SHADER_NONE;
for (unsigned i = 0; i < shader->passes; i++)
{
enum rarch_shader_type pass_type = gfx_shader_parse_type(shader->pass[i].source.cg,
RARCH_SHADER_NONE);
switch (pass_type)
{
case RARCH_SHADER_CG:
case RARCH_SHADER_GLSL:
if (type == RARCH_SHADER_NONE)
type = pass_type;
else if (type != pass_type)
return RARCH_SHADER_NONE;
break;
default:
return RARCH_SHADER_NONE;
}
}
return type;
}
static void shader_manager_set_preset(struct gfx_shader *shader, enum rarch_shader_type type, const char *path)
2013-04-13 23:27:13 +00:00
{
RARCH_LOG("Setting RGUI shader: %s.\n", path ? path : "N/A (stock)");
bool ret = video_set_shader_func(type, path);
if (ret)
{
// Makes sure that we use RGUI CGP shader on driver reinit.
// Only do this when the cgp actually works to avoid potential errors.
strlcpy(g_settings.video.shader_path, path ? path : "",
sizeof(g_settings.video.shader_path));
g_settings.video.shader_enable = true;
if (path && shader)
{
// Load stored CGP into RGUI menu on success.
// Used when a preset is directly loaded.
// No point in updating when the CGP was created from RGUI itself.
config_file_t *conf = config_file_new(path);
if (conf)
{
gfx_shader_read_conf_cgp(conf, shader);
gfx_shader_resolve_relative(shader, path);
config_file_free(conf);
}
rgui->need_refresh = true;
}
2013-04-13 23:27:13 +00:00
}
else
{
RARCH_ERR("Setting RGUI CGP failed.\n");
g_settings.video.shader_enable = false;
}
}
static int shader_manager_toggle_setting(rgui_handle_t *rgui, unsigned setting, rgui_action_t action)
{
unsigned dist_shader = setting - RGUI_SETTINGS_SHADER_0;
unsigned dist_filter = setting - RGUI_SETTINGS_SHADER_0_FILTER;
unsigned dist_scale = setting - RGUI_SETTINGS_SHADER_0_SCALE;
2013-05-04 20:29:22 +00:00
if (setting == RGUI_SETTINGS_SHADER_FILTER)
2013-04-13 23:45:33 +00:00
{
switch (action)
{
case RGUI_ACTION_START:
g_settings.video.smooth = true;
break;
case RGUI_ACTION_LEFT:
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
g_settings.video.smooth = !g_settings.video.smooth;
break;
default:
break;
}
}
else if (setting == RGUI_SETTINGS_SHADER_APPLY)
{
if (!driver.video->set_shader || action != RGUI_ACTION_OK)
return 0;
RARCH_LOG("Applying shader ...\n");
2013-04-11 14:01:42 +00:00
enum rarch_shader_type type = shader_manager_get_type(&rgui->shader);
if (rgui->shader.passes && type != RARCH_SHADER_NONE)
{
2013-04-11 14:01:42 +00:00
const char *conf_path = type == RARCH_SHADER_GLSL ? "rgui.glslp" : "rgui.cgp";
char cgp_path[PATH_MAX];
const char *shader_dir = *g_settings.video.shader_dir ?
g_settings.video.shader_dir : g_settings.system_directory;
2013-04-11 14:01:42 +00:00
fill_pathname_join(cgp_path, shader_dir, conf_path, sizeof(cgp_path));
config_file_t *conf = config_file_new(NULL);
if (!conf)
return 0;
gfx_shader_write_conf_cgp(conf, &rgui->shader);
config_file_write(conf, cgp_path);
config_file_free(conf);
2013-04-11 14:01:42 +00:00
shader_manager_set_preset(NULL, type, cgp_path);
}
else
{
type = gfx_shader_parse_type("", DEFAULT_SHADER_TYPE);
if (type == RARCH_SHADER_NONE)
{
#if defined(HAVE_GLSL)
type = RARCH_SHADER_GLSL;
#elif defined(HAVE_CG) || defined(HAVE_HLSL)
type = RARCH_SHADER_CG;
#endif
}
shader_manager_set_preset(NULL, type, NULL);
}
}
else if (setting == RGUI_SETTINGS_SHADER_PASSES)
{
switch (action)
{
case RGUI_ACTION_START:
rgui->shader.passes = 0;
break;
case RGUI_ACTION_LEFT:
if (rgui->shader.passes)
rgui->shader.passes--;
break;
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
if (rgui->shader.passes < RGUI_MAX_SHADERS)
rgui->shader.passes++;
break;
default:
break;
}
rgui->need_refresh = true;
}
2013-04-13 23:27:13 +00:00
else if ((dist_shader % 3) == 0 || setting == RGUI_SETTINGS_SHADER_PRESET)
{
dist_shader /= 3;
2013-04-13 23:27:13 +00:00
struct gfx_shader_pass *pass = setting == RGUI_SETTINGS_SHADER_PRESET ?
&rgui->shader.pass[dist_shader] : NULL;
switch (action)
{
case RGUI_ACTION_OK:
rgui_list_push(rgui->menu_stack, g_settings.video.shader_dir, setting, rgui->selection_ptr);
rgui->selection_ptr = 0;
rgui->need_refresh = true;
break;
case RGUI_ACTION_START:
2013-04-13 23:27:13 +00:00
if (pass)
*pass->source.cg = '\0';
break;
default:
break;
}
}
else if ((dist_filter % 3) == 0)
{
dist_filter /= 3;
struct gfx_shader_pass *pass = &rgui->shader.pass[dist_filter];
switch (action)
{
case RGUI_ACTION_START:
rgui->shader.pass[dist_filter].filter = RARCH_FILTER_UNSPEC;
break;
case RGUI_ACTION_LEFT:
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
{
unsigned delta = action == RGUI_ACTION_LEFT ? 2 : 1;
pass->filter = (enum gfx_filter_type)((pass->filter + delta) % 3);
break;
}
default:
break;
}
}
else if ((dist_scale % 3) == 0)
{
dist_scale /= 3;
struct gfx_shader_pass *pass = &rgui->shader.pass[dist_scale];
switch (action)
{
case RGUI_ACTION_START:
pass->fbo.scale_x = pass->fbo.scale_y = 0;
pass->fbo.valid = false;
break;
case RGUI_ACTION_LEFT:
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
{
unsigned current_scale = pass->fbo.scale_x;
unsigned delta = action == RGUI_ACTION_LEFT ? 5 : 1;
current_scale = (current_scale + delta) % 6;
pass->fbo.valid = current_scale;
pass->fbo.scale_x = pass->fbo.scale_y = current_scale;
break;
}
default:
break;
}
}
return 0;
}
#endif
static int video_option_toggle_setting(rgui_handle_t *rgui, unsigned setting, rgui_action_t action)
{
switch (setting)
{
case RGUI_SETTINGS_VIDEO_ROTATION:
if (action == RGUI_ACTION_START)
{
settings_set(1ULL << S_DEF_AUDIO_CONTROL_RATE);
video_set_rotation_func(g_extern.console.screen.orientation);
}
else if (action == RGUI_ACTION_LEFT)
{
settings_set(1ULL << S_ROTATION_DECREMENT);
video_set_rotation_func(g_extern.console.screen.orientation);
}
else if (action == RGUI_ACTION_RIGHT)
{
settings_set(1ULL << S_ROTATION_INCREMENT);
video_set_rotation_func(g_extern.console.screen.orientation);
}
break;
case RGUI_SETTINGS_VIDEO_FILTER:
if (action == RGUI_ACTION_START)
settings_set(1ULL << S_DEF_HW_TEXTURE_FILTER);
else
settings_set(1ULL << S_HW_TEXTURE_FILTER);
if (driver.video_poke->set_filtering)
driver.video_poke->set_filtering(driver.video_data, 1, g_settings.video.smooth);
break;
case RGUI_SETTINGS_VIDEO_GAMMA:
if (action == RGUI_ACTION_START)
{
g_extern.console.screen.gamma_correction = 0;
if (driver.video_poke->apply_state_changes)
driver.video_poke->apply_state_changes(driver.video_data);
}
else if (action == RGUI_ACTION_LEFT)
{
if(g_extern.console.screen.gamma_correction > 0)
{
g_extern.console.screen.gamma_correction--;
if (driver.video_poke->apply_state_changes)
driver.video_poke->apply_state_changes(driver.video_data);
}
}
else if (action == RGUI_ACTION_RIGHT)
{
if(g_extern.console.screen.gamma_correction < MAX_GAMMA_SETTING)
{
g_extern.console.screen.gamma_correction++;
if (driver.video_poke->apply_state_changes)
driver.video_poke->apply_state_changes(driver.video_data);
}
}
break;
case RGUI_SETTINGS_VIDEO_INTEGER_SCALE:
if (action == RGUI_ACTION_START)
settings_set(1ULL << S_DEF_SCALE_INTEGER);
else if (action == RGUI_ACTION_LEFT ||
action == RGUI_ACTION_RIGHT ||
action == RGUI_ACTION_OK)
settings_set(1ULL << S_SCALE_INTEGER_TOGGLE);
if (driver.video_poke->apply_state_changes)
driver.video_poke->apply_state_changes(driver.video_data);
break;
case RGUI_SETTINGS_VIDEO_ASPECT_RATIO:
if (action == RGUI_ACTION_START)
settings_set(1ULL << S_DEF_ASPECT_RATIO);
else if (action == RGUI_ACTION_LEFT)
settings_set(1ULL << S_ASPECT_RATIO_DECREMENT);
else if (action == RGUI_ACTION_RIGHT)
settings_set(1ULL << S_ASPECT_RATIO_INCREMENT);
if (driver.video_poke->set_aspect_ratio)
driver.video_poke->set_aspect_ratio(driver.video_data, g_settings.video.aspect_ratio_idx);
break;
case RGUI_SETTINGS_TOGGLE_FULLSCREEN:
if (action == RGUI_ACTION_OK)
rarch_set_fullscreen(!g_settings.video.fullscreen);
break;
#ifdef GEKKO
case RGUI_SETTINGS_VIDEO_RESOLUTION:
if (action == RGUI_ACTION_LEFT)
{
if(rgui_current_gx_resolution > 0)
{
rgui_current_gx_resolution--;
gx_set_video_mode(rgui_gx_resolutions[rgui_current_gx_resolution][0], rgui_gx_resolutions[rgui_current_gx_resolution][1]);
}
}
else if (action == RGUI_ACTION_RIGHT)
{
if (rgui_current_gx_resolution < GX_RESOLUTIONS_LAST - 1)
{
2013-05-24 16:38:13 +00:00
#ifdef HW_RVL
if ((rgui_current_gx_resolution + 1) > GX_RESOLUTIONS_640_480)
if (CONF_GetVideo() != CONF_VIDEO_PAL)
return 0;
2013-05-24 16:38:13 +00:00
#endif
rgui_current_gx_resolution++;
gx_set_video_mode(rgui_gx_resolutions[rgui_current_gx_resolution][0],
rgui_gx_resolutions[rgui_current_gx_resolution][1]);
}
}
break;
#endif
#ifdef HW_RVL
case RGUI_SETTINGS_VIDEO_SOFT_FILTER:
if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE))
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE);
else
g_extern.lifecycle_mode_state |= (1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE);
if (driver.video_poke->apply_state_changes)
driver.video_poke->apply_state_changes(driver.video_data);
break;
#endif
case RGUI_SETTINGS_VIDEO_VSYNC:
switch (action)
{
case RGUI_ACTION_START:
settings_set(1ULL << S_DEF_VIDEO_VSYNC);
break;
case RGUI_ACTION_LEFT:
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
settings_set(1ULL << S_VIDEO_VSYNC_TOGGLE);
break;
default:
break;
}
break;
case RGUI_SETTINGS_VIDEO_HARD_SYNC:
switch (action)
{
case RGUI_ACTION_START:
g_settings.video.hard_sync = false;
break;
case RGUI_ACTION_LEFT:
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
g_settings.video.hard_sync = !g_settings.video.hard_sync;
break;
default:
break;
}
break;
case RGUI_SETTINGS_VIDEO_BLACK_FRAME_INSERTION:
switch (action)
{
case RGUI_ACTION_START:
g_settings.video.black_frame_insertion = false;
break;
case RGUI_ACTION_LEFT:
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
g_settings.video.black_frame_insertion = !g_settings.video.black_frame_insertion;
break;
default:
break;
}
break;
case RGUI_SETTINGS_VIDEO_CROP_OVERSCAN:
switch (action)
{
case RGUI_ACTION_START:
g_settings.video.crop_overscan = true;
break;
case RGUI_ACTION_LEFT:
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
g_settings.video.crop_overscan = !g_settings.video.crop_overscan;
break;
default:
break;
}
break;
case RGUI_SETTINGS_VIDEO_WINDOW_SCALE_X:
case RGUI_SETTINGS_VIDEO_WINDOW_SCALE_Y:
{
float *scale = setting == RGUI_SETTINGS_VIDEO_WINDOW_SCALE_X ? &g_settings.video.xscale : &g_settings.video.yscale;
float old_scale = *scale;
switch (action)
{
case RGUI_ACTION_START:
*scale = 3.0f;
break;
case RGUI_ACTION_LEFT:
*scale -= 1.0f;
break;
case RGUI_ACTION_RIGHT:
*scale += 1.0f;
break;
default:
break;
}
*scale = roundf(*scale);
*scale = max(*scale, 1.0f);
if (old_scale != *scale && !g_settings.video.fullscreen)
rarch_set_fullscreen(g_settings.video.fullscreen); // Reinit video driver.
break;
}
case RGUI_SETTINGS_VIDEO_SWAP_INTERVAL:
{
unsigned old = g_settings.video.swap_interval;
switch (action)
{
case RGUI_ACTION_START:
g_settings.video.swap_interval = 1;
break;
case RGUI_ACTION_LEFT:
g_settings.video.swap_interval--;
break;
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
g_settings.video.swap_interval++;
break;
default:
break;
}
g_settings.video.swap_interval = min(g_settings.video.swap_interval, 4);
g_settings.video.swap_interval = max(g_settings.video.swap_interval, 1);
if (old != g_settings.video.swap_interval && driver.video && driver.video_data)
video_set_nonblock_state_func(false); // This will update the current swap interval. Since we're in RGUI now, always apply VSync.
break;
}
case RGUI_SETTINGS_VIDEO_HARD_SYNC_FRAMES:
switch (action)
{
case RGUI_ACTION_START:
g_settings.video.hard_sync_frames = 0;
break;
case RGUI_ACTION_LEFT:
if (g_settings.video.hard_sync_frames > 0)
g_settings.video.hard_sync_frames--;
break;
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
if (g_settings.video.hard_sync_frames < 3)
g_settings.video.hard_sync_frames++;
break;
default:
break;
}
break;
case RGUI_SETTINGS_VIDEO_REFRESH_RATE_AUTO:
switch (action)
{
case RGUI_ACTION_START:
g_extern.measure_data.frame_time_samples_count = 0;
break;
case RGUI_ACTION_OK:
{
double refresh_rate = 0.0;
double deviation = 0.0;
unsigned sample_points = 0;
if (driver_monitor_fps_statistics(&refresh_rate, &deviation, &sample_points))
{
driver_set_monitor_refresh_rate(refresh_rate);
// Incase refresh rate update forced non-block video.
video_set_nonblock_state_func(false);
}
break;
}
default:
break;
}
break;
default:
break;
}
return 0;
}
static void rgui_settings_path_populate_entries(rgui_handle_t *rgui)
{
rgui_list_clear(rgui->selection_buf);
rgui_list_push(rgui->selection_buf, "Browser Directory", RGUI_BROWSER_DIR_PATH, 0);
#ifdef HAVE_DYNAMIC
rgui_list_push(rgui->selection_buf, "Core Directory", RGUI_LIBRETRO_DIR_PATH, 0);
#endif
2013-05-04 20:29:22 +00:00
#ifdef HAVE_SHADER_MANAGER
rgui_list_push(rgui->selection_buf, "Shader Directory", RGUI_SHADER_DIR_PATH, 0);
2013-05-04 20:29:22 +00:00
#endif
rgui_list_push(rgui->selection_buf, "Savestate Directory", RGUI_SAVESTATE_DIR_PATH, 0);
rgui_list_push(rgui->selection_buf, "Savefile Directory", RGUI_SAVEFILE_DIR_PATH, 0);
#ifdef HAVE_OVERLAY
rgui_list_push(rgui->selection_buf, "Overlay Directory", RGUI_OVERLAY_DIR_PATH, 0);
#endif
rgui_list_push(rgui->selection_buf, "System Directory", RGUI_SYSTEM_DIR_PATH, 0);
#ifdef HAVE_SCREENSHOTS
rgui_list_push(rgui->selection_buf, "Screenshot Directory", RGUI_SCREENSHOT_DIR_PATH, 0);
#endif
}
static void rgui_settings_controller_populate_entries(rgui_handle_t *rgui)
2012-07-16 21:57:43 +00:00
{
rgui_list_clear(rgui->selection_buf);
#ifdef HAVE_OVERLAY
rgui_list_push(rgui->selection_buf, "Overlay Preset", RGUI_SETTINGS_OVERLAY_PRESET, 0);
2013-05-17 21:26:11 +00:00
rgui_list_push(rgui->selection_buf, "Overlay Opacity", RGUI_SETTINGS_OVERLAY_OPACITY, 0);
rgui_list_push(rgui->selection_buf, "Overlay Scale", RGUI_SETTINGS_OVERLAY_SCALE, 0);
#endif
rgui_list_push(rgui->selection_buf, "Player", RGUI_SETTINGS_BIND_PLAYER, 0);
rgui_list_push(rgui->selection_buf, "Device", RGUI_SETTINGS_BIND_DEVICE, 0);
rgui_list_push(rgui->selection_buf, "Device Type", RGUI_SETTINGS_BIND_DEVICE_TYPE, 0);
if (driver.input && driver.input->set_keybinds)
{
rgui_list_push(rgui->selection_buf, "DPad Emulation", RGUI_SETTINGS_BIND_DPAD_EMULATION, 0);
rgui_list_push(rgui->selection_buf, "Up", RGUI_SETTINGS_BIND_UP, 0);
rgui_list_push(rgui->selection_buf, "Down", RGUI_SETTINGS_BIND_DOWN, 0);
rgui_list_push(rgui->selection_buf, "Left", RGUI_SETTINGS_BIND_LEFT, 0);
rgui_list_push(rgui->selection_buf, "Right", RGUI_SETTINGS_BIND_RIGHT, 0);
rgui_list_push(rgui->selection_buf, "A", RGUI_SETTINGS_BIND_A, 0);
rgui_list_push(rgui->selection_buf, "B", RGUI_SETTINGS_BIND_B, 0);
rgui_list_push(rgui->selection_buf, "X", RGUI_SETTINGS_BIND_X, 0);
rgui_list_push(rgui->selection_buf, "Y", RGUI_SETTINGS_BIND_Y, 0);
rgui_list_push(rgui->selection_buf, "Start", RGUI_SETTINGS_BIND_START, 0);
rgui_list_push(rgui->selection_buf, "Select", RGUI_SETTINGS_BIND_SELECT, 0);
rgui_list_push(rgui->selection_buf, "L", RGUI_SETTINGS_BIND_L, 0);
rgui_list_push(rgui->selection_buf, "R", RGUI_SETTINGS_BIND_R, 0);
rgui_list_push(rgui->selection_buf, "L2", RGUI_SETTINGS_BIND_L2, 0);
rgui_list_push(rgui->selection_buf, "R2", RGUI_SETTINGS_BIND_R2, 0);
rgui_list_push(rgui->selection_buf, "L3", RGUI_SETTINGS_BIND_L3, 0);
rgui_list_push(rgui->selection_buf, "R3", RGUI_SETTINGS_BIND_R3, 0);
}
}
static int rgui_viewport_iterate(rgui_handle_t *rgui, rgui_action_t action)
2012-08-21 01:56:07 +00:00
{
rarch_viewport_t *custom = &g_extern.console.screen.viewports.custom_vp;
unsigned menu_type = 0;
rgui_list_get_last(rgui->menu_stack, NULL, &menu_type);
2012-08-21 01:56:07 +00:00
struct retro_game_geometry *geom = &g_extern.system.av_info.geometry;
int stride_x = g_settings.video.scale_integer ?
geom->base_width : 1;
int stride_y = g_settings.video.scale_integer ?
geom->base_height : 1;
2012-08-21 01:56:07 +00:00
switch (action)
{
case RGUI_ACTION_UP:
if (menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT)
{
custom->y -= stride_y;
custom->height += stride_y;
2012-08-21 01:56:07 +00:00
}
else if (custom->height >= (unsigned)stride_y)
custom->height -= stride_y;
if (driver.video_poke->apply_state_changes)
driver.video_poke->apply_state_changes(driver.video_data);
2012-08-21 01:56:07 +00:00
break;
2012-08-21 01:56:07 +00:00
case RGUI_ACTION_DOWN:
if (menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT)
{
custom->y += stride_y;
2013-04-21 08:05:12 +00:00
if (custom->height >= (unsigned)stride_y)
custom->height -= stride_y;
2012-08-21 01:56:07 +00:00
}
else
custom->height += stride_y;
if (driver.video_poke->apply_state_changes)
driver.video_poke->apply_state_changes(driver.video_data);
2012-08-21 01:56:07 +00:00
break;
2012-08-21 01:56:07 +00:00
case RGUI_ACTION_LEFT:
if (menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT)
{
custom->x -= stride_x;
custom->width += stride_x;
2012-08-21 01:56:07 +00:00
}
else if (custom->width >= (unsigned)stride_x)
custom->width -= stride_x;
if (driver.video_poke->apply_state_changes)
driver.video_poke->apply_state_changes(driver.video_data);
2012-08-21 01:56:07 +00:00
break;
2012-08-21 01:56:07 +00:00
case RGUI_ACTION_RIGHT:
if (menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT)
{
custom->x += stride_x;
if (custom->width >= (unsigned)stride_x)
custom->width -= stride_x;
2012-08-21 01:56:07 +00:00
}
else
custom->width += stride_x;
if (driver.video_poke->apply_state_changes)
driver.video_poke->apply_state_changes(driver.video_data);
2012-08-21 01:56:07 +00:00
break;
2012-08-21 01:56:07 +00:00
case RGUI_ACTION_CANCEL:
rgui_list_pop(rgui->menu_stack, &rgui->selection_ptr);
2012-08-21 01:56:07 +00:00
if (menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT_2)
{
rgui_list_push(rgui->menu_stack, "",
RGUI_SETTINGS_CUSTOM_VIEWPORT,
rgui->selection_ptr);
}
2012-08-21 01:56:07 +00:00
break;
2012-08-21 01:56:07 +00:00
case RGUI_ACTION_OK:
rgui_list_pop(rgui->menu_stack, &rgui->selection_ptr);
if (menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT
&& !g_settings.video.scale_integer)
{
rgui_list_push(rgui->menu_stack, "",
RGUI_SETTINGS_CUSTOM_VIEWPORT_2,
rgui->selection_ptr);
}
2012-08-21 01:56:07 +00:00
break;
case RGUI_ACTION_START:
if (!g_settings.video.scale_integer)
{
rarch_viewport_t vp;
driver.video->viewport_info(driver.video_data, &vp);
if (menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT)
{
custom->width += custom->x;
custom->height += custom->y;
custom->x = 0;
custom->y = 0;
}
else
{
custom->width = vp.full_width - custom->x;
custom->height = vp.full_height - custom->y;
}
if (driver.video_poke->apply_state_changes)
driver.video_poke->apply_state_changes(driver.video_data);
}
break;
2012-08-21 01:56:07 +00:00
case RGUI_ACTION_SETTINGS:
rgui_list_pop(rgui->menu_stack, &rgui->selection_ptr);
2012-08-21 01:56:07 +00:00
break;
case RGUI_ACTION_MESSAGE:
rgui->msg_force = true;
break;
2012-08-21 01:56:07 +00:00
default:
break;
}
rgui_list_get_last(rgui->menu_stack, NULL, &menu_type);
2012-08-21 01:56:07 +00:00
render_text(rgui);
const char *base_msg = NULL;
char msg[64];
if (g_settings.video.scale_integer)
{
custom->x = 0;
custom->y = 0;
custom->width = ((custom->width + geom->base_width - 1) / geom->base_width) * geom->base_width;
custom->height = ((custom->height + geom->base_height - 1) / geom->base_height) * geom->base_height;
base_msg = "Set scale";
snprintf(msg, sizeof(msg), "%s (%4ux%4u, %u x %u scale)",
base_msg,
custom->width, custom->height,
custom->width / geom->base_width,
custom->height / geom->base_height);
}
else
{
if (menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT)
base_msg = "Set Upper-Left Corner";
else if (menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT_2)
base_msg = "Set Bottom-Right Corner";
snprintf(msg, sizeof(msg), "%s (%d, %d : %4ux%4u)",
base_msg, custom->x, custom->y, custom->width, custom->height);
}
render_messagebox(rgui, msg);
2013-01-11 03:36:40 +00:00
if (!custom->width)
custom->width = stride_x;
if (!custom->height)
custom->height = stride_y;
aspectratio_lut[ASPECT_RATIO_CUSTOM].value =
(float)custom->width / custom->height;
if (driver.video_poke->apply_state_changes)
driver.video_poke->apply_state_changes(driver.video_data);
2013-01-11 03:36:40 +00:00
return 0;
2012-08-21 01:56:07 +00:00
}
static int rgui_settings_iterate(rgui_handle_t *rgui, rgui_action_t action)
{
rgui->frame_buf_pitch = RGUI_WIDTH * 2;
unsigned type = 0;
2013-03-17 20:18:56 +00:00
const char *label = NULL;
if (action != RGUI_ACTION_REFRESH)
rgui_list_get_at_offset(rgui->selection_buf, rgui->selection_ptr, &label, &type);
2013-03-17 20:18:56 +00:00
if (type == RGUI_SETTINGS_CORE)
2013-04-27 13:14:59 +00:00
{
#if defined(HAVE_DYNAMIC)
2013-03-17 20:18:56 +00:00
label = rgui->libretro_dir;
#elif defined(HAVE_LIBRETRO_MANAGEMENT)
label = default_paths.core_dir;
2013-04-27 13:14:59 +00:00
#else
label = ""; // Shouldn't happen ...
#endif
2013-04-27 13:14:59 +00:00
}
else if (type == RGUI_SETTINGS_DISK_APPEND)
label = rgui->base_path;
2013-03-17 20:18:56 +00:00
const char *dir = NULL;
unsigned menu_type = 0;
rgui_list_get_last(rgui->menu_stack, &dir, &menu_type);
if (rgui->need_refresh)
action = RGUI_ACTION_NOOP;
2012-07-16 21:57:43 +00:00
switch (action)
{
case RGUI_ACTION_UP:
if (rgui->selection_ptr > 0)
rgui->selection_ptr--;
2012-07-16 21:57:43 +00:00
else
rgui->selection_ptr = rgui->selection_buf->size - 1;
2012-07-16 21:57:43 +00:00
break;
case RGUI_ACTION_DOWN:
if (rgui->selection_ptr + 1 < rgui->selection_buf->size)
rgui->selection_ptr++;
2012-07-16 21:57:43 +00:00
else
rgui->selection_ptr = 0;
2012-07-16 21:57:43 +00:00
break;
2013-04-20 23:25:56 +00:00
case RGUI_ACTION_CANCEL:
if (rgui->menu_stack->size > 1)
{
rgui_list_pop(rgui->menu_stack, &rgui->selection_ptr);
rgui->need_refresh = true;
}
break;
case RGUI_ACTION_LEFT:
2012-07-16 21:57:43 +00:00
case RGUI_ACTION_RIGHT:
case RGUI_ACTION_OK:
case RGUI_ACTION_START:
2013-04-07 21:39:52 +00:00
if (type == RGUI_SETTINGS_OPEN_FILEBROWSER && action == RGUI_ACTION_OK)
{
rgui_list_push(rgui->menu_stack, rgui->base_path, RGUI_FILE_DIRECTORY, rgui->selection_ptr);
rgui->selection_ptr = 0;
2013-04-07 21:39:52 +00:00
rgui->need_refresh = true;
}
2013-05-21 02:17:26 +00:00
else if ((type == RGUI_SETTINGS_OPEN_HISTORY || menu_type_is_directory_browser(type)) && action == RGUI_ACTION_OK)
2013-04-27 23:35:31 +00:00
{
2013-05-21 02:17:26 +00:00
rgui_list_push(rgui->menu_stack, "", type, rgui->selection_ptr);
2013-04-27 23:35:31 +00:00
rgui->selection_ptr = 0;
rgui->need_refresh = true;
}
2013-04-27 13:14:59 +00:00
else if ((menu_type_is_settings(type) || type == RGUI_SETTINGS_CORE || type == RGUI_SETTINGS_DISK_APPEND) && action == RGUI_ACTION_OK)
{
rgui_list_push(rgui->menu_stack, label, type, rgui->selection_ptr);
rgui->selection_ptr = 0;
rgui->need_refresh = true;
}
2012-08-21 01:56:07 +00:00
else if (type == RGUI_SETTINGS_CUSTOM_VIEWPORT && action == RGUI_ACTION_OK)
{
rgui_list_push(rgui->menu_stack, "", type, rgui->selection_ptr);
// Start with something sane.
rarch_viewport_t *custom = &g_extern.console.screen.viewports.custom_vp;
driver.video->viewport_info(driver.video_data, custom);
aspectratio_lut[ASPECT_RATIO_CUSTOM].value =
(float)custom->width / custom->height;
g_settings.video.aspect_ratio_idx = ASPECT_RATIO_CUSTOM;
if (driver.video_poke->set_aspect_ratio)
driver.video_poke->set_aspect_ratio(driver.video_data,
g_settings.video.aspect_ratio_idx);
2012-08-21 01:56:07 +00:00
}
else
2013-01-11 03:36:40 +00:00
{
int ret = rgui_settings_toggle_setting(rgui, type, action, menu_type);
if (ret)
2013-01-11 03:36:40 +00:00
return ret;
}
2012-07-16 21:57:43 +00:00
break;
case RGUI_ACTION_REFRESH:
rgui->selection_ptr = 0;
rgui->need_refresh = true;
2012-07-16 21:57:43 +00:00
break;
case RGUI_ACTION_MESSAGE:
rgui->msg_force = true;
break;
2012-07-16 21:57:43 +00:00
default:
break;
}
rgui_list_get_last(rgui->menu_stack, &dir, &menu_type);
if (rgui->need_refresh && !(menu_type == RGUI_FILE_DIRECTORY ||
#ifdef HAVE_SHADER_MANAGER
menu_type_is_shader_browser(menu_type) ||
#endif
2013-05-21 02:17:26 +00:00
menu_type_is_directory_browser(menu_type) ||
#ifdef HAVE_OVERLAY
menu_type == RGUI_SETTINGS_OVERLAY_PRESET ||
#endif
2013-04-27 23:35:31 +00:00
menu_type == RGUI_SETTINGS_CORE || menu_type == RGUI_SETTINGS_DISK_APPEND ||
menu_type == RGUI_SETTINGS_OPEN_HISTORY))
{
rgui->need_refresh = false;
if (menu_type == RGUI_SETTINGS_INPUT_OPTIONS)
rgui_settings_controller_populate_entries(rgui);
else if (menu_type == RGUI_SETTINGS_PATH_OPTIONS)
rgui_settings_path_populate_entries(rgui);
else if (menu_type == RGUI_SETTINGS_OPTIONS)
2013-05-05 20:02:30 +00:00
rgui_settings_options_populate_entries(rgui);
else if (menu_type == RGUI_SETTINGS_CORE_OPTIONS)
rgui_settings_core_options_populate_entries(rgui);
else if (menu_type == RGUI_SETTINGS_AUDIO_OPTIONS)
rgui_settings_audio_options_populate_entries(rgui);
else if (menu_type == RGUI_SETTINGS_DISK_OPTIONS)
rgui_settings_disc_options_populate_entries(rgui);
else if (menu_type == RGUI_SETTINGS_VIDEO_OPTIONS)
rgui_settings_video_options_populate_entries(rgui);
#ifdef HAVE_SHADER_MANAGER
else if (menu_type == RGUI_SETTINGS_SHADER_OPTIONS)
rgui_settings_shader_manager_populate_entries(rgui);
#endif
else
rgui_settings_populate_entries(rgui);
}
render_text(rgui);
2012-07-16 21:57:43 +00:00
2013-01-11 03:36:40 +00:00
return 0;
2012-07-16 21:57:43 +00:00
}
2013-04-27 23:35:31 +00:00
static void history_parse(rgui_handle_t *rgui)
{
size_t history_size = rom_history_size(rgui->history);
for (size_t i = 0; i < history_size; i++)
{
const char *path = NULL;
const char *core_path = NULL;
const char *core_name = NULL;
rom_history_get_index(rgui->history, i,
&path, &core_path, &core_name);
char fill_buf[PATH_MAX];
if (path)
{
char path_short[PATH_MAX];
fill_pathname(path_short, path_basename(path), "", sizeof(path_short));
snprintf(fill_buf, sizeof(fill_buf), "%s (%s)",
path_short, core_name);
}
else
strlcpy(fill_buf, core_name, sizeof(fill_buf));
2013-04-27 23:35:31 +00:00
rgui_list_push(rgui->selection_buf, fill_buf, RGUI_FILE_PLAIN, 0);
}
}
static bool directory_parse(rgui_handle_t *rgui, const char *directory, unsigned menu_type, void *ctx)
2013-03-11 03:21:40 +00:00
{
if (!*directory)
{
#if defined(GEKKO)
#ifdef HW_RVL
rgui_list_push(ctx, "sd:/", menu_type, 0);
rgui_list_push(ctx, "usb:/", menu_type, 0);
2013-03-11 03:21:40 +00:00
#endif
#if !(defined(HAVE_MINIOGC) && defined(HW_RVL))
rgui_list_push(ctx, "carda:/", menu_type, 0);
rgui_list_push(ctx, "cardb:/", menu_type, 0);
#endif
2013-03-11 03:21:40 +00:00
#elif defined(_XBOX1)
rgui_list_push(ctx, "C:\\", menu_type, 0);
rgui_list_push(ctx, "D:\\", menu_type, 0);
rgui_list_push(ctx, "E:\\", menu_type, 0);
rgui_list_push(ctx, "F:\\", menu_type, 0);
rgui_list_push(ctx, "G:\\", menu_type, 0);
#elif defined(_WIN32)
unsigned drives = GetLogicalDrives();
char drive[] = " :\\";
for (unsigned i = 0; i < 32; i++)
{
drive[0] = 'A' + i;
if (drives & (1 << i))
rgui_list_push(ctx, drive, menu_type, 0);
}
2013-03-11 03:21:40 +00:00
#elif defined(__CELLOS_LV2__)
rgui_list_push(ctx, "app_home:/", menu_type, 0);
rgui_list_push(ctx, "dev_hdd0:/", menu_type, 0);
rgui_list_push(ctx, "dev_hdd1:/", menu_type, 0);
rgui_list_push(ctx, "host_root:/", menu_type, 0);
#else
rgui_list_push(ctx, "/", menu_type, 0);
2013-03-11 03:21:40 +00:00
#endif
return true;
2013-03-11 03:21:40 +00:00
}
#if defined(GEKKO) && defined(HW_RVL)
LWP_MutexLock(gx_device_mutex);
int dev = gx_get_device_from_path(directory);
if (dev != -1 && !gx_devices[dev].mounted && gx_devices[dev].interface->isInserted())
fatMountSimple(gx_devices[dev].name, gx_devices[dev].interface);
LWP_MutexUnlock(gx_device_mutex);
#endif
2013-03-17 20:18:56 +00:00
const char *exts;
char ext_buf[1024];
if (menu_type == RGUI_SETTINGS_CORE)
2013-03-17 20:18:56 +00:00
exts = EXT_EXECUTABLES;
#ifdef HAVE_SHADER_MANAGER
2013-04-13 23:27:13 +00:00
else if (menu_type == RGUI_SETTINGS_SHADER_PRESET)
exts = "cgp|glslp";
else if (menu_type_is_shader_browser(menu_type))
2013-04-11 14:01:42 +00:00
exts = "cg|glsl";
#endif
#ifdef HAVE_OVERLAY
else if (menu_type == RGUI_SETTINGS_OVERLAY_PRESET)
exts = "cfg";
#endif
2013-05-21 02:17:26 +00:00
else if (menu_type_is_directory_browser(menu_type))
exts = ""; // we ignore files anyway
2013-03-17 20:18:56 +00:00
else if (rgui->info.valid_extensions)
{
exts = ext_buf;
if (*rgui->info.valid_extensions)
2013-04-30 21:58:32 +00:00
snprintf(ext_buf, sizeof(ext_buf), "%s|zip", rgui->info.valid_extensions);
else
*ext_buf = '\0';
}
2013-03-17 20:18:56 +00:00
else
exts = g_extern.system.valid_extensions;
struct string_list *list = dir_list_new(directory, exts, true);
2013-03-11 03:21:40 +00:00
if (!list)
return false;
dir_list_sort(list, true);
2013-05-21 02:17:26 +00:00
if (menu_type_is_directory_browser(menu_type))
rgui_list_push(ctx, "<Use this directory>", RGUI_FILE_USE_DIRECTORY, 0);
2013-03-11 03:21:40 +00:00
for (size_t i = 0; i < list->size; i++)
{
bool is_dir = list->elems[i].attr.b;
2013-05-21 02:17:26 +00:00
if (menu_type_is_directory_browser(menu_type) && !is_dir)
continue;
2013-03-11 03:21:40 +00:00
#ifdef HAVE_LIBRETRO_MANAGEMENT
if (menu_type == RGUI_SETTINGS_CORE && (is_dir || strcasecmp(list->elems[i].data, SALAMANDER_FILE) == 0))
2013-03-11 03:57:17 +00:00
continue;
#endif
2013-03-11 03:21:40 +00:00
2013-03-16 10:16:55 +00:00
// Need to preserve slash first time.
const char *path = list->elems[i].data;
if (*directory)
path = path_basename(path);
2013-04-12 07:08:07 +00:00
// Push menu_type further down in the chain.
// Needed for shader manager currently.
2013-03-16 10:16:55 +00:00
rgui_list_push(ctx, path,
2013-04-12 07:08:07 +00:00
is_dir ? menu_type : RGUI_FILE_PLAIN, 0);
2013-03-11 03:21:40 +00:00
}
string_list_free(list);
return true;
}
2013-04-18 21:00:27 +00:00
int rgui_iterate(rgui_handle_t *rgui)
2012-05-06 02:04:33 +00:00
{
2013-04-21 08:05:12 +00:00
rgui_action_t action = RGUI_ACTION_NOOP;
2013-04-18 21:00:27 +00:00
// don't run anything first frame, only capture held inputs for old_input_state
if (rgui->trigger_state & (1ULL << DEVICE_NAV_UP))
2013-04-18 21:00:27 +00:00
action = RGUI_ACTION_UP;
else if (rgui->trigger_state & (1ULL << DEVICE_NAV_DOWN))
2013-04-18 21:00:27 +00:00
action = RGUI_ACTION_DOWN;
else if (rgui->trigger_state & (1ULL << DEVICE_NAV_LEFT))
2013-04-18 21:00:27 +00:00
action = RGUI_ACTION_LEFT;
else if (rgui->trigger_state & (1ULL << DEVICE_NAV_RIGHT))
2013-04-18 21:00:27 +00:00
action = RGUI_ACTION_RIGHT;
else if (rgui->trigger_state & (1ULL << DEVICE_NAV_B))
2013-04-18 21:00:27 +00:00
action = RGUI_ACTION_CANCEL;
else if (rgui->trigger_state & (1ULL << DEVICE_NAV_A))
2013-04-18 21:00:27 +00:00
action = RGUI_ACTION_OK;
else if (rgui->trigger_state & (1ULL << DEVICE_NAV_SELECT))
2013-04-18 21:00:27 +00:00
action = RGUI_ACTION_START;
else if (rgui->trigger_state & (1ULL << DEVICE_NAV_START))
2013-04-18 21:00:27 +00:00
action = RGUI_ACTION_SETTINGS;
const char *dir = 0;
unsigned menu_type = 0;
rgui_list_get_last(rgui->menu_stack, &dir, &menu_type);
2013-01-13 20:26:12 +00:00
int ret = 0;
2013-04-18 21:00:27 +00:00
if (driver.video_poke && driver.video_poke->set_texture_enable)
driver.video_poke->set_texture_frame(driver.video_data, menu_framebuf,
false, RGUI_WIDTH, RGUI_HEIGHT, 1.0f);
if (menu_type_is_settings(menu_type))
return rgui_settings_iterate(rgui, action);
else if (menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT || menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT_2)
2012-08-21 01:56:07 +00:00
return rgui_viewport_iterate(rgui, action);
if (rgui->need_refresh && action != RGUI_ACTION_MESSAGE)
action = RGUI_ACTION_NOOP;
2012-05-06 02:04:33 +00:00
switch (action)
{
case RGUI_ACTION_UP:
if (rgui->selection_ptr > 0)
rgui->selection_ptr--;
2012-06-27 04:43:25 +00:00
else
rgui->selection_ptr = rgui->selection_buf->size - 1;
2012-05-06 02:04:33 +00:00
break;
case RGUI_ACTION_DOWN:
if (rgui->selection_ptr + 1 < rgui->selection_buf->size)
rgui->selection_ptr++;
2012-06-27 04:43:25 +00:00
else
rgui->selection_ptr = 0;
2012-05-06 02:04:33 +00:00
break;
case RGUI_ACTION_LEFT:
2013-04-04 20:27:16 +00:00
if (rgui->selection_ptr > 8)
rgui->selection_ptr -= 8;
else
rgui->selection_ptr = 0;
break;
case RGUI_ACTION_RIGHT:
if (rgui->selection_ptr + 8 < rgui->selection_buf->size)
rgui->selection_ptr += 8;
else
rgui->selection_ptr = rgui->selection_buf->size - 1;
break;
2012-05-06 02:04:33 +00:00
case RGUI_ACTION_CANCEL:
if (rgui->menu_stack->size > 1)
2012-05-06 02:04:33 +00:00
{
rgui->need_refresh = true;
rgui_list_pop(rgui->menu_stack, &rgui->selection_ptr);
2012-05-06 02:04:33 +00:00
}
break;
case RGUI_ACTION_OK:
{
if (rgui->selection_buf->size == 0)
2013-01-11 03:36:40 +00:00
return 0;
2012-05-06 02:04:33 +00:00
2012-07-28 19:36:03 +00:00
const char *path = 0;
unsigned type = 0;
rgui_list_get_at_offset(rgui->selection_buf, rgui->selection_ptr, &path, &type);
2012-05-06 02:04:33 +00:00
if (
#ifdef HAVE_SHADER_MANAGER
menu_type_is_shader_browser(type) ||
#endif
2013-05-21 02:17:26 +00:00
menu_type_is_directory_browser(type) ||
#ifdef HAVE_OVERLAY
type == RGUI_SETTINGS_OVERLAY_PRESET ||
#endif
type == RGUI_SETTINGS_CORE ||
2013-04-27 13:14:59 +00:00
type == RGUI_SETTINGS_DISK_APPEND ||
type == RGUI_FILE_DIRECTORY)
2012-05-06 02:04:33 +00:00
{
char cat_path[PATH_MAX];
fill_pathname_join(cat_path, dir, path, sizeof(cat_path));
2012-05-06 02:04:33 +00:00
rgui_list_push(rgui->menu_stack, cat_path, type, rgui->selection_ptr);
rgui->selection_ptr = 0;
rgui->need_refresh = true;
}
2012-05-06 02:04:33 +00:00
else
{
#ifdef HAVE_SHADER_MANAGER
if (menu_type_is_shader_browser(menu_type))
{
2013-04-13 23:27:13 +00:00
if (menu_type == RGUI_SETTINGS_SHADER_PRESET)
{
char shader_path[PATH_MAX];
fill_pathname_join(shader_path, dir, path, sizeof(shader_path));
shader_manager_set_preset(&rgui->shader, gfx_shader_parse_type(shader_path, RARCH_SHADER_NONE),
2013-04-13 23:27:13 +00:00
shader_path);
}
else
{
unsigned pass = (menu_type - RGUI_SETTINGS_SHADER_0) / 3;
fill_pathname_join(rgui->shader.pass[pass].source.cg,
dir, path, sizeof(rgui->shader.pass[pass].source.cg));
}
// Pop stack until we hit shader manager again.
rgui_flush_menu_stack_type(rgui, RGUI_SETTINGS_SHADER_OPTIONS);
}
else
#endif
if (menu_type == RGUI_SETTINGS_CORE)
{
2013-03-11 04:34:25 +00:00
#if defined(HAVE_DYNAMIC)
fill_pathname_join(g_settings.libretro, dir, path, sizeof(g_settings.libretro));
2013-03-17 20:18:56 +00:00
libretro_free_system_info(&rgui->info);
libretro_get_system_info(g_settings.libretro, &rgui->info,
&rgui->load_no_rom);
// No ROM needed for this core, load game immediately.
if (rgui->load_no_rom)
{
g_extern.lifecycle_mode_state |= (1ULL << MODE_LOAD_GAME);
*g_extern.fullpath = '\0';
rgui->msg_force = true;
ret = -1;
}
2013-03-17 20:18:56 +00:00
// Core selection on non-console just updates directory listing.
// Will take affect on new ROM load.
2013-05-21 22:29:48 +00:00
#elif defined(GEKKO) && defined(HW_RVL)
rarch_environment_cb(RETRO_ENVIRONMENT_SET_LIBRETRO_PATH, (void*)path);
2013-03-17 20:18:56 +00:00
fill_pathname_join(g_extern.fullpath, default_paths.core_dir,
SALAMANDER_FILE, sizeof(g_extern.fullpath));
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME);
g_extern.lifecycle_mode_state |= (1ULL << MODE_EXITSPAWN);
2013-03-17 20:18:56 +00:00
ret = -1;
2013-03-11 04:34:25 +00:00
#endif
rgui_flush_menu_stack(rgui);
}
#ifdef HAVE_OVERLAY
else if (menu_type == RGUI_SETTINGS_OVERLAY_PRESET)
{
fill_pathname_join(g_settings.input.overlay, dir, path, sizeof(g_settings.input.overlay));
if (driver.overlay)
input_overlay_free(driver.overlay);
driver.overlay = input_overlay_new(g_settings.input.overlay);
if (!driver.overlay)
RARCH_ERR("Failed to load overlay.\n");
rgui_flush_menu_stack_type(rgui, RGUI_SETTINGS_INPUT_OPTIONS);
}
#endif
2013-04-27 13:14:59 +00:00
else if (menu_type == RGUI_SETTINGS_DISK_APPEND)
{
char image[PATH_MAX];
fill_pathname_join(image, dir, path, sizeof(image));
rarch_disk_control_append_image(image);
g_extern.lifecycle_mode_state |= 1ULL << MODE_GAME;
rgui_flush_menu_stack(rgui);
2013-04-27 13:14:59 +00:00
ret = -1;
}
2013-04-27 23:35:31 +00:00
else if (menu_type == RGUI_SETTINGS_OPEN_HISTORY)
{
load_menu_game_history(rgui->selection_ptr);
rgui_flush_menu_stack(rgui);
2013-04-27 23:35:31 +00:00
ret = -1;
}
2013-05-21 02:17:26 +00:00
else if (menu_type == RGUI_BROWSER_DIR_PATH)
{
strlcpy(g_settings.rgui_browser_directory, dir, sizeof(g_settings.rgui_browser_directory));
strlcpy(rgui->base_path, dir, sizeof(rgui->base_path));
rgui_flush_menu_stack_type(rgui, RGUI_SETTINGS_PATH_OPTIONS);
}
#ifdef HAVE_SCREENSHOTS
else if (menu_type == RGUI_SCREENSHOT_DIR_PATH)
{
strlcpy(g_settings.screenshot_directory, dir, sizeof(g_settings.screenshot_directory));
rgui_flush_menu_stack_type(rgui, RGUI_SETTINGS_PATH_OPTIONS);
}
#endif
2013-05-21 02:17:26 +00:00
else if (menu_type == RGUI_SAVEFILE_DIR_PATH)
{
strlcpy(g_extern.savefile_dir, dir, sizeof(g_extern.savefile_dir));
rgui_flush_menu_stack_type(rgui, RGUI_SETTINGS_PATH_OPTIONS);
}
#ifdef HAVE_OVERLAY
else if (menu_type == RGUI_OVERLAY_DIR_PATH)
{
strlcpy(g_extern.overlay_dir, dir, sizeof(g_extern.overlay_dir));
rgui_flush_menu_stack_type(rgui, RGUI_SETTINGS_PATH_OPTIONS);
}
#endif
2013-05-21 02:17:26 +00:00
else if (menu_type == RGUI_SAVESTATE_DIR_PATH)
{
strlcpy(g_extern.savestate_dir, dir, sizeof(g_extern.savestate_dir));
rgui_flush_menu_stack_type(rgui, RGUI_SETTINGS_PATH_OPTIONS);
}
2013-09-15 21:09:23 +00:00
#ifdef HAVE_DYNAMIC
else if (menu_type == RGUI_LIBRETRO_DIR_PATH)
{
strlcpy(rgui->libretro_dir, dir, sizeof(g_extern.savestate_dir));
rgui_flush_menu_stack_type(rgui, RGUI_SETTINGS_PATH_OPTIONS);
}
2013-09-15 21:09:23 +00:00
#endif
2013-05-21 02:17:26 +00:00
else if (menu_type == RGUI_SHADER_DIR_PATH)
{
strlcpy(g_settings.video.shader_dir, dir, sizeof(g_settings.video.shader_dir));
rgui_flush_menu_stack_type(rgui, RGUI_SETTINGS_PATH_OPTIONS);
}
else if (menu_type == RGUI_SYSTEM_DIR_PATH)
{
strlcpy(g_settings.system_directory, dir, sizeof(g_settings.system_directory));
rgui_flush_menu_stack_type(rgui, RGUI_SETTINGS_PATH_OPTIONS);
}
else
{
fill_pathname_join(g_extern.fullpath, dir, path, sizeof(g_extern.fullpath));
2013-01-22 00:12:02 +00:00
g_extern.lifecycle_mode_state |= (1ULL << MODE_LOAD_GAME);
rgui_flush_menu_stack(rgui);
rgui->msg_force = true;
2013-03-17 20:18:56 +00:00
ret = -1;
}
2012-05-06 02:04:33 +00:00
}
break;
}
case RGUI_ACTION_REFRESH:
rgui->selection_ptr = 0;
2012-05-06 02:04:33 +00:00
rgui->need_refresh = true;
break;
2012-07-16 21:57:43 +00:00
case RGUI_ACTION_SETTINGS:
rgui->need_refresh = true;
while (rgui->menu_stack->size > 1)
rgui_list_pop(rgui->menu_stack, &rgui->selection_ptr);
return rgui_settings_iterate(rgui, RGUI_ACTION_REFRESH);
case RGUI_ACTION_MESSAGE:
rgui->msg_force = true;
break;
2012-05-06 02:04:33 +00:00
default:
2012-06-30 01:53:00 +00:00
break;
2012-05-06 02:04:33 +00:00
}
// refresh values in case the stack changed
rgui_list_get_last(rgui->menu_stack, &dir, &menu_type);
if (rgui->need_refresh && (menu_type == RGUI_FILE_DIRECTORY ||
#ifdef HAVE_SHADER_MANAGER
menu_type_is_shader_browser(menu_type) ||
#endif
2013-05-21 02:17:26 +00:00
menu_type_is_directory_browser(menu_type) ||
#ifdef HAVE_OVERLAY
menu_type == RGUI_SETTINGS_OVERLAY_PRESET ||
#endif
2013-04-27 23:35:31 +00:00
menu_type == RGUI_SETTINGS_CORE ||
menu_type == RGUI_SETTINGS_OPEN_HISTORY ||
menu_type == RGUI_SETTINGS_DISK_APPEND))
2012-05-06 02:04:33 +00:00
{
rgui->need_refresh = false;
rgui_list_clear(rgui->selection_buf);
2013-04-27 23:35:31 +00:00
if (menu_type == RGUI_SETTINGS_OPEN_HISTORY)
history_parse(rgui);
else
directory_parse(rgui, dir, menu_type, rgui->selection_buf);
// Before a refresh, we could have deleted a file on disk, causing
// selection_ptr to suddendly be out of range. Ensure it doesn't overflow.
if (rgui->selection_ptr >= rgui->selection_buf->size && rgui->selection_buf->size)
rgui->selection_ptr = rgui->selection_buf->size - 1;
else if (!rgui->selection_buf->size)
rgui->selection_ptr = 0;
2012-05-06 02:04:33 +00:00
}
render_text(rgui);
2013-01-11 03:36:40 +00:00
2013-01-13 20:26:12 +00:00
return ret;
2012-05-06 02:04:33 +00:00
}
2013-03-09 14:33:44 +00:00
int rgui_input_postprocess(void *data, uint64_t old_state)
2013-03-09 14:33:44 +00:00
{
(void)data;
2013-04-18 21:00:27 +00:00
2013-04-17 19:11:13 +00:00
int ret = 0;
if ((rgui->trigger_state & (1ULL << DEVICE_NAV_MENU)) &&
g_extern.main_is_init &&
!g_extern.libretro_dummy)
2013-03-09 14:33:44 +00:00
{
2013-05-05 13:20:45 +00:00
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU_INGAME_EXIT);
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
ret = -1;
2013-03-09 14:33:44 +00:00
}
2013-05-05 13:20:45 +00:00
if (g_extern.lifecycle_mode_state & (1ULL << MODE_MENU_INGAME_EXIT))
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU_INGAME_EXIT);
2013-04-17 19:11:13 +00:00
2013-04-27 22:23:58 +00:00
if (ret < 0)
{
unsigned type = 0;
rgui_list_get_last(rgui->menu_stack, NULL, &type);
while (type != RGUI_SETTINGS)
{
rgui_list_pop(rgui->menu_stack, &rgui->selection_ptr);
rgui_list_get_last(rgui->menu_stack, NULL, &type);
}
}
2013-04-17 19:11:13 +00:00
return ret;
2013-03-09 14:33:44 +00:00
}