User:Compyx

From vice-emu
Revision as of 22:55, 16 June 2023 by Compyx (talk | contribs) (Start collection observations on the SDL UI code on my personal Wiki paga)
Jump to navigation Jump to search

Personal notes, observations and rants

SDL UI code

Since I'm tasked with updating the SDL code to use the generic UI actions and hotkeys code and use those UI actions from the menu items, hotkeys and custom joystick mappings, and the code is poorly documented, I'll be writing down some observations on how the SDL UI code works here.

Menu items

Menu items are defined with the type ui_menu_entry_t (in uimenu.h):

typedef struct ui_menu_entry_s {
    char *string;
    ui_menu_entry_type_t type;
    ui_callback_t callback;
    ui_callback_data_t data;
    ui_menu_status_type_t status;
} ui_menu_entry_t;

The string is used to display the item text in the menus. It is used by sdl_ui_display_item() to render a menu item. The type determines what to do when the user activates the item, types include radio buttons, toggle buttons, submenus, and dialogs. When an item is activated the callback is called with data as its argument. The return value of the callback (a const char*) is used to update the item's state or to exit the UI (more on that later). The status field is used for radio buttons to display the selection's state (or something like that).

The various menu item types are defined as:

typedef enum {
    /* Text item (no operation): if data == 1 text colors are inverted */
    MENU_ENTRY_TEXT = 0,

    /* Resource toggle: no UI needed, callback is used */
    MENU_ENTRY_RESOURCE_TOGGLE,

    /* Resource radio: no UI needed, callback is used, data is the resource value */
    MENU_ENTRY_RESOURCE_RADIO,

    /* Resource int: needs UI, callback is used */
    MENU_ENTRY_RESOURCE_INT,

    /* Resource string: needs UI, callback is used */
    MENU_ENTRY_RESOURCE_STRING,

    /* Submenu: needs UI, data points to the submenu */
    MENU_ENTRY_SUBMENU,

    /* Dynamic submenu: needs UI, data points to the submenu, hotkeys disabled */
    MENU_ENTRY_DYNAMIC_SUBMENU,

    /* Custom dialog: needs UI */
    MENU_ENTRY_DIALOG,

    /* Other: no UI needed */
    MENU_ENTRY_OTHER,

    /* Other: no UI needed */
    MENU_ENTRY_OTHER_TOGGLE
} ui_menu_entry_type_t;