GUI Procedures



A NAS GUI dialog is stored as an array/tree of NAS_WIDGET objects, each one containing the fields:

   typedef int NAS_PROC(int msg, struct NAS_WIDGET *d, BITMAP *wnd, int c);
   typedef unsigned long int U_LINT;
   typedef struct NAS_WIDGET
   {
      NAS_PROC *proc            - Dialog procedure (message handler)
      int x, y, w, h;           - Position and size of the object
      char *label;              - Text label for a widget
      char key;                 - ASCII keyboard shortcut
      U_LINT flags;             - Flags about the status of the object
      void *dp;                 - Pointer to more object-specific data
      struct NAS_WIDGET *child; - Pointer to a nested child widget list
      NAS_WIDGET *next;         - Pointer to the next widget in the list
      NAS_WIDGET *prev;         - Pointer to the previous widget in the list
   } NAS_WIDGET;

The array should end with an object which has the proc pointer set to NULL.

The flags field may contain any combination of the bit flags:

        D_EXIT          - This object should close the dialog when it is 
                          clicked
        D_SELECTED      - This object is selected
        D_GOTFOCUS      - This object has got the input focus
        D_GOTMOUSE      - The mouse is currently on top of this object
        D_HIDDEN        - This object is hidden and inactive
        D_DISABLED      - This object is greyed-out and inactive
        D_DIRTY         - This object needs to be redrawn
        D_INTERNAL      - Don't use this! It is for internal use by the
                          library...
        D_USER          - Any powers of two above this are free for your own 
                          use

Extended NAS GUI flags:
        D_DEFAULT_W        - This object should resize to a default width               
        D_DEFAULT_H        - This object should resize to a default height              
        D_RESIZE           - Allows a dialog to resize (dialog only)
        D_MOVABLE          - Allows a dialog to move with the mouse (dialog 
                             only)      
        D_MAXIMIZE         - Allows a dialog to maximize (dialog only)          
        D_MINIMIZE         - Allows a dialog to minimize (dialog only)
        D_HELP             - Displays the help icon on a dialog (dialog only) 
                             NOT IMPLIMENTED                    
        D_GRIP             - Displays the resize grip on a dialog (dialog only)                 
        D_SEPARATOR        - Displays a separator if a menu is present on a 
                             dialog (dialog only)               
        D_MULTISELECT      - Allows a listbox to have multiple selected items 
                             (listbox only) NOT IMPLIMENTED                     
        D_TOGGLEBUTTON     - Allows a button to toggle on and off (button only)

Note: NAS GUI's flag field is extened (unsigned long int), this allows for more flexibility in the number of flags it can have.

Each object is controlled by a dialog procedure, which is stored in the proc pointer. This will be called by the dialog manager whenever any action concerning the object is required, or you can call it directly with the object_message() function. The dialog procedure should follow the form:

   int foo(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);

It will be passed a flag (msg) indicating what action it should perform, a pointer to the object concerned (d), if msg is MSG_CHAR or MSG_XCHAR, the key that was pressed (c), and (wnd) is a pointer to a valid canvas bitmap with which to draw to. NAS GUI doesn't draw to the screen until nas_update_dialog is called and all widgets are drawn to an offscreen bitmap object.
Note:
d is a pointer to a specific object, and not to the entire dialog.

The dialog procedure should return one of the values:

        D_O_K             - Normal return status
        D_CLOSE           - Tells the dialog manager to close the dialog
        D_REDRAW          - Tells the dialog manager to redraw the entire dialog
        D_REDRAWME        - Tells the dialog manager to redraw the current object
        D_WANTFOCUS       - Requests that the input focus be given to this object
        D_WANTDIALOGFOCUS - Requests that the input focus be given to this dialog
        D_USED_CHAR       - MSG_CHAR and MSG_XCHAR return this if they used the 
                            key
        D_ERROR           - Error occurred, dialog will be immediately terminated

Extended NAS GUI return values:
        D_DESTROY      - Like the allegro GUI, procedures keep information that 
                         is reused. If you send D_DESTROY however all 
                         information that is kept in memory about all widgets 
                         will be destroyed.

Dialog procedures may be called with any of the messages:

MSG_START:
Tells the object to initialise itself. The dialog manager sends this to all the objects in a dialog just before it displays the dialog.

MSG_END:
Sent to all objects when closing a dialog, allowing them to perform whatever cleanup operations they require.

MSG_DRAW:
Tells the object to draw itself onto the screen. The mouse pointer will be turned off when this message is sent, so the drawing code does not need to worry about it.

MSG_CLICK:
Informs the object that a mouse button has been clicked while the mouse was on top of the object. Typically an object will perform its own mouse tracking as long as the button is held down, and only return from this message handler when it is released.

MSG_DCLICK:
Sent when the user double-clicks on an object. A MSG_CLICK will be sent when the button is first pressed, then MSG_DCLICK if it is released and pressed again within a short space of time.

MSG_KEY:
Sent when the keyboard shortcut for the object is pressed, or if enter, space, or a joystick button is pressed while it has the input focus.

MSG_CHAR:
When a key is pressed, this message is sent to the object that has the input focus, with a readkey() format character code (ASCII value in the low byte, scancode in the high byte) as the c parameter. If the object deals with the keypress it should return D_USED_CHAR, otherwise it should return D_O_K to allow the default keyboard interface to operate. If you need to access Unicode character input, you should use MSG_UCHAR instead of MSG_CHAR.

MSG_UCHAR:
If an object ignores the MSG_CHAR input, this message will be sent immediately after it, passed the full Unicode key value as the c parameter. This enables you to read character codes greater than 255, but cannot tell you anything about the scancode: if you need to know that, use MSG_CHAR instead. This handler should return D_USED_CHAR if it processed the input, or D_O_K otherwise.

MSG_XCHAR:
When a key is pressed, Allegro will send a MSG_CHAR and MSG_UCHAR to the object with the input focus. If this object doesn't process the key (ie. it returns D_O_K rather than D_USED_CHAR), the dialog manager will look for an object with a matching keyboard shortcut in the key field, and send it a MSG_KEY. If this fails, it broadcasts a MSG_XCHAR to all objects in the dialog, allowing them to respond to special keypresses even when they don't have the input focus. Normally you should ignore this message (return D_O_K rather than D_USED_CHAR), in which case Allegro will perform default actions such as moving the focus in response to the arrow keys and closing the dialog if ESC is pressed.

MSG_WANTFOCUS:
Queries whether an object is willing to accept the input focus. It should return D_WANTFOCUS if it does, or D_O_K if it isn't interested in getting user input.

MSG_GOTFOCUS:
MSG_LOSTFOCUS:
Sent whenever an object gains or loses the input focus. These messages will always be followed by a MSG_DRAW, to let objects display themselves differently when they have the input focus. If you return D_WANTFOCUS in response to a MSG_LOSTFOCUS event, this will prevent your object from losing the focus when the mouse moves off it onto the screen background or some inert object, so it will only lose the input focus when some other object is ready to take over the focus (this trick is used by the nas_edit_proc() object).

MSG_WANTDIALOGFOCUS:
Queries whether an object is willing to accept dialog focus. It should return D_WANTDIALOGFOCUS if it does, or D_O_K if it isn't interested in getting user input.

MSG_GOTDIALOGFOCUS:
MSG_LOSTDIALOGFOCUS:
Sent whenever a dialog gaines or loses input focus.

