home *** CD-ROM | disk | FTP | other *** search
/ PC Media 23 / PC MEDIA CD23.iso / share / prog / anubis / alert.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-04  |  9.7 KB  |  272 lines

  1. // ALERT.H
  2. // (C) Anubis Software.
  3. // 27 de Septiembre de 1994
  4. // Librería, que sirve para el uso y gestión de alertas.
  5. #ifndef ALERT.H
  6. #define ALERT.H
  7.  
  8.  
  9. // --------------------------------------+
  10. // Inclusión de librerias de Borland C++ |
  11. // --------------------------------------+
  12. #include <dos.h>
  13. #include <mem.h>
  14.  
  15. // ------------------------------------------+
  16. // Inclusión de librerias de Anubis Software |
  17. // ------------------------------------------+
  18. #include "mouse.h"
  19. #include "textmode.h"
  20. #include "teclado.h"
  21.  
  22. // ---------------------------------------------
  23. // Definición de tipos de la estructura alerta.
  24. // ---------------------------------------------
  25. typedef struct BOTON  {
  26.    char          nombre[15],
  27.          letra_activacion;
  28.    int           posx,
  29.          posy,
  30.          posxl,
  31.          color_texto,
  32.          color_fondo,
  33.          color_seleccionado,
  34.          color_letra,
  35.          longitud,
  36.          code_return;
  37.    unsigned char caracteristicas;
  38.    struct BOTON  *siguiente;
  39. } boton;
  40.  
  41. typedef struct ALERTA {
  42.    char          nombre[15];
  43.    char          texto1[40];
  44.    char          texto2[40];
  45.    char          texto3[40];
  46.    char          ai,
  47.          ad,
  48.          abi,
  49.          abd,
  50.          horizontal,
  51.          vertical;
  52.    int           posx,
  53.          posy,
  54.          ancho,
  55.          alto,
  56.          color_fondo,
  57.          color_texto,
  58.          color_marco,
  59.          color_botones,
  60.          color_seleccionado;
  61.    unsigned char caracteristicas;
  62.    struct BOTON  *botones;
  63. } alert;
  64.  
  65.  
  66. // --------------------------------------------------------
  67. // Declaración e implementación de las funciones del menu.
  68. // --------------------------------------------------------
  69.  
  70. // ----------------------------------------------------------------------
  71. // result = evnt_alert(alerta);
  72. //
  73. // int result   --> Contiene el codigo de retorno de la decisión que se ha tomado.
  74. // alert alerta --> Es la alerta que vamos a gestionar.
  75. //
  76. // Esta función, es la encargada de todo cuanto queremos gestionar. Es decir,
  77. // se encarga de poner la alerta en pantalla, determinar que eventos se han utilizado
  78. // y finalmente devolver la pantalla a su estado anterior.
  79. // No utiliza funciones de la Bios, sino que lo hace directamente sobre la
  80. // memoria de video por cuestones de eficiencia, orgullo, etc..
  81. //
  82. int evnt_alert(alert alerta)
  83. {
  84.    char auxi[80];
  85.    int x,y,i;
  86.    char tecla;
  87.    boton *boto,*auxiliar;
  88.  
  89.    ide_mouse();
  90.    Save_Screen(1);
  91.    tipo_cursor(CURSOR_INVISIBLE);
  92.    i=alerta.ancho;
  93.    while (i--) auxi[i]=' ';
  94.    auxi[alerta.ancho]=0;
  95.    y=alerta.posy;
  96.    x=alerta.posx;
  97.    escribe(alerta.ai,x++,y,alerta.color_texto,alerta.color_marco);
  98.    while (x<alerta.posx+alerta.ancho)
  99.       escribe(alerta.horizontal,x++,y,alerta.color_texto,alerta.color_marco);
  100.    escribe(alerta.ad,x,y,alerta.color_texto,alerta.color_marco);
  101.    x=alerta.posx;
  102.    y++;
  103.    escribe(auxi,x,y,alerta.color_texto,alerta.color_fondo);
  104.    escribe(alerta.vertical,x++,y,alerta.color_texto,alerta.color_marco);
  105.    escribe(' ',x++,y,alerta.color_texto,alerta.color_fondo);
  106.    escribe(alerta.texto1,x,y,alerta.color_texto,alerta.color_fondo);
  107.    escribe(alerta.vertical,alerta.posx+alerta.ancho,y,alerta.color_texto,alerta.color_marco);
  108.    x=alerta.posx;
  109.    y++;
  110.    escribe(auxi,x,y,alerta.color_texto,alerta.color_fondo);
  111.    escribe(alerta.vertical,x++,y,alerta.color_texto,alerta.color_marco);
  112.    escribe(' ',x++,y,alerta.color_texto,alerta.color_fondo);
  113.    escribe(alerta.texto2,x,y,alerta.color_texto,alerta.color_fondo);
  114.    escribe(alerta.vertical,alerta.posx+alerta.ancho,y,alerta.color_texto,alerta.color_marco);
  115.    x=alerta.posx;
  116.    y++;
  117.    escribe(auxi,x,y,alerta.color_texto,alerta.color_fondo);
  118.    escribe(alerta.vertical,x++,y,alerta.color_texto,alerta.color_marco);
  119.    escribe(' ',x++,y,alerta.color_texto,alerta.color_fondo);
  120.    escribe(alerta.texto3,x,y,alerta.color_texto,alerta.color_fondo);
  121.    escribe(alerta.vertical,alerta.posx+alerta.ancho,y,alerta.color_texto,alerta.color_marco);
  122.    x=alerta.posx;
  123.    while (alerta.posy+alerta.alto-2 > y++)  {
  124.       escribe(auxi,x,y,alerta.color_texto,alerta.color_fondo);
  125.       escribe(alerta.vertical,x,y,alerta.color_texto,alerta.color_marco);
  126.       escribe(alerta.vertical,alerta.posx+alerta.ancho,y,alerta.color_texto,alerta.color_marco);
  127.    }// end while
  128.    escribe(alerta.abi,x++,y,alerta.color_texto,alerta.color_marco);
  129.    while(x < alerta.posx+alerta.ancho)
  130.       escribe(alerta.horizontal,x++,y,alerta.color_texto,alerta.color_marco);
  131.    escribe(alerta.abd,alerta.posx+alerta.ancho,y,alerta.color_texto,alerta.color_marco);
  132.    // Hasta aqui, hemos dibujado la alerta, ahora vamos a dibujar los botones.
  133.    boto = alerta.botones;
  134.    while (boto != NULL)   {
  135.       escribe((*boto).nombre,alerta.posx+(*boto).posx,alerta.posy+(*boto).posy,(*boto).color_texto,(*boto).color_fondo);
  136.       escribe((*boto).letra_activacion,alerta.posx+(*boto).posx+(*boto).posxl-1,alerta.posy+(*boto).posy,(*boto).color_letra,(*boto).color_fondo);
  137.       boto = (*boto).siguiente;
  138.    }// end while
  139.    // Ahora, gestionamos, los botones, y esperamos a que se pulse sobre
  140.    // alguno de ellos.
  141.    // Inicializamos la variable auxiliar que recorre las opciones del menu
  142.    auxiliar = alerta.botones;
  143.    // Ponemos en reverso a la selección auxiliar.
  144.    escribe( (*auxiliar).nombre,alerta.posx+(*auxiliar).posx,alerta.posy+(*auxiliar).posy,(*auxiliar).color_texto,(*auxiliar).color_seleccionado);
  145.    escribe( (*auxiliar).letra_activacion,alerta.posx+(*auxiliar).posx+(*auxiliar).posxl-1,alerta.posy+(*auxiliar).posy,(*auxiliar).color_letra,(*auxiliar).color_seleccionado);
  146.    show_mouse();
  147.  
  148.  
  149.    // Mientras no se pulse ESC
  150.    tecla = teclado();
  151.    while ( tecla != 27 )  {
  152.       //Si se ha pulsado una tecla
  153.       if ( kbhit() )  {
  154.      tecla = getch();
  155.      if (tecla == 0)  {
  156.         tecla = getch();
  157.         while (kbhit() ) getch();
  158.         // Segun cual sea la tecla, hacemos una u otra cosa.
  159.         switch (tecla)  {
  160.  
  161.            // Se ha pulsado la tecla ->
  162.            case 77: {
  163.           if ( (*auxiliar).siguiente != NULL)   {
  164.               // Poner en normal a auxiliar
  165.              ide_mouse();
  166.              escribe( (*auxiliar).nombre,alerta.posx+(*auxiliar).posx,alerta.posy+(*auxiliar).posy,(*auxiliar).color_texto,(*auxiliar).color_fondo);
  167.              escribe( (*auxiliar).letra_activacion,alerta.posx+(*auxiliar).posx+(*auxiliar).posxl-1,alerta.posy+(*auxiliar).posy,(*auxiliar).color_letra,(*auxiliar).color_fondo);
  168.              // Pasamos al siguiente item.
  169.              auxiliar = (*auxiliar).siguiente;
  170.              // Y lo ponemos en reverso.
  171.              escribe( (*auxiliar).nombre,alerta.posx+(*auxiliar).posx,alerta.posy+(*auxiliar).posy,(*auxiliar).color_texto,(*auxiliar).color_seleccionado);
  172.              escribe( (*auxiliar).letra_activacion,alerta.posx+(*auxiliar).posx+(*auxiliar).posxl-1,alerta.posy+(*auxiliar).posy,(*auxiliar).color_letra,(*auxiliar).color_seleccionado);
  173.              show_mouse();
  174.            }// end if
  175.           break;
  176.            }// end case
  177.  
  178.            // Se ha pulsado la tecla <-
  179.            case 75: {
  180.           boton *aux;
  181.           if ( auxiliar != alerta.botones )  {
  182.  
  183.              // Poner en normal a auxiliar
  184.              ide_mouse();
  185.              escribe( (*auxiliar).nombre,alerta.posx+(*auxiliar).posx,alerta.posy+(*auxiliar).posy,(*auxiliar).color_texto,(*auxiliar).color_fondo);
  186.              escribe( (*auxiliar).letra_activacion,alerta.posx+(*auxiliar).posx+(*auxiliar).posxl-1,alerta.posy+(*auxiliar).posy,(*auxiliar).color_letra,(*auxiliar).color_fondo);
  187.              //Pasamos al item anterior
  188.              aux = alerta.botones;
  189.              while ( (*aux).siguiente != auxiliar )
  190.             aux = (*aux).siguiente;
  191.              auxiliar = aux;
  192.               // Poner en reverso a auxiliar
  193.              escribe( (*auxiliar).nombre,alerta.posx+(*auxiliar).posx,alerta.posy+(*auxiliar).posy,(*auxiliar).color_texto,(*auxiliar).color_seleccionado);
  194.              escribe( (*auxiliar).letra_activacion,alerta.posx+(*auxiliar).posx+(*auxiliar).posxl-1,alerta.posy+(*auxiliar).posy,(*auxiliar).color_letra,(*auxiliar).color_seleccionado);
  195.              show_mouse();
  196.  
  197.           }// end if
  198.           break;
  199.            }// end case
  200.         }// end switch
  201.      }  else  {
  202.         while (kbhit()) getch();
  203.         switch (tecla)  {
  204.            // Se ha pulsado RETURN
  205.            case 13:  {
  206.           Restore_Screen(1);
  207.           tipo_cursor(OLD_CURSOR);
  208.           return( (*auxiliar).code_return );
  209.            }// end case
  210.  
  211.            // Se ha pulsado cualquier otra tecla
  212.            default: {
  213.           boton *aux;
  214.           aux = alerta.botones;
  215.           while( aux != NULL )  {
  216.              if( (*aux).letra_activacion == tecla)  {
  217.             Restore_Screen(1);
  218.             tipo_cursor(OLD_CURSOR);
  219.             return ( (*aux).code_return);
  220.              }// end if
  221.              aux = (*aux).siguiente;
  222.           }// end while
  223.            }// end case
  224.         }// end switch
  225.      }// end if
  226.       }  else  {
  227.      struct mouse raton;
  228.      boton *aux;
  229.      raton = inf_mouse();
  230.      if (mouse_evento & 2)  {
  231.         mouse_evento = 0;
  232.         aux = alerta.botones;
  233.         while ( aux != NULL )  {
  234.            if ( ( alerta.posx+(*aux).posx <= (raton.posx/8)+1 ) &&
  235.            ( alerta.posx+(*aux).posx + (*aux).longitud > (raton.posx/8)+1) &&
  236.            ( alerta.posy+(*aux).posy == (raton.posy / 8)+1 ) )  {
  237.           Restore_Screen(1);
  238.           tipo_cursor(OLD_CURSOR);
  239.           return ((*aux).code_return);
  240.            }// end if
  241.            aux = (*aux).siguiente;
  242.         }// end while
  243.      }// end if
  244.       }// end if
  245.    }// end while
  246.    ide_mouse();
  247.    Restore_Screen(1);
  248.    show_mouse();
  249.    tipo_cursor(OLD_CURSOR);
  250.    return(0);
  251. }// end evnt_alert
  252.  
  253.  
  254. /*
  255. main()
  256. {
  257.    init_mouse();
  258.    InitMouse(0xfe);
  259.    show_mouse();
  260.    alert  alerta = {"Super_Alerta","Atencion","Peligro Inminente","Perdida de Datos.",
  261.             '*','*','*','*','-','|',20,10,30,10,1,0,1,5,6,0,NULL};
  262.    boton  ok = {"  O.K  ",'O',3,7,3,10,3,15,13,7,0,0,NULL};
  263.    boton  ok1= {" Cancel ",'C',12,7,2,10,3,15,13,8,0,0,NULL};
  264.    ok.siguiente = &ok1;
  265.    alerta.botones = &ok;
  266.    clrscr();
  267.    evnt_alert(alerta);
  268.    return(0);
  269. }
  270. */
  271. #endif
  272.