mirror of
https://github.com/libretro/RetroArch
synced 2025-03-30 16:20:27 +00:00
(Menu) Split up reusable menu_action code to menu_action.c
This commit is contained in:
parent
81073c96ef
commit
4a14658278
1
Makefile
1
Makefile
@ -133,6 +133,7 @@ ifeq ($(HAVE_MENU_COMMON), 1)
|
||||
frontend/menu/menu_input_line_cb.o \
|
||||
frontend/menu/menu_common.o \
|
||||
frontend/menu/menu_navigation.o \
|
||||
frontend/menu/menu_action.o \
|
||||
frontend/menu/menu_entries.o
|
||||
endif
|
||||
|
||||
|
@ -92,6 +92,7 @@ ifeq ($(HAVE_MENU_COMMON), 1)
|
||||
frontend/menu/menu_input_line_cb.o \
|
||||
frontend/menu/menu_common.o \
|
||||
frontend/menu/menu_navigation.o \
|
||||
frontend/menu/menu_action.o \
|
||||
frontend/menu/menu_entries.o
|
||||
endif
|
||||
|
||||
|
@ -144,6 +144,7 @@ ifeq ($(HAVE_MENU_COMMON), 1)
|
||||
frontend/menu/menu_input_line_cb.o \
|
||||
frontend/menu/menu_common.o \
|
||||
frontend/menu/menu_navigation.o \
|
||||
frontend/menu/menu_action.o \
|
||||
frontend/menu/menu_entries.o
|
||||
endif
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include "menu_common_backend.h"
|
||||
#include "../menu_action.h"
|
||||
#include "../menu_entries.h"
|
||||
#include "../menu_navigation.h"
|
||||
#include "../menu_input_line_cb.h"
|
||||
@ -208,44 +209,6 @@ static int menu_common_setting_set_perf(unsigned setting, unsigned action,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void menu_common_setting_set_current_boolean(
|
||||
rarch_setting_t *setting, unsigned action)
|
||||
{
|
||||
if (
|
||||
!strcmp(setting->name, "savestate") ||
|
||||
!strcmp(setting->name, "loadstate"))
|
||||
{
|
||||
if (action == MENU_ACTION_START)
|
||||
g_settings.state_slot = 0;
|
||||
else if (action == MENU_ACTION_LEFT)
|
||||
{
|
||||
// Slot -1 is (auto) slot.
|
||||
if (g_settings.state_slot >= 0)
|
||||
g_settings.state_slot--;
|
||||
}
|
||||
else if (action == MENU_ACTION_RIGHT)
|
||||
g_settings.state_slot++;
|
||||
else if (action == MENU_ACTION_OK)
|
||||
*setting->value.boolean = !(*setting->value.boolean);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_OK:
|
||||
case MENU_ACTION_LEFT:
|
||||
case MENU_ACTION_RIGHT:
|
||||
*setting->value.boolean = !(*setting->value.boolean);
|
||||
break;
|
||||
case MENU_ACTION_START:
|
||||
*setting->value.boolean = setting->default_value.boolean;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (setting->change_handler)
|
||||
setting->change_handler(setting);
|
||||
}
|
||||
|
||||
static void menu_common_setting_set_current_path_selection(
|
||||
rarch_setting_t *setting, const char *start_path,
|
||||
@ -268,140 +231,6 @@ static void menu_common_setting_set_current_path_selection(
|
||||
setting->change_handler(setting);
|
||||
}
|
||||
|
||||
void menu_common_setting_set_current_fraction(
|
||||
rarch_setting_t *setting, unsigned action)
|
||||
{
|
||||
if (!strcmp(setting->name, "video_refresh_rate_auto"))
|
||||
{
|
||||
if (action == MENU_ACTION_START)
|
||||
g_extern.measure_data.frame_time_samples_count = 0;
|
||||
else if (action == MENU_ACTION_OK)
|
||||
{
|
||||
double refresh_rate, 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. */
|
||||
rarch_main_command(RARCH_CMD_VIDEO_SET_BLOCKING_STATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(setting->name, "fastforward_ratio"))
|
||||
{
|
||||
bool clamp_value = false;
|
||||
if (action == MENU_ACTION_START)
|
||||
*setting->value.fraction = setting->default_value.fraction;
|
||||
else if (action == MENU_ACTION_LEFT)
|
||||
{
|
||||
*setting->value.fraction -= setting->step;
|
||||
|
||||
/* Avoid potential rounding errors when going from 1.1 to 1.0. */
|
||||
if (*setting->value.fraction < 0.95f)
|
||||
*setting->value.fraction = setting->default_value.fraction;
|
||||
else
|
||||
clamp_value = true;
|
||||
}
|
||||
else if (action == MENU_ACTION_RIGHT)
|
||||
{
|
||||
*setting->value.fraction += setting->step;
|
||||
clamp_value = true;
|
||||
}
|
||||
if (clamp_value)
|
||||
g_settings.fastforward_ratio =
|
||||
max(min(*setting->value.fraction, setting->max), 1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_LEFT:
|
||||
*setting->value.fraction =
|
||||
*setting->value.fraction - setting->step;
|
||||
|
||||
if (setting->enforce_minrange)
|
||||
{
|
||||
if (*setting->value.fraction < setting->min)
|
||||
*setting->value.fraction = setting->min;
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_ACTION_RIGHT:
|
||||
case MENU_ACTION_OK:
|
||||
*setting->value.fraction =
|
||||
*setting->value.fraction + setting->step;
|
||||
|
||||
if (setting->enforce_maxrange)
|
||||
{
|
||||
if (*setting->value.fraction > setting->max)
|
||||
*setting->value.fraction = setting->max;
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_ACTION_START:
|
||||
*setting->value.fraction = setting->default_value.fraction;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (setting->change_handler)
|
||||
setting->change_handler(setting);
|
||||
}
|
||||
|
||||
void menu_common_setting_set_current_unsigned_integer(
|
||||
rarch_setting_t *setting, unsigned id, unsigned action)
|
||||
{
|
||||
if (id == MENU_FILE_LINEFEED)
|
||||
{
|
||||
if (action == MENU_ACTION_OK)
|
||||
menu_key_start_line(driver.menu, setting->short_description,
|
||||
setting->name, st_uint_callback);
|
||||
else if (action == MENU_ACTION_START)
|
||||
*setting->value.unsigned_integer =
|
||||
setting->default_value.unsigned_integer;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_LEFT:
|
||||
if (*setting->value.unsigned_integer != setting->min)
|
||||
*setting->value.unsigned_integer =
|
||||
*setting->value.unsigned_integer - setting->step;
|
||||
|
||||
if (setting->enforce_minrange)
|
||||
{
|
||||
if (*setting->value.unsigned_integer < setting->min)
|
||||
*setting->value.unsigned_integer = setting->min;
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_ACTION_RIGHT:
|
||||
case MENU_ACTION_OK:
|
||||
*setting->value.unsigned_integer =
|
||||
*setting->value.unsigned_integer + setting->step;
|
||||
|
||||
if (setting->enforce_maxrange)
|
||||
{
|
||||
if (*setting->value.unsigned_integer > setting->max)
|
||||
*setting->value.unsigned_integer = setting->max;
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_ACTION_START:
|
||||
*setting->value.unsigned_integer =
|
||||
setting->default_value.unsigned_integer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (setting->change_handler)
|
||||
setting->change_handler(setting);
|
||||
}
|
||||
|
||||
|
||||
static void menu_common_setting_set_current_string_path(
|
||||
rarch_setting_t *setting, const char *dir, const char *path)
|
||||
{
|
||||
|
@ -73,11 +73,5 @@ enum
|
||||
};
|
||||
#endif
|
||||
|
||||
void menu_common_setting_set_current_boolean(
|
||||
rarch_setting_t *setting, unsigned action);
|
||||
void menu_common_setting_set_current_fraction(
|
||||
rarch_setting_t *setting, unsigned action);
|
||||
void menu_common_setting_set_current_unsigned_integer(
|
||||
rarch_setting_t *setting, unsigned id, unsigned action);
|
||||
|
||||
#endif
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include "menu_common_backend.h"
|
||||
#include "../menu_action.h"
|
||||
#include "../menu_navigation.h"
|
||||
|
||||
#include "../../../gfx/gfx_common.h"
|
||||
|
191
frontend/menu/menu_action.c
Normal file
191
frontend/menu/menu_action.c
Normal file
@ -0,0 +1,191 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2014 - Daniel De Matteis
|
||||
*
|
||||
* 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 "menu_common.h"
|
||||
#include "menu_input_line_cb.h"
|
||||
#include "menu_action.h"
|
||||
|
||||
void menu_common_setting_set_current_boolean(
|
||||
rarch_setting_t *setting, unsigned action)
|
||||
{
|
||||
if (
|
||||
!strcmp(setting->name, "savestate") ||
|
||||
!strcmp(setting->name, "loadstate"))
|
||||
{
|
||||
if (action == MENU_ACTION_START)
|
||||
g_settings.state_slot = 0;
|
||||
else if (action == MENU_ACTION_LEFT)
|
||||
{
|
||||
// Slot -1 is (auto) slot.
|
||||
if (g_settings.state_slot >= 0)
|
||||
g_settings.state_slot--;
|
||||
}
|
||||
else if (action == MENU_ACTION_RIGHT)
|
||||
g_settings.state_slot++;
|
||||
else if (action == MENU_ACTION_OK)
|
||||
*setting->value.boolean = !(*setting->value.boolean);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_OK:
|
||||
case MENU_ACTION_LEFT:
|
||||
case MENU_ACTION_RIGHT:
|
||||
*setting->value.boolean = !(*setting->value.boolean);
|
||||
break;
|
||||
case MENU_ACTION_START:
|
||||
*setting->value.boolean = setting->default_value.boolean;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (setting->change_handler)
|
||||
setting->change_handler(setting);
|
||||
}
|
||||
|
||||
void menu_common_setting_set_current_unsigned_integer(
|
||||
rarch_setting_t *setting, unsigned id, unsigned action)
|
||||
{
|
||||
if (id == MENU_FILE_LINEFEED)
|
||||
{
|
||||
if (action == MENU_ACTION_OK)
|
||||
menu_key_start_line(driver.menu, setting->short_description,
|
||||
setting->name, st_uint_callback);
|
||||
else if (action == MENU_ACTION_START)
|
||||
*setting->value.unsigned_integer =
|
||||
setting->default_value.unsigned_integer;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_LEFT:
|
||||
if (*setting->value.unsigned_integer != setting->min)
|
||||
*setting->value.unsigned_integer =
|
||||
*setting->value.unsigned_integer - setting->step;
|
||||
|
||||
if (setting->enforce_minrange)
|
||||
{
|
||||
if (*setting->value.unsigned_integer < setting->min)
|
||||
*setting->value.unsigned_integer = setting->min;
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_ACTION_RIGHT:
|
||||
case MENU_ACTION_OK:
|
||||
*setting->value.unsigned_integer =
|
||||
*setting->value.unsigned_integer + setting->step;
|
||||
|
||||
if (setting->enforce_maxrange)
|
||||
{
|
||||
if (*setting->value.unsigned_integer > setting->max)
|
||||
*setting->value.unsigned_integer = setting->max;
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_ACTION_START:
|
||||
*setting->value.unsigned_integer =
|
||||
setting->default_value.unsigned_integer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (setting->change_handler)
|
||||
setting->change_handler(setting);
|
||||
}
|
||||
|
||||
void menu_common_setting_set_current_fraction(
|
||||
rarch_setting_t *setting, unsigned action)
|
||||
{
|
||||
if (!strcmp(setting->name, "video_refresh_rate_auto"))
|
||||
{
|
||||
if (action == MENU_ACTION_START)
|
||||
g_extern.measure_data.frame_time_samples_count = 0;
|
||||
else if (action == MENU_ACTION_OK)
|
||||
{
|
||||
double refresh_rate, 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. */
|
||||
rarch_main_command(RARCH_CMD_VIDEO_SET_BLOCKING_STATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(setting->name, "fastforward_ratio"))
|
||||
{
|
||||
bool clamp_value = false;
|
||||
if (action == MENU_ACTION_START)
|
||||
*setting->value.fraction = setting->default_value.fraction;
|
||||
else if (action == MENU_ACTION_LEFT)
|
||||
{
|
||||
*setting->value.fraction -= setting->step;
|
||||
|
||||
/* Avoid potential rounding errors when going from 1.1 to 1.0. */
|
||||
if (*setting->value.fraction < 0.95f)
|
||||
*setting->value.fraction = setting->default_value.fraction;
|
||||
else
|
||||
clamp_value = true;
|
||||
}
|
||||
else if (action == MENU_ACTION_RIGHT)
|
||||
{
|
||||
*setting->value.fraction += setting->step;
|
||||
clamp_value = true;
|
||||
}
|
||||
if (clamp_value)
|
||||
g_settings.fastforward_ratio =
|
||||
max(min(*setting->value.fraction, setting->max), 1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_LEFT:
|
||||
*setting->value.fraction =
|
||||
*setting->value.fraction - setting->step;
|
||||
|
||||
if (setting->enforce_minrange)
|
||||
{
|
||||
if (*setting->value.fraction < setting->min)
|
||||
*setting->value.fraction = setting->min;
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_ACTION_RIGHT:
|
||||
case MENU_ACTION_OK:
|
||||
*setting->value.fraction =
|
||||
*setting->value.fraction + setting->step;
|
||||
|
||||
if (setting->enforce_maxrange)
|
||||
{
|
||||
if (*setting->value.fraction > setting->max)
|
||||
*setting->value.fraction = setting->max;
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_ACTION_START:
|
||||
*setting->value.fraction = setting->default_value.fraction;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (setting->change_handler)
|
||||
setting->change_handler(setting);
|
||||
}
|
31
frontend/menu/menu_action.h
Normal file
31
frontend/menu/menu_action.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2014 - Daniel De Matteis
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _MENU_ACTION_H
|
||||
#define _MENU_ACTION_H
|
||||
|
||||
#include "../../settings_data.h"
|
||||
|
||||
void menu_common_setting_set_current_boolean(
|
||||
rarch_setting_t *setting, unsigned action);
|
||||
|
||||
void menu_common_setting_set_current_fraction(
|
||||
rarch_setting_t *setting, unsigned action);
|
||||
|
||||
void menu_common_setting_set_current_unsigned_integer(
|
||||
rarch_setting_t *setting, unsigned id, unsigned action);
|
||||
|
||||
#endif
|
@ -603,6 +603,7 @@ MENU
|
||||
#ifdef HAVE_MENU
|
||||
#include "../frontend/menu/menu_input_line_cb.c"
|
||||
#include "../frontend/menu/menu_common.c"
|
||||
#include "../frontend/menu/menu_action.c"
|
||||
#include "../frontend/menu/menu_entries.c"
|
||||
#include "../frontend/menu/menu_navigation.c"
|
||||
|
||||
|
@ -225,6 +225,7 @@
|
||||
<ClCompile Include="..\..\frontend\menu\disp\rgui.c" />
|
||||
<ClCompile Include="..\..\frontend\menu\menu_common.c" />
|
||||
<ClCompile Include="..\..\frontend\menu\menu_input_line_cb.c" />
|
||||
<ClCompile Include="..\..\frontend\menu\menu_action.c" />
|
||||
<ClCompile Include="..\..\frontend\menu\menu_entries.c" />
|
||||
<ClCompile Include="..\..\frontend\menu\menu_navigation.c" />
|
||||
<ClCompile Include="..\..\core_info.c" />
|
||||
@ -422,4 +423,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
Loading…
x
Reference in New Issue
Block a user