This class facilitates the easy creation of user interfaces that convey their usage entirely through audio.
audio_form::get_last_error().Activate progress updates on a progress bar control.
bool audio_form::activate_progress_timer(int control_index);
bool: true if the progress bar was successfully activated, false otherwise.
Add a string item to a list control.
bool audio_form::add_list_item(int control_index, string option, int position = -1, bool selected = false, bool focus_if_first = true);bool audio_form::add_list_item(int control_index, string option, string id, int position = -1, bool selected = false, bool focus_if_first = true);bool: true if the item was successfully added, false otherwise.
This function only works on list controls.
Clear a list control of all its items.
bool audio_form::clear_list(int control_index);
bool: true if the list was successfully cleared, false otherwise.
Creates a new button and adds it to the audio form.
int audio_form::create_button(string caption, bool primary = false, bool cancel = false, bool overwrite = true);
int: the control index of the new button, or -1 if there was an error. To get error information, look at audio_form::get_last_error();.
Creates a new checkbox and adds it to the audio form.
int audio_form::create_checkbox(string caption, bool initial_value = false, bool read_only = false);
int: the control index of the new checkbox, or -1 if there was an error. To get error information, see audio_form::get_last_error();.
Creates an input box control on the audio form.
int audio_form::create_input_box(string caption, string default_text = "", string password_mask = "", int maximum_length = 0, bool read_only = false, bool multiline = false, bool multiline_enter = true);
int: the control index of the new input box, or -1 if there was an error. To get error information, look at audio_form::get_last_error();.
Creates a new keyboard area and adds it to the audio form.
int audio_form::create_keyboard_area(string caption);
int: the control index of the new keyboard area, or -1 if there was an error. To get error information, see audio_form::get_last_error();.
Creates a new link and adds it to the audio form.
int audio_form::create_link(string caption, string url);
int: the control index of the new link, or -1 if there was an error. To get error information, see audio_form::get_last_error();.
The link control is similar to buttons, but this opens the given link when pressed. This also speaks the error message if the link cannot be opened or the link isn't an actual URL. If you want the maximum possible customization, use audio_form::create_button method instead.
Creates a new list control and adds it to the audio form.
int audio_form::create_list(string caption, int maximum_items = 0, bool multiselect = false, bool repeat_boundary_items = false);
int: the control index of the new list, or -1 if there was an error. To get error information, look at audio_form::get_last_error();.
Creates a new progress bar control and adds it to the audio form.
int audio_form::create_progress_bar(string caption, int speak_interval = 5, bool speak_global = true);
int: the control index of the new progress bar, or -1 if there was an error. To get error information, look at audio_form::get_last_error();.
Creates a new slider control and adds it to the audio form.
int audio_form::create_slider(string caption, double default_value = 50, double minimum_value = 0, double maximum_value = 100, string text = "", double step_size = 1);
int: the control index of the new slider, or -1 if there was an error. To get error information, see audio_form::get_last_error();.
Creates a new status bar and adds it to the audio form.
int audio_form::create_status_bar(string caption, string text);
int: the control index of the new status bar, or -1 if there was an error. To get error information, see audio_form::get_last_error();.
Creates a new sub form and adds it to the audio form.
int audio_form::create_subform(string caption, audio_form@ f);
string caption: the label to associate with the sub form.
audio_form@ f: an object pointing to an already created form.
int: the control index of the new sub form control, or -1 if there was an error. To get error information, look at audio_form::get_last_error();.
#include "form.nvgt"
// some imaginary global application variables.
bool logostart = true, menuwrap = false, firespace = false, radar = true;
// First, lets make a class which stores a category name and the form that the category is linked to.
class settings_category {
string name;
audio_form@ f;
settings_category(string n, audio_form@ f) {
this.name = n;
@this.f = @f;
}
}
void settings_dialog() {
// Define some categories and settings on each category like this:
audio_form fc_general;
fc_general.create_window();
int f_logostart = fc_general.create_checkbox("Play &logo on startup", logostart);
int f_menuwrap = fc_general.create_checkbox("Wrap &menus", menuwrap);
audio_form fc_gameplay;
fc_gameplay.create_window();
int f_firespace = fc_gameplay.create_checkbox("Use space instead of control to &fire", firespace);
int f_radar = fc_gameplay.create_checkbox("Enable the &radar", firespace);
// Add as many categories as you want this way.
audio_form f; // The overarching main form.
f.create_window("Settings", false, true);
int f_category_list = f.create_tab_panel("&Category"); // The user will select categories from here. Note: you can also use create_list.
int f_category_display = f.create_subform("General settings", @fc_general); // Now by default, the main form embeds the general category form right there.
int f_ok = f.create_button("&Save settings", true);
int f_cancel = f.create_button("Cancel", false, true);
// Now lets create a structured list of categories that can be browsed based on the class above.
settings_category@[] categories = {
settings_category("General", @fc_general),
settings_category("Gameplay", @fc_gameplay)
};
// And then add the list of categories to the form's list.
for (uint i = 0; i < categories.length(); i++) {
f.add_list_item(f_category_list, categories[i].name);
}
// Focus the form's list position on the general category, then set the form's initial focused control to the category list.
f.set_list_position(f_category_list, 0);
f.focus(0);
settings_category@ last_category = @categories[0]; // A handle to the currently selected category so we can detect changes to the selection.
// Finally this is the loop that does the rest of the magic.
while (!f.is_pressed(f_cancel)) {
wait(5);
f.monitor();
int pos = f.get_list_position(f_category_list);
settings_category@ selected_category = null;
if (pos > -1 and pos < categories.length())
@selected_category = @categories[pos];
if (@last_category != @selected_category) {
last_category.f.subform_control_index = -1; // Later improvements to audio form will make this line be handled internally.
last_category.f.focus_silently(0); // Make sure that if the category is reselected, it is focused on the first control.
@last_category = @selected_category;
f.set_subform(f_category_display, @selected_category.f);
f.set_caption(f_category_display, selected_category.name + " settings");
}
// The following is a special feature I came up with in stw which makes it so that if you are in the category list, keyboard shortcuts from the entire form will work regardless of category.
if (f.get_current_focus() == f_category_list and key_down(KEY_LALT) or key_down(KEY_RALT)) {
for (uint i = 0; i < categories.length(); i++) {
if (categories[i].f.check_shortcuts(true)) {
f.set_list_position(f_category_list, i);
@last_category = @categories[i];
f.set_subform(f_category_display, @last_category.f);
f.set_caption(f_category_display, last_category.name + " settings");
f.focus(f_category_display);
break;
}
}
}
// Now we can finally check for the save button.
if (f.is_pressed(f_ok)) {
logostart = fc_general.is_checked(f_logostart);
menuwrap = fc_general.is_checked(f_menuwrap);
firespace = fc_gameplay.is_checked(f_firespace);
radar = fc_gameplay.is_checked(f_radar);
return;
}
}
}
// Lets make this thing run so we can see it work.
void main() {
show_window("test");
settings_dialog();
}
Creates a window to show audio form controls.
void audio_form::create_window();
void audio_form::create_window(string window_title, bool change_screen_title = true, bool say_dialog = true, bool silent = false);
string window_title: the title of the window.
bool change_screen_title = true: whether or not the main window's title should be set as well.
bool say_dialog = true: whether or not the window should be reported as a dialog (in the context of the audio form).
bool silent = false: should this window be shown silently?
#include "form.nvgt"
#include "speech.nvgt"
void main() {
audio_form f;
f.create_window("Test");
wait(50); // Give screen readers time to speak the window title.
int f_exit = f.create_button("exit");
f.focus(f_exit);
while (true) {
wait(5);
f.monitor();
if (f.is_pressed(f_exit))
exit();
}
}
Removes a control with a particular index from the audio form.
bool audio_form::delete_control(int control_index);
bool: true if the control was successfully deleted, false otherwise.
Remove an item from a list control.
bool audio_form::delete_list_item(int control_index, int list_index, bool reset_cursor = true, bool speak_deletion_status = true);
bool: true if the item was successfully deleted, false otherwise.
Unselect any currently selected items in a list control.
bool audio_form::delete_list_selections(int control_index, bool reset_cursor = true, bool speak_deletion_status = true);
bool: true if the selection was successfully cleared, false otherwise.
Edits the value of a list item.
bool audio_form::edit_list_item(int control_index, string new_option, int position);
bool: true if the item's value was successfully updated, false otherwise.
Modifies the ID of a list item.
bool audio_form::edit_list_item_id(int control_index, string new_id, int position);
bool: true if the item's ID was successfully updated, false otherwise.
Set a particular control to have the keyboard focus, and notify the user.
bool audio_form::focus(int control_index);
bool: true if the control was successfully focused, false otherwise.
Set a particular control to have the keyboard focus, and notify the user (cutting off any previous speech).
bool audio_form::focus_interrupt(int control_index);
bool: true if the control was successfully focused, false otherwise.
Set a particular control to have the keyboard focus, without notifying the user.
bool audio_form::focus_silently(int control_index);
bool: true if the control was successfully focused, false otherwise.
Get the control index of the cancel button (e.g. the button activated when pressing escape anywhere on an audio form).
int audio_form::get_cancel_button();
int: the control index of the cancel button.
Get the caption of a control.
string audio_form::get_caption(int control_index);
string: the caption of the control.
Get a list of all currently checked items in a list control.
int[]@ audio_form::get_checked_list_items(int control_index);
int[]@: handle to an array containing the index of every checked item in the list.
This function only works on multiselect lists. If you want something that also works on single-select lists, see get_list_selections().
Returns the number of controls currently present on the form.
int audio_form::get_control_count();
int: the number of controls currently on the form.
Returns the type of a control.
int audio_form::get_control_type(int control_index);
int: the type of the control (see control_types for more information).
Get the control index of the control with the keyboard focus.
int audio_form::get_current_focus();
int: the control index that currently has the keyboard focus.
Get the custom type of the control, if available.
string audio_form::get_custom_type(int control_index);
string: the custom type set on this control if available, an empty string otherwise.
Get the control index of the default button (e.g. the button activated when pressing enter anywhere on an audio form).
int audio_form::get_default_button();
int: the control index of the default button.
Get the last error that was raised from this form.
int audio_form::get_last_error();
int: the last error code raised by this audio_form ( see audioform_errorcodes for more information).
As noted in the introduction to this class, exceptions are not used here. Instead, we indicate errors through this function.
Get the current line column of an input box.
int audio_form::get_line_column(int control_index);
int: The line column of the input box, or -1 if there was an error.
This method only works on input boxes.
Get the current line number of an input box.
int audio_form::get_line_number(int control_index);
int: The line number of the input box, or -1 if there was an error.
This method only works on input boxes.
Retrieves the URL of the link control.
string audio_form::get_link_url(int control_index);
string: the URL.
This method only works on link control.
Get the number of items contained in a list control.
int audio_form::get_list_count(int control_index);
int: the number of items in the list.
Get the index of a list item by its ID.
int audio_form::get_list_index_by_id(int control_index, string id);
int: the index of the item, -1 on error.
Get the text of a particular list item.
string audio_form::get_list_item(int control_index, int list_index);
string: the text of the item.
Get the ID of a particular list item.
string audio_form::get_list_item_id(int control_index, int list_index);
string: the ID of the item.
Get the user's currently focused item in a list control.
int audio_form::get_list_position(int control_index);
int: the user's current cursor position in the list.
Get a list of all items currently selected in a list control.
int[]@ audio_form::get_list_selections(int control_index);
int[]@: handle to an array containing the index of every selected item in the list (see remarks).
In the context of this function, a selected item is any item that is checked (if the list supports multiselection), as well as the currently selected item. If you want to only get the state of checked list items, see the get_checked_list_items() function.
Get the value of a progress bar.
int audio_form::get_progress(int control_index);
int: the current value of the progress bar.
This method only works on progress bar controls.
Get the value of a slider.
double audio_form::get_slider(int control_index);
double: the current value of the slider. In case of error, this may return -1. To get error information, see audio_form::get_last_error();.
This method only works on slider control.
Get the maximum value of a slider.
double audio_form::get_slider_maximum_value(int control_index);
double: the maximum allowable value the slider may be set to. In case of error, this may return -1. To get error information, see audio_form::get_last_error();.
This method only works on slider control.
Get the minimum value of a slider.
double audio_form::get_slider_minimum_value(int control_index);
double: the minimum allowable value the slider may be set to. In case of error, this may return -1. To get error information, see audio_form::get_last_error();.
This method only works on slider control.
Get the text from an input box or status bar.
string audio_form::get_text(int control_index);
string: The text from the control, or an empty string if there was an error.
This method only works on input boxes and status bars.
Determines whether the control has its custom type set.
bool audio_form::has_custom_type(int control_index);
bool: true if the control has its custom type set, false otherwise.
Please note that this method is equivalent to audio_form::get_custom_type(control_index).empty()
Get the state of a checkbox.
bool audio_form::is_checked(int control_index);
bool: true if the checkbox is checked, false otherwise.
This function only works on checkbox controls.
Determines whether the text of a given control contains characters that are not allowed, set by the audio_form::set_disallowed_chars method.
bool audio_form::is_disallowed_char(int control_index, string char, bool search_all = true);
bool: true if the text of the control contains disallowed characters, false otherwise.
The search_all parameter will match the characters depending upon its state. If set to false, the entire string will be searched. If set to true, it will loop through each character and see if one of them contains disallowed character. Thus, you will usually set this to true. One example you might set to false is when the form only has 1 character length, but it is not required, it is looping each character already. However, it is also a good idea to turn this off for the maximum possible performance if you're sure that the input only requires 1 length of characters.
Determine if a particular control is enabled or not.
bool audio_form::is_enabled(int control_index);
bool: true if the control is enabled, false if it's disabled.
Determine if the list item at a particular index is checked or not.
bool audio_form::is_list_item_checked(int control_index, int item_index);
bool: true if the item exists and is checked, false otherwise.
Determine if a particular control is multiline or not.
bool audio_form::is_multiline(int control_index);
bool: true if the control is multiline, false otherwise.
This function only works on input boxes.
Determine if a particular button was just pressed.
bool audio_form::is_pressed(int control_index);
bool: true if the button was just pressed, false otherwise.
This function only works on button controls.
Determine if a particular control is read-only or not.
bool audio_form::is_read_only(int control_index);
bool: true if the control is read-only, false if it's not.
This function only works on input boxes and checkboxes.
Determine if a particular control is visible or not.
bool audio_form::is_visible(int control_index);
bool: true if the control is visible, false if it's invisible.
Processes all keyboard input, and dispatches all events to the form. Should be called in your main loop.
int audio_form::monitor();
int: this value can be ignored for users of this class; it's used internally for subforms.
Pause updating of a progress bar control.
bool audio_form::pause_progress_timer(int control_index);
bool: true if the progress bar was paused, false otherwise.
Set the primary and cancel flags of a button.
`bool audio_form::set_button_attributes(int control_index, bool primary, bool cancel, bool overwrite = true);
bool: true if the attributes were successfully set, false otherwise.
Sets the caption of a control.
bool audio_form::set_caption(int control_index, string caption);
bool: true if the caption was successfully set, false otherwise.
The caption is read every time a user focuses this particular control.
It is possible to associate hotkeys with controls by putting an "&" symbol in the caption. For example, setting the caption of a button to "E&xit" would assign the hotkey alt+x to focus it.
Set the state of a checkbox (either checked or unchecked).
bool audio_form::set_checkbox_mark(int control_index, bool checked);
bool: true if the operation was successful, false otherwise. To get error information, look at audio_form::get_last_error();.
Sets a custom type for a control.
bool audio_form::set_custom_type(int control_index, string custom_type);
bool: true if the custom text type was successfully set, false otherwise.
Sets default and cancel buttons for this form.
bool set_default_controls(int primary, int cancel);
bool: true if the controls were successfully set, false otherwise.
Sets the default keyboard echo of controls on your form.
bool audio_form::set_default_keyboard_echo(int keyboard_echo, bool update_controls = true);
bool: true if the echo was successfully set, false otherwise.
Sets the whitelist/blacklist characters of a control.
bool audio_form::set_disallowed_chars(int control_index, string chars, bool use_only_disallowed_chars = false, string char_disallowed_description = "");
bool: true if the characters were successfully set, false otherwise.
Setting the use_only_disallowed_chars parameter to true will restrict all characters that are not in the list. This is useful to prevent other characters in number inputs.
Setting the chars parameter to empty will clear the characters and will switch back to default.
Please note that these character sets will also restrict the text from being pasted if the clipboard contains disallowed characters.
Toggles whether the control can use go to line functionality.
bool audio_form::set_enable_go_to_index(int control_index, bool enabled);
bool: true if the state was successfully set, false otherwise.
Toggles whether the control can use search functionality.
bool audio_form::set_enable_search(int control_index, bool enabled);
bool: true if the state was successfully set, false otherwise.
Set the keyboard echo for a particular control.
bool audio_form::set_keyboard_echo(int control_index, int keyboard_echo);
bool: true if the keyboard echo was successfully set, false otherwise.
Sets the URL of the link control.
bool audio_form::set_link_url(int control_index, string new_url);
bool: true on success, false on failure.
This method only works on link control.
Configures how the multi-letter navigation works in a list control.
bool audio_form::set_list_multinavigation(int control_index, bool letters, bool numbers, bool nav_translate = true);
bool: true if the settings were successfully set, false otherwise.
Set the user's cursor in a list control.
bool audio_form::set_list_position(int control_index, int position = -1, bool speak_new_item = false);
bool: true if the cursor position was successfully set, false otherwise.
Sets the properties of a list control.
bool audio_form::set_list_propertyes(int control_index, bool multiselect=false, bool repeat_boundary_items=false);
bool: true on success, false on failure.
Sets the progress percentage on the progress control.
bool audio_form::set_progress(int control_index, int value);
bool: true on success, false on failure.
This method only works on progress control.
Sets the value of the slider control.
bool audio_form::set_slider(int control_index, double value, double min = -1, double max = -1);
bool: true on success, false on failure.
This method only works on slider control.
Set the enabled/visible state of a control.
bool audio_form::set_state(int control_index, bool enabled, bool visible);
bool: true if the state was successfully set, false otherwise.
Sets a sub form to use on the current form.
bool audio_form::set_subform(int control_index, audio_form@ f);
int control_index: the control index of the sub form created with audio_form::create_subform method.
audio_form@ f: an object pointing to an already created form.
bool: true if the operation was successful, false otherwise. To get error information, look at audio_form::get_last_error();.
#include "form.nvgt"
// some imaginary global application variables.
bool logostart = true, menuwrap = false, firespace = false, radar = true;
// First, lets make a class which stores a category name and the form that the category is linked to.
class settings_category {
string name;
audio_form@ f;
settings_category(string n, audio_form@ f) {
this.name = n;
@this.f = @f;
}
}
void settings_dialog() {
// Define some categories and settings on each category like this:
audio_form fc_general;
fc_general.create_window();
int f_logostart = fc_general.create_checkbox("Play &logo on startup", logostart);
int f_menuwrap = fc_general.create_checkbox("Wrap &menus", menuwrap);
audio_form fc_gameplay;
fc_gameplay.create_window();
int f_firespace = fc_gameplay.create_checkbox("Use space instead of control to &fire", firespace);
int f_radar = fc_gameplay.create_checkbox("Enable the &radar", firespace);
// Add as many categories as you want this way.
audio_form f; // The overarching main form.
f.create_window("Settings", false, true);
int f_category_list = f.create_tab_panel("&Category"); // The user will select categories from here. Note: you can also use create_list.
int f_category_display = f.create_subform("General settings", @fc_general); // Now by default, the main form embeds the general category form right there.
int f_ok = f.create_button("&Save settings", true);
int f_cancel = f.create_button("Cancel", false, true);
// Now lets create a structured list of categories that can be browsed based on the class above.
settings_category@[] categories = {
settings_category("General", @fc_general),
settings_category("Gameplay", @fc_gameplay)
};
// And then add the list of categories to the form's list.
for (uint i = 0; i < categories.length(); i++) {
f.add_list_item(f_category_list, categories[i].name);
}
// Focus the form's list position on the general category, then set the form's initial focused control to the category list.
f.set_list_position(f_category_list, 0);
f.focus(0);
settings_category@ last_category = @categories[0]; // A handle to the currently selected category so we can detect changes to the selection.
// Finally this is the loop that does the rest of the magic.
while (!f.is_pressed(f_cancel)) {
wait(5);
f.monitor();
int pos = f.get_list_position(f_category_list);
settings_category@ selected_category = null;
if (pos > -1 and pos < categories.length())
@selected_category = @categories[pos];
if (@last_category != @selected_category) {
last_category.f.subform_control_index = -1; // Later improvements to audio form will make this line be handled internally.
last_category.f.focus_silently(0); // Make sure that if the category is reselected, it is focused on the first control.
@last_category = @selected_category;
f.set_subform(f_category_display, @selected_category.f);
f.set_caption(f_category_display, selected_category.name + " settings");
}
// The following is a special feature I came up with in stw which makes it so that if you are in the category list, keyboard shortcuts from the entire form will work regardless of category.
if (f.get_current_focus() == f_category_list and key_down(KEY_LALT) or key_down(KEY_RALT)) {
for (uint i = 0; i < categories.length(); i++) {
if (categories[i].f.check_shortcuts(true)) {
f.set_list_position(f_category_list, i);
@last_category = @categories[i];
f.set_subform(f_category_display, @last_category.f);
f.set_caption(f_category_display, last_category.name + " settings");
f.focus(f_category_display);
break;
}
}
}
// Now we can finally check for the save button.
if (f.is_pressed(f_ok)) {
logostart = fc_general.is_checked(f_logostart);
menuwrap = fc_general.is_checked(f_menuwrap);
firespace = fc_gameplay.is_checked(f_firespace);
radar = fc_gameplay.is_checked(f_radar);
return;
}
}
}
// Lets make this thing run so we can see it work.
void main() {
show_window("test");
settings_dialog();
}
Sets the text of the control.
bool audio_form::set_text(int control_index, string new_text);
bool: true on success, false on failure.
This method only works on input field, slider, and status bar.
Determine if the form is currently active.
bool audio_form::active;
This enum contains any error values that can be returned by the audio_form::get_last_error(); function.
Lists all possible event types that can be raised.
This is a complete list of all control types available in the audio form, as well as a brief description of what they do.
This is a list of constants that specify text editing modes, used mainly with audio_form::edit_text();.
See the audio_form::edit_text(); documentation for more information.
This enum provides constants to be used with the character echo functionality in input boxes.
Set whether or not the right Alt key should be disabled in input boxes, mostly useful for users with non-english keyboards.
bool audioform_input_disable_ralt;
Set the default echo mode for all the forms. Default is textflag_characters
int audioform_keyboard_echo;
A list of characters that should be considered word boundaries for navigation in an input box.
string audioform_word_separators;