00001 /**********************************************************/ 00002 /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/ 00003 /* 00004 Copyright: 1995 - Grupo de Voz (DAET) ETSII/IT-Bilbao 00005 00006 Nombre fuente................ xmouse.c 00007 Nombre paquete............... - 00008 Lenguaje fuente.............. C (Borland C/C++ 3.1) 00009 Estado....................... Completado 00010 Dependencia Hard/OS.......... - 00011 Codigo condicional........... - 00012 00013 Codificacion................. Borja Etxebarria 00014 00015 Version dd/mm/aa Autor Proposito de la edicion 00016 ------- -------- -------- ----------------------- 00017 1.0.0 28/06/98 Borja repasillo gordo 00018 0.0.1 14/06/98 Borja repasillo general 00019 0.0.0 16/08/96 Borja Codificacion inicial. 00020 00021 ======================== Contenido ======================== 00022 User interface. Manejo de estados del raton. 00023 Los codigos de evento son compatibles con los de teclado (xkbd()). 00024 =========================================================== 00025 */ 00026 /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/ 00027 /**********************************************************/ 00028 00029 #include "xmouse.h" 00030 00031 /**********************************************************/ 00032 00033 #define XMOUSE_AUTOREP 00034 #define XMOUSE_REP_IDELAY 200 00035 #define XMOUSE_REP_RATE 40 00036 #define XMOUSE_REP_DELAY (1000/XMOUSE_REP_RATE) 00037 00038 #ifdef XMOUSE_AUTOREP 00039 #include "chrono.h" 00040 #endif 00041 00042 /**********************************************************/ 00043 00044 PRIVATE BOOL _ml, _mr, _mb; 00045 PRIVATE INT16 _mx, _my; 00046 00047 #ifdef XMOUSE_AUTOREP 00048 PRIVATE chrono _cr; 00049 INT _crms; 00050 #endif 00051 00052 /**********************************************************/ 00053 00054 VOID xmouse_initialize( VOID ) 00055 { 00056 _ml = FALSE; 00057 _mr = FALSE; 00058 _mb = FALSE; 00059 _mx = -1; 00060 _my = -1; 00061 #ifdef XMOUSE_AUTOREP 00062 _crms=XMOUSE_REP_IDELAY; 00063 chrono_start(&_cr); 00064 #endif 00065 } 00066 00067 /**********************************************************/ 00068 00069 UINT16 xmouse_get( INT16* x, INT16* y ) 00070 { 00071 return xmouse_getstat(x,y) & (~(UINT16)(XMOUSE_LKEY|XMOUSE_RKEY)); 00072 } 00073 00074 /**********************************************************/ 00075 00076 UINT16 xmouse_getstat( INT16* x, INT16* y ) 00077 { 00078 #define LKEY (m&MOUSE_LEFTKEY) 00079 #define RKEY (m&MOUSE_RIGHTKEY) 00080 #ifdef XMOUSE_AUTOREP 00081 #define CRIRESET() (chrono_reset(&_cr), _crms=XMOUSE_REP_IDELAY) 00082 #else 00083 #define CRIRESET() 00084 #endif 00085 00086 UINT16 m, code; 00087 00088 m = mouse_get(x,y); 00089 code=M_None; 00090 if ((*x!=_mx)||(*y!=_my)) { 00091 code = M_Move; 00092 _mx=*x; 00093 _my=*y; 00094 } 00095 if (_mb && !(LKEY && RKEY)) { _mb=FALSE; code=M_BUp; CRIRESET(); } 00096 else if (_ml && !LKEY) { _ml=FALSE; code=M_LUp; CRIRESET(); } 00097 else if (_mr && !RKEY) { _mr=FALSE; code=M_RUp; CRIRESET(); } 00098 else if (!_ml && LKEY) { _ml=TRUE; code=M_LDown; CRIRESET(); } 00099 else if (!_mr && RKEY) { _mr=TRUE; code=M_RDown; CRIRESET(); } 00100 else if (!_mb && LKEY && RKEY) { _mb=TRUE; code=M_BDown; CRIRESET(); } 00101 #ifdef XMOUSE_AUTOREP 00102 else if (LKEY||RKEY) { 00103 if (chrono_ms(&_cr)>_crms) { 00104 chrono_reset(&_cr); 00105 _crms=XMOUSE_REP_DELAY; 00106 if (LKEY&&RKEY) code=M_BDownRep; 00107 else if (LKEY) code=M_LDownRep; 00108 else if (RKEY) code=M_RDownRep; 00109 } 00110 } 00111 #endif 00112 if (LKEY) code |= XMOUSE_LKEY; 00113 if (RKEY) code |= XMOUSE_RKEY; 00114 00115 return code; 00116 } 00117 00118 /**********************************************************/