Native dialogs support
- ALLEGRO_FILECHOOSER
- ALLEGRO_TEXTLOG
- al_init_native_dialog_addon
- al_shutdown_native_dialog_addon
- al_create_native_file_dialog
- al_show_native_file_dialog
- al_get_native_file_dialog_count
- al_get_native_file_dialog_path
- al_destroy_native_file_dialog
- al_show_native_message_box
- al_open_native_text_log
- al_close_native_text_log
- al_append_native_text_log
- al_get_native_text_log_event_source
- al_get_allegro_native_dialog_version
These functions are declared in the following header file. Link with allegro_dialog.
#include <allegro5/allegro_native_dialog.h>
ALLEGRO_FILECHOOSER
typedef struct ALLEGRO_FILECHOOSER ALLEGRO_FILECHOOSER;
Opaque handle to a native file dialog.
ALLEGRO_TEXTLOG
typedef struct ALLEGRO_TEXTLOG ALLEGRO_TEXTLOG;
Opaque handle to a text log window.
al_init_native_dialog_addon
bool al_init_native_dialog_addon(void)
Initialise the native dialog addon.
Returns true on success, false on error.
Since: 5.0.9, 5.1.0
Note: Prior to Allegro 5.1.0 native dialog functions could be called without explicit initialisation, but that is now deprecated. Future functionality may require explicit initialisation. An exception is al_show_native_message_box, which may be useful to show an error message if Allegro fails to initialise.
See also: al_shutdown_native_dialog_addon
al_shutdown_native_dialog_addon
void al_shutdown_native_dialog_addon(void)
Shut down the native dialog addon.
Since: 5.0.9, 5.1.5
See also: al_init_native_dialog_addon
al_create_native_file_dialog
ALLEGRO_FILECHOOSER *al_create_native_file_dialog(
char 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.
Parameters:
initial_path: The initial search path and filename. Can be NULL. To start with a blank file name the string should end with a directory separator (this should be the common case).
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.
Returns:
A handle to the dialog which you can pass to al_show_native_file_dialog to display it, and from which you then can query the results. When you are done, call al_destroy_native_file_dialog on it.
If a dialog window could not be created then this function returns NULL.
al_show_native_file_dialog
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.
al_get_native_file_dialog_count
int al_get_native_file_dialog_count(const ALLEGRO_FILECHOOSER *dialog)
Returns the number of files selected, or 0 if the dialog was cancelled.
al_get_native_file_dialog_path
const char *al_get_native_file_dialog_path(
const ALLEGRO_FILECHOOSER *dialog, size_t i)
Returns one of the selected paths.
al_destroy_native_file_dialog
void al_destroy_native_file_dialog(ALLEGRO_FILECHOOSER *dialog)
Frees up all resources used by the file dialog.
al_show_native_message_box
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
buttons
is not NULL. - ALLEGRO_MESSAGEBOX_YES_NO
- Instead of the "OK" button display Yes/No buttons. Ignored if
buttons
is not NULL.
al_show_native_message_box may be called without Allegro being installed. This is useful to report an error to initialise Allegro itself.
Returns:
- 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.
If 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.
Example:
int 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
);
al_open_native_text_log
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:
- ALLEGRO_TEXTLOG_NO_CLOSE
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.
- ALLEGRO_TEXTLOG_MONOSPACE
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.
See also: al_append_native_text_log, al_close_native_text_log
al_close_native_text_log
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
al_append_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.
al_get_native_text_log_event_source
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:
- ALLEGRO_EVENT_NATIVE_DIALOG_CLOSE
- 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.
al_get_allegro_native_dialog_version
uint32_t al_get_allegro_native_dialog_version(void)
Returns the (compiled) version of the addon, in the same format as al_get_allegro_version.