home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / dos / prg / vidal / c / testbgi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-22  |  4.4 KB  |  177 lines

  1. /*comment utiliser le driver vga256.bgi */
  2. /* voila en image la reponse */
  3. /* on peut virer pas mal d'include */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <stdarg.h>
  8. #include <ctype.h>
  9. #include <graphics.h>
  10. #include <alloc.h>
  11. #include <math.h>
  12. #include <dos.h>
  13. #include <conio.h>
  14. #define TRUE            1
  15. #define FALSE            0
  16. typedef int Bool;               /* Boolean data: true or false */
  17. /* the global variables */
  18. int GfxMode = 1;    /* graphics mode number, or 0 for text */
  19.             /* 1 = 320x200, 2 = 640x480, 3 = 800x600, 4 = 1024x768 */
  20.             /* positive = 16 colors, negative = 256 colors */
  21. int OrigX;        /* the X origin */
  22. int OrigY;        /* the Y origin */
  23. int Scale;        /* the scale value */
  24. int PointerX;        /* X position of pointer */
  25. int PointerY;        /* Y position of pointer */
  26. int ScrMaxX;        /* maximum X screen coord */
  27. int ScrMaxY;        /* maximum Y screen coord */
  28. int ScrCenterX;        /* X coord of screen center */
  29. int ScrCenterY;        /* Y coord of screen center */
  30. /****************************/
  31. //   mouse function
  32. /****************************/
  33. void MontrePointeur()
  34. { _AX      =  0x1;geninterrupt(0x33);}
  35. void CachePointeur()
  36. {_AX      =  0x2;geninterrupt(0x33);}
  37. int MouseStat(int *Nbbouton)
  38. { int Status;
  39.  _AX       =   0x0;
  40.  geninterrupt(0x33);
  41.  Status    =  _AX;
  42.  *Nbbouton =  _BX;
  43.  return Status;
  44. }
  45. void modif_pos_souris(int colonne,int ligne)
  46. {
  47.  _AX       =   0x4;
  48.  _CX       =   colonne;
  49.  _DX       =   ligne;
  50.  geninterrupt(0x33);
  51. }
  52. void LectureMouse(int *x,int *y,int *bouton)
  53. {
  54.   /**** y ligne *****/
  55.   /**** x colonne ***/
  56. union REGS ri,ro;
  57. ri.x.ax= 0x3;
  58. int86(0x33,&ri,&ro);
  59. *x=ro.x.cx/2;
  60. *y=ro.x.dx;
  61. *bouton=ro.x.bx;
  62. }
  63.  
  64. /*terminate the graphics display*/
  65. void TermGfx()
  66. {
  67.    if (GfxMode)
  68.    {
  69.       closegraph();
  70.       GfxMode = 0;
  71.    }
  72. }
  73. /*
  74.    switch from VGA 16 colours to VGA 256 colours
  75. */
  76. Bool SwitchToVGA256()
  77. {
  78.    static int gdriver = -1;
  79.    int gmode, errorcode;
  80.  
  81.    if (GfxMode > 0 && gdriver != VGA) /* if 16 colors and not failed before */
  82.    {
  83.       if (gdriver == -1)
  84.       {
  85.      gdriver = installuserdriver( "VGA256", NULL);
  86.      errorcode = graphresult();
  87.       }
  88.       closegraph();
  89.       gmode = 0;
  90.       initgraph( &gdriver, &gmode, NULL);
  91.       errorcode = graphresult();
  92.       if (errorcode != grOk)
  93.       {
  94.      /* failed for 256 colors - back to 16 colors */
  95.      gdriver = VGA;
  96.      gmode = VGAHI;
  97.      initgraph( &gdriver, &gmode, NULL);
  98.      errorcode = graphresult();
  99.       }
  100.       if (errorcode != grOk) /* shouldn't happen */
  101.      perror(grapherrormsg( errorcode));
  102.       GfxMode = -1 /* 320x200x256 */;
  103.       ScrMaxX = getmaxx();
  104.       ScrMaxY = getmaxy();
  105.       ScrCenterX = ScrMaxX / 2;
  106.       ScrCenterY = ScrMaxY / 2;
  107.       return TRUE;
  108.    }
  109.    return FALSE;
  110. }
  111. /*switch from VGA 256 colours to VGA 16 colours*/
  112. BoolSwitchToVGA16()
  113. {
  114.    int gdriver, gmode, errorcode;
  115.  
  116.    if (GfxMode == -1) /* switch only if we are in 320x200x256 colors */
  117.    {
  118.       closegraph();
  119.       gdriver = VGA;
  120.       gmode = VGAHI;
  121.       initgraph( &gdriver, &gmode, NULL);
  122.       errorcode = graphresult();
  123.       if (errorcode != grOk) /* shouldn't happen */
  124.      perror(grapherrormsg( errorcode));
  125.       GfxMode = 2; /* 640x480x16 */
  126.       ScrMaxX = getmaxx();
  127.       ScrMaxY = getmaxy();
  128.       ScrCenterX = ScrMaxX / 2;
  129.       ScrCenterY = ScrMaxY / 2;
  130.       return TRUE;
  131.    }
  132.    return FALSE;
  133. }
  134. /*
  135.    draw a filled-in 3D-box on the screen from screen coords
  136. */
  137.  
  138. void DrawScreenBox3D( int Xstart, int Ystart, int Xend, int Yend)
  139. {
  140.    setfillstyle( 1, LIGHTGRAY);
  141.    bar( Xstart + 1, Ystart + 1, Xend - 1, Yend - 1);
  142.    setcolor( DARKGRAY);
  143.    line( Xstart, Yend, Xend, Yend);
  144.    line( Xend, Ystart, Xend, Yend);
  145.    if (Xend - Xstart > 20 && Yend - Ystart > 20)
  146.    {
  147.       line( Xstart + 1, Yend - 1, Xend - 1, Yend - 1);
  148.       line( Xend - 1, Ystart + 1, Xend - 1, Yend - 1);
  149.       setcolor( WHITE);
  150.       line( Xstart + 1, Ystart + 1, Xstart + 1, Yend - 1);
  151.       line( Xstart + 1, Ystart + 1, Xend - 1, Ystart + 1);
  152.    }
  153.    setcolor( WHITE);
  154.    line( Xstart, Ystart, Xend, Ystart);
  155.    line( Xstart, Ystart, Xstart, Yend);
  156.    setcolor( BLACK);
  157. }
  158. main()
  159. {int NbBouton;
  160. SwitchToVGA256();
  161. if (MouseStat(&NbBouton))
  162.  {
  163.   MontrePointeur();
  164. DrawScreenBox3D(10,10,20,20);
  165. getch();
  166. CachePointeur();
  167. BoolSwitchToVGA16();
  168. MontrePointeur();
  169. DrawScreenBox3D(10,10,20,20);
  170. getch();
  171.   CachePointeur();
  172.    }
  173.  else {fprintf(stderr,"souris non presente\n");}
  174. TermGfx();
  175. }
  176. /* end of file */
  177.