MSG_GOTMOUSE:
MSG_LOSTMOUSE:
Sent when the mouse moves on top of or away from an object. Unlike the focus messages, these are not followed by a MSG_DRAW, so if the object is displayed differently when the mouse is on top of it, it is responsible for redrawing itself in response to these messages.

MSG_IDLE:
Sent whenever the dialog manager has nothing better to do.

MSG_RADIO:
Sent by radio button objects to deselect other buttons in the same group when they are clicked. The group number is passed in the c message parameter.

MSG_WHEEL:
Sent to the focused object whenever the mouse wheel moves. The c message parameter contains the number of clicks.

MSG_LPRESS, MSG_MPRESS, MSG_RPRESS:
Sent when the corresponding mouse button is pressed.

MSG_LRELEASE, MSG_MRELEASE, MSG_RRELEASE:
Sent when the corresponding mouse button is released.

Extended NAS GUI messages:

MSG_SIZE:
Sent to all objects before MSG_START. This allows any resizing to be done before everything is initialized for good.

MSG_RESIZE:
Sent to all objects when the dialog resizes. This allows any widgets to change size and modify contents if needed. All canvas objects must be reinitialized on MSG_RESIZE because the dialog window becomes invalid.

MSG_MOUSEMOVED:
Sent to all objects when the mouse moves.

MSG_ADD:
Sent to the listbox procedure when items are added.

MSG_REMOVE:
Sent to the listbox procedure when items are removed.

MSG_CURSOR:
This is used to keep track of a cursor blink change in edit boxes.

MSG_MOVE:
Sent to all objects when the dialog is moving.

MSG_DESTROY:
This message is used to destroy all internal states kept by a procedure.

MSG_KEYPRESS:
Sent when any key is pressed. The c message parameter will hold the scancode.

MSG_KEYRELEASE:
Sent when any key is released. The c message parameter will be the scancode.

MSG_MENU:
Sent when a menu item gets the mouse, this allows other items to close their child menus.

MSG_THEME:
Sent if a theme change occurrs.

Memory Manager ID's:

        MEM_STATES              - Internal State (usually a structure 
                                  containing fields)    
        MEM_BACKGROUND          - Background information (usually a bitmap)
        MEM_DIALOG_BITMAP       - Dialog window
        MEM_DIALOG_BACKGROUND   - Dialog background bitmap
        MEM_CANVAS              - Canvas object used for nested widgets 
                                  (subbitmap)   
        MEM_USER                - Free for internal use

NAS GUI provides several standard dialog procedures. You can use these as they are to provide simple user interface objects, or you can call them from within your own dialog procedures, resulting in a kind of OOP inheritance. For instance, you could make an object which calls nas_button_proc to draw itself, but handles the click message in a different way, or an object which calls nas_button_proc for everything except drawing itself, so it would behave like a normal button but could look completely different, this is essentially how listboxes, buttons, checkboxes, radio buttons, and scrollboxes operate.

int nas_box_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
Draws a box. You can set the type to any one of these defines:

        NAS_BOX_RAISED - Raised box
        NAS_BOX_SUNKEN - Sunken box
        NAS_BOX_RIDGE  - Box with a ridge around the edge
        NAS_BOX_GROOVE - Box with a groove around the edge

int nas_set_box_type(NAS_WIDGET *d, int type);
Sets the box type, see nas_box_proc for the types.

int nas_get_box_type(NAS_WIDGET *d);
Returns the type of box.

int nas_bitmap_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
Draws a bitmap. You can set the bitmap blit type with any one of these defines:

        NAS_BITMAP_BLIT                - Simple blit, w and h will clip the 
                                         bitmap if less than the bitmaps 
                                         width and height
        NAS_BITMAP_MASKED_BLIT         - Masked blit with transparent pixels 
                                         skipped, w and h will clip
        NAS_BITMAP_STRETCH_BLIT        - Stretched to fit
        NAS_BITMAP_MASKED_STRETCH_BLIT - Stretched to fit and transparent 
                                         pixels skipped

int nas_set_bitmap(NAS_WIDGET *d, BITMAP *bmp);
Sets the bitmap. If the bitmap was previously set by nas_set_bitmap_ex the procedure will act accordingly and destroy the internal bitmap. You must exclusively destroy this bitmap.

BITMAP *nas_get_bitmap(NAS_WIDGET *d);
Returns the bitmap.

int nas_set_bitmap_ex(NAS_WIDGET *d, const char *path);
Sets the bitmap via a path, you do not need to explicity destroy this bitmap, the procedure will do this for you.

int nas_set_bitmap_type(NAS_WIDGET *d, int type);
Sets the bitmap draw type, see nas_bitmap_proc for the types.

int nas_get_bitmap_type(NAS_WIDGET *d);
Returns the currenty bitmap draw type.

int set_bitmap_callback(NAS_WIDGET *d, int (*callback)(void *dp), void *dp);
Sets a callback that will be called when a bitmap image is clicked. The dp field can be used to send in any type of data.

int nas_text_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
Draws text onto a dialog. Any '&' characters in the string will be replaced with lines underneath the following character, for displaying keyboard shortcuts (as in MS Windows). To display a single ampersand, put "&&". You can modify the text string through nas_set_label and nas_get_label.

int nas_set_text_align(NAS_WIDGET *d, int align);
Sets the text alignment. Align can be one of the following defines:

        NAS_TEXT_ALIGN_LEFT     - Text is left aligned, same as 
                                  nas_text_proc
        NAS_TEXT_ALIGN_CENTER   - Text is centered, same as 
                                  nas_ctext_proc
        NAS_TEXT_ALIGN_RIGHT    - Text is right aligned, same as 
                                  nas_rtext_proc

int nas_get_text_align(NAS_WIDGET *d);
Returns the text alignment.

int nas_set_text_color(NAS_WIDGET *d, int col);
Sets the text color.

int nas_get_text_color(NAS_WIDGET *d);
Returns the text color.

int nas_set_text_shadow_color(NAS_WIDGET *d, int col);
Sets the text shadow color.

int nas_get_text_shadow_color(NAS_WIDGET *d);
Returns the text shadow color.

int nas_set_label(NAS_WIDGET *d, const char *label);
Sets the text string for a text field. Anything currently in the text field will be replaced by the new string. This function sets the text for the follwing widgets: nas_button_proc, nas_check_proc, nas_radio_proc, nas_groupbox_proc, nas_progress_proc, nas_text, nas_ctext, nas_rtext, and nas_textscroll_proc.

char *nas_get_label(NAS_WIDGET *d);
Gets the text string for a text field. Use caution (i.e. a temporary buffer) if manually editing this string. This function gets the text for the follwing widgets: nas_button_proc, nas_check_proc, nas_radio_proc, nas_groupbox_proc, nas_progress_proc, nas_text, nas_ctext, nas_rtext, and nas_textscroll_proc.

int nas_button_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
A button object (the dp field points to the text string). This object can be selected by clicking on it with the mouse or by pressing its keyboard shortcut. If the D_TOGGLEBUTTON flag is set, selecting it will toggle it on and off, otherwise it will act as a normal winbutton. Like nas_text_proc(), ampersands can be used to display the keyboard shortcut of the button.

int nas_set_button_callback(NAS_WIDGET *d, int (*callback)(void *dp), void *dp);
Sets a callback on a button that is activated when the button is pressed. The return value of the callback is returned by the button procedure that invoked it. The dp field can be used for any type of data and will be passed into the callback.

