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 __MENU_ENTRIES_H__
17 #define __MENU_ENTRIES_H__
18 
19 #include <stdint.h>
20 #include <stddef.h>
21 
22 #include <boolean.h>
23 #include <retro_common_api.h>
24 
25 #include <lists/file_list.h>
26 
27 #include "menu_setting.h"
28 #include "menu_input.h"
29 #include "menu_displaylist.h"
30 
31 RETRO_BEGIN_DECLS
32 
33 #define MENU_SUBLABEL_MAX_LENGTH 1024
34 
35 #define MENU_SEARCH_FILTER_MAX_TERMS  8
36 #define MENU_SEARCH_FILTER_MAX_LENGTH 64
37 
38 enum menu_entries_ctl_state
39 {
40    MENU_ENTRIES_CTL_NONE = 0,
41    MENU_ENTRIES_CTL_SETTINGS_GET,
42    MENU_ENTRIES_CTL_SET_REFRESH,
43    MENU_ENTRIES_CTL_UNSET_REFRESH,
44    MENU_ENTRIES_CTL_NEEDS_REFRESH,
45    /* Sets the starting index of the menu entry list. */
46    MENU_ENTRIES_CTL_SET_START,
47    /* Returns the starting index of the menu entry list. */
48    MENU_ENTRIES_CTL_START_GET,
49    MENU_ENTRIES_CTL_REFRESH,
50    MENU_ENTRIES_CTL_CLEAR,
51    MENU_ENTRIES_CTL_SHOW_BACK
52 };
53 
54 enum menu_list_type
55 {
56    MENU_LIST_PLAIN = 0,
57    MENU_LIST_HORIZONTAL,
58    MENU_LIST_TABS
59 };
60 
61 enum menu_entry_type
62 {
63    MENU_ENTRY_ACTION = 0,
64    MENU_ENTRY_BOOL,
65    MENU_ENTRY_INT,
66    MENU_ENTRY_UINT,
67    MENU_ENTRY_FLOAT,
68    MENU_ENTRY_PATH,
69    MENU_ENTRY_DIR,
70    MENU_ENTRY_STRING,
71    MENU_ENTRY_HEX,
72    MENU_ENTRY_BIND,
73    MENU_ENTRY_ENUM,
74    MENU_ENTRY_SIZE
75 };
76 
77 
78 typedef struct menu_ctx_list
79 {
80    const char  *path;
81    char        *fullpath;
82    const char  *label;
83    file_list_t *list;
84    void        *entry;
85    size_t idx;
86    size_t selection;
87    size_t size;
88    size_t list_size;
89    unsigned entry_type;
90    unsigned action;
91    enum menu_list_type type;
92 } menu_ctx_list_t;
93 
94 typedef struct menu_serch_terms
95 {
96    size_t size;
97    char terms[MENU_SEARCH_FILTER_MAX_TERMS][MENU_SEARCH_FILTER_MAX_LENGTH];
98 } menu_serch_terms_t;
99 
100 typedef struct menu_file_list_cbs
101 {
102    rarch_setting_t *setting;
103    int (*action_iterate)(const char *label, unsigned action);
104    int (*action_deferred_push)(menu_displaylist_info_t *info);
105    int (*action_select)(const char *path, const char *label, unsigned type,
106          size_t idx, size_t entry_idx);
107    int (*action_get_title)(const char *path, const char *label,
108          unsigned type, char *s, size_t len);
109    int (*action_ok)(const char *path, const char *label, unsigned type,
110          size_t idx, size_t entry_idx);
111    int (*action_cancel)(const char *path, const char *label, unsigned type,
112          size_t idx);
113    int (*action_scan)(const char *path, const char *label, unsigned type,
114          size_t idx);
115    int (*action_start)(const char *path, const char *label, unsigned type,
116          size_t idx, size_t entry_idx);
117    int (*action_info)(unsigned type,  const char *label);
118    int (*action_left)(unsigned type, const char *label, bool wraparound);
119    int (*action_right)(unsigned type, const char *label, bool wraparound);
120    int (*action_label)(file_list_t *list,
121          unsigned type, unsigned i,
122          const char *label, const char *path,
123          char *s, size_t len);
124    int (*action_sublabel)(file_list_t *list,
125          unsigned type, unsigned i,
126          const char *label, const char *path,
127          char *s, size_t len);
128    void (*action_get_value)(file_list_t* list,
129          unsigned *w, unsigned type, unsigned i,
130          const char *label, char *s, size_t len,
131          const char *path,
132          char *path_buf, size_t path_buf_size);
133    menu_serch_terms_t search;
134    enum msg_hash_enums enum_idx;
135    char action_sublabel_cache[MENU_SUBLABEL_MAX_LENGTH];
136    char action_title_cache   [512];
137    bool checked;
138 } menu_file_list_cbs_t;
139 
140 typedef struct menu_entry
141 {
142    size_t entry_idx;
143    unsigned idx;
144    unsigned type;
145    unsigned spacing;
146    enum msg_hash_enums enum_idx;
147    char path[255];
148    char label[255];
149    char sublabel[MENU_SUBLABEL_MAX_LENGTH];
150    char rich_label[255];
151    char value[255];
152    char password_value[255];
153    bool checked;
154    bool path_enabled;
155    bool label_enabled;
156    bool rich_label_enabled;
157    bool value_enabled;
158    bool sublabel_enabled;
159 } menu_entry_t;
160 
161 int menu_entries_get_title(char *title, size_t title_len);
162 
163 int menu_entries_get_core_title(char *title_msg, size_t title_msg_len);
164 
165 file_list_t *menu_entries_get_selection_buf_ptr(size_t idx);
166 
167 file_list_t *menu_entries_get_menu_stack_ptr(size_t idx);
168 
169 void menu_entries_append(file_list_t *list, const char *path, const char *label,
170       unsigned type, size_t directory_ptr, size_t entry_idx);
171 
172 void menu_entries_get_last_stack(const char **path, const char **label,
173       unsigned *file_type, enum msg_hash_enums *enum_idx, size_t *entry_idx);
174 
175 menu_file_list_cbs_t *menu_entries_get_last_stack_actiondata(void);
176 
177 void menu_entries_pop_stack(size_t *ptr, size_t idx, bool animate);
178 
179 void menu_entries_flush_stack(const char *needle, unsigned final_type);
180 
181 size_t menu_entries_get_stack_size(size_t idx);
182 
183 size_t menu_entries_get_size(void);
184 
185 void menu_entries_prepend(file_list_t *list,
186       const char *path, const char *label,
187       enum msg_hash_enums enum_idx,
188       unsigned type, size_t directory_ptr, size_t entry_idx);
189 
190 bool menu_entries_append_enum(file_list_t *list,
191       const char *path, const char *label,
192       enum msg_hash_enums enum_idx,
193       unsigned type, size_t directory_ptr, size_t entry_idx);
194 
195 bool menu_entries_ctl(enum menu_entries_ctl_state state, void *data);
196 
197 bool menu_entries_search_push(const char *search_term);
198 bool menu_entries_search_pop(void);
199 menu_serch_terms_t *menu_entries_search_get_terms(void);
200 /* Convenience function: Appends list of current
201  * search terms to specified string */
202 void menu_entries_search_append_terms_string(char *s, size_t len);
203 /* Searches current menu list for specified 'needle'
204  * string. If string is found, returns true and sets
205  * 'idx' to the matching list entry index. */
206 bool menu_entries_list_search(const char *needle, size_t *idx);
207 
208 /* Menu entry interface -
209  *
210  * This provides an abstraction of the currently displayed
211  * menu.
212  *
213  * It is organized into an event-based system where the UI companion
214  * calls this functions and RetroArch responds by changing the global
215  * state (including arranging for these functions to return different
216  * values).
217  *
218  * Its only interaction back to the UI is to arrange for
219  * notify_list_loaded on the UI companion.
220  */
221 
222 void menu_entry_get(menu_entry_t *entry, size_t stack_idx,
223       size_t i, void *userdata, bool use_representation);
224 
225 int menu_entry_action(
226       menu_entry_t *entry, size_t i, enum menu_action action);
227 
228 #define MENU_ENTRY_INIT(entry) \
229    entry.path[0]            = '\0'; \
230    entry.label[0]           = '\0'; \
231    entry.sublabel[0]        = '\0'; \
232    entry.rich_label[0]      = '\0'; \
233    entry.value[0]           = '\0'; \
234    entry.password_value[0]  = '\0'; \
235    entry.enum_idx           = MSG_UNKNOWN; \
236    entry.entry_idx          = 0; \
237    entry.idx                = 0; \
238    entry.type               = 0; \
239    entry.spacing            = 0; \
240    entry.path_enabled       = true; \
241    entry.label_enabled      = true; \
242    entry.rich_label_enabled = true; \
243    entry.value_enabled      = true; \
244    entry.sublabel_enabled   = true
245 
246 RETRO_END_DECLS
247 
248 #endif
249