00001 00007 // /** 00008 // *@defgroup mouse mouse.c 00009 // *Handles mouse input 00010 // *@note Does not trigger mouse events; events are handled by the mousehandler function in the handler.c 00011 // *routines. The mousehandler function is called by this modules mousecheck function via a function pointer. 00012 // *@{ 00013 // */ 00014 00015 /*----------------------------------------------------------------------------------------------------------*/ 00016 00017 #ifndef _ALLEGRO5_ 00018 #define _ALLEGRO5_ 00019 #include <allegro5/allegro5.h> 00020 #endif // _ALLEGRO5_ 00021 00022 #ifndef _MOUSE_ 00023 #define _MOUSE_ 00024 #include "../include/mouse.h" 00025 #endif // _MOUSE_ 00026 00027 /*----------------------------------------------------------------------------------------------------------*/ 00028 00029 // A structure that contains info on mouse input, state etc 00030 // FIXME: A duplicate of the Allegro provided mouse structure, find a more elegant solution 00031 static MOUSE mouse; 00032 00033 /*----------------------------------------------------------------------------------------------------------*/ 00034 00035 // Set the MOUSE_? and MOUSE_?_NEW flags 00036 void mousedown(ALLEGRO_MOUSE_EVENT *mouse_data) 00037 { 00038 mouse.button |= (MOUSE_L | MOUSE_L_NEW) << ((mouse_data->button-1)*2); 00039 } 00040 00041 /*----------------------------------------------------------------------------------------------------------*/ 00042 00043 // Clear the MOUSE_? flag, but not the MOUSE_?_NEW flag 00044 void mouseup(ALLEGRO_MOUSE_EVENT *mouse_data) 00045 { 00046 mouse.button &= (~MOUSE_L) << ((mouse_data->button-1)*2); 00047 } 00048 00049 /*----------------------------------------------------------------------------------------------------------*/ 00050 00051 // Updates mouse coordinate states 00052 void mouseaxes(ALLEGRO_MOUSE_EVENT *mouse_data) 00053 { 00054 mouse.dx = mouse_data->x - mouse.x; 00055 mouse.dy = mouse_data->y - mouse.y; 00056 mouse.dz = mouse_data->z - mouse.z; 00057 mouse.x = mouse_data->x; 00058 mouse.y = mouse_data->y; 00059 mouse.z = mouse_data->z; 00060 } 00061 00062 /*----------------------------------------------------------------------------------------------------------*/ 00063 00064 // Clears mouse flags and mouse axes states 00065 void mouseupdate(void) 00066 { 00067 // Clear all the MOUSE_?_NEW flags 00068 mouse.button &= ~0xAAAAAAAA; 00069 00070 // Clear all change in mouse axes states 00071 mouse.dx = 0; 00072 mouse.dy = 0; 00073 mouse.dz = 0; 00074 } 00075 00076 /*----------------------------------------------------------------------------------------------------------*/ 00077 00078 // Check for mouse input, calls a fucntion pointer too by the function pointer 00079 void* mousecheck(MOUSE_CALLBACK func, void* data) 00080 { 00081 return func(&mouse, data); 00082 } 00083 00084 /*----------------------------------------------------------------------------------------------------------*/ 00085 00086 // /** 00087 // *@} 00088 // */