int nas_set_button_icon(NAS_WIDGET *d, BITMAP *ico, int dir, int spacing);
Adds a bitmapped icon to a button. The ico parameter takes in an equally divided, horizontally spaced, four part bitmap similar to nas_icon_proc/nas_add_icon. The spacing parameter is used to add spacing between text and the icon. The dir parameter can be one of these defines:

        NAS_BUTTON_ICON_LEFT    - Icon is left justified, centered on height
        NAS_BUTTON_ICON_TOP     - Icon is drawn above the text field, centered on width

int nas_set_button_icon_ex(NAS_WIDGET *d, const char *path, int dir, int spacing);
Adds a bitmapped icon to a button. The path specifies the path to the icon and it is stored internally. The spacing parameter is identical to nas_set_button_icon.

int nas_check_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
A checkbox object. You can set an optional callback or set the alignment through nas_set_checkbox_callback or nas_set_checkbox_align.

int nas_set_checkbox_callback(NAS_WIDGET *d, int (*callback)(void *dp), void *dp);
Sets the checkbox callback. The dp field can be used for any type of data and will be passed into the callback.

int nas_set_checkbox_align(NAS_WIDGET *d, int align);
Sets the alignment of the checkbox in relation to its text. The align parameter can be any one of these defines:

        NAS_CHECKBOX_ALING_LEFT         - Checkbox is to the left of the text
        NAS_CHECKBOX_ALIGN_RIGHT        - Checkbox is to the right of the text

int nas_get_checkbox_align(NAS_WIDGET *d);
Returns the alignment of the checkbox.

int nas_radio_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
A radio button object. A dialog can contain any number of radio button groups: selecting a radio button causes other buttons within the same group to be deselected. You can set an optional callback or set the alignment or group through helper functions.

int nas_set_radio_callback(NAS_WIDGET *d, int (*callback)(void *dp), void *dp);
Sets the radio callback. The dp field can be used for any type of data and will be passed into the callback.

int nas_set_radio_align(NAS_WIDGET *d, int align);
Ses the alignment of a radio button in relation to its text. The align parameter can by any one of these defines:

        NAS_RADIO_ALING_LEFT            - Radio button is to the left of the text
        NAS_RADIO_ALIGN_RIGHT           - Radio button is to the right of the text

int nas_get_radio_align(NAS_WIDGET *d);
Returns the alignment of a radio button.

int nas_set_radio_group(NAS_WIDGET *d, int group);
Sets the group id for a radio button.

int nas_get_radio_group(NAS_WIDGET *d);
Returns the group id for a radio button.

int nas_icon_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
A bitmap button, the icon will be stretched to fit inside w and h.

int nas_set_icon(NAS_WIDGET *d, BITMAP *ico);
Sets the icon button image, if the icon was set via a path the procedure will take care of destroying the internal bitmap before setting the new one. The button is a bitmap with 4 equal icons inside tiled horizontally

BITMAP *nas_get_icon(NAS_WIDGET *d);
Returns the icon.

int nas_set_icon_ex(NAS_WIDGET *d, const char *path);
Sets the icon via a path instead of a bitmap pointer, this is held internally and destroyed upon destroying the widget.

int nas_set_icon_callback(NAS_WIDGET *d, int (*callback)(void *dp), void *dp);
Sets the icon click callback. The dp field can be used for any type of data and will be passed into the callback.

int nas_keyboard_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
This is an invisible object for implementing keyboard shortcuts. You can put an ASCII code in the key field of the dialog object (a character such as 'a' to respond to a simple keypress, or a number 1-26 to respond to a control key a-z), or you can put a keyboard scancode in. When one of these keys is pressed, the object will call the function set to it by nas_set_keyboard_callback. This should return an int, which will be passed back to the dialog manager, so it can return D_O_K, D_REDRAW, D_CLOSE, etc.

int nas_set_keyboard_callback(NAS_WIDGET *d, int (*callback)(void *dp), void *dp);
Sets the keyboard callback that will be called when a key or set of keys are pressed. The dp field can be used for any type of data and will be passed into the callback.

int nas_edit_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
An editable text object. When it has the input focus (obtained by clicking on it with the mouse), text can be typed into this object. The string is stored internally and you can set the maximum length via helper functions.

int nas_set_editbox_text(NAS_WIDGET *d, char *text);
Sets the editbox text string, anything that was currently in the editbox will be erased. If you wish to modify the string in any way be sure to use an external temporary buffer to copy the existing string into, modify it, then call this function to set the string.

char *nas_get_editbox_text(NAS_WIDGET *d);
Gets the string text for an editbox.

int nas_get_editbox_length(NAS_WIDGET *d);
Gets the maximum length of the string for an editbox.

int nas_set_editbox_length(NAS_WIDGET *d, int maxlen);
Sets the maxumum length of the string for an editbox. You can pass -1 for maxlen and the editbox will have infinite length.

int nas_set_editbox_callback(NAS_WIDGET *d, int (*callback)(void *dp), void *dp);
Sets a callback for an editbox that is invoked upon pressing enter on the keyboard. The return value for this callback is returned by the editbox procedure that called it. The dp field can be used for any type of data and will be passed into the callback.

int nas_list_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
A list box object. This will allow the user to scroll through a list of items and to select one by clicking or with the arrow keys. Listboxes have been designed to be extensively flexible. A listbox not only can contain text but bitmap objects or special structures with your own data. A listbox contains a list of list items with the following prototype:

        typedef struct list_item
        {
                unsigned char status;   - Status of the listitem (selected, 
                                          highlighted, or neither)
                void *userobj;          - Custom list object (default is 
                                          plain text)
                struct list_item *next; - Pointer to the next item in the 
                                          list
        } LIST_ITEM;

int nas_set_listbox_click_callback(NAS_WIDGET *d, int (*callback)(int msg, LIST_ITEM *item, void *dp));
Sets the listbox callback invoked when a listitem is clicked, msg will be a copy of D_CLICK or D_DCLICK and item will be the item that was clicked. The return value of this callback is returned through the listbox that called it.

int nas_set_listbox_draw_callback(NAS_WIDGET *d, void (*callback)(BITMAP *dest, int x, int y, LIST_ITEM *item));
Sets the listbox callback invoked when a listitem needs to draw itself. Dest is the bitmap with wich to draw onto at location x and y. The list_item is the current item wanting to draw. You only need to set this if you are doing anything other than plain text output. You can have any custom drawing routine in here.

int nas_set_listbox_destroy_callback(NAS_WIDGET *d, void (*callback)(LIST_ITEM *item));
Sets the listbox callback invoked when deleting an object from the list. You only need to set this if you have custom data in the list that needs special means of destroying any memory it may use.

int nas_listbox_insert(NAS_WIDGET *d, void *userobj, int sizeobj, int w, int h);
Inserts a custom item or plain text into a listbox, sizeobj is the size of the object you are inserting, w and h are it's dimensions.

int nas_get_listbox_numitems(NAS_WIDGET *d);
Returns the number of items in a listbox.

LIST_ITEM *nas_get_listbox_item(NAS_WIDGET *d, unsigned int index);
Gets an item at a specific index from within a listbox, returns NULL if it's not found.

int nas_listbox_delete(NAS_WIDGET *d, unsigned int index);
Deletes an item at a specific index from a listbox.

