raton en c
Hola, mira te presento un programa referente a lo que pides. Sólo que contiene algunos errores que te tocaría modificarlos. Pero de nada a algo, creo que pudiera al menos, auxiliarte. El código es:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <string.h>
#define BOTON_D 1
#define BOTON_I 2
#define SOFTWARE 0
#define HARDWARE 1
#define llamadaRaton int86(0x33,&inReg,&outReg) /*Llamada de la interrupcion 33 para utilizar el raton*/
enum {false=0, true=1}; /*Ennumeraciones para definir verdadero y falso*/
enum {off=0, on=1};
/** Cursor del raton y sus efectos
*bit de mascara Bit de mascara Bit de pantalla
* de pantalla del cursor
* 0 0 0
* 0 1 0
* 1 0 NO AFECTADO
* 1 1 INVERTIDO
*/
/*Union de registros para manejar la salida y la entrada da la interrupcion 33*/
union REGS inReg, outReg;
//Verificacion del raton
typedef struct {
int presente, //es true si esta presente
botones; //numeros del botones del raton
}rResultado;
//estado de los botones
typedef struct {
int estadoBoton, //bits 0-2 en on si hay boton pulsado
contadorBoton, //contador de veces que se pulso el boton
ejeX,ejeY; //posicion del cursor
}rEstado;
//eventos del raton
typedef struct {
unsigned bandera, //registros de un evento del raton
boton, //boton seleccionado
ejeX, ejeY; //posicion del cursor
}eventoRaton;
//estrucutra de soporte del cursor del raton en modo grafico
typedef struct {
unsigned int mascaraPantalla[16],
mascaraCursor[16],
xCor,yCor;
}gCursor;
static gCursor FLECHA={
//Mascara de la pantalla
{0x1FFF,0x0FFF,0x07FF,0x03FF,
0x01FF,0x00FF,0x007F,0x003F,
0x001F,0x003F,0x01FF,0x01FF,
0xE0FF,0xF0FF,0xF8FF,0xF8FF },
//MASCARA DEL CURSOR
{0x0000,0x4000,0x6000,0x7000,
0x7800,0x7C00,0x7E00,0x7F00,
0x7F80,0x7C00,0x4C00,0x0600,
0x0600,0x0300,0x0300,0x0000 },
//coordenadas en x e y
1,1
};
static gCursor VIGA={
//mascara de la pantalla
{0xF3FF,0xE1FF,0xE1FF,0xE1FF,
0xE1FF,0xE049,0xE000,0x8000,
0x0000,0x0000,0x07FC,0x07F8,
0x9FF9,0x8FF1,0xC003,0xE007 },
//mascara del cursor
{0x0C30,0x0240,0x0180,0x0180,
0x0180,0x0180,0x0180,0x0180,
0x0180,0x0180,0x0180,0x0180,
0x0180,0x0180,0x0240,0x0C30},
//COORDENAS EN X e Y
7,7
};
struct Raton {
int rVisible; //estador del cursor del raton
int rMove; //si hubo movimiento
static eventoRaton far*rEventos; //eventos del raton
Raton() //constructor
{
rVisible=0;
rMove=false;
}
/**
*pone en estado inicial al raton , devuelve un apuntador a la
*estructura rResultado indicando si el raton esta instalado
*y si lo esta, devuelve tambien el numero de botones, siempre
*es llamado en la inicializacion.
*/
rResultado *rIniciar()
{
rResultado m;
rVisible=off;
inReg.x.ax=0; //funcion 0 del raton
llamadaRaton;
m.presente=outReg.x.ax;
m.botones=outReg.x.bx;
if(m.presente) rMuestra(true);
return &m;
}
/**
*Muestra el cursor del raton
*/
void rMuestra(int presente)
{
if (presente){
inReg.x.ax=1; //funcion 1 del raton
if(!rVisible) llamadaRaton; // lo muestra
rVisible=on;
}
else{
inReg.x.ax=2; //funcion 2 del raton
if(rVisible)llamadaRaton; //lo muestra
rVisible=off;
}
}
/**Devuelve un apuntador a la estrcutura rEstado con la posicion
*del cursor y el estado del boton
*/
rEstado rPos(void)
{
rEstado m;
inReg.x.ax=3; //funcion 3 del raton
llamadaRaton; //estado del boton
m.estadoBoton=outReg.x.bx;
m.ejeX=outReg.x.cx; //coordenada en X
m.ejeY=outReg.x.dx; //coordenada en Y
rMove=true;
return m;
}
/**
*Situa el cursor en la posicon (ejeX, ejeY)
*/
void rSitua(int ejeX, int ejeY)
{
inReg.x.ax=4;//funcion 4 del raton
inReg.x.cx=ejeX;
inReg.x.dx=ejeY;
llamadaRaton;
}
/**
*Devuelve informacion sobre el boton pulsado; estado actual
*(pulsado o no), numero de veces que se pulso desde la llamada
*anterior, posicion dle cursor de la ultima vez que se pulso
*el boton (se reinicia la cuenta y la informcion), boton 0 o el
*de la izquierda, 1 derecha en el raton de Mirosoft, 2 en el
*de LogiTech
*/
rEstado rPulsado (int boton)
{
rEstado m;
inReg.x.ax=5; //funcion 5 del raton
//peticion de un boton determinado
inReg.x.bx=boton;
llamadaRaton;
m.estadoBoton=outReg.x.ax;
m.contadorBoton=outReg.x.bx;
m.ejeX=outReg.x.cx;
m.ejeY=outReg.x.dx;
return m;
}
/**
*Devuelve informacion sobre el voton liberado
*/
rEstado rLiberado(int boton)
{
rEstado m;
inReg.x.ax=6; //funcion 6 del raton
//peticion de un boton determinado
inReg.x.bx=boton;
llamadaRaton;
m.estadoBoton=outReg.x.ax;
m.contadorBoton=outReg.x.bx;
m.ejeX=outReg.x.cx;
m.ejeY=outReg.x.dx;
return m;
}
/**
*Establece el rango horizontal, maximo y minomo para el cursor del raton:
*pone el cursor dentro de ese rango, si esta fuera
*cuando se invoca. Si se inviertem los valores de minX y maxX,
*los intercambia.
*/
void rLimiteX(int minX, int maxX)
{
inReg.x.ax=7; //funcion 7 del raton
inReg.x.cx=minX;
inReg.x.dx=maxX;
llamadaRaton;
}
/**
*Establce los limites verticales, trabaja parecido a la funcion
*anterior
*/
void rLimiteY(int minY, int maxY)
{
inReg.x.ax=8; //funcion 8 del raton
inReg.x.cx=minY;
inReg.x.dx=maxY;
llamadaRaton;
}
/**
*RELACION DE PASO Y FRENTE A PASO EN X CON RAZON r/8
*/
void rRelacionPaso(int dimX, int dimY)
{
//por omision es 16 en vertical
inReg.x.ax=15;
inReg.x.cx=dimX;
inReg.x.dx=dimY;
llamadaRaton;
}
/**
*Se relaciona al area de la pantalla donde el cursor del raton
*no sera visible, utilizada para actualziar la pantalla
*/
void rOculto(int izquierda, int arriba, int derecha, int abajo)
{
inReg.x.ax=16;
inReg.x.cx=izquierda;
inReg.x.dx=arriba;
inReg.x.si=derecha;
inReg.x.di=abajo;
llamadaRaton;
}
/**
*Establece la velocidad en mickeys /segundo del cursor del
*raton
*/
void rVelocidad (int velocidad)
{
inReg.x.ax=19;
inReg.x.dx=velocidad;
llamadaRaton;
}
};
/**
*Estrucutrua para generar el raton en modo grafico */
struct gRaton{
Raton raton; //instancia de la estructura que soporta el raton
/**
*Establece la forma del cursor en modo grafico
*/
void ponCursor(int ejeX, int ejeY, unsigned segMascara, unsigned despMascara)
{
struct SREGS seg;
inReg.x.ax=9; //funcion 9 del cursor
inReg.x.bx=ejeX; //cursor punto activo
inReg.x.cx=ejeY; //cursor punto activo
inReg.x.dx=despMascara;
seg.es=segMascara;
int86x(0x33,&inReg,&outReg,&seg);
}
void otroPonCursor(gCursor esteCursor)
{
ponCursor(esteCursor.xCor,esteCursor.yCor,_DS,(unsigned)esteCursor.mascaraPantalla);
}
void rBrillante(int puesto)
{
if(puesto) inReg.x.ax=13; //funcion 13 =on
else inReg.x.ax=14; //funcion 14=off
llamadaRaton;
}
};
struct tRaton{
Raton raton; //instancia del soporte del raton
/**
*Establece el tipo de cursor de texto, donde 0=software
*1=hardware. Para cursor de software tipoCursor y sInicio
*son las mascaras de la pantalla y del cursor. Para el cursor
*de hardware tipoCursor y sInicio especifican las lineas de
*inicio y fin, es decir, la forma del cursor.
*/
void ponCursor(int tipoCursor, unsigned sInicio, unsigned sFin)
{
inReg.x.ax=10;
inReg.x.bx=tipoCursor;
inReg.x.cx=sInicio;
inReg.x.dx=sFin;
llamadaRaton;
}
void rBrillante (int puesto)
{
if (puesto)inReg.x.ax=13; //funcion 13=on
else inReg.x.ax=14; //funcion 14=off
llamadaRaton;
}
};
void iniciaGraficos(void)
{
int gDriver=DETECT,gMode,gError;
initgraph(&gDriver,&gMode,"c:\borlandcbgi");
gError=graphresult();
if(gError!=grOk){
printf("n Error grafico:%s",grapherrormsg(gError));
printf("n Programa Abortado.");
printf("n Pulse una tecla para terminar...");
getch();
exit (1);
}
cleardevice();
}
void finalizaGraficos(void)
{
closegraph();
}
void recuadroItem(int x, int y, int ancho, int alto, char *texto)
{
settextjustify(CENTER_TEXT,CENTER_TEXT);
rectangle(x,y,x+ancho,y+alto);
outtextxy(x+(ancho/2),y+(alto/2), texto);
}
void menuGrafico()
{
settextjustify(CENTER_TEXT,CENTER_TEXT);
recuadroItem( 10,320,110,20,"Con posicion");
recuadroItem(140,320,110,20,"Sin posicion");
recuadroItem(265,320,110,20,"Velocidad");
recuadroItem(390,320,110,20,"Oculta");
recuadroItem(515,320,110,20,"Salir");
}
int tPos(int posX, int posY, int xIni,int yIni ,int ancho, int alto)
{
if((posX>xIni&&posX<=xIni+ancho)&&(posY>yIni&&posY<=yIni+alto)) return true;
return false;
}
void cambiaVelocidad(gRaton&rat)
{
char tecla;
char velCh[]="Velocidad:";
char vel[10];
int i=0,terminar=false,iVel;
setviewport(269,0,379,42, true);
settextjustify(CENTER_TEXT,CENTER_TEXT);
rat.otroPonCursor(VIGA);
rat.raton.rSitua(277,30);
do{
rat.raton.rMuestra(false);
clearviewport();
setcolor(15); //LIGHTBLUE
rectangle(0,0,110,40);
outtextxy(50,10,velCh);
rat.raton.rSitua(277+i*8,30);
rat.raton.rMuestra(true);
tecla=getch();
if (tecla==0x0D) terminar=true;
else
if(tecla==0x08&&(i>1)) i=2;
else
if(i>5)i--;
else{
char ch[2];
ch[0]=tecla;
ch[1]=' ';
setcolor(15);
outtextxy(277+i*8,30,ch);
if((int)tecla>47&&(int)tecla<58)vel[i]=tecla;
}
if((int)tecla>47&&(int)tecla<58)i++;
}while(!terminar);
vel[i]=' ';
rat.otroPonCursor(FLECHA);
rat.raton.rMuestra(false);
clearviewport();
setviewport(0,0,getmaxx(),getmaxy(),true);
iVel=atoi(vel);
rat.raton.rVelocidad(iVel);
rat.raton.rMuestra(true);
}
void muestraPos(gRaton&rat,int hazlo)
{
char corX[5],corY[5],cord[14];
rEstado estado=rat.raton.rPos();
int x=estado.ejeX;
int y=estado.ejeY;
itoa(x,corX,10);
itoa(y,corY,10);
strcpy(cord,corX);
strcat(cord,",");
strcat(cord,corY);
int lg=strlen(cord);
cord[lg]=' ';
if(hazlo==true) setviewport(269,0,379,22,true);
clearviewport();
setcolor(0);
for(int yy=0;yy<15;yy++) line (1,1+yy,99,1+yy);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(15);
rectangle(0,0,100,20);
outtextxy(50,10,cord);
}
void ocultaPos(gRaton&rat)
{
clearviewport();
setviewport(0,0,getmaxx(),getmaxy(),true);
rat.raton.rMuestra(true);
}
void main(void)
{
int salir=false, muestra=false, otro=true,hazlo=false;
int x,y;
gRaton rat;
rEstado posicion;
rResultado *result;
iniciaGraficos();
result=rat.raton.rIniciar();
menuGrafico();
if(result->presente)
do{
posicion=rat.raton.rPulsado(BOTON_I);
x=posicion.ejeX;
y=posicion.ejeY;
if(posicion.contadorBoton){
if(tPos(posicion.ejeX,posicion.ejeY,15,320,110,20)){
muestra=true;
otro=false;
hazlo=true;
}
else
if(tPos(posicion.ejeX,posicion.ejeY,140,320,110,20)){
muestra=false;
otro=false;
}
else
if(tPos(posicion.ejeX,posicion.ejeY,265,320,110,20)){
cambiaVelocidad(rat);
otro=true;
}
else
if(tPos(posicion.ejeX,posicion.ejeY,390,320,110,20)){
rat.raton.rMuestra(false);
delay(1500);
rat.raton.rMuestra(true);
otro=true;
}
else
if(tPos(posicion.ejeX,posicion.ejeY,515,320,110,20))
salir=true;
if(muestra==true&&otro==false){
muestraPos(rat,hazlo);
hazlo=false;
}
else
if(muestra==false&&otro==false){
ocultaPos(rat);
otro=true;
}
}
else{
posicion=rat.raton.rPos();
if(rat.raton.rMove==true)
if((x!=posicion.ejeX||y!=posicion.ejeY)&&(muestra==true&&otro==false)){
muestraPos(rat,hazlo);
hazlo=false;
}
else rat.raton.rMove=false;
}
}while(!salir);
tRaton tRat;
tRat.raton.rIniciar();
tRat.ponCursor(HARDWARE,11,12);
finalizaGraficos();
}
Bueno, me despido saludos.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <string.h>
#define BOTON_D 1
#define BOTON_I 2
#define SOFTWARE 0
#define HARDWARE 1
#define llamadaRaton int86(0x33,&inReg,&outReg) /*Llamada de la interrupcion 33 para utilizar el raton*/
enum {false=0, true=1}; /*Ennumeraciones para definir verdadero y falso*/
enum {off=0, on=1};
/** Cursor del raton y sus efectos
*bit de mascara Bit de mascara Bit de pantalla
* de pantalla del cursor
* 0 0 0
* 0 1 0
* 1 0 NO AFECTADO
* 1 1 INVERTIDO
*/
/*Union de registros para manejar la salida y la entrada da la interrupcion 33*/
union REGS inReg, outReg;
//Verificacion del raton
typedef struct {
int presente, //es true si esta presente
botones; //numeros del botones del raton
}rResultado;
//estado de los botones
typedef struct {
int estadoBoton, //bits 0-2 en on si hay boton pulsado
contadorBoton, //contador de veces que se pulso el boton
ejeX,ejeY; //posicion del cursor
}rEstado;
//eventos del raton
typedef struct {
unsigned bandera, //registros de un evento del raton
boton, //boton seleccionado
ejeX, ejeY; //posicion del cursor
}eventoRaton;
//estrucutra de soporte del cursor del raton en modo grafico
typedef struct {
unsigned int mascaraPantalla[16],
mascaraCursor[16],
xCor,yCor;
}gCursor;
static gCursor FLECHA={
//Mascara de la pantalla
{0x1FFF,0x0FFF,0x07FF,0x03FF,
0x01FF,0x00FF,0x007F,0x003F,
0x001F,0x003F,0x01FF,0x01FF,
0xE0FF,0xF0FF,0xF8FF,0xF8FF },
//MASCARA DEL CURSOR
{0x0000,0x4000,0x6000,0x7000,
0x7800,0x7C00,0x7E00,0x7F00,
0x7F80,0x7C00,0x4C00,0x0600,
0x0600,0x0300,0x0300,0x0000 },
//coordenadas en x e y
1,1
};
static gCursor VIGA={
//mascara de la pantalla
{0xF3FF,0xE1FF,0xE1FF,0xE1FF,
0xE1FF,0xE049,0xE000,0x8000,
0x0000,0x0000,0x07FC,0x07F8,
0x9FF9,0x8FF1,0xC003,0xE007 },
//mascara del cursor
{0x0C30,0x0240,0x0180,0x0180,
0x0180,0x0180,0x0180,0x0180,
0x0180,0x0180,0x0180,0x0180,
0x0180,0x0180,0x0240,0x0C30},
//COORDENAS EN X e Y
7,7
};
struct Raton {
int rVisible; //estador del cursor del raton
int rMove; //si hubo movimiento
static eventoRaton far*rEventos; //eventos del raton
Raton() //constructor
{
rVisible=0;
rMove=false;
}
/**
*pone en estado inicial al raton , devuelve un apuntador a la
*estructura rResultado indicando si el raton esta instalado
*y si lo esta, devuelve tambien el numero de botones, siempre
*es llamado en la inicializacion.
*/
rResultado *rIniciar()
{
rResultado m;
rVisible=off;
inReg.x.ax=0; //funcion 0 del raton
llamadaRaton;
m.presente=outReg.x.ax;
m.botones=outReg.x.bx;
if(m.presente) rMuestra(true);
return &m;
}
/**
*Muestra el cursor del raton
*/
void rMuestra(int presente)
{
if (presente){
inReg.x.ax=1; //funcion 1 del raton
if(!rVisible) llamadaRaton; // lo muestra
rVisible=on;
}
else{
inReg.x.ax=2; //funcion 2 del raton
if(rVisible)llamadaRaton; //lo muestra
rVisible=off;
}
}
/**Devuelve un apuntador a la estrcutura rEstado con la posicion
*del cursor y el estado del boton
*/
rEstado rPos(void)
{
rEstado m;
inReg.x.ax=3; //funcion 3 del raton
llamadaRaton; //estado del boton
m.estadoBoton=outReg.x.bx;
m.ejeX=outReg.x.cx; //coordenada en X
m.ejeY=outReg.x.dx; //coordenada en Y
rMove=true;
return m;
}
/**
*Situa el cursor en la posicon (ejeX, ejeY)
*/
void rSitua(int ejeX, int ejeY)
{
inReg.x.ax=4;//funcion 4 del raton
inReg.x.cx=ejeX;
inReg.x.dx=ejeY;
llamadaRaton;
}
/**
*Devuelve informacion sobre el boton pulsado; estado actual
*(pulsado o no), numero de veces que se pulso desde la llamada
*anterior, posicion dle cursor de la ultima vez que se pulso
*el boton (se reinicia la cuenta y la informcion), boton 0 o el
*de la izquierda, 1 derecha en el raton de Mirosoft, 2 en el
*de LogiTech
*/
rEstado rPulsado (int boton)
{
rEstado m;
inReg.x.ax=5; //funcion 5 del raton
//peticion de un boton determinado
inReg.x.bx=boton;
llamadaRaton;
m.estadoBoton=outReg.x.ax;
m.contadorBoton=outReg.x.bx;
m.ejeX=outReg.x.cx;
m.ejeY=outReg.x.dx;
return m;
}
/**
*Devuelve informacion sobre el voton liberado
*/
rEstado rLiberado(int boton)
{
rEstado m;
inReg.x.ax=6; //funcion 6 del raton
//peticion de un boton determinado
inReg.x.bx=boton;
llamadaRaton;
m.estadoBoton=outReg.x.ax;
m.contadorBoton=outReg.x.bx;
m.ejeX=outReg.x.cx;
m.ejeY=outReg.x.dx;
return m;
}
/**
*Establece el rango horizontal, maximo y minomo para el cursor del raton:
*pone el cursor dentro de ese rango, si esta fuera
*cuando se invoca. Si se inviertem los valores de minX y maxX,
*los intercambia.
*/
void rLimiteX(int minX, int maxX)
{
inReg.x.ax=7; //funcion 7 del raton
inReg.x.cx=minX;
inReg.x.dx=maxX;
llamadaRaton;
}
/**
*Establce los limites verticales, trabaja parecido a la funcion
*anterior
*/
void rLimiteY(int minY, int maxY)
{
inReg.x.ax=8; //funcion 8 del raton
inReg.x.cx=minY;
inReg.x.dx=maxY;
llamadaRaton;
}
/**
*RELACION DE PASO Y FRENTE A PASO EN X CON RAZON r/8
*/
void rRelacionPaso(int dimX, int dimY)
{
//por omision es 16 en vertical
inReg.x.ax=15;
inReg.x.cx=dimX;
inReg.x.dx=dimY;
llamadaRaton;
}
/**
*Se relaciona al area de la pantalla donde el cursor del raton
*no sera visible, utilizada para actualziar la pantalla
*/
void rOculto(int izquierda, int arriba, int derecha, int abajo)
{
inReg.x.ax=16;
inReg.x.cx=izquierda;
inReg.x.dx=arriba;
inReg.x.si=derecha;
inReg.x.di=abajo;
llamadaRaton;
}
/**
*Establece la velocidad en mickeys /segundo del cursor del
*raton
*/
void rVelocidad (int velocidad)
{
inReg.x.ax=19;
inReg.x.dx=velocidad;
llamadaRaton;
}
};
/**
*Estrucutrua para generar el raton en modo grafico */
struct gRaton{
Raton raton; //instancia de la estructura que soporta el raton
/**
*Establece la forma del cursor en modo grafico
*/
void ponCursor(int ejeX, int ejeY, unsigned segMascara, unsigned despMascara)
{
struct SREGS seg;
inReg.x.ax=9; //funcion 9 del cursor
inReg.x.bx=ejeX; //cursor punto activo
inReg.x.cx=ejeY; //cursor punto activo
inReg.x.dx=despMascara;
seg.es=segMascara;
int86x(0x33,&inReg,&outReg,&seg);
}
void otroPonCursor(gCursor esteCursor)
{
ponCursor(esteCursor.xCor,esteCursor.yCor,_DS,(unsigned)esteCursor.mascaraPantalla);
}
void rBrillante(int puesto)
{
if(puesto) inReg.x.ax=13; //funcion 13 =on
else inReg.x.ax=14; //funcion 14=off
llamadaRaton;
}
};
struct tRaton{
Raton raton; //instancia del soporte del raton
/**
*Establece el tipo de cursor de texto, donde 0=software
*1=hardware. Para cursor de software tipoCursor y sInicio
*son las mascaras de la pantalla y del cursor. Para el cursor
*de hardware tipoCursor y sInicio especifican las lineas de
*inicio y fin, es decir, la forma del cursor.
*/
void ponCursor(int tipoCursor, unsigned sInicio, unsigned sFin)
{
inReg.x.ax=10;
inReg.x.bx=tipoCursor;
inReg.x.cx=sInicio;
inReg.x.dx=sFin;
llamadaRaton;
}
void rBrillante (int puesto)
{
if (puesto)inReg.x.ax=13; //funcion 13=on
else inReg.x.ax=14; //funcion 14=off
llamadaRaton;
}
};
void iniciaGraficos(void)
{
int gDriver=DETECT,gMode,gError;
initgraph(&gDriver,&gMode,"c:\borlandcbgi");
gError=graphresult();
if(gError!=grOk){
printf("n Error grafico:%s",grapherrormsg(gError));
printf("n Programa Abortado.");
printf("n Pulse una tecla para terminar...");
getch();
exit (1);
}
cleardevice();
}
void finalizaGraficos(void)
{
closegraph();
}
void recuadroItem(int x, int y, int ancho, int alto, char *texto)
{
settextjustify(CENTER_TEXT,CENTER_TEXT);
rectangle(x,y,x+ancho,y+alto);
outtextxy(x+(ancho/2),y+(alto/2), texto);
}
void menuGrafico()
{
settextjustify(CENTER_TEXT,CENTER_TEXT);
recuadroItem( 10,320,110,20,"Con posicion");
recuadroItem(140,320,110,20,"Sin posicion");
recuadroItem(265,320,110,20,"Velocidad");
recuadroItem(390,320,110,20,"Oculta");
recuadroItem(515,320,110,20,"Salir");
}
int tPos(int posX, int posY, int xIni,int yIni ,int ancho, int alto)
{
if((posX>xIni&&posX<=xIni+ancho)&&(posY>yIni&&posY<=yIni+alto)) return true;
return false;
}
void cambiaVelocidad(gRaton&rat)
{
char tecla;
char velCh[]="Velocidad:";
char vel[10];
int i=0,terminar=false,iVel;
setviewport(269,0,379,42, true);
settextjustify(CENTER_TEXT,CENTER_TEXT);
rat.otroPonCursor(VIGA);
rat.raton.rSitua(277,30);
do{
rat.raton.rMuestra(false);
clearviewport();
setcolor(15); //LIGHTBLUE
rectangle(0,0,110,40);
outtextxy(50,10,velCh);
rat.raton.rSitua(277+i*8,30);
rat.raton.rMuestra(true);
tecla=getch();
if (tecla==0x0D) terminar=true;
else
if(tecla==0x08&&(i>1)) i=2;
else
if(i>5)i--;
else{
char ch[2];
ch[0]=tecla;
ch[1]=' ';
setcolor(15);
outtextxy(277+i*8,30,ch);
if((int)tecla>47&&(int)tecla<58)vel[i]=tecla;
}
if((int)tecla>47&&(int)tecla<58)i++;
}while(!terminar);
vel[i]=' ';
rat.otroPonCursor(FLECHA);
rat.raton.rMuestra(false);
clearviewport();
setviewport(0,0,getmaxx(),getmaxy(),true);
iVel=atoi(vel);
rat.raton.rVelocidad(iVel);
rat.raton.rMuestra(true);
}
void muestraPos(gRaton&rat,int hazlo)
{
char corX[5],corY[5],cord[14];
rEstado estado=rat.raton.rPos();
int x=estado.ejeX;
int y=estado.ejeY;
itoa(x,corX,10);
itoa(y,corY,10);
strcpy(cord,corX);
strcat(cord,",");
strcat(cord,corY);
int lg=strlen(cord);
cord[lg]=' ';
if(hazlo==true) setviewport(269,0,379,22,true);
clearviewport();
setcolor(0);
for(int yy=0;yy<15;yy++) line (1,1+yy,99,1+yy);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(15);
rectangle(0,0,100,20);
outtextxy(50,10,cord);
}
void ocultaPos(gRaton&rat)
{
clearviewport();
setviewport(0,0,getmaxx(),getmaxy(),true);
rat.raton.rMuestra(true);
}
void main(void)
{
int salir=false, muestra=false, otro=true,hazlo=false;
int x,y;
gRaton rat;
rEstado posicion;
rResultado *result;
iniciaGraficos();
result=rat.raton.rIniciar();
menuGrafico();
if(result->presente)
do{
posicion=rat.raton.rPulsado(BOTON_I);
x=posicion.ejeX;
y=posicion.ejeY;
if(posicion.contadorBoton){
if(tPos(posicion.ejeX,posicion.ejeY,15,320,110,20)){
muestra=true;
otro=false;
hazlo=true;
}
else
if(tPos(posicion.ejeX,posicion.ejeY,140,320,110,20)){
muestra=false;
otro=false;
}
else
if(tPos(posicion.ejeX,posicion.ejeY,265,320,110,20)){
cambiaVelocidad(rat);
otro=true;
}
else
if(tPos(posicion.ejeX,posicion.ejeY,390,320,110,20)){
rat.raton.rMuestra(false);
delay(1500);
rat.raton.rMuestra(true);
otro=true;
}
else
if(tPos(posicion.ejeX,posicion.ejeY,515,320,110,20))
salir=true;
if(muestra==true&&otro==false){
muestraPos(rat,hazlo);
hazlo=false;
}
else
if(muestra==false&&otro==false){
ocultaPos(rat);
otro=true;
}
}
else{
posicion=rat.raton.rPos();
if(rat.raton.rMove==true)
if((x!=posicion.ejeX||y!=posicion.ejeY)&&(muestra==true&&otro==false)){
muestraPos(rat,hazlo);
hazlo=false;
}
else rat.raton.rMove=false;
}
}while(!salir);
tRaton tRat;
tRat.raton.rIniciar();
tRat.ponCursor(HARDWARE,11,12);
finalizaGraficos();
}
Bueno, me despido saludos.
