Native dialogs support
These functions are declared in the following header file. Link with allegro_dialog.
typedef struct ALLEGRO_FILECHOOSER ALLEGRO_FILECHOOSER;
Opaque handle to a native file dialog.
typedef struct ALLEGRO_TEXTLOG ALLEGRO_TEXTLOG;
Opaque handle to a text log window.
ALLEGRO_FILECHOOSER *al_create_native_file_dialog( ALLEGRO_PATH const *initial_path, char const *title, char const *patterns, int mode)
Creates a new native file dialog. You should only have one such dialog opened at a time.
- initial_path: The initial search path and filename. Can be NULL.
- title: Title of the dialog.
- patterns: A list of semi-colon separated patterns to match. You should always include the pattern "*.*" as usually the MIME type and not the file pattern is relevant. If no file patterns are supported by the native dialog, this parameter is ignored.
- mode: 0, or a combination of the flags below.
Possible flags for the 'flags' parameter are:
- ALLEGRO_FILECHOOSER_FILE_MUST_EXIST: If supported by the native dialog, it will not allow entering new names, but just allow existing files to be selected. Else it is ignored.
- ALLEGRO_FILECHOOSER_SAVE: If the native dialog system has a different dialog for saving (for example one which allows creating new directories), it is used. Else ignored.
- ALLEGRO_FILECHOOSER_FOLDER: If there is support for a separate dialog to select a folder instead of a file, it will be used.
- ALLEGRO_FILECHOOSER_PICTURES: If a different dialog is available for selecting pictures, it is used. Else ignored.
- ALLEGRO_FILECHOOSER_SHOW_HIDDEN: If the platform supports it, also hidden files will be shown.
- ALLEGRO_FILECHOOSER_MULTIPLE: If supported, allow selecting multiple files.
If a dialog window could not be created then this function returns NULL.
bool al_show_native_file_dialog(ALLEGRO_DISPLAY *display, ALLEGRO_FILECHOOSER *dialog)
Show the dialog window. The display may be NULL, otherwise the given display is treated as the parent if possible.
This function blocks the calling thread until it returns, so you may want to spawn a thread with al_create_thread and call it from inside that thread.
Returns true on success, false on failure.
int al_get_native_file_dialog_count(const ALLEGRO_FILECHOOSER *dialog)
Returns the number of files selected, or 0 if the dialog was cancelled.
const ALLEGRO_PATH *al_get_native_file_dialog_path( const ALLEGRO_FILECHOOSER *dialog, size_t i)
Returns one of the selected paths.
void al_destroy_native_file_dialog(ALLEGRO_FILECHOOSER *dialog)
Frees up all resources used by the file dialog.
int al_show_native_message_box(ALLEGRO_DISPLAY *display, char const *title, char const *heading, char const *text, char const *buttons, int flags)
Show a native GUI message box. This can be used for example to display an error message if creation of an initial display fails. The display may be NULL, otherwise the given display is treated as the parent if possible.
The message box will have a single "OK" button and use the style informative dialog boxes usually have on the native system. If the
buttons parameter is not NULL, you can instead specify the button text in a string, with buttons separated by a vertical bar (|).
|ALLEGRO_MESSAGEBOX_WARN||The message is a warning. This may cause a different icon (or other effects).|
|ALLEGRO_MESSAGEBOX_ERROR||The message is an error.|
|ALLEGRO_MESSAGEBOX_QUESTION||The message is a question.|
|ALLEGRO_MESSAGEBOX_OK_CANCEL||Instead of the "OK" button also display a cancel button. Ignored if |
|ALLEGRO_MESSAGEBOX_YES_NO||Instead of the "OK" button display Yes/No buttons. Ignored if |
- 0 if the dialog window was closed without activating a button.
- 1 if the OK or Yes button was pressed.
- 2 if the Cancel or No button was pressed.
buttons is not NULL, the number of the pressed button is returned, starting with 1.
If a message box could not be created then this returns 0, as if the window was dismissed without activating a button.
button = al_show_native_message_box( display, "Warning", "Are you sure?", "If you click yes then you are confirming that \"Yes\"" "is your response to the query which you have" "generated by the action you took to open this" "message box.", NULL, ALLEGRO_MESSAGEBOX_YES_NO );
ALLEGRO_TEXTLOG *al_open_native_text_log(char const *title, int flags)
Opens a window to which you can append log messages with al_append_native_text_log. This can be useful for debugging if you don't want to depend on a console being available.
Use al_close_native_text_log to close the window again.
The flags available are:
Prevent the window from having a close button. Otherwise if the close button is pressed an event is generated; see al_get_native_text_log_event_source.
Use a monospace font to display the text.
Returns NULL if there was an error opening the window, or if text log windows are not implemented on the platform.
void al_close_native_text_log(ALLEGRO_TEXTLOG *textlog)
Closes a message log window opened with al_open_native_text_log earlier.
Does nothing if passed NULL.
See also: al_open_native_text_log
void al_append_native_text_log(ALLEGRO_TEXTLOG *textlog, char const *format, ...)
Appends a line of text to the message log window and scrolls to the bottom (if the line would not be visible otherwise). This works like printf. A line is continued until you add a newline character.
If the window is NULL then this function will fall back to calling printf. This makes it convenient to support logging to a window or a terminal.
ALLEGRO_EVENT_SOURCE *al_get_native_text_log_event_source( ALLEGRO_TEXTLOG *textlog)
Get an event source for a text log window. The possible events are:
- The window was requested to be closed, either by pressing the close button or pressing Escape on the keyboard. The user.data1 field will hold a pointer to the ALLEGRO_TEXTLOG which generated the event. The user.data2 field will be 1 if the event was generated as a result of a key press; otherwise it will be zero.
Returns the (compiled) version of the addon, in the same format as al_get_allegro_version.