int nas_listbox_clear(NAS_WIDGET *d);
Clears the entire contents from a listbox.

int nas_listbox_sort(NAS_WIDGET *d, int sizeobj, int (*compar)(const void *, const void *));
Sorts the contents of a listbox based on a comparison function.

int nas_listbox_select(NAS_WIDGET *d, unsigned int index);
Selects an item in a listbox based on its index.

int nas_listbox_highlight(NAS_WIDGET *d, unsigned int index);
Highlights an item in a listbox based on its index.

int nas_listbox_unselect(NAS_WIDGET *d);
Unselects all items in a listbox.

int nas_get_listbox_selected(NAS_WIDGET *d, LIST_ITEM **item);
Returns the selected item in a listbox.

LIST_ITEM *nas_get_listbox_highlighted(NAS_WIDGET *d);
Returns the highlighted item in a listbox.

int nas_listbox_disable(NAS_WIDGET *d);
Disables a listbox.

int nas_listbox_enable(NAS_WIDGET *d);
Reenables a listbox.

int nas_set_listbox_itemheight(NAS_WIDGET *d, int itemheight);
Sets the itemheight of all the items in a listbox.

int nas_get_listbox_itemheight(NAS_WIDGET *d);
Returns the item height of the items in a listbox.

void nas_set_listbox_focus(NAS_WIDGET *d, int to);
Sets the focus of a listbox, the to field can be any one of the following defines:

        NAS_LIST_SEEK_SELECTION - Seeks to the current selection, centered
        NAS_LIST_SEEK_START     - Seeks to the beginning of the list
        NAS_LIST_SEEK_END       - Seeks to the end of the list

void nas_listbox_textout(BITMAP *dest, int x, int y, char *txt, LIST_ITEM *item);
Default textout function of a listbox, this draws the text and selection rectangle behind it. This can be used in a custom textoutput callback where the text is stored differently but you want the same effect.

int nas_combo_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
Combobox procedure. This procedure binds together an editbox, listbox, and button.

int nas_combobox_insert(NAS_WIDGET *d, char *text);
Inserts a text string into a combobox listbox.

int nas_get_combobox_numitems(NAS_WIDGET *d);
Returns the number of items currently inserted into the combobox.

char *nas_get_combobox_item(NAS_WIDGET *d, unsigned int index);
Returns the text string at the given index in the combobox.

int nas_delete_combobox_item(NAS_WIDGET *d, unsigned int index);
Removes the text string at the given index from the combobox.

int nas_combobox_clear(NAS_WIDGET *d);
Clears the entire contents of the combobox listbox.

int nas_combobox_sort(NAS_WIDGET *d, int sizeobj, int (*compar)(const void *, const void *));
Sorts the combobox listbox.

int nas_textbox_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
Editable textbox procedure.

int nas_set_textbox_text(NAS_WIDGET *d, char *text);
Sets the textbox text string, anything that was currently in the textbox will be erased. If you wish to modify the string in any way be sure to use an external temporary buffer to copy the existing string into, modify it, then call this function to set the string.

char *nas_get_textbox_text(NAS_WIDGET *d);
Gets the string text for an textbox.

int nas_get_textbox_length(NAS_WIDGET *d);
Gets the maximum length of the string for an textbox.

int nas_set_textbox_length(NAS_WIDGET *d, int maxlen);
Sets the maxumum length of the string for an textbox. You can pass -1 for maxlen and the textbox will have infinite length.

int nas_slider_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
A slider control object. It will display as a vertical slider if h is greater than or equal to w, otherwise it will display as a horizontal slider, if the width is greater than the height, then height will be set automatically depending on the theme, and vice versa for a vertical slider, so it's safe to set the height or width to 0 depending since it will be set for you.

int nas_set_slider_callback(NAS_WIDGET *d, int (*callback)(int max, int pos));
Sets a callback that is invoked every time the slider moves, max val and it's current position are sent in.

int nas_setup_slider(NAS_WIDGET *d, int type, int steps);
Sets the handle type and number of steps a slider has, by default the number of steps to a slider is infinite. Type can be any of the following definitions:

        NAS_SLIDER_NORMAL - Default square handle
        NAS_SLIDER_LEFT   - Handle points left
        NAS_SLIDER_RIGHT  - Handle points right
        NAS_SLIDER_UP     - Handle points up
        NAS_SLIDER_DOWN   - Handle points down
Stepping is 0 based, meaning with the stepping of 1 the slider goes from 0 to max exclusively, stepping of 2 means it goes 0, 50%, and max exclusively.

int nas_set_slider_label_callback(NAS_WIDGET *d, void (*callback)(BITMAP *canvas, int x, int y, int *width, int *height, U_LINT *flags, int val, int tick));
Sets the slider label callback, this can be used to add picture or text labels to the slider if stepping is enabled. The callback receives an x and y coordinate with which to draw to, this is determined by width and height which should be returned when canvas is NULL. As well there is a flags field which when canvas is NULL can be set to any of these return types which can also be OR'd together:

        NAS_SLIDER_TICK_MINOR - Default
        NAS_SLIDER_TICK_MAJOR - Longer tick
        NAS_SLIDER_ITEM_DOWN  - Default
        NAS_SLIDER_ITEM_UP    - Object displayed above the slider
        NAS_SLIDER_ITEM_RIGHT - Default
        NAS_SLIDER_ITEM_LEFT  - Object displayed to the left of the slider

int nas_set_slider_position(NAS_WIDGET *d, int pos);
Sets the slider position and redraws the slider.

int nas_get_slider_position(NAS_WIDGET *d);
Returns the current slider position.

int nas_set_slider_maxval(NAS_WIDGET *d, int max);
Sets the sliders maximum value.

int nas_get_slider_maxval(NAS_WIDGET *d);
Returns the sliders maximum value.

int nas_groupbox_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
A groupbox procedure. The dp field points to a text string that will be displayed at the top of the groupbox, the text area will be clipped between the groupbox width, and since the background information is saved, the dp field can be modified followed by a call to nas_object_message(d, MSG_DRAW, 0);. If h is 0 then a single horizontal bar will be drawn instead of a box directly centered behind the text.

int nas_set_groupbox_callback(NAS_WIDGET *d, int (*callback)(void *dp), void *dp);
Sets the groupbox callback that is invoked when the text label is double clicked. The dp field can be used for any type of data and will be passed into the callback.

int nas_yield_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
An invisible helper object that yields timeslices for the scheduler (if the system supports it) when the gui has nothing to do but waiting for user actions. You should put one instance of this object in each dialog array because it may be needed on systems with an unusual scheduling algorithm (for instance QNX) in order to make the GUI fully responsive. This is simply a wrapper for d_yield_proc.

int nas_dialog_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
Main dialog procedure, this should be the first item in a dialog structure. All procedures following this will draw to this object. This displays a dialog box, including dialog header customized to the theme and is fully dragable, resizable, can be minimized, rolled up (dependent on theme), and maximized. The dp field is a pointer to optional text that will be displayed in the header. The flags field can be any of the following defines OR'ed together:

        D_DEFAULT_W     - Dialog assumes a default width                
        D_DEFAULT_H     - Dialog assumes a default height               
        D_RESIZE        - Allows a dialog to resize
        D_MOVABLE       - Allows a dialog to move with the mouse        
        D_MAXIMIZE      - Allows a dialog to maximize   
        D_MINIMIZE      - Allows a dialog to minimize 
        D_EXIT          - Displays the exit icon on a dialog
        D_HELP          - Displays the help icon on a dialog NOT IMPLIMENTED                    
        D_GRIP          - Displays the resize grip on a dialog                  
        D_SEPARATOR     - Displays a separator if a menu is present on a 
                          dialog

