Mouse Subsystem



void nasmouse_init(void);
Initializes the mouse subsystem. Called automatically by init_nas(), but must be called if you want to implement your own library using nasmouse. Returns 1 on success, 0 otherwise. This function loads the default cursor set as well, so you do not need to call nasmouse_load_mouse() unless changing themes.

void nasmouse_exit(void);
Shuts down the mouse subystem. Called automatically by nas_exit(), but must be called before exiting if you impliment your own library using nasmouse.

int nasmouse_load_mouse(const char *path);
Loads a .cfg mouse configuration file and sets all mouse sprites. Depending on some themes this function may take a while to return as it generates all the shadows as well. Returns 1 on success, 0 otherwise. You can also call nasmouse_load_mouse() multiple times in succession without worrying about leaks as it will automatically free any already loaded cursor and if the cursor set is already loaded this function will return 1 without reloading the same set.

inline void nasmouse_redraw_mouse();
Redraws the mouse when called updating all screen contents as well. Useful for forcing a mouse update.

void nasmouse_update_mouse(void);
Updates the mouse cursor if animated or if it moves. Called automatically by nas_update_screen(), but this function must be called once every game loop if implementing your own library using nasmouse.

void nasmouse_scare_mouse(void);
Similar to scare_mouse(), hides the mouse while redrawing. Note: You do not have to manually scare and unscare the mouse in a custom procedure, the DRS system does this for you only if needed.

void nasmouse_unscare_mouse(void);
Similar to unscare_mouse(), unhides the mouse after redrawing.

int nasmouse_set_mouse_sprite(int sprite);
Sets the mouse sprite, unlike set_mouse_sprite this function does not take in a bitmap pointer, instead it takes in one of these defines:

        NASMOUSE_ARROW       - Default arrow cursor
        NASMOUSE_CROSS       - Cross cursor
        NASMOUSE_HAND        - Hand cursor, useful for hyperlinks
        NASMOUSE_NO          - Very very bad cursor, click and burn thing
        NASMOUSE_WAIT        - Wait state cursor
        NASMOUSE_HANDWRITING - Handwriting cursor
        NASMOUSE_HELP        - Help cursor, displayed when user wants to get 
                               a help popup for a particular object
        NASMOUSE_SIZEALL     - Sizeall cursor, for dragging or resizing
        NASMOUSE_SIZENWSE    - Sizenwse cursor, for resizing
        NASMOUSE_SIZENESW    - Sizenesw cursor, for resizing
        NASMOUSE_SIZEWE      - Sizewe cursor, for resizing
        NASMOUSE_SIZENS      - Sizens cursor, for resizing
        NASMOUSE_IBEAM       - Ibeam cursor, useful for text input and 
                               highlighting
        NASMOUSE_UPARROW     - Uparrow cursor
        NASMOUSE_BUTTON      - Button cursor, not available in all themes,
                               displayed when moving over a button object
        NASMOUSE_APPSTARTING - Application starting cursor, useful when 
                               starting a new dialog, or processing 
                               background stuff

Note: not all of these cursors are needed in a mouse config file, you can set a sprite even if it does not exist, in that case the cursor will simply not change state. The only cursor required to exist is NASMOUSE_ARROW. The return value is the value of the old cursor before it was changed, in the case nothing changed then the current sprite will be returned. It is usually wise to capture the old state so that when you are done with the new cursor you can restore the previous state.

void nasmouse_show_mouse(BITMAP *bmp);
The mouse pointer will be drawn onto the specified bitmap. To hide the mouse pointer, call nasmouse_show_mouse(NULL). This is set to the buffer variable sent in by nas_do_dialog(), so a manual call to this function is normally not needed unless you are implementing your own lib.

void nasmouse_destroy_mouse(void);
Destroys the mouse cursors and shadows that are loaded, usually a good idea to call before exiting the program, however nas_exit() calls this for you.

void nasmouse_show_shadow(int val);
Used to toggle shadows on or off. The val field can be set to these defines:

        NASMOUSE_HIDE_SHADOW - Disables shadows
        NASMOUSE_SHOW_SHADOW - Enables shadows

void nasmouse_set_shadow_offset(int offsetx, int offsety);
Sets the shadow offset, can be any value but is relative to the upper left corner of the cursor sprite.

void nasmouse_set_shadow_intensity(int intensity);
Sets the shadow intensity, a higher value the more translucent the shadow will become.

void nasmouse_set_shadow_focus(int focus);
Sets the amount of blurring to apply to the shadows, a higher value will result in a thicker more blurred shadow outline.

int nasmouse_get_mouse_sprite(void);
Returns the current cursor, useful when querying what cursor is set without having to call nasmouse_set_mouse_sprite();

void nasmouse_position_mouse(int x, int y);
Positions the mouse to the x and y coordinates.

void nasmouse_position_mouse_z(int z);
Positions the mouse wheel variable.

void nasmouse_set_mouse_range(int x1, int y1, int x2, int y2);
Sets the area of the screen within which the mouse can move. Pass the top left corner and the bottom right corner (inclusive). If you don't call this function the range defaults to (0, 0, SCREEN_W-1, SCREEN_H-1).

void nasmouse_set_mouse_speed(int xspeed, int yspeed);
Sets the mouse speed. Larger values of xspeed and yspeed represent slower mouse movement: the default for both is 2.

void nasmouse_get_mouse_mickeys(int *mickeyx, int *mickeyy);
Measures how far the mouse has moved since the last call to this function. The mouse will continue to generate movement mickeys even when it reaches the edge of the screen, so this form of input can be useful for games that require an infinite range of mouse movement.

void nasmouse_scare_mouse_area(int x, int y, int w, int h);
Works the same as nasmouse_scare_mouse() but only scares the mouse if it lies within the given rectangle. The shadow also counts as part of the area.

void nasmouse_get_mouse_area(int *x, int *y, int *w, int *h);
Sets the mouse area into x, y, w, and h. The shadow is also counted as part of the area. Useful for determining if the mouse lies within an area.

void nasmouse_set_mouse_screen(BITMAP *bmp);
Sets the screen with which the mouse will show up on. This defaults to the Allegro screen bitmap but can be overriden to point to any other screen bitmap.


Back to Contents