home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / graphics / window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-31  |  2.7 KB  |  79 lines

  1. /* WINDOW.C illustrates windows and coordinate systems, using the
  2.  * following functions:
  3.  *    _setviewport   _setvieworg    _setcliprgn     _setwindow
  4.  *    _rectangle     _rectangle_w   _rectangle_wxy  _clearscreen
  5.  *    _ellipse       _ellipse_w     _ellipse_wxy
  6.  *
  7.  * Although not all illustrated here, functions ending in _w
  8.  * are similar to _rectangle_w and _ellipse_w; functions ending
  9.  * in _wxy are similar to _rectangle_wxy and _ellipse_wxy.
  10.  */
  11.  
  12. #include <conio.h>
  13. #include <graph.h>
  14. #include <stdlib.h>
  15.  
  16. main()
  17. {
  18.     short xhalf, yhalf, xquar, yquar;
  19.     struct _wxycoord upleft, botright;
  20.     struct videoconfig vc;
  21.     short mode = _VRES16COLOR;
  22.  
  23.     while( !_setvideomode( mode ) )     /* Find best graphics mode   */
  24.         mode--;
  25.     if( mode == _TEXTMONO )
  26.         exit( 1 );                      /* No graphics available     */
  27.     _getvideoconfig( &vc );
  28.  
  29.     xhalf = vc.numxpixels / 2;
  30.     yhalf = vc.numypixels / 2;
  31.     xquar = xhalf / 2;
  32.     yquar = yhalf / 2;
  33.  
  34.     /* First window - integer physical coordinates */
  35.     _setviewport( 0, 0, xhalf - 1, yhalf - 1 );
  36.     _rectangle( _GBORDER, 0,  0, xhalf - 1, yhalf - 1 );
  37.     _ellipse( _GFILLINTERIOR, xquar / 4, yquar / 4,
  38.                               xhalf - (xquar / 4), yhalf - (yquar / 4) );
  39.     getch();
  40.     _clearscreen( _GVIEWPORT );
  41.     _rectangle( _GBORDER, 0,  0, xhalf - 1, yhalf - 1 );
  42.  
  43.     /* Second window - integer world coordinates with clip region */
  44.     _setcliprgn( xhalf, 0, vc.numxpixels, yhalf );
  45.     _setvieworg( xhalf + xquar - 1, yquar - 1 );
  46.     _rectangle( _GBORDER, -xquar + 1, -yquar + 1, xquar, yquar );
  47.     _ellipse( _GFILLINTERIOR, (-xquar * 3) / 4, (-yquar * 3) / 4,
  48.                               (xquar * 3) / 4, (yquar * 3) / 4 );
  49.     getch();
  50.     _clearscreen( _GVIEWPORT );
  51.     _rectangle( _GBORDER, -xquar + 1, -yquar + 1, xquar, yquar );
  52.  
  53.     /* Third window */
  54.     _setviewport( xhalf, yhalf, vc.numxpixels - 1, vc.numypixels - 1 );
  55.     _setwindow( 0, -4.0, -5.0, 4.0, 5.0 );
  56.     _rectangle_w( _GBORDER, -4.0, -5.0, 4.0, 5.0 );
  57.     _ellipse_w( _GFILLINTERIOR, -3.0, -3.5, 3.0, 3.5 );
  58.     getch();
  59.     _clearscreen( _GVIEWPORT );
  60.     _rectangle_w( _GBORDER, -4.0, -5.0, 4.0, 5.0 );
  61.  
  62.     /* Fourth window */
  63.     _setviewport( 0, yhalf, xhalf - 1, vc.numypixels - 1 );
  64.     _setwindow( 0, -4.0, -5.0, 4.0, 5.0 );
  65.     upleft.wx = -4.0;
  66.     upleft.wy = -5.0;
  67.     botright.wx = 4.0;
  68.     botright.wy = 5.0;
  69.     _rectangle_wxy( _GBORDER, &upleft, &botright );
  70.     upleft.wx = -3.0;
  71.     upleft.wy = -3.5;
  72.     botright.wx = 3.0;
  73.     botright.wy = 3.5;
  74.     _ellipse_wxy( _GFILLINTERIOR, &upleft, &botright );
  75.  
  76.     getch();
  77.     exit( !_setvideomode( _DEFAULTMODE ) );
  78. }
  79.