int nas_set_dialog_title(NAS_WIDGET *d, const char *text);
Sets the title for a dialog, anything that was in the title before this function was called is replaced.

char *nas_get_dialog_title(NAS_WIDGET *d);
Gets the title for a dialog.

int nas_set_dialog_callback(NAS_WIDGET *d, int (*callback)(NAS_WIDGET *d, int msg, int *w, int *h));
Sets an optional callback that can be used to set the size and layout of widgets within it.

int nas_set_dialog_close_callback(NAS_WIDGET *d, int (*callback)(void *dp), void *dp);
Sets an optional close callback that is invoked on MSG_EXIT. The dp field can be used for any type of data and will be passed into the callback.

int nas_set_dialog_icon(NAS_WIDGET *d, BITMAP *ico);
Sets an optional icon to a dialog.

int nas_set_dialog_icon_ex(NAS_WIDGET *d, const char *path);
Same as nas_set_dialog_icon but takes in a path instead of a pointer. The icon is stored internally and freed when the dialog is destroyed.

NAS_WIDGET *nas_add_dialog_menu(NAS_WIDGET *d, const char *text);
Adds an optional menu item to a dialog. The returned widget pointer is a menu which you can use to add menu items too.

int nas_refresh_dialog(NAS_WIDGET *d, int part);
Used to refresh a dialog, sending MSG_DRAW to a dialog will not redraw it unless you call this function. Later this will be extended to use animated dialogs since you have complete control over which part redraws. Part can be any one of these defines and can be OR'ed together:

        NAS_DIALOG_TOP          - Redraws the top of the dialog
        NAS_DIALOG_BOTTOM       - Redraws the bottom of the dialog
        NAS_DIALOG_LEFT         - Redraws the left side of the dialog
        NAS_DIALOG_RIGHT        - Redraws the right side of the dialog
        NAS_DIALOG_MENU         - Redraws the dialog menu
        NAS_DIALOG_BODY         - Redraws the dialog body
        NAS_DIALOG_CONTENTS     - Redraws all widgets

void nas_position_dialog(NAS_WIDGET *d, int x, int y);
Repositions a dialog box.

void nas_get_dialog_mickeys(int *mx, int *my);
Returns the number of pixels a dialog has moved, similar to get_mouse_mickeys, only with dialogs.

void nas_centre_dialog(NAS_WIDGET *d);
Centres a dialgo box.

int nas_resize_dialog(NAS_WIDGET *d, int w, int h);
Resizes a dialog box, w and h are the canvas size and not the total size of the dialog. The return value can be any one of these defines OR'ed together:

        NAS_DIALOG_RESIZE_NONE  - Dialog didn't resize at all
        NAS_DIALOG_RESIZE_TOP   - Dialog resized from the top
        NAS_DIALOG_RESIZE_END   - Dialog resized from the bottom
        NAS_DIALOG_RESIZE_LEFT  - Dialog resized from the left
        NAS_DIALOG_RESIZE_RIGHT - Dialog resized from the right

int nas_set_dialog_state(NAS_WIDGET *d, int flag);
Sets the dialog state. Flag can be any one of these defines:

        NAS_MINIMIZE_DIALOG     - Minimizes a dialog
        NAS_MAXIMIZE_DIALOG     - Maximizes a dialog
        NAS_STICKY_DIALOG       - Prevents a dialog from moving
        NAS_UNSTICKY_DIALOG     - Allows a dialog to move freely again
        NAS_ROLLUP_DIALOG       - Rolls up a dialog
        NAS_RESTORE_DIALOG      - Restores a dialog to a normal state

NAS_WIDGET *nas_find_mouse_dialog(void);
Returns the dialog the mouse is directly over. If multiple dialogs are under the mouse, the topmost dialog will be returned.

int nas_progress_proc(int msg, NAS_WIDGET *d, int c);
Displays a progress box with an optional text string.

int nas_set_progress_idle_callback(NAS_WIDGET *d, int (*callback)(NAS_WIDGET *d));
Sets an idle callback that is invoked on MSG_IDLE for a progress box, this can be used to update the progress box.

int nas_set_progress_click_callback(NAS_WIDGET *d, int (*callback)(int max, int pos));
Sets the click callback invoked on MSG_LPRESS for a progress box, max val and it's current position is sent in.

int nas_set_progress_position(NAS_WIDGET *d, int pos);
Sets the position of the progress box in relation to its maximum value.

int nas_get_progress_position(NAS_WIDGET *d);
Gets the position of the progress box, ranges from 0 to maximim value.

int nas_set_progress_maxval(NAS_WIDGET *d, int max);
Sets the maximum value for a progress box.

int nas_get_progress_maxval(NAS_WIDGET *d);
Gets the maximum value for a progress box.

int nas_separator_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
A separator object, good for drawing horizontal or vertical lines on a dialog. If h is greater than or equal to w, a vertical separator will be drawn, otherwise a horizontal one will be drawn instead. The width and height are automatically set depending on whether it's vertical or horizontal since the theme determines how thick the separator for the current theme is.

int nas_textscroll_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
Scrolls text on a dialog.

int nas_set_textscroll_delay(NAS_WIDGET *d, int delay);
Helper function to set a timed delay which pauses the scroller. A delay of 40 for example will delay the scroller 40 ticks of the gui timer. Returns 1 on success 0 otherwise.

int nas_set_textscroll_direction(NAS_WIDGET *d, int dir);
Helper function to set the direction in which the scroller scrolls the text. Returns 1 on success, 0 otherwise. Dir can be set to one of these defines:

        NAS_TEXTSCROLL_NORMAL  - Scrolls text right to left
        NAS_TEXTSCROLL_REVERSE - Scrolls text left to right

int nas_get_textscroll_direction(NAS_WIDGET *d);
Helper function that returns the direction the text is scrolling at.

int nas_set_textscroll_speed(NAS_WIDGET *d, int speed);
Helper function to set the speed at which the text scrolls. Speed is a timer delay so 0 is fastest, anything higher is slower.

int nas_get_textscroll_speed(NAS_WIDGET *d);
Helper function that returns the speed the text is scrolling at.

int nas_set_textscroll_position(NAS_WIDGET *d, int pos);
Helper function to set the position of the text in pixels.

int nas_get_textscroll_position(NAS_WIDGET *d);
Helper function that returns the position of the text in pixels.

int nas_scrollbox_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
Scrollbox object. This object is unique in that it uses none of the widget variables so it's entirely safe to wrap it inside of a custom procedure without worrying about it conflicting with anything. This is exactly what I did for the listbox and textbox procedures. In order for it to scroll anything you must set a callback.

The type field in any one of the scrollbar functions will be one of these defines:

        NAS_SCROLL_VERTICAL     - Vertical scrollbar
        NAS_SCROLL_HORIZONTAL   - Horizontal Scrollbar

