home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / volume_3.zip / GRAPHVGA.CPP < prev    next >
C/C++ Source or Header  |  1995-10-08  |  5KB  |  179 lines

  1. #include <graphics.h>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <process.h>
  5. #include <stdlib.h>
  6. #include "c:\tc\graphvga.h"
  7.  
  8.  
  9. //Global
  10. int Max_X;
  11. int Max_Y;
  12.  
  13. //******************************************************************
  14. //********* Sets up Graphics mode for Mode you choose **************
  15. //******************************************************************
  16. //This is set up to default to VGA mode 9 640 by 480 16 colors
  17. void InitGraphics(int VIDEOMODE=9)
  18. {
  19. int gdriver,gmode,errorcode;
  20.  
  21. /* register a driver that was added into graphics.lib */
  22. /* For information on adding the driver, see the
  23. /* BGIOBJ section of UTIL.DOC */
  24. errorcode = registerbgidriver(EGAVGA_driver);
  25.  
  26. /* report any registration errors */
  27. if (errorcode < 0)
  28. {
  29.    printf("Graphics error: %s\n", grapherrormsg(errorcode));
  30.    printf("Press any key to halt:");
  31.    getch();
  32.    exit(1); /* terminate with an error code */
  33. }
  34.  
  35. switch(VIDEOMODE)
  36.     {
  37.      case 1:  gdriver = CGA, gmode = CGAHI; break;
  38.      case 2:  gdriver = EGA, gmode = EGAHI; break;
  39.      case 3:  gdriver = EGA, gmode = EGALO; break;
  40.      case 4:  gdriver = EGA64, gmode = EGALO;break;
  41.      case 5:  gdriver = EGA64, gmode = EGAHI;break;
  42.      case 6:  gdriver = VGA, gmode = VGALO; break;
  43.      case 7:  gdriver = VGA, gmode = VGAMED; break;
  44.      case 8:  gdriver = IBM8514, gmode = IBM8514LO; break;
  45.      case 9:  gdriver = VGA, gmode = VGAHI; break;
  46.      default:
  47.      detectgraph(&gdriver, &gmode);
  48.      break;
  49.     }
  50.  
  51.    initgraph(&gdriver, &gmode, "");
  52.    if ( (errorcode = graphresult()) != grOk)
  53.    {
  54.     printf("Graphics error: %s\n", grapherrormsg(errorcode));
  55.     printf("Press any key to halt:");
  56.     getch();
  57.     exit(1); /* terminate with an error code */
  58.    }
  59. cleardevice();
  60. Max_X = getmaxx();
  61. Max_Y = getmaxy();
  62. return;
  63. }
  64.  
  65.  
  66.  
  67. //******************************************************************
  68. //********************** Draws a Box *******************************
  69. //******************************************************************
  70. // X     -> upper left horiz corner of box
  71. // Y     -> upper left vert  corner of box
  72. //width  -> width of box starting from X to the right
  73. //height -> height of box starting from Y down
  74. //color well is color ...it restores color before leaving
  75. //fillsw ->  1 Draws a filled box using indiviual pixels
  76. //           0 Draws a empty box
  77. //           3 Draws a filled box using floodfill()
  78. //NOW E...-> There are other ways to draw a filled box, but
  79. //this is easier to understand. Basically less different
  80. //graphics calls.
  81. //This is set up with default peramaters to fill screen with a blue
  82. //Background
  83. void DrawBox(int X=1,int Y=1,int width=Max_X,int height=Max_Y,int color=BLUE,int fillsw=3)
  84. {
  85. int Local_X;
  86. int Local_Y;
  87. int Local_Width = X + width;
  88. int Local_Height = Y + height;
  89. int oldcolor = getcolor();
  90. Hide_Mouse();
  91.    if(fillsw == 1)
  92.     {
  93.     for(Local_Y = Y;Local_Y < Local_Height; Local_Y++)
  94.       {
  95.            for(Local_X = X;Local_X < Local_Width;Local_X++)
  96.         {
  97.         putpixel(Local_X,Local_Y,color);
  98.         }
  99.        }
  100.      }
  101.     else if(fillsw == 0)
  102.      {
  103.     setcolor(color);
  104.     line(X,Y,X+width,Y);
  105.     line(X+width,Y,X+width,Y+height);
  106.     line(X+width,Y+height,X,Y+height);
  107.     line(X,Y+height,X,Y);
  108.     setcolor(oldcolor);
  109.      }
  110.     else if(fillsw == 3)
  111.      {
  112.     setcolor(color);
  113.     line(X,Y,X+width,Y);
  114.     line(X+width,Y,X+width,Y+height);
  115.     line(X+width,Y+height,X,Y+height);
  116.     line(X,Y+height,X,Y);
  117.     setfillstyle(SOLID_FILL,color);
  118.     floodfill(X+(width/2),Y+(height/2),color);
  119.     setcolor(oldcolor);
  120.      }
  121. Display_Mouse();
  122. return;
  123. }
  124.  
  125.  
  126.  
  127.  
  128.  
  129. void DrawLine2(int x1,int y1,int x2,int y2,int sprite2=TRUE,int Line_Color=TRUE,int Line_Mouse = TRUE,int Line_Thickness=TRUE,int Line_Style=TRUE,int Line_Pattern=TRUE)
  130. {
  131. if(!Line_Mouse) Hide_Mouse();
  132.  
  133. struct linesettingstype lineinfo;
  134.  
  135. /* get information about current line settings */
  136. getlinesettings(&lineinfo);
  137. int oldstyle = lineinfo.linestyle;
  138. int oldthick = lineinfo.thickness;
  139. int oldpattern = lineinfo.upattern;
  140.  
  141. if(!Line_Thickness) setlinestyle(Line_Style,Line_Pattern,Line_Thickness);
  142.  
  143.  
  144. int default_color = getcolor();
  145. if(!Line_Color)     setcolor(Line_Color);
  146.  
  147.  
  148. if(!sprite2) setwritemode(XOR_PUT);
  149.  
  150. line(x1,y1,x2,y2);
  151.  
  152. if(!sprite2) setwritemode(COPY_PUT);
  153.  
  154.  
  155.  
  156. if(!Line_Color)     setcolor(default_color);
  157. if(!Line_Thickness) setlinestyle(oldstyle,oldpattern,oldthick);
  158. if(!Line_Mouse) Display_Mouse();
  159. return;
  160. }
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168. void DrawLine(int x1,int y1,int x2,int y2,int sprite2=TRUE)
  169. {
  170.  
  171. if(!sprite2) setwritemode(XOR_PUT);
  172.  
  173. line(x1,y1,x2,y2);
  174.  
  175. //if(!sprite2) setwritemode(COPY_PUT);
  176.  
  177. return;
  178. }
  179.