core_option_manager.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /* RetroArch - A frontend for libretro.
  2. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
  3. * Copyright (C) 2011-2017 - Daniel De Matteis
  4. *
  5. * RetroArch is free software: you can redistribute it and/or modify it under the terms
  6. * of the GNU General Public License as published by the Free Software Found-
  7. * ation, either version 3 of the License, or (at your option) any later version.
  8. *
  9. * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. * PURPOSE. See the GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with RetroArch.
  14. * If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef CORE_OPTION_MANAGER_H__
  17. #define CORE_OPTION_MANAGER_H__
  18. #include <stddef.h>
  19. #include <boolean.h>
  20. #include <retro_common_api.h>
  21. #include <lists/string_list.h>
  22. #include <lists/nested_list.h>
  23. #include <file/config_file.h>
  24. #include <libretro.h>
  25. #include <retro_miscellaneous.h>
  26. RETRO_BEGIN_DECLS
  27. struct core_option
  28. {
  29. char *desc;
  30. char *desc_categorized;
  31. char *info;
  32. char *info_categorized;
  33. char *key;
  34. char *category_key;
  35. struct string_list *vals;
  36. struct string_list *val_labels;
  37. /* opt_idx: option index, used for internal
  38. * bookkeeping */
  39. size_t opt_idx;
  40. /* default_index, index: correspond to
  41. * option *value* indices */
  42. size_t default_index;
  43. size_t index;
  44. uint32_t key_hash;
  45. bool visible;
  46. };
  47. struct core_category
  48. {
  49. char *key;
  50. char *desc;
  51. char *info;
  52. uint32_t key_hash;
  53. };
  54. /* TODO/FIXME: This struct should be made
  55. * 'private', with restricted access to its
  56. * members via interface functions. This
  57. * requires significant refactoring... */
  58. struct core_option_manager
  59. {
  60. config_file_t *conf;
  61. char conf_path[PATH_MAX_LENGTH];
  62. struct core_category *cats;
  63. struct core_option *opts;
  64. nested_list_t *option_map;
  65. size_t cats_size;
  66. size_t size;
  67. bool updated;
  68. };
  69. typedef struct core_option_manager core_option_manager_t;
  70. /*********************/
  71. /* Option Conversion */
  72. /*********************/
  73. /**
  74. * core_option_manager_convert_v1:
  75. *
  76. * @options_v1 : an array of retro_core_option_definition
  77. * structs
  78. *
  79. * Converts an array of core option v1 definitions into
  80. * a v2 core options struct. Returned pointer must be
  81. * freed using core_option_manager_free_converted().
  82. *
  83. * Returns: Valid pointer to a new v2 core options struct
  84. * if successful, otherwise NULL.
  85. **/
  86. struct retro_core_options_v2 *core_option_manager_convert_v1(
  87. const struct retro_core_option_definition *options_v1);
  88. /**
  89. * core_option_manager_convert_v1_intl:
  90. *
  91. * @options_v1_intl : pointer to a retro_core_options_intl
  92. * struct
  93. *
  94. * Converts a v1 'international' core options definition
  95. * struct into a v2 core options struct. Returned pointer
  96. * must be freed using core_option_manager_free_converted().
  97. *
  98. * Returns: Valid pointer to a new v2 core options struct
  99. * if successful, otherwise NULL.
  100. **/
  101. struct retro_core_options_v2 *core_option_manager_convert_v1_intl(
  102. const struct retro_core_options_intl *options_v1_intl);
  103. /**
  104. * core_option_manager_convert_v2_intl:
  105. *
  106. * @options_v2_intl : pointer to a retro_core_options_v2_intl
  107. * struct
  108. *
  109. * Converts a v2 'international' core options struct
  110. * into a regular v2 core options struct. Returned pointer
  111. * must be freed using core_option_manager_free_converted().
  112. *
  113. * Returns: Valid pointer to a new v2 core options struct
  114. * if successful, otherwise NULL.
  115. **/
  116. struct retro_core_options_v2 *core_option_manager_convert_v2_intl(
  117. const struct retro_core_options_v2_intl *options_v2_intl);
  118. /**
  119. * core_option_manager_free_converted:
  120. *
  121. * @options_v2 : pointer to a retro_core_options_v2
  122. * struct
  123. *
  124. * Frees the pointer returned by any
  125. * core_option_manager_convert_*() function.
  126. **/
  127. void core_option_manager_free_converted(
  128. struct retro_core_options_v2 *options_v2);
  129. /**************************************/
  130. /* Initialisation / De-Initialisation */
  131. /**************************************/
  132. /**
  133. * core_option_manager_new_vars:
  134. *
  135. * @conf_path : Filesystem path to write core option
  136. * config file to
  137. * @src_conf_path : Filesystem path from which to load
  138. * initial config settings.
  139. * @vars : Pointer to core option variable array
  140. * handle
  141. *
  142. * Legacy version of core_option_manager_new().
  143. * Creates and initializes a core manager handle.
  144. *
  145. * Returns: handle to new core manager handle if successful,
  146. * otherwise NULL.
  147. **/
  148. core_option_manager_t *core_option_manager_new_vars(
  149. const char *conf_path, const char *src_conf_path,
  150. const struct retro_variable *vars);
  151. /**
  152. * core_option_manager_new:
  153. *
  154. * @conf_path : Filesystem path to write core option
  155. * config file to
  156. * @src_conf_path : Filesystem path from which to load
  157. * initial config settings.
  158. * @options_v2 : Pointer to retro_core_options_v2 struct
  159. * @categorized : Flag specifying whether core option
  160. * category information should be read
  161. * from @options_v2
  162. *
  163. * Creates and initializes a core manager handle. Parses
  164. * information from a retro_core_options_v2 struct.
  165. * If @categorized is false, all option category
  166. * assignments will be ignored.
  167. *
  168. * Returns: handle to new core manager handle if successful,
  169. * otherwise NULL.
  170. **/
  171. core_option_manager_t *core_option_manager_new(
  172. const char *conf_path, const char *src_conf_path,
  173. const struct retro_core_options_v2 *options_v2,
  174. bool categorized);
  175. /**
  176. * core_option_manager_free:
  177. *
  178. * @opt : options manager handle
  179. *
  180. * Frees specified core options manager handle.
  181. **/
  182. void core_option_manager_free(core_option_manager_t *opt);
  183. /********************/
  184. /* Category Getters */
  185. /********************/
  186. /**
  187. * core_option_manager_get_category_desc:
  188. *
  189. * @opt : options manager handle
  190. * @key : core option category id string
  191. *
  192. * Fetches the 'description' text of the core option
  193. * category identified by @key (used as the
  194. * category label in the menu).
  195. *
  196. * Returns: description string (menu label) of the
  197. * specified option category if successful,
  198. * otherwise NULL.
  199. **/
  200. const char *core_option_manager_get_category_desc(core_option_manager_t *opt,
  201. const char *key);
  202. /**
  203. * core_option_manager_get_category_info:
  204. *
  205. * @opt : options manager handle
  206. * @key : core option category id string
  207. *
  208. * Fetches the 'info' text of the core option
  209. * category identified by @key (used as the category
  210. * sublabel in the menu).
  211. *
  212. * Returns: information string (menu sublabel) of
  213. * the specified option category if successful,
  214. * otherwise NULL.
  215. **/
  216. const char *core_option_manager_get_category_info(core_option_manager_t *opt,
  217. const char *key);
  218. /**
  219. * core_option_manager_get_category_visible:
  220. *
  221. * @opt : options manager handle
  222. * @key : core option category id string
  223. *
  224. * Queries whether the core option category
  225. * identified by @key should be displayed in
  226. * the frontend menu. (A category is deemed to
  227. * be visible if at least one of the options
  228. * in the category is visible)
  229. *
  230. * @return true if option category should be
  231. * displayed by the frontend, otherwise false.
  232. **/
  233. bool core_option_manager_get_category_visible(core_option_manager_t *opt,
  234. const char *key);
  235. /******************/
  236. /* Option Getters */
  237. /******************/
  238. /**
  239. * core_option_manager_get_idx:
  240. *
  241. * @opt : options manager handle
  242. * @key : core option key string (variable to query
  243. * in RETRO_ENVIRONMENT_GET_VARIABLE)
  244. * @idx : index of core option corresponding
  245. * to @key
  246. *
  247. * Fetches the index of the core option identified
  248. * by the specified @key.
  249. *
  250. * @return true if option matching the specified
  251. * key was found, otherwise false.
  252. **/
  253. bool core_option_manager_get_idx(core_option_manager_t *opt,
  254. const char *key, size_t *idx);
  255. /**
  256. * core_option_manager_get_val_idx:
  257. *
  258. * @opt : options manager handle
  259. * @idx : core option index
  260. * @val : string representation of the
  261. * core option value
  262. * @val_idx : index of core option value
  263. * corresponding to @val
  264. *
  265. * Fetches the index of the core option value
  266. * identified by the specified core option @idx
  267. * and @val string.
  268. *
  269. * Returns: true if option value matching the
  270. * specified option index and value string
  271. * was found, otherwise false.
  272. **/
  273. bool core_option_manager_get_val_idx(core_option_manager_t *opt,
  274. size_t idx, const char *val, size_t *val_idx);
  275. /**
  276. * core_option_manager_get_desc:
  277. *
  278. * @opt : options manager handle
  279. * @idx : core option index
  280. * @categorized : flag specifying whether to
  281. * fetch the categorised description
  282. * or the legacy fallback
  283. *
  284. * Fetches the 'description' of the core option at
  285. * index @idx (used as the option label in the menu).
  286. * If menu has option category support, @categorized
  287. * should be true. (At present, only the Qt interface
  288. * requires @categorized to be false)
  289. *
  290. * Returns: description string (menu label) of the
  291. * specified option if successful, otherwise NULL.
  292. **/
  293. const char *core_option_manager_get_desc(core_option_manager_t *opt,
  294. size_t idx, bool categorized);
  295. /**
  296. * core_option_manager_get_info:
  297. *
  298. * @opt : options manager handle
  299. * @idx : core option index
  300. * @categorized : flag specifying whether to
  301. * fetch the categorised information
  302. * or the legacy fallback
  303. *
  304. * Fetches the 'info' text of the core option at
  305. * index @idx (used as the option sublabel in the
  306. * menu). If menu has option category support,
  307. * @categorized should be true. (At present, only
  308. * the Qt interface requires @categorized to be false)
  309. *
  310. * Returns: information string (menu sublabel) of the
  311. * specified option if successful, otherwise NULL.
  312. **/
  313. const char *core_option_manager_get_info(core_option_manager_t *opt,
  314. size_t idx, bool categorized);
  315. /**
  316. * core_option_manager_get_val:
  317. *
  318. * @opt : options manager handle
  319. * @idx : core option index
  320. *
  321. * Fetches the string representation of the current
  322. * value of the core option at index @idx.
  323. *
  324. * Returns: core option value string if successful,
  325. * otherwise NULL.
  326. **/
  327. const char *core_option_manager_get_val(core_option_manager_t *opt,
  328. size_t idx);
  329. /**
  330. * core_option_manager_get_val_label:
  331. *
  332. * @opt : options manager handle
  333. * @idx : core option index
  334. *
  335. * Fetches the 'label' text (used for display purposes
  336. * in the menu) for the current value of the core
  337. * option at index @idx.
  338. *
  339. * Returns: core option value label string if
  340. * successful, otherwise NULL.
  341. **/
  342. const char *core_option_manager_get_val_label(core_option_manager_t *opt,
  343. size_t idx);
  344. /**
  345. * core_option_manager_get_visible:
  346. *
  347. * @opt : options manager handle
  348. * @idx : core option index
  349. *
  350. * Queries whether the core option at index @idx
  351. * should be displayed in the frontend menu.
  352. *
  353. * Returns: true if option should be displayed by
  354. * the frontend, otherwise false.
  355. **/
  356. bool core_option_manager_get_visible(core_option_manager_t *opt,
  357. size_t idx);
  358. /******************/
  359. /* Option Setters */
  360. /******************/
  361. /**
  362. * core_option_manager_set_val:
  363. *
  364. * @opt : options manager handle
  365. * @idx : core option index
  366. * @val_idx : index of the value to set
  367. * @refresh_menu : flag specifying whether menu
  368. * should be refreshed if changes
  369. * to option visibility are detected
  370. *
  371. * Sets the core option at index @idx to the
  372. * option value corresponding to @val_idx.
  373. * After setting the option value, a request
  374. * will be made for the core to update the
  375. * in-menu visibility of all options; if
  376. * visibility changes are detected and
  377. * @refresh_menu is true, the menu will be
  378. * redrawn.
  379. **/
  380. void core_option_manager_set_val(core_option_manager_t *opt,
  381. size_t idx, size_t val_idx, bool refresh_menu);
  382. /**
  383. * core_option_manager_adjust_val:
  384. *
  385. * @opt : options manager handle
  386. * @idx : core option index
  387. * @adjustment : offset to apply from current
  388. * value index
  389. * @refresh_menu : flag specifying whether menu
  390. * should be refreshed if changes
  391. * to option visibility are detected
  392. *
  393. * Modifies the value of the core option at
  394. * index @idx by incrementing the current option
  395. * value index by @adjustment.
  396. * After setting the option value, a request
  397. * will be made for the core to update the
  398. * in-menu visibility of all options; if
  399. * visibility changes are detected and
  400. * @refresh_menu is true, the menu will be
  401. * redrawn.
  402. **/
  403. void core_option_manager_adjust_val(core_option_manager_t* opt,
  404. size_t idx, int adjustment, bool refresh_menu);
  405. /**
  406. * core_option_manager_set_default:
  407. *
  408. * @opt : options manager handle
  409. * @idx : core option index
  410. * @refresh_menu : flag specifying whether menu
  411. * should be refreshed if changes
  412. * to option visibility are detected
  413. *
  414. * Resets the core option at index @idx to
  415. * its default value.
  416. * After setting the option value, a request
  417. * will be made for the core to update the
  418. * in-menu visibility of all options; if
  419. * visibility changes are detected and
  420. * @refresh_menu is true, the menu will be
  421. * redrawn.
  422. **/
  423. void core_option_manager_set_default(core_option_manager_t *opt,
  424. size_t idx, bool refresh_menu);
  425. /**
  426. * core_option_manager_set_visible:
  427. *
  428. * @opt : options manager handle
  429. * @key : core option key string (variable to query
  430. * in RETRO_ENVIRONMENT_GET_VARIABLE)
  431. * @visible : flag specifying whether option should
  432. * be shown in the menu
  433. *
  434. * Sets the in-menu visibility of the core option
  435. * identified by the specified @key.
  436. **/
  437. void core_option_manager_set_visible(core_option_manager_t *opt,
  438. const char *key, bool visible);
  439. /**********************/
  440. /* Configuration File */
  441. /**********************/
  442. /**
  443. * core_option_manager_flush:
  444. *
  445. * @opt : options manager handle
  446. * @conf : configuration file handle
  447. *
  448. * Writes all core option key-pair values from the
  449. * specified core option manager handle to the
  450. * specified configuration file struct.
  451. **/
  452. void core_option_manager_flush(core_option_manager_t *opt,
  453. config_file_t *conf);
  454. RETRO_END_DECLS
  455. #endif