int nas_set_scroll_callback(NAS_WIDGET *d, void (*nas_scroll_callback)(NAS_WIDGET *d, int x, int y, int width, int height, int hpos, int vpos));
Sets the scrollbox callback, x and y specify where to draw, width and height are the area of the scrollbox window, and hpos and vpos are the positions of the scrollbars. All clipping is done before this callback is invoked so there is no need to worry about drawing past the edges of the scrollbox.

int nas_setup_scroll(NAS_WIDGET *d, int type, int flags, int pos, int item_height, int total_items);
Sets up a scrollbar, item_height is the height of the individual items, total_items is the total number of items, pos is the position to start at, and flags can be any one of the following defines:

        NAS_SCROLL_NORMAL       - Normal scrollbar actions
        NAS_SCROLL_DONT_HIDE    - Always displays scrollbar
        NAS_SCROLL_SHOW_HANDLE  - Always displays the handle (when disabled)

int nas_get_scrollbar_height(NAS_WIDGET *d, int type);
Returns the height of a scrollbar

int nas_get_scrollbar_width(NAS_WIDGET *d, int type);
Returns the width of a scrollbar

void nas_get_scroll_view_area(NAS_WIDGET *d, int *x, int *y, int *width, int *height);
Gets the scrollbox viewable area, defined by x, y, width, and height.

int nas_get_scroll_view_width(NAS_WIDGET *d);
Returns the scrollbox viewable width.

int nas_get_scroll_view_height(NAS_WIDGET *d);
Returns the scrollbox viewable height.

void nas_get_scroll_total_area(NAS_WIDGET *d, int *x, int *y, int *width, int *height);
Gets the scrollbox total area defined by x, y, width, and height. Unlike the viewable area this is the area minus the scrollbars.

void nas_get_scroll_total_width(NAS_WIDGET *d);
Returns the scrollbox total width.

void nas_get_scroll_total_height(NAS_WIDGET *d);
Returns the scrollbox total height.

int nas_scroll_has_focus(NAS_WIDGET *d, int type);
Returns 1 if the scollbar has control of the mouse, 0 if it does not.

int nas_set_scroll_items(NAS_WIDGET *d, int type, int total_items);
Sets the number of items for a particular scrollbar.

int nas_set_scroll_delta(NAS_WIDGET *d, int type, int delta);
Sets the delta or change a scrollbar will have when scrolling objects.

int nas_get_scroll_position(NAS_WIDGET *d, int type);
Gets a scrollbars position.

int nas_set_scroll_position(NAS_WIDGET *d, int type, int pos);
Sets a scrollbars position.

int nas_disable_scroll(NAS_WIDGET *d, int type);
Disables a scrollbar.

int nas_enable_scroll(NAS_WIDGET *d, int type);
Enables a scrollbar.

int nas_invalidate_scroll(NAS_WIDGET *d, int type);
Redraws a scrollbar.

int nas_tabbox_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
Tabbox procedure. The default is an empty box with no tabs, use nas_add_tab to add tabs to the tabbox.

NAS_WIDGET *nas_add_tab(NAS_WIDGET *d, const char *text);
Adds a tab to a tabbox with an optional text label. By default the first tab added is selected. You can add buttons or any other widgets to the newly created tab as you would a dialog.

void nas_destroy_tabs(NAS_WIDGET *d);
Destroys all tabs in a tabbox.

int nas_remove_tab(NAS_WIDGET *d, NAS_WIDGET *tab);
Removes the tab from the tabbox.

NAS GUI has been extended to utilize a new and easier method of creating dialog boxes:

NAS_WIDGET *nas_create_dialog(int x, int y, int w, int h, U_LINT flags, const char *text);
Creates a dialog with an optional text label. The w and h parameters are the canvas size and not the real size of the dialog box. The dialog itself will be slightly larger.

void nas_destroy_dialog(NAS_WIDGET *d);
Destroys a dialog and all of it's children.

NAS GUI has been extended to utilize a new and easier method of creating widgets:

NAS_WIDGET *nas_add_button(NAS_WIDGET *d, int x, int y, int w, int h, char key, U_LINT flags, const char *text, int (*callback)(void *dp), void *dp);
Adds a button with an optional text label and callback.

NAS_WIDGET *nas_add_checkbox(NAS_WIDGET *d, int x, int y, int w, int h, char key, U_LINT flags, const char *text, int (*callback)(void *dp), void *dp);
Adds a checkbox with an optional text label and callback.

NAS_WIDGET *nas_add_radio(NAS_WIDGET *d, int x, int y, int w, int h, char key, U_LINT flags, int group, const char *text, int (*callback)(void *dp), void *dp);
Adds a radio button with an optional text label and a callback. The group parameter is used to group radio buttons together.

NAS_WIDGET *nas_add_bitmap(NAS_WIDGET *d, int x, int y, int w, int h, BITMAP *bmp, int type);
Adds a bitmap with a rendering type that can be any one of these defines:

        NAS_BITMAP_BLIT                - Simple blit, w and h will clip the 
                                         bitmap if less than the bitmaps 
                                         width and height
        NAS_BITMAP_MASKED_BLIT         - Masked blit with transparent pixels 
                                         skipped, w and h will clip
        NAS_BITMAP_STRETCH_BLIT        - Stretched to fit
        NAS_BITMAP_MASKED_STRETCH_BLIT - Stretched to fit and transparent 
                                         pixels skipped

NAS_WIDGET *nas_add_bitmap_ex(NAS_WIDGET *d, int x, int y, int w, int h, const char *path, int type);
Adds a bitmap via a path, you do not have to destroy the bitmap that is loaded.

NAS_WIDGET *nas_add_box(NAS_WIDGET *d, int x, int y, int w, int h, int type);
Adds a box with a rendering type that can be any one of the following defines:

        NAS_BOX_RAISED - Raised box
        NAS_BOX_SUNKEN - Sunken box
        NAS_BOX_RIDGE  - Box with a ridge around the edge
        NAS_BOX_GROOVE - Box with a groove around the edge
Note: Boxes can contain nested widgets.

NAS_WIDGET *nas_add_editbox(NAS_WIDGET *d, int x, int y, int w, int h, U_LINT flags, const char *text, int len);
Adds an editbox. Text is an array and len specifies the number of elements in that array.

NAS_WIDGET *nas_add_groupbox(NAS_WIDGET *d, int x, int y, int w, int h, U_LINT flags, const char *text);
Adds a groupbox with an optional text label.
Note:
Groupboxes can contain nested widgets.

NAS_WIDGET *nas_add_icon(NAS_WIDGET *d, int x, int y, int w, int h, U_LINT flags, BITMAP *ico, int (*callback)(void *dp), void *dp);
Adds a clickable icon (bitmap button) to a dialog with an optional callback.

NAS_WIDGET *nas_add_icon_ex(NAS_WIDGET *d, int x, int y, int w, int h, U_LINT flags, const char *path, int (*callback)(void *dp), void *dp);
Adds a clickable icon (bitmap button) to a dialog with an optional callback, takes in a path instead of a bitmap.

NAS_WIDGET *nas_add_shortcut(NAS_WIDGET *d, char key, int (*callback)(void *dp), void *dp);
Adds a keyboard shortcut to a dialog with an optional callback.

NAS_WIDGET *nas_add_shortcut_ex(NAS_WIDGET *d, int scancode, int ascii, int (*callback)(void *dp), void *dp);
Adds a keyboard shortcut to a dialog with an optional callback. The scancode and ascii character are used instead of a character key.

