1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
|
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2017 - 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 <compat/strl.h>
#include <file/file_path.h>
#include <lists/string_list.h>
#include <string/stdstring.h>
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
#include "../menu_driver.h"
#include "../menu_cbs.h"
#include "../menu_input.h"
#include "../menu_setting.h"
#include "../menu_shader.h"
#include "../../audio/audio_driver.h"
#include "../../configuration.h"
#include "../../core.h"
#include "../../core_info.h"
#include "../../managers/core_option_manager.h"
#include "../../managers/cheat_manager.h"
#include "../../retroarch.h"
#include "../../performance_counters.h"
#include "../../gfx/video_driver.h"
#include "../../input/input_driver.h"
#include "../../input/input_remapping.h"
#include "../../config.def.h"
#ifndef BIND_ACTION_START
#define BIND_ACTION_START(cbs, name) \
cbs->action_start = name; \
cbs->action_start_ident = #name;
#endif
static int action_start_audio_mixer_stream_volume(unsigned type, const char *label)
{
unsigned offset = (type - MENU_SETTINGS_AUDIO_MIXER_STREAM_ACTIONS_VOLUME_BEGIN);
if (offset >= AUDIO_MIXER_MAX_STREAMS)
return 0;
audio_driver_mixer_set_stream_volume(offset, 1.0f);
return 0;
}
static int action_start_remap_file_load(unsigned type, const char *label)
{
input_remapping_set_defaults(true);
return 0;
}
static int action_start_video_filter_file_load(unsigned type, const char *label)
{
settings_t *settings = config_get_ptr();
if (!settings)
return -1;
settings->paths.path_softfilter_plugin[0] = '\0';
command_event(CMD_EVENT_REINIT, NULL);
return 0;
}
static int generic_action_start_performance_counters(struct retro_perf_counter **counters,
unsigned offset, unsigned type, const char *label)
{
if (counters[offset])
{
counters[offset]->total = 0;
counters[offset]->call_cnt = 0;
}
return 0;
}
static int action_start_performance_counters_core(unsigned type, const char *label)
{
struct retro_perf_counter **counters = retro_get_perf_counter_libretro();
unsigned offset = type - MENU_SETTINGS_LIBRETRO_PERF_COUNTERS_BEGIN;
return generic_action_start_performance_counters(counters, offset, type, label);
}
static int action_start_performance_counters_frontend(unsigned type,
const char *label)
{
struct retro_perf_counter **counters = retro_get_perf_counter_rarch();
unsigned offset = type - MENU_SETTINGS_PERF_COUNTERS_BEGIN;
return generic_action_start_performance_counters(counters, offset, type, label);
}
static int action_start_input_desc(unsigned type, const char *label)
{
settings_t *settings = config_get_ptr();
unsigned inp_desc_index_offset = type - MENU_SETTINGS_INPUT_DESC_BEGIN;
unsigned inp_desc_user = inp_desc_index_offset / (RARCH_FIRST_CUSTOM_BIND + 4);
unsigned inp_desc_button_index_offset = inp_desc_index_offset - (inp_desc_user * (RARCH_FIRST_CUSTOM_BIND + 4));
(void)label;
if (inp_desc_button_index_offset < RARCH_FIRST_CUSTOM_BIND)
{
const struct retro_keybind *keyptr = &input_config_binds[inp_desc_user]
[inp_desc_button_index_offset];
settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset] = keyptr->id;
}
else
settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset] =
inp_desc_button_index_offset - RARCH_FIRST_CUSTOM_BIND;
return 0;
}
static int action_start_shader_action_parameter(
unsigned type, const char *label)
{
video_shader_ctx_t shader_info;
struct video_shader_parameter *param = NULL;
unsigned parameter = type - MENU_SETTINGS_SHADER_PARAMETER_0;
video_shader_driver_get_current_shader(&shader_info);
if (!shader_info.data)
return 0;
param = &shader_info.data->parameters
[parameter];
param->current = param->initial;
param->current = MIN(MAX(param->minimum, param->current), param->maximum);
return menu_shader_manager_clear_parameter(parameter);
}
static int action_start_shader_pass(unsigned type, const char *label)
{
menu_handle_t *menu = NULL;
if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu))
return menu_cbs_exit();
menu->scratchpad.unsigned_var = type - MENU_SETTINGS_SHADER_PASS_0;
menu_shader_manager_clear_pass_path(menu->scratchpad.unsigned_var);
return 0;
}
static int action_start_shader_scale_pass(unsigned type, const char *label)
{
unsigned pass = type - MENU_SETTINGS_SHADER_PASS_SCALE_0;
menu_shader_manager_clear_pass_scale(pass);
return 0;
}
static int action_start_shader_filter_pass(unsigned type, const char *label)
{
unsigned pass = type - MENU_SETTINGS_SHADER_PASS_FILTER_0;
return menu_shader_manager_clear_pass_filter(pass);
}
static int action_start_netplay_mitm_server(unsigned type, const char *label)
{
settings_t *settings = config_get_ptr();
strlcpy(settings->arrays.netplay_mitm_server, netplay_mitm_server, sizeof(settings->arrays.netplay_mitm_server));
return 0;
}
static int action_start_shader_watch_for_changes(unsigned type, const char *label)
{
settings_t *settings = config_get_ptr();
settings->bools.video_shader_watch_files = video_shader_watch_files;
return 0;
}
static int action_start_shader_num_passes(unsigned type, const char *label)
{
return menu_shader_manager_clear_num_passes();
}
static int action_start_cheat_num_passes(unsigned type, const char *label)
{
if (cheat_manager_get_size())
{
bool refresh = false;
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
cheat_manager_realloc(0);
}
return 0;
}
static int action_start_core_setting(unsigned type,
const char *label)
{
unsigned idx = type - MENU_SETTINGS_CORE_OPTION_START;
core_option_manager_t *coreopts = NULL;
if (rarch_ctl(RARCH_CTL_CORE_OPTIONS_LIST_GET, &coreopts))
core_option_manager_set_default(coreopts, idx);
return 0;
}
static int action_start_playlist_association(unsigned type, const char *label)
{
int found;
char new_playlist_cores[PATH_MAX_LENGTH];
struct string_list *stnames = NULL;
struct string_list *stcores = NULL;
core_info_list_t *list = NULL;
settings_t *settings = config_get_ptr();
const char *path = path_basename(label);
core_info_get_list(&list);
if (!list)
return -1;
new_playlist_cores[0] = '\0';
stnames = string_split(settings->arrays.playlist_names, ";");
stcores = string_split(settings->arrays.playlist_cores, ";");
found = string_list_find_elem(stnames, path);
if (found)
string_list_set(stcores, found-1,
file_path_str(FILE_PATH_DETECT));
string_list_join_concat(new_playlist_cores,
sizeof(new_playlist_cores), stcores, ";");
strlcpy(settings->arrays.playlist_cores,
new_playlist_cores, sizeof(settings->arrays.playlist_cores));
string_list_free(stcores);
string_list_free(stnames);
return 0;
}
static int action_start_video_resolution(unsigned type, const char *label)
{
unsigned width = 0, height = 0;
global_t *global = global_get_ptr();
/* Reset the resolution id to zero */
global->console.screen.resolutions.current.id = 0;
if (video_driver_get_video_output_size(&width, &height))
{
char msg[PATH_MAX_LENGTH];
msg[0] = '\0';
video_driver_set_video_mode(width, height, true);
strlcpy(msg, "Resetting to: DEFAULT", sizeof(msg));
runloop_msg_queue_push(msg, 1, 100, true);
}
return 0;
}
static int action_start_lookup_setting(unsigned type, const char *label)
{
return menu_setting_set(type, label, MENU_ACTION_START, false);
}
static int menu_cbs_init_bind_start_compare_label(menu_file_list_cbs_t *cbs)
{
if (cbs->enum_idx != MSG_UNKNOWN)
{
switch (cbs->enum_idx)
{
case MENU_ENUM_LABEL_REMAP_FILE_LOAD:
BIND_ACTION_START(cbs, action_start_remap_file_load);
break;
case MENU_ENUM_LABEL_VIDEO_FILTER:
BIND_ACTION_START(cbs, action_start_video_filter_file_load);
break;
case MENU_ENUM_LABEL_VIDEO_SHADER_PASS:
BIND_ACTION_START(cbs, action_start_shader_pass);
break;
case MENU_ENUM_LABEL_VIDEO_SHADER_SCALE_PASS:
BIND_ACTION_START(cbs, action_start_shader_scale_pass);
break;
case MENU_ENUM_LABEL_VIDEO_SHADER_FILTER_PASS:
BIND_ACTION_START(cbs, action_start_shader_filter_pass);
break;
case MENU_ENUM_LABEL_SHADER_WATCH_FOR_CHANGES:
BIND_ACTION_START(cbs, action_start_shader_watch_for_changes);
break;
case MENU_ENUM_LABEL_VIDEO_SHADER_NUM_PASSES:
BIND_ACTION_START(cbs, action_start_shader_num_passes);
break;
case MENU_ENUM_LABEL_CHEAT_NUM_PASSES:
BIND_ACTION_START(cbs, action_start_cheat_num_passes);
break;
case MENU_ENUM_LABEL_SCREEN_RESOLUTION:
BIND_ACTION_START(cbs, action_start_video_resolution);
break;
case MENU_ENUM_LABEL_NETPLAY_MITM_SERVER:
BIND_ACTION_START(cbs, action_start_netplay_mitm_server);
break;
default:
return -1;
}
}
return 0;
}
static int menu_cbs_init_bind_start_compare_type(menu_file_list_cbs_t *cbs,
unsigned type)
{
if (type >= MENU_SETTINGS_SHADER_PARAMETER_0
&& type <= MENU_SETTINGS_SHADER_PARAMETER_LAST)
{
BIND_ACTION_START(cbs, action_start_shader_action_parameter);
}
else if (type >= MENU_SETTINGS_SHADER_PRESET_PARAMETER_0
&& type <= MENU_SETTINGS_SHADER_PRESET_PARAMETER_LAST)
{
BIND_ACTION_START(cbs, action_start_shader_action_parameter);
}
else if (type >= MENU_SETTINGS_LIBRETRO_PERF_COUNTERS_BEGIN &&
type <= MENU_SETTINGS_LIBRETRO_PERF_COUNTERS_END)
{
BIND_ACTION_START(cbs, action_start_performance_counters_core);
}
else if (type >= MENU_SETTINGS_INPUT_DESC_BEGIN
&& type <= MENU_SETTINGS_INPUT_DESC_END)
{
BIND_ACTION_START(cbs, action_start_input_desc);
}
else if (type >= MENU_SETTINGS_PERF_COUNTERS_BEGIN &&
type <= MENU_SETTINGS_PERF_COUNTERS_END)
{
BIND_ACTION_START(cbs, action_start_performance_counters_frontend);
}
else if ((type >= MENU_SETTINGS_PLAYLIST_ASSOCIATION_START))
{
BIND_ACTION_START(cbs, action_start_playlist_association);
}
else if ((type >= MENU_SETTINGS_CORE_OPTION_START))
{
BIND_ACTION_START(cbs, action_start_core_setting);
}
else if (type == MENU_LABEL_SCREEN_RESOLUTION)
{
BIND_ACTION_START(cbs, action_start_video_resolution);
}
else
return -1;
return 0;
}
int menu_cbs_init_bind_start(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx)
{
if (!cbs)
return -1;
if (type >= MENU_SETTINGS_AUDIO_MIXER_STREAM_ACTIONS_VOLUME_BEGIN
&& type <= MENU_SETTINGS_AUDIO_MIXER_STREAM_ACTIONS_VOLUME_END)
{
BIND_ACTION_START(cbs, action_start_audio_mixer_stream_volume);
return 0;
}
BIND_ACTION_START(cbs, action_start_lookup_setting);
if (menu_cbs_init_bind_start_compare_label(cbs) == 0)
return 0;
if (menu_cbs_init_bind_start_compare_type(cbs, type) == 0)
return 0;
return -1;
}
|