00001 /**********************************************************/ 00002 /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/ 00003 /* 00004 Copyright: 1995 - Grupo de Voz (DAET) ETSII/IT-Bilbao 00005 00006 Nombre fuente................ ACCEL.C 00007 Nombre paquete............... - 00008 Lenguaje fuente.............. C (Borland C/C++ 3.1) 00009 Estado....................... Completado 00010 Dependencia Hard/OS.......... reloj PC 00011 Codigo condicional........... - 00012 00013 Codificacion................. Borja Etxebarria 00014 00015 Version dd/mm/aa Autor Proposito de la edicion 00016 ------- -------- -------- ----------------------- 00017 0.1.0 01/07/98 Borja nuevo algoritmo aceleracion 00018 0.0.1 22/05/96 Borja bug. en documentacion 00019 0.0.0 23/11/95 Borja Codificacion inicial. 00020 00021 ======================== Contenido ======================== 00022 Acelerador (para cursores graficos...) 00023 00024 Uso tipico, algo asi: 00025 00026 00027 INT16 key; 00028 UINT16 step; 00029 BOOL salir; 00030 00031 accel_ini(40,1500); <-- de 1 a 40 en 1.5 segundos, con Repsol Super Sport 00032 salir = FALSE; 00033 00034 do { 00035 key = xgetch(); <-- sig. tecla 00036 step = accel_get(key); <-- lee aceleracion 00037 00038 switch (key) { 00039 LEFT: <-- cursor izquierdo 00040 pos -= step; <-- decrementa tanto como indique el acelerador 00041 if (!xkbnextsame()) <-- si la sig. tecla es igual, no pinta nada 00042 repinta(); 00043 break; 00044 RIGHT: 00045 pos += step; 00046 if (!xkbnextsame()) 00047 repinta(); 00048 break; 00049 ESC: 00050 salir = TRUE; 00051 break; 00052 default: 00053 beep(); 00054 break; 00055 } 00056 } while (!salir); 00057 00058 =========================================================== 00059 */ 00060 /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/ 00061 /**********************************************************/ 00062 00063 #include "accel.h" 00064 00065 /**********************************************************/ 00066 00067 #define ms2tic(ms) ((ms+27)/55) 00068 00069 /**********************************************************/ 00070 00071 PRIVATE UINT32 _old_timer; 00072 PRIVATE UINT16 _old_event; 00073 PRIVATE UINT16 _max, _thres; 00074 PRIVATE UINT16 _accel; 00075 00076 /**********************************************************/ 00077 00078 PRIVATE UINT32 long get_tic( void ) 00079 { 00080 return *((pfUINT32)0x046C); 00081 } 00082 00083 /**********************************************************/ 00084 /* Inicializa acelerador. 00085 {max} es la aceleracion maxima a alcanzar (la minima es 1). 00086 {thres_ms} es el tiempo (en milisegundos) por debajo del cual 00087 se acelera el teclado. Por encima de este tiempo, se resetea 00088 la aceleracion al valor minimo. */ 00089 00090 VOID accel_ini( UINT16 max, UINT16 thres_ms ) 00091 { 00092 _old_event = 0; 00093 _thres= ms2tic(thres_ms); 00094 _accel = 1; 00095 _max = max; 00096 _old_timer = get_tic()-2*_thres; 00097 } 00098 00099 /**********************************************************/ 00100 /* {devuelve} el valor de la aceleracion (1 a {max}) a utilizar 00101 para el evento {event}. */ 00102 00103 UINT16 accel_get( UINT16 event ) 00104 { 00105 UINT32 timer; 00106 00107 timer = get_tic(); 00108 00109 if ((timer-_old_timer<_thres)&&(event==_old_event)) { 00110 if (_accel<_max) _accel++; 00111 } 00112 else 00113 _accel = 1; 00114 00115 _old_event = event; 00116 _old_timer = timer; 00117 return _accel; 00118 } 00119 00120 /**********************************************************/