NAS_WIDGET *nas_add_listbox(NAS_WIDGET *d, int x, int y, int w, int h, U_LINT flags, int (*callback)(int msg, LIST_ITEM *item, void *dp), void *dp);
Adds a listbox to a dialog with an optional click callback.

NAS_WIDGET *nas_add_combobox(NAS_WIDGET *d, int x, int y, int w, int h, U_LINT flags);
Adds a combobox to a dialog.

NAS_WIDGET *nas_add_progress(NAS_WIDGET *d, int x, int y, int w, int h, U_LINT flags, int pos, int max, const char *text);
Adds a progress bar to a dialog with an optional text label. Pos and max are used to set the starting position and max value of the progress bar.

NAS_WIDGET *nas_add_scrollbox(NAS_WIDGET *d, int x, int y, int w, int h, U_LINT flags);
Adds a scrollbox object to a dialog.

NAS_WIDGET *nas_add_separator(NAS_WIDGET *d, int x, int y, int w, int h);
Adds a vertical or horizontal separator to a dialog.

NAS_WIDGET *nas_add_slider(NAS_WIDGET *d, int x, int y, int w, int h, U_LINT flags, int pos, int max);
Adds a vertical or horizontal slider to a dialog box, pos and max determine it's position and max value.

NAS_WIDGET *nas_add_tabbox(NAS_WIDGET *d, int x, int y, int w, int h, U_LINT flags);
Adds a tabbox to a dialog.
Note:
Tabboxes contain nested widgets.

NAS_WIDGET *nas_add_text(NAS_WIDGET *d, int x, int y, int w, int h, U_LINT flags, int align, const char *text);
Adds text to a dialog, align can be one of the following defines:

        NAS_TEXT_ALIGN_LEFT     - Text is left aligned, same as 
                                  nas_text_proc
        NAS_TEXT_ALIGN_CENTER   - Text is centered, same as 
                                  nas_ctext_proc
        NAS_TEXT_ALIGN_RIGHT    - Text is right aligned, same as 
                                  nas_rtext_proc

NAS_WIDGET *nas_add_textbox(NAS_WIDGET *d, int x, int y, int w, int h, U_LINT flags, const char *text, int len);
Adds a textbox to a dialog, text contains a text array and len is the number of elements in that array.

NAS_WIDGET *nas_add_textscroll(NAS_WIDGET *d, int x, int y, int w, int h, U_LINT flags, const char *text);
Adds a textscroll object to a dialog, text points to the text that is to be scrolled.

NAS_WIDGET *nas_add_yield(NAS_WIDGET *d);
Adds yield_timeslice to the dialog.

int nas_menu_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
Main menu box. This holds the menu items much like a dialog holds buttons.

int nas_popup_menu(NAS_WIDGET *menu, int x, int y);
Pops up a menu at the given x and y coordinates.

NAS_WIDGET *nas_create_menu(NAS_WIDGET *menu_item, const char *text);
Creates a menu with an optional text heading, this heading is not available in all themes. The menu_item field can either be NULL for a first level menu or if you are using child menus you can make it a child menu by supplying it with a valid menu item.

int nas_destroy_menu(NAS_WIDGET *menu);
Destroys a menu.

int nas_set_menu_text(NAS_WIDGET *menu, const char *text);
Sets the menu heading text.

char *nas_get_menu_text(NAS_WIDGET *menu);
Returns the menu heading text.

int nas_menu_item_proc(int msg, NAS_WIDGET *d, BITMAP *wnd, int c);
Menu item, this is the menues buttons.

NAS_WIDGET *nas_add_menu_item(NAS_WIDGET *menu, char key, const char *text);
Adds a menu item to a menu with an optional keybord shortcut, text label. If the text label is NULL then a horizontal separator is displayed instead.

int nas_remove_menu_item(NAS_WIDGET *menu_item);
Removes a menu item from a menu.

int nas_set_menu_item_callback(NAS_WIDGET *menu_item, int (*callback)(void *dp), void *dp);
Sets a menu item callback, the return value should always be D_CLOSE.

int nas_set_menu_item_text(NAS_WIDGET *menu_item, const char *text);
Sets the menu item text.

char *nas_get_menu_item_text(NAS_WIDGET *menu_item);
Returns the menu item text.

int nas_set_menu_item_status(NAS_WIDGET *menu_item, int status);
Sets the menu item status. The status field can be any one of these defines:

        NAS_MENU_ITEM_UNSELECTED  - Menu item is unselected
        NAS_MENU_ITEM_SELECTED    - Menu item is selected

int nas_get_menu_item_status(NAS_WIDGET *menu_item);
Gets the menu item status.

int nas_set_menu_item_icon(NAS_WIDGET *menu_item, BITMAP *icon);
Sets an optional menu item icon that will be displayed to the left of the text, the icon must by 16x16. A menu item cannot be selected and have an icon at the same time, therefore if an icon is set the selected checkmark icon will not be displayed.

int nas_set_menu_item_icon_ex(NAS_WIDGET *menu_item, const char *path);
Sets an optional menu item icon by path instead of pointer.

NAS_WIDGET *nas_add_widget(NAS_WIDGET *d, NAS_PROC *proc, int x, int y, int w, int h, char key, U_LINT flags, void *dp);
Adds a generic widget, proc should be a valid procedure. This can be used to add custom procs to a dialog.

NAS_WIDGET *nas_get_widget(NAS_WIDGET *d, int index);
Gets the child widget at the index specified. For example: nas_get_widget(some_dialog, 3), returns the fourth widget within some_dialog.

void nas_destroy_widget(NAS_WIDGET *d);
Destroys a single widget.

int nas_dialog_is_active(NAS_WIDGET *dialog);
Returns 1 if the dialog is currently in the active dialog list, 0 otherwise. Usefull for determining if a dialog is currently running or not.

NAS_WIDGET *nas_file_select(const char *header, const char *path, const char *ext, int x, int y, int w, int h, U_LINT flags, int (*callback)(char *path));
Displays a file select dialog box, header will be displayed at the top of the dialog box, path is optional and can be set to a starting path. The ext field is optional file extensions you wish to limit the search by, in the format of "BMP:JPG" with any number of types. The flags field can be any one of the dialog flags you can set an optional callback that will be sent in the complete path returned by the dialog box.

NAS_WIDGET *nas_theme_select(int x, int y, int w, int h);
Displays a file select dialog box that allows you to search and select a theme to set.

int nas_msg(const char *title, int flags, const char *msg, ...);
Message box dialog. When called a dialog with the specified title and message will appear. The flags field can be these defines OR'ed together.

        NAS_MSG_OKONLY           - OK button only
        NAS_MSG_OKCANCEL         - OK and Cancel Buttons
        NAS_MSG_ABORTRETRYIGNORE - Abort, Retry, Ignore Buttons
        NAS_MSG_YESNOCANCEL      - Yes, No, Cancel Buttons
        NAS_MSG_YESNO            - Yes and No Buttons
        NAS_MSG_RETRYCANCEL      - Retry and Cancel Buttons
        NAS_MSG_CRITICAL         - Critical icon
        NAS_MSG_QUESTION         - Question icon
        NAS_MSG_EXCLAMATION      - Exclamation icon
        NAS_MSG_INFORMATION      - Information icon
        NAS_MSG_MODAL            - Modal dialog

int nas_switch_theme(char *path);
Changes the theme during runtime, used by nas_theme_select. Returns 0 on failure, 1 otherwise.

