1 /* 2 * ui.h - Atari user interface definitions 3 * 4 * Copyright (C) 1995-1998 David Firth 5 * Copyright (C) 1998-2008 Atari800 development team (see DOC/CREDITS) 6 * 7 * This file is part of the Atari800 emulator project which emulates 8 * the Atari 400, 800, 800XL, 130XE, and 5200 8-bit computers. 9 * 10 * Atari800 is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * Atari800 is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with Atari800; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 */ 24 #ifndef UI_H_ 25 #define UI_H_ 26 27 #include "config.h" 28 #include <stdio.h> /* FILENAME_MAX */ 29 #include "atari.h" 30 31 /* Three legitimate entries to UI module. */ 32 int UI_SelectCartType(int k); 33 void UI_Run(void); 34 35 extern int UI_is_active; 36 extern int UI_alt_function; 37 extern int UI_current_function; 38 39 #ifdef CRASH_MENU 40 extern int UI_crash_code; 41 extern UWORD UI_crash_address; 42 extern UWORD UI_crash_afterCIM; 43 #endif 44 45 #define UI_MAX_DIRECTORIES 8 46 47 extern char UI_atari_files_dir[UI_MAX_DIRECTORIES][FILENAME_MAX]; 48 extern char UI_saved_files_dir[UI_MAX_DIRECTORIES][FILENAME_MAX]; 49 extern int UI_n_atari_files_dir; 50 extern int UI_n_saved_files_dir; 51 52 #ifdef GUI_SDL 53 void PLATFORM_SetJoystickKey(int joystick, int direction, int value); 54 void PLATFORM_GetJoystickKeyName(int joystick, int direction, char *buffer, int bufsize); 55 int GetRawKey(void); 56 #endif 57 58 #ifdef DIRECTX 59 void PLATFORM_GetButtonAssignments(int stick, int button, char *buffer, int bufsize); 60 void PLATFORM_SetButtonAssignment(int stick, int button, int value); 61 int GetKeyName(void); 62 #endif 63 64 /* Menu codes for Alt+letter shortcuts. 65 Store in UI_alt_function and put AKEY_UI in INPUT_key_code. */ 66 #define UI_MENU_DISK 0 67 #define UI_MENU_CARTRIDGE 1 68 #define UI_MENU_RUN 2 69 #define UI_MENU_SYSTEM 3 70 #define UI_MENU_SOUND 4 71 #define UI_MENU_SOUND_RECORDING 5 72 #define UI_MENU_DISPLAY 6 73 #define UI_MENU_SETTINGS 7 74 #define UI_MENU_SAVESTATE 8 75 #define UI_MENU_LOADSTATE 9 76 #define UI_MENU_PCX 10 77 #define UI_MENU_PCXI 11 78 #define UI_MENU_BACK 12 79 #define UI_MENU_RESETW 13 80 #define UI_MENU_RESETC 14 81 #define UI_MENU_MONITOR 15 82 #define UI_MENU_ABOUT 16 83 #define UI_MENU_EXIT 17 84 #define UI_MENU_CASSETTE 18 85 #define UI_MENU_CONTROLLER 19 86 #define UI_MENU_WINDOWS 20 87 88 #ifdef DIRECTX 89 #define UI_MENU_SAVE_CONFIG 21 90 #define UI_MENU_FUNCT_KEY_HELP 22 91 #define UI_MENU_HOT_KEY_HELP 23 92 #endif 93 94 /* Structure of menu item. Each menu is just an array of items of this structure 95 terminated by UI_MENU_END */ 96 typedef struct 97 { 98 UWORD flags; /* Flags, see values below */ 99 SWORD retval; /* Value returned by Select when this item is selected */ 100 /* < 0 means that item is strictly informative and cannot be selected */ 101 char *prefix; /* Text to prepend the item */ 102 char *item; /* Main item text */ 103 const char *suffix; /* Optional text to show after the item text (e.g. key shortcut) */ 104 /* or (if (flags & UI_ITEM_TIP) != 0) "tooltip" */ 105 } UI_tMenuItem; 106 107 /* The following are item types, mutually exclusive. */ 108 #define UI_ITEM_HIDDEN 0x00 /* Item does not appear in the menu */ 109 #define UI_ITEM_ACTION 0x01 /* Item invokes an action */ 110 #define UI_ITEM_CHECK 0x02 /* Item represents a boolean value */ 111 #define UI_ITEM_FILESEL 0x03 /* Item invokes file/directory selection */ 112 #define UI_ITEM_SUBMENU 0x04 /* Item opens a submenu */ 113 #define UI_ITEM_END 0x05 /* Indicates end of menu */ 114 /* UI_ITEM_CHECK means that the value of UI_ITEM_CHECKED is shown. 115 UI_ITEM_FILESEL and UI_ITEM_SUBMENU are just for optional decorations, 116 so the user knows what happens when he/she selects this item. */ 117 #define UI_ITEM_TYPE 0x0f 118 119 /* The following are bit masks and should be combined with one of the above item types. */ 120 #define UI_ITEM_CHECKED 0x10 /* The boolean value for UI_ITEM_CHECK is true */ 121 #define UI_ITEM_TIP 0x20 /* suffix is shown when the item is selected rather than on its right */ 122 123 #if defined(_WIN32_WCE) || defined(DREAMCAST) 124 /* No function keys nor Alt+letter on Windows CE, Sega DC */ 125 #define UI_MENU_ACCEL(keystroke) NULL 126 #else 127 #define UI_MENU_ACCEL(keystroke) keystroke 128 #endif 129 130 #define UI_MENU_LABEL(item) { UI_ITEM_ACTION, -1, NULL, item, NULL } 131 #define UI_MENU_ACTION(retval, item) { UI_ITEM_ACTION, retval, NULL, item, NULL } 132 #define UI_MENU_ACTION_PREFIX(retval, prefix, item) { UI_ITEM_ACTION, retval, prefix, item, NULL } 133 #define UI_MENU_ACTION_PREFIX_TIP(retval, prefix, item, tip) { UI_ITEM_ACTION | UI_ITEM_TIP, retval, prefix, item, tip } 134 #define UI_MENU_ACTION_ACCEL(retval, item, keystroke) { UI_ITEM_ACTION, retval, NULL, item, UI_MENU_ACCEL(keystroke) } 135 #define UI_MENU_ACTION_TIP(retval, item, tip) { UI_ITEM_ACTION | UI_ITEM_TIP, retval, NULL, item, tip } 136 #define UI_MENU_CHECK(retval, item) { UI_ITEM_CHECK, retval, NULL, item, NULL } 137 #define UI_MENU_FILESEL(retval, item) { UI_ITEM_FILESEL, retval, NULL, item, NULL } 138 #define UI_MENU_FILESEL_PREFIX(retval, prefix, item) { UI_ITEM_FILESEL, retval, prefix, item, NULL } 139 #define UI_MENU_FILESEL_PREFIX_TIP(retval, prefix, item, tip) { UI_ITEM_FILESEL | UI_ITEM_TIP, retval, prefix, item, tip } 140 #define UI_MENU_FILESEL_ACCEL(retval, item, keystroke) { UI_ITEM_FILESEL, retval, NULL, item, UI_MENU_ACCEL(keystroke) } 141 #define UI_MENU_FILESEL_TIP(retval, item, tip) { UI_ITEM_FILESEL | UI_ITEM_TIP, retval, NULL, item, tip } 142 #define UI_MENU_SUBMENU(retval, item) { UI_ITEM_SUBMENU, retval, NULL, item, NULL } 143 #define UI_MENU_SUBMENU_SUFFIX(retval, item, suffix) { UI_ITEM_SUBMENU, retval, NULL, item, suffix } 144 #define UI_MENU_SUBMENU_ACCEL(retval, item, keystroke) { UI_ITEM_SUBMENU, retval, NULL, item, UI_MENU_ACCEL(keystroke) } 145 #define UI_MENU_END { UI_ITEM_END, 0, NULL, NULL, NULL } 146 147 /* UI driver entry prototypes */ 148 149 /* Select provides simple selection from menu. 150 title can be used as a caption. 151 If (flags & UI_SELECT_POPUP) != 0 the menu is a popup menu. 152 default_item is initially selected item (not item # but rather retval from menu structure). 153 menu is array of items of type UI_tMenuItem, must be termintated by UI_MENU_END. 154 If seltype is non-null, it is used to return selection type (see UI_USER_* below). 155 UI_USER_DRAG_UP and UI_USER_DRAG_DOWN are returned only if (flags & UI_SELECT_DRAG) != 0. 156 Returned is retval of the selected item or -1 if the user cancelled selection, 157 or -2 if the user pressed "magic key" (Tab). */ 158 typedef int (*UI_fnSelect)(const char *title, int flags, int default_item, const UI_tMenuItem *menu, int *seltype); 159 /* SelectInt returns an integer chosen by the user from the range min_value..max_value. 160 default_value is the initial selection and the value returned if the selection is cancelled. */ 161 typedef int (*UI_fnSelectInt)(int default_value, int min_value, int max_value); 162 /* SelectSlider selects integer chosen by user from the range 0..max_value. 163 start_value is the slider's initial value. The label displayed at the slider is created 164 by calling label_fun. This function takes three parameters: 165 - *label - a buffer into which the label shuld be written to (not longer than 10 chars, 166 excluding the trailing \0); 167 - value - the slider's current value, on which the label should be based; 168 - *user_data - a pointer to any data provided by user in SelectSlider's 169 *user_data parameter. 170 Returns -1 when the user has cancelled. 171 The return value should be converted by user to a usable range. */ 172 typedef int (*UI_fnSelectSlider)(char const *title, int start_value, int max_value, 173 void (*label_fun)(char *label, int value, void *user_data), 174 void *user_data); 175 /* EditString provides string input. pString is shown initially and can be modified by the user. 176 It won't exceed nSize characters, including NUL. Note that pString may be modified even 177 when the user pressed Esc. */ 178 typedef int (*UI_fnEditString)(const char *title, char *string, int size); 179 /* GetSaveFilename and GetLoadFilename return fully qualified file name via pFilename. 180 pDirectories are "favourite" directories (there are nDirectories of them). 181 Selection starts in the directory of the passed pFilename (i.e. pFilename must be initialized) 182 or (if pFilename[0] == '\0') in the first "favourite" directory. */ 183 typedef int (*UI_fnGetSaveFilename)(char *filename, char directories[][FILENAME_MAX], int n_directories); 184 typedef int (*UI_fnGetLoadFilename)(char *filename, char directories[][FILENAME_MAX], int n_directories); 185 /* GetDirectoryPath is a directory browser */ 186 typedef int (*UI_fnGetDirectoryPath)(char *directory); 187 /* Message is just some kind of MessageBox */ 188 typedef void (*UI_fnMessage)(const char *message, int waitforkey); 189 /* InfoScreen displays a "long" message. 190 Caution: lines in pMessage should be ended with '\0', the message should be terminated with '\n'. */ 191 typedef void (*UI_fnInfoScreen)(const char *title, const char *message); 192 /* Init is called to initialize driver every time UI code is executed. 193 Driver must be protected against multiple inits. */ 194 typedef void (*UI_fnInit)(void); 195 196 /* Bit masks for flags */ 197 #define UI_SELECT_POPUP 0x01 198 #define UI_SELECT_DRAG 0x02 199 200 /* Values returned via seltype */ 201 #define UI_USER_SELECT 1 202 #define UI_USER_TOGGLE 2 203 #define UI_USER_DELETE 3 204 #define UI_USER_DRAG_UP 4 205 #define UI_USER_DRAG_DOWN 5 206 207 typedef struct 208 { 209 UI_fnSelect fSelect; 210 UI_fnSelectInt fSelectInt; 211 UI_fnSelectSlider fSelectSlider; 212 UI_fnEditString fEditString; 213 UI_fnGetSaveFilename fGetSaveFilename; 214 UI_fnGetLoadFilename fGetLoadFilename; 215 UI_fnGetDirectoryPath fGetDirectoryPath; 216 UI_fnMessage fMessage; 217 UI_fnInfoScreen fInfoScreen; 218 UI_fnInit fInit; 219 } UI_tDriver; 220 221 /* Current UI driver. Port can override it and set pointer to port 222 specific driver */ 223 extern UI_tDriver *UI_driver; 224 225 #endif /* UI_H_ */ 226