home *** CD-ROM | disk | FTP | other *** search
- // ALERT.H
- // (C) Anubis Software.
- // 27 de Septiembre de 1994
- // Librería, que sirve para el uso y gestión de alertas.
- #ifndef ALERT.H
- #define ALERT.H
-
-
- // --------------------------------------+
- // Inclusión de librerias de Borland C++ |
- // --------------------------------------+
- #include <dos.h>
- #include <mem.h>
-
- // ------------------------------------------+
- // Inclusión de librerias de Anubis Software |
- // ------------------------------------------+
- #include "mouse.h"
- #include "textmode.h"
- #include "teclado.h"
-
- // ---------------------------------------------
- // Definición de tipos de la estructura alerta.
- // ---------------------------------------------
- typedef struct BOTON {
- char nombre[15],
- letra_activacion;
- int posx,
- posy,
- posxl,
- color_texto,
- color_fondo,
- color_seleccionado,
- color_letra,
- longitud,
- code_return;
- unsigned char caracteristicas;
- struct BOTON *siguiente;
- } boton;
-
- typedef struct ALERTA {
- char nombre[15];
- char texto1[40];
- char texto2[40];
- char texto3[40];
- char ai,
- ad,
- abi,
- abd,
- horizontal,
- vertical;
- int posx,
- posy,
- ancho,
- alto,
- color_fondo,
- color_texto,
- color_marco,
- color_botones,
- color_seleccionado;
- unsigned char caracteristicas;
- struct BOTON *botones;
- } alert;
-
-
- // --------------------------------------------------------
- // Declaración e implementación de las funciones del menu.
- // --------------------------------------------------------
-
- // ----------------------------------------------------------------------
- // result = evnt_alert(alerta);
- //
- // int result --> Contiene el codigo de retorno de la decisión que se ha tomado.
- // alert alerta --> Es la alerta que vamos a gestionar.
- //
- // Esta función, es la encargada de todo cuanto queremos gestionar. Es decir,
- // se encarga de poner la alerta en pantalla, determinar que eventos se han utilizado
- // y finalmente devolver la pantalla a su estado anterior.
- // No utiliza funciones de la Bios, sino que lo hace directamente sobre la
- // memoria de video por cuestones de eficiencia, orgullo, etc..
- //
- int evnt_alert(alert alerta)
- {
- char auxi[80];
- int x,y,i;
- char tecla;
- boton *boto,*auxiliar;
-
- ide_mouse();
- Save_Screen(1);
- tipo_cursor(CURSOR_INVISIBLE);
- i=alerta.ancho;
- while (i--) auxi[i]=' ';
- auxi[alerta.ancho]=0;
- y=alerta.posy;
- x=alerta.posx;
- escribe(alerta.ai,x++,y,alerta.color_texto,alerta.color_marco);
- while (x<alerta.posx+alerta.ancho)
- escribe(alerta.horizontal,x++,y,alerta.color_texto,alerta.color_marco);
- escribe(alerta.ad,x,y,alerta.color_texto,alerta.color_marco);
- x=alerta.posx;
- y++;
- escribe(auxi,x,y,alerta.color_texto,alerta.color_fondo);
- escribe(alerta.vertical,x++,y,alerta.color_texto,alerta.color_marco);
- escribe(' ',x++,y,alerta.color_texto,alerta.color_fondo);
- escribe(alerta.texto1,x,y,alerta.color_texto,alerta.color_fondo);
- escribe(alerta.vertical,alerta.posx+alerta.ancho,y,alerta.color_texto,alerta.color_marco);
- x=alerta.posx;
- y++;
- escribe(auxi,x,y,alerta.color_texto,alerta.color_fondo);
- escribe(alerta.vertical,x++,y,alerta.color_texto,alerta.color_marco);
- escribe(' ',x++,y,alerta.color_texto,alerta.color_fondo);
- escribe(alerta.texto2,x,y,alerta.color_texto,alerta.color_fondo);
- escribe(alerta.vertical,alerta.posx+alerta.ancho,y,alerta.color_texto,alerta.color_marco);
- x=alerta.posx;
- y++;
- escribe(auxi,x,y,alerta.color_texto,alerta.color_fondo);
- escribe(alerta.vertical,x++,y,alerta.color_texto,alerta.color_marco);
- escribe(' ',x++,y,alerta.color_texto,alerta.color_fondo);
- escribe(alerta.texto3,x,y,alerta.color_texto,alerta.color_fondo);
- escribe(alerta.vertical,alerta.posx+alerta.ancho,y,alerta.color_texto,alerta.color_marco);
- x=alerta.posx;
- while (alerta.posy+alerta.alto-2 > y++) {
- escribe(auxi,x,y,alerta.color_texto,alerta.color_fondo);
- escribe(alerta.vertical,x,y,alerta.color_texto,alerta.color_marco);
- escribe(alerta.vertical,alerta.posx+alerta.ancho,y,alerta.color_texto,alerta.color_marco);
- }// end while
- escribe(alerta.abi,x++,y,alerta.color_texto,alerta.color_marco);
- while(x < alerta.posx+alerta.ancho)
- escribe(alerta.horizontal,x++,y,alerta.color_texto,alerta.color_marco);
- escribe(alerta.abd,alerta.posx+alerta.ancho,y,alerta.color_texto,alerta.color_marco);
- // Hasta aqui, hemos dibujado la alerta, ahora vamos a dibujar los botones.
- boto = alerta.botones;
- while (boto != NULL) {
- escribe((*boto).nombre,alerta.posx+(*boto).posx,alerta.posy+(*boto).posy,(*boto).color_texto,(*boto).color_fondo);
- escribe((*boto).letra_activacion,alerta.posx+(*boto).posx+(*boto).posxl-1,alerta.posy+(*boto).posy,(*boto).color_letra,(*boto).color_fondo);
- boto = (*boto).siguiente;
- }// end while
- // Ahora, gestionamos, los botones, y esperamos a que se pulse sobre
- // alguno de ellos.
- // Inicializamos la variable auxiliar que recorre las opciones del menu
- auxiliar = alerta.botones;
- // Ponemos en reverso a la selección auxiliar.
- escribe( (*auxiliar).nombre,alerta.posx+(*auxiliar).posx,alerta.posy+(*auxiliar).posy,(*auxiliar).color_texto,(*auxiliar).color_seleccionado);
- escribe( (*auxiliar).letra_activacion,alerta.posx+(*auxiliar).posx+(*auxiliar).posxl-1,alerta.posy+(*auxiliar).posy,(*auxiliar).color_letra,(*auxiliar).color_seleccionado);
- show_mouse();
-
-
- // Mientras no se pulse ESC
- tecla = teclado();
- while ( tecla != 27 ) {
- //Si se ha pulsado una tecla
- if ( kbhit() ) {
- tecla = getch();
- if (tecla == 0) {
- tecla = getch();
- while (kbhit() ) getch();
- // Segun cual sea la tecla, hacemos una u otra cosa.
- switch (tecla) {
-
- // Se ha pulsado la tecla ->
- case 77: {
- if ( (*auxiliar).siguiente != NULL) {
- // Poner en normal a auxiliar
- ide_mouse();
- escribe( (*auxiliar).nombre,alerta.posx+(*auxiliar).posx,alerta.posy+(*auxiliar).posy,(*auxiliar).color_texto,(*auxiliar).color_fondo);
- escribe( (*auxiliar).letra_activacion,alerta.posx+(*auxiliar).posx+(*auxiliar).posxl-1,alerta.posy+(*auxiliar).posy,(*auxiliar).color_letra,(*auxiliar).color_fondo);
- // Pasamos al siguiente item.
- auxiliar = (*auxiliar).siguiente;
- // Y lo ponemos en reverso.
- escribe( (*auxiliar).nombre,alerta.posx+(*auxiliar).posx,alerta.posy+(*auxiliar).posy,(*auxiliar).color_texto,(*auxiliar).color_seleccionado);
- escribe( (*auxiliar).letra_activacion,alerta.posx+(*auxiliar).posx+(*auxiliar).posxl-1,alerta.posy+(*auxiliar).posy,(*auxiliar).color_letra,(*auxiliar).color_seleccionado);
- show_mouse();
- }// end if
- break;
- }// end case
-
- // Se ha pulsado la tecla <-
- case 75: {
- boton *aux;
- if ( auxiliar != alerta.botones ) {
-
- // Poner en normal a auxiliar
- ide_mouse();
- escribe( (*auxiliar).nombre,alerta.posx+(*auxiliar).posx,alerta.posy+(*auxiliar).posy,(*auxiliar).color_texto,(*auxiliar).color_fondo);
- escribe( (*auxiliar).letra_activacion,alerta.posx+(*auxiliar).posx+(*auxiliar).posxl-1,alerta.posy+(*auxiliar).posy,(*auxiliar).color_letra,(*auxiliar).color_fondo);
- //Pasamos al item anterior
- aux = alerta.botones;
- while ( (*aux).siguiente != auxiliar )
- aux = (*aux).siguiente;
- auxiliar = aux;
- // Poner en reverso a auxiliar
- escribe( (*auxiliar).nombre,alerta.posx+(*auxiliar).posx,alerta.posy+(*auxiliar).posy,(*auxiliar).color_texto,(*auxiliar).color_seleccionado);
- escribe( (*auxiliar).letra_activacion,alerta.posx+(*auxiliar).posx+(*auxiliar).posxl-1,alerta.posy+(*auxiliar).posy,(*auxiliar).color_letra,(*auxiliar).color_seleccionado);
- show_mouse();
-
- }// end if
- break;
- }// end case
- }// end switch
- } else {
- while (kbhit()) getch();
- switch (tecla) {
- // Se ha pulsado RETURN
- case 13: {
- Restore_Screen(1);
- tipo_cursor(OLD_CURSOR);
- return( (*auxiliar).code_return );
- }// end case
-
- // Se ha pulsado cualquier otra tecla
- default: {
- boton *aux;
- aux = alerta.botones;
- while( aux != NULL ) {
- if( (*aux).letra_activacion == tecla) {
- Restore_Screen(1);
- tipo_cursor(OLD_CURSOR);
- return ( (*aux).code_return);
- }// end if
- aux = (*aux).siguiente;
- }// end while
- }// end case
- }// end switch
- }// end if
- } else {
- struct mouse raton;
- boton *aux;
- raton = inf_mouse();
- if (mouse_evento & 2) {
- mouse_evento = 0;
- aux = alerta.botones;
- while ( aux != NULL ) {
- if ( ( alerta.posx+(*aux).posx <= (raton.posx/8)+1 ) &&
- ( alerta.posx+(*aux).posx + (*aux).longitud > (raton.posx/8)+1) &&
- ( alerta.posy+(*aux).posy == (raton.posy / 8)+1 ) ) {
- Restore_Screen(1);
- tipo_cursor(OLD_CURSOR);
- return ((*aux).code_return);
- }// end if
- aux = (*aux).siguiente;
- }// end while
- }// end if
- }// end if
- }// end while
- ide_mouse();
- Restore_Screen(1);
- show_mouse();
- tipo_cursor(OLD_CURSOR);
- return(0);
- }// end evnt_alert
-
-
- /*
- main()
- {
- init_mouse();
- InitMouse(0xfe);
- show_mouse();
- alert alerta = {"Super_Alerta","Atencion","Peligro Inminente","Perdida de Datos.",
- '*','*','*','*','-','|',20,10,30,10,1,0,1,5,6,0,NULL};
- boton ok = {" O.K ",'O',3,7,3,10,3,15,13,7,0,0,NULL};
- boton ok1= {" Cancel ",'C',12,7,2,10,3,15,13,8,0,0,NULL};
- ok.siguiente = &ok1;
- alerta.botones = &ok;
- clrscr();
- evnt_alert(alerta);
- return(0);
- }
- */
- #endif
-