void nas_set_buffer(BITMAP *bmp);
Sets the backbuffer which the dialogs will draw to.

void nas_set_screen(BITMAP *bmp);
Sets the screen which the dialogs will show up on. This defaults to screen but can be overridden to any other screen bitmap.

The behaviour of the dialog manager can be controlled by the variables:

extern int (*gui_mouse_x)();
extern int (*gui_mouse_y)();
extern int (*gui_mouse_z)();
extern int (*gui_mouse_b)();
Hook functions, used by the GUI routines whenever they need to access the mouse state. These are used in NAS because widgets are positioned at a relative offset, you must use the gui_mouse functions in order for custom procedures to perceive the mouse location properly.

int nas_offer_focus(NAS_WIDGET *d, NAS_WIDGET *obj, NAS_WIDGET **focus_obj, int force);
Offers the input focus to a particular object. Normally the function sends the MSG_WANTFOCUS message to query whether the object is willing to accept the focus. However, passing any non zero value as force argument instructs the function to authoritatively set the focus to the object.

inline int nas_object_message(NAS_WIDGET *dialog, int msg, int c);
Sends a message to an object and returns the answer it has generated. Remember that the first parameter is the dialog object that you wish to send the message to. For example, to make the second object in a dialog draw itself, you might write:

      nas_object_message(nas_get_widget(dialog, 1), MSG_DRAW, 0);
or you may wish to use direct pointers instead of nas_get_widget.

int nas_dialog_message(NAS_WIDGET *dialog, int msg, int c, NAS_WIDGET **obj);
Sends a message to all the objects in an array. If any of the dialog procedures return values other than D_O_K, it returns the value and sets obj to the object which produced it.

int nas_broadcast_dialog_message(int msg, int c);
Broadcasts a message to all the objects in the active dialog. If any of the dialog procedures return values other than D_O_K, it returns that value.

int nas_global_dialog_message(int msg, int c);
Broadcasts a message to all dialogs in the active dialog queue. If any of the dialog procedures return values other than D_O_K, it returns that value.

void nas_set_dialog_flag(NAS_WIDGET *d, U_LINT flag);
Sets a flag(s) on all nested widgets from d.

void nas_unset_dialog_flag(NAS_WIDGET *d, U_LINT flag);
Unsets a flag(s) on all nested widgets from d.

void nas_destroy_bg();
Destroys the background bitmap of a dialog procedure.

void nas_destroy_window();
Destroys the window context of a dialog procedure.

BITMAP *nas_get_window();
Gets the window context of a dialog procedure.

BITMAP *nas_get_bg();
Gets the background bitmap of a dialog procedure.

BITMAP *nas_create_bg(int w, int h, int flags);
Creates a background bitmap for a dialog procedure, the flags field can be any one of the following defines:

        NAS_VID_BITMAP - Creates a video bitmap
        NAS_MEM_BITMAP - Creates a memory bitmap
        NAS_SYS_BITMAP - Creates a system bitmap

BITMAP *nas_create_window(int w, int h, int flags);
Creates a window context for a dialog procedure, the flags field can be any one of the following defines:

        NAS_VID_BITMAP - Creates a video bitmap
        NAS_MEM_BITMAP - Creates a memory bitmap
        NAS_SYS_BITMAP - Creates a system bitmap

NAS_WIDGET *nas_get_parent(NAS_WIDGET *w);
Returns the parent widget of a nested widget.

NAS_CANVAS *nas_create_canvas(NAS_WIDGET *d, int x, int y, int w, int h);
Creates a canvas object for a widget. This must be called for nested widgets in a custom procedure. This is what all nested widgets will draw to. A canvas has the following prototype:

        typedef struct NAS_CANVAS
        {
                int x, y;           - Canvas coordinates
                BITMAP *canvas;     - Canvas context
        }NAS_CANVAS;

NAS_CANVAS *nas_get_canvas(NAS_WIDGET *d);
Gets the canvas object for a widget. This is its parents canvas object and not its own if it exists, the canvas object that is returned is the object with with the widget is supposed to draw to. If you wish to draw to a widgets own canvas object you can do so with get_mem, the object that will be returned is the canvas object set by that widget, this is what its children will draw to.

void nas_destroy_canvas(NAS_WIDGET *d);
Destroys a canvas object for a widget. This is its own canvas object and not its parents.

void nas_invalidate_canvas(NAS_WIDGET *d, int x, int y, int w, int h);
Same as invalidate_rect only it works with nested widgets. This invalidates a rectangle for the DRS system to render to the screen.

void nas_get_abs_pos(NAS_WIDGET *d, int *x, int *y);
Returns the absolute position of a widget in relation to the dialog.

NAS_WIDGET *nas_get_root(void);
Returns the root/dialog widget of a dialog.

void nas_handle_button(NAS_WIDGET *d, int x, int y, int w, int h, unsigned char *state);
Handles a virtual button object independent of the dialog procedure. This is should be called in any procedure on MSG_IDLE. The state field will be returned as any one of these states OR'ed together:

        NAS_BUTTON_STATE_NORMAL   - Button in normal state
        NAS_BUTTON_STATE_AWAY     - Mouse clicked outside button
        NAS_BUTTON_STATE_FOCUS    - Button has gained control   
        NAS_BUTTON_STATE_SELECTED - Mouse clicked inside button
        NAS_BUTTON_STATE_GOTMOUSE - Mouse inside button, but not clicked
        NAS_BUTTON_STATE_DISABLED - Button is disabled
        NAS_BUTTON_STATE_DIRTY    - Button needs refreshed
        NAS_BUTTON_STATE_RELEASED - Button has been released
        NAS_BUTTON_STATE_USER     - Button state that can be used for 
                                    anything

int nas_button_state(unsigned char state);
Turns a button state into an index of normal, highlighted, pressed, or disabled for drawing.

int nas_flag_state(U_LINT flag);
Turns the flag field into an index of normal, highlighted, pressed, or disabled for drawing.

int nas_shadow_mode(int col[][2], int num_col);
Returns NASFONT_SHADOW if a list of text objects have a shadow, NASFONT_NORMAL otherwise, this is useful for determining if a theme has any text state with shadows. The return value is then used to determine height for example since shadows would make the text a bit higher.

int nas_get_visible_area(NAS_WIDGET *d, int *x, int *y, int *x2, int *y2);
Returns the visible area of a widget bound by x, y, x2, and y2. This allows widgets to only gain focus if they are visible.

void nas_update_screen();
Updates the mouse and screen, automatically called by nas_update_dialog.

extern NAS_ACTIVE_LIST *nas_current_active_player;
Points to the currently "active" dialog/player. This is used to iterate through the dialog list and update each one individually through a circular queue.

extern NAS_ACTIVE_LIST *nas_active_list_endptr;
Points to the end of the curcular queue used to hold all the active dialogs. The next pointer points to the beginning of the list, while the prev pointer points to the dialog just under the top dialog. The queue has a Z-order meaning that items at the end of the list are the topmost. The queue is circular meaning that it wraps around upon itself.

extern BITMAP *nas_buffer;
Global pointer to the backbuffer. Set upon nas_do_dialog.

extern BITMAP *nas_screen;
Global pointer to the visible screen. Set to screen by default.

extern volatile int nas_gui_timer;
GUI timer variable used for timing and delays.


Back to Contents