1 /*  RetroArch - A frontend for libretro.
2  *  Copyright (C) 2011-2017 - Daniel De Matteis
3  *
4  *  RetroArch is free software: you can redistribute it and/or modify it under the terms
5  *  of the GNU General Public License as published by the Free Software Found-
6  *  ation, either version 3 of the License, or (at your option) any later version.
7  *
8  *  RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9  *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10  *  PURPOSE.  See the GNU General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License along with RetroArch.
13  *  If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 #ifndef __SETTING_LIST_H
17 #define __SETTING_LIST_H
18 
19 #include <boolean.h>
20 
21 #include <retro_common_api.h>
22 
23 #include "command.h"
24 #include "msg_hash.h"
25 
26 RETRO_BEGIN_DECLS
27 
28 enum setting_type
29 {
30    ST_NONE = 0,
31    ST_ACTION,
32    ST_BOOL,
33    ST_INT,
34    ST_UINT,
35    ST_SIZE,
36    ST_FLOAT,
37    ST_PATH,
38    ST_DIR,
39    ST_STRING,
40    ST_STRING_OPTIONS,
41    ST_HEX,
42    ST_BIND,
43    ST_GROUP,
44    ST_SUB_GROUP,
45    ST_END_GROUP,
46    ST_END_SUB_GROUP
47 };
48 
49 enum ui_setting_type
50 {
51    ST_UI_TYPE_NONE = 0,
52    ST_UI_TYPE_CHECKBOX,
53    ST_UI_TYPE_UINT_COLOR_BUTTON,
54    ST_UI_TYPE_UINT_SPINBOX,
55    ST_UI_TYPE_UINT_COMBOBOX,
56    ST_UI_TYPE_UINT_RADIO_BUTTONS,
57    ST_UI_TYPE_FLOAT_COLOR_BUTTON,
58    ST_UI_TYPE_FLOAT_SPINBOX,
59    ST_UI_TYPE_FLOAT_SLIDER_AND_SPINBOX,
60    ST_UI_TYPE_SIZE_SPINBOX,
61    ST_UI_TYPE_BIND_BUTTON,
62    ST_UI_TYPE_DIRECTORY_SELECTOR,
63    ST_UI_TYPE_FILE_SELECTOR,
64    ST_UI_TYPE_FONT_SELECTOR,
65    ST_UI_TYPE_STRING_COMBOBOX,
66    ST_UI_TYPE_STRING_LINE_EDIT,
67    ST_UI_TYPE_PASSWORD_LINE_EDIT,
68    ST_UI_TYPE_LAST
69 };
70 
71 enum setting_flags
72 {
73    SD_FLAG_NONE           = 0,
74    SD_FLAG_PATH_DIR       = (1 << 0),
75    SD_FLAG_PATH_FILE      = (1 << 1),
76    SD_FLAG_ALLOW_EMPTY    = (1 << 2),
77    SD_FLAG_HAS_RANGE      = (1 << 3),
78    SD_FLAG_ALLOW_INPUT    = (1 << 4),
79    SD_FLAG_IS_DRIVER      = (1 << 5),
80    SD_FLAG_EXIT           = (1 << 6),
81    SD_FLAG_CMD_APPLY_AUTO = (1 << 7),
82    SD_FLAG_BROWSER_ACTION = (1 << 8),
83    SD_FLAG_ADVANCED       = (1 << 9),
84    SD_FLAG_LAKKA_ADVANCED = (1 << 10)
85 };
86 
87 enum settings_free_flags
88 {
89    SD_FREE_FLAG_VALUES    = (1 << 0),
90    SD_FREE_FLAG_NAME      = (1 << 1),
91    SD_FREE_FLAG_SHORT     = (1 << 2)
92 };
93 
94 typedef struct rarch_setting rarch_setting_t;
95 typedef struct rarch_setting_group_info rarch_setting_group_info_t;
96 
97 typedef void (*change_handler_t               )(rarch_setting_t *setting);
98 typedef int  (*action_left_handler_t          )(rarch_setting_t *setting, size_t idx, bool wraparound);
99 typedef int  (*action_right_handler_t         )(rarch_setting_t *setting, size_t idx, bool wraparound);
100 typedef int  (*action_up_handler_t            )(rarch_setting_t *setting);
101 typedef int  (*action_down_handler_t          )(rarch_setting_t *setting);
102 typedef int  (*action_start_handler_t         )(rarch_setting_t *setting);
103 typedef int  (*action_cancel_handler_t        )(rarch_setting_t *setting);
104 typedef int  (*action_ok_handler_t            )(rarch_setting_t *setting, size_t idx, bool wraparound);
105 typedef int  (*action_select_handler_t        )(rarch_setting_t *setting, size_t idx, bool wraparound);
106 typedef void (*get_string_representation_t    )(rarch_setting_t *setting, char *s, size_t len);
107 
108 struct rarch_setting_group_info
109 {
110    const char *name;
111 };
112 
113 struct rarch_setting
114 {
115    double               min;
116    double               max;
117 
118    uint64_t             flags;
119    uint64_t             free_flags;
120 
121    struct
122    {
123       const char     *off_label;
124       const char     *on_label;
125    } boolean;
126    struct
127    {
128       const char     *empty_path;
129    } dir;
130    const char           *rounding_fraction;
131    const char           *name;
132    const char           *short_description;
133    const char           *group;
134    const char           *subgroup;
135    const char           *parent_group;
136    const char           *values;
137 
138    change_handler_t              change_handler;
139    change_handler_t              read_handler;
140    action_start_handler_t        action_start;
141    action_left_handler_t         action_left;
142    action_right_handler_t        action_right;
143    action_up_handler_t           action_up;
144    action_down_handler_t         action_down;
145    action_cancel_handler_t       action_cancel;
146    action_ok_handler_t           action_ok;
147    action_select_handler_t       action_select;
148    get_string_representation_t   get_string_representation;
149 
150    struct
151    {
152       union
153       {
154          bool                 *boolean;
155          char                 *string;
156          int                  *integer;
157          unsigned int         *unsigned_integer;
158          float                *fraction;
159          struct retro_keybind *keybind;
160          size_t               *sizet;
161       } target;
162    } value;
163 
164 
165    union
166    {
167       const char                 *string;
168       const struct retro_keybind *keybind;
169       size_t                     sizet;
170       int                        integer;
171       unsigned int               unsigned_integer;
172       float                      fraction;
173       bool                       boolean;
174    } default_value;
175 
176    union
177    {
178       size_t         sizet;
179       int            integer;
180       unsigned int   unsigned_integer;
181       float          fraction;
182       bool           boolean;
183    } original_value;
184 
185    uint32_t             index_offset;
186    uint32_t             size;
187    unsigned             bind_type;
188    float                step;
189 
190    enum event_command   cmd_trigger_idx;
191    enum ui_setting_type ui_type;
192    enum setting_type    browser_selection_type;
193    enum msg_hash_enums  enum_idx;
194    enum msg_hash_enums  enum_value_idx;
195    enum setting_type    type;
196 
197    int16_t              offset_by;
198    uint8_t              index;
199 
200    bool                 cmd_trigger_event_triggered;
201    bool                 dont_use_enum_idx_representation;
202    bool                 enforce_minrange;
203    bool                 enforce_maxrange;
204 };
205 
206 /**
207  * setting_set_with_string_representation:
208  * @setting            : pointer to setting
209  * @value              : value for the setting (string)
210  *
211  * Set a settings' value with a string. It is assumed
212  * that the string has been properly formatted.
213  **/
214 int setting_set_with_string_representation(
215       rarch_setting_t* setting, const char *value);
216 
217 unsigned setting_get_bind_type(rarch_setting_t *setting);
218 
219 int setting_string_action_start_generic(rarch_setting_t *setting);
220 
221 int setting_generic_action_ok_default(rarch_setting_t *setting, size_t idx, bool wraparound);
222 
223 int setting_generic_action_start_default(rarch_setting_t *setting);
224 
225 void setting_get_string_representation_size_in_mb(rarch_setting_t *setting,
226       char *s, size_t len);
227 
228 int setting_uint_action_left_with_refresh(rarch_setting_t *setting, size_t idx, bool wraparound);
229 int setting_uint_action_right_with_refresh(rarch_setting_t *setting, size_t idx, bool wraparound);
230 int setting_uint_action_left_default(rarch_setting_t *setting, size_t idx, bool wraparound);
231 int setting_uint_action_right_default(rarch_setting_t *setting, size_t idx, bool wraparound);
232 
233 void setting_get_string_representation_uint(rarch_setting_t *setting, char *s, size_t len);
234 void setting_get_string_representation_hex_and_uint(rarch_setting_t *setting, char *s, size_t len);
235 
236 RETRO_END_DECLS
237 
238 #endif
239