home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap15 / getput.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-07  |  3.7 KB  |  137 lines

  1. /*  getput.c -- illustrates _getimage(), _putimage(), */
  2. /*              the image-background interaction, and */
  3. /*              the aspect ratio                      */
  4. /* If you load graphics.qlb, no program list is needed*/
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>  /* declares malloc()  */
  8. #include <graph.h>
  9. #include <conio.h>
  10. #define ESC '\033'
  11.  
  12. /* The following variables describe various          */
  13. /* coordinates and sizes.                            */
  14. /* They are declared externally so that they can be  */
  15. /* shared easily by several functions.               */
  16. int X1, Yb1, X2, Y2, Xdelta, Xside, Yside; /* image  */
  17. int Xmid, Xmax, Ymid, Ymax;           /* background  */
  18. int Xps, Xpr, Xand, Xor, Xxor, Ytop, Ybot; /* copies */
  19. int X[3], Y[3];
  20. float Ar;    /* aspect ratio */
  21.  
  22. struct videoconfig Vc;
  23. char Mask[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0};
  24. void Initialize(void), Drawfig(void),
  25.       Drawbackground(void), Drawcopies(void);
  26.  
  27. main(argc, argv)
  28. int argc;
  29. char *argv[];
  30. {
  31.     int mode = _MRES4COLOR;
  32.  
  33.     if (argc > 1)
  34.         mode = atoi(argv[1]);
  35.     if (_setvideomode(mode) == 0)
  36.     {
  37.         fprintf(stderr, "Can't handle mode %d\n", mode);
  38.         exit(1);
  39.     }
  40.     Initialize();
  41.     Drawfig();
  42.     Drawbackground();
  43.     Drawcopies();
  44.     _settextposition(1, 1);
  45.     _outtext("Press a key to end");
  46.     _settextposition(3, 1);
  47.     _outtext("_GPSET _GPRESET _GAND");
  48.     _settextposition(11, 5);
  49.     _outtext("_GOR _GXOR");
  50.     getch();
  51.     _setvideomode(_DEFAULTMODE);
  52. }
  53.  
  54. void Initialize()
  55. {
  56.     _getvideoconfig(&Vc);
  57.     Ar = (float) (10 * Vc.numypixels)/
  58.           (6.5 * Vc.numxpixels);
  59.     _setlogorg(0, 0);
  60.     Xmid = Vc.numxpixels / 2;
  61.     Ymid = Vc.numypixels / 2;
  62.     Xmax = Vc.numxpixels - 1;
  63.     Ymax = Vc.numypixels - 1;
  64.     /* locate three background rectangles */
  65.     X[0] = Xmid;
  66.     Y[0] = 0;
  67.     X[1] = Xmid;
  68.     Y[1] = Ymid;
  69.     X[2] = 0;
  70.     Y[2] = Ymid;
  71.     X1 = 0.2 * Vc.numxpixels;
  72.     Yb1 = 0.2 * Vc.numypixels;
  73.     Xdelta = 0.033 * Vc.numxpixels;
  74.     Xside = 3 * Xdelta;
  75.     Yside = 3 * Ar * Xdelta;
  76.     X2 = X1 + Xside;
  77.     Y2 = Yb1 + Yside;
  78.     /* offsets for _putimage() */
  79.     Xps = .05 * Vc.numxpixels;
  80.     Xpr = .20 * Vc.numxpixels;
  81.     Xand = 0.35 * Vc.numxpixels;
  82.     Xor = .10 * Vc.numxpixels;
  83.     Xxor = .30 * Vc.numxpixels;
  84.     Ytop = .05 * Vc.numypixels;
  85.     Ybot = 2 * Ytop + Yside;
  86.     _selectpalette(0);
  87. }
  88.  
  89. void Drawfig()
  90. {
  91.     _setcolor(1);
  92.     _rectangle(_GFILLINTERIOR, X1, Yb1,
  93.                X1 + Xdelta , Y2);
  94.     _setcolor(2);
  95.     _rectangle(_GFILLINTERIOR,X1 + Xdelta + 1, Yb1,
  96.                X1 + 2 * Xdelta, Y2);
  97.     _setcolor(3);
  98.     _rectangle(_GFILLINTERIOR,X1 +  2 * Xdelta + 1,
  99.                Yb1, X2, Y2);
  100.  
  101. }
  102.  
  103. void Drawbackground()
  104. {
  105.     _setfillmask(Mask);
  106.     _setcolor(1);
  107.     _rectangle(_GFILLINTERIOR, Xmid, 0, Xmax - 1, Ymid - 1);
  108.     _setcolor(2);
  109.     _rectangle(_GFILLINTERIOR, Xmid, Ymid, Xmax, Ymax);
  110.     _setcolor (3);
  111.     _rectangle(_GFILLINTERIOR, 0, Ymid, Xmid - 1, Ymax);
  112.  
  113. }
  114.  
  115. void Drawcopies()
  116. {
  117.     int quad;   /* quadrant used */
  118.     char far *storage;
  119.  
  120.     storage = (char far *) malloc((unsigned)_imagesize(
  121.                X1, Yb1, X2, Y2));
  122.     _getimage(X1, Yb1, X2, Y2, storage);
  123.  
  124.     for (quad = 0; quad < 3; quad++)
  125.         {
  126.         _putimage(X[quad] + Xps, Y[quad] + Ytop,
  127.                   storage, _GPSET);
  128.         _putimage(X[quad] + Xpr, Y[quad] + Ytop,
  129.                   storage, _GPRESET);
  130.         _putimage (X[quad] + Xand, Y[quad] + Ytop,
  131.                    storage, _GAND);
  132.         _putimage (X[quad] + Xor, Y[quad] + Ybot,
  133.                    storage, _GOR);
  134.         _putimage(X[quad] + Xxor, Y[quad] + Ybot,
  135.                   storage, _GXOR);
  136.         }
  137. }