home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / DEMOS / GR_TEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-17  |  4.7 KB  |  189 lines

  1. /*********************
  2.  *
  3.  *  gr_test.c - graphics test program.
  4.  *
  5.  *  Purpose: This file contains functions to test the graphics functions.
  6.  *           It will test CGA or EGA color adapters.
  7.  *
  8.  *  Blackstar C Function Library
  9.  *  (c) Copyright 1985 Sterling Castle Software
  10.  *
  11.  *******/
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <dos.h>
  16. #include "blackstr.h"
  17. #include "kb_head.h"
  18. #include "gr_head.h"
  19. #include "sc_head.h"
  20. #include "sy_head.h"
  21. #include "co_head.h"
  22.  
  23.  
  24. short int *shape;
  25. short int shape1[] = {1,5,4,15,12,8,6,3,0,0,EOS,EOS};
  26. char *ptr;
  27. char *pic;
  28.  
  29. void main()
  30. {
  31.     int i;
  32.     pic = malloc(16384);
  33.     shape = (short int *)malloc(5000*sizeof(short int));
  34.  
  35.     /******************************************************
  36.      INITIALIZE SYSTEM AND SCREEN FOR PROPER ADAPTER TYPE
  37.     *******************************************************/
  38.     kb_init(NULL,NULL,NULL);
  39.     sc_init(NUL,NUL,NUL);          /* just get current parms */
  40.     switch (sc_adp_) {
  41.     case MON_ADP:
  42.         {
  43.         sc_clr();
  44.         sy_beep();
  45.         sc_puts("\n\rSorry, you need a color adapter to run this demo.\n");
  46.         exit(0);
  47.         }
  48.         break;
  49.  
  50.     case CGA_ADP:
  51.         gr_init(GR320,WHITE,BLUE,gr_cgap1_);
  52.         sc_setcur(5,22);
  53.         sc_puts("Graphics Test Program - 320x200");
  54.         break;
  55.  
  56.     case EGA_ADP:
  57.         gr_init(EGA_10,WHITE,BLUE,NULL);
  58.         sc_setcur(5,22);
  59.         sc_puts("EGA Graphics Test Program - 640x350");
  60.         break;
  61.  
  62.     default:
  63.         sc_setcur(5,20);
  64.         sc_puts("Screen adapter not recognized..\n\r");
  65.         exit(0);
  66.     }
  67.     /************************
  68.      DO A RECTANGLE CLEAR
  69.     *************************/
  70.     sc_setcur(0,23); sc_eeol();
  71.     sc_setcur(2,23);
  72.     sc_puts("Clear a rectangle - 1 pixel at a time");
  73.     gr_windo(0,0,grcols_,grrows_);
  74.  
  75.     gr_setpt(100,100);
  76.  
  77.     for(i=0; i<50; ++i)
  78.     for(int j=0;j<50;++j)
  79.         gr_setpt(i+135,j);
  80.  
  81.     /********************************************
  82.      DRAW SOME LINES ON THE SCREEN IN CYAN
  83.     *********************************************/
  84.     sc_setcur(0,23); sc_eeol();
  85.     sc_setcur(7,23);
  86.     sc_puts("Push any key to draw lines");
  87.     kb_getchar();
  88.     gr_pen(0,LCYAN);
  89.     for (i = 0; i <= 32; i++)
  90.     gr_line(i*10, 0, 160, 170);
  91.  
  92.     /************************
  93.      DRAW AND FILL A BOX
  94.     *************************/
  95.     sc_setcur(0,23); sc_eeol();
  96.     sc_setcur(1,23);
  97.     sc_puts("Push any key to draw a box and fill it");
  98.     kb_getchar();
  99.     gr_windo(8,8,110,110);
  100.     gr_clr();
  101.     gr_box(10,10,100,100);
  102.     gr_box(22,22,50,50);
  103.     gr_box (15,60,88,95);
  104.     gr_fill(50,55);
  105.  
  106.  
  107.     /***************************
  108.      GET AND RESTORE A WINDO
  109.     ****************************/
  110.     sc_setcur(0,23); sc_eeol();
  111.     sc_setcur(6,23);
  112.     sc_puts("Push any key to get windo ");
  113.     kb_getchar();
  114.     ptr = gr_getwin(0,0,100,10);
  115.     sc_setcur(0,23); sc_eeol();
  116.     sc_setcur(6,23);
  117.     sc_puts("push key to re-locate windo ");
  118.     kb_getchar();
  119.     gr_putwin(ptr,200,100,300,110);
  120.     free(ptr);
  121.  
  122.  
  123.     /**************************
  124.      DRAW AND COPY A SHAPE
  125.     ****************************/
  126.     sc_setcur(0,23); sc_eeol();
  127.     sc_setcur(6,23);
  128.     sc_puts("Push any key to draw shape");
  129.     kb_getchar();
  130.     gr_wfull();
  131.     gr_pos(50,110);
  132.     gr_draw(shape1); /* draws shape on screen */ 
  133.     sc_setcur(0,23); sc_eeol();
  134.     sc_setcur(6,23);
  135.     sc_puts("Push any key to copy shape");
  136.     kb_getchar();
  137.     gr_box(45,90,80,120);
  138.     gr_windo(45,90,80,120);
  139.     gr_scan(shape);  /* scan screen to shape */
  140.     gr_wfull();
  141.     gr_pos(100,130);
  142.     gr_draw(shape);  /* draw it in new location */
  143.  
  144.  
  145.     /**********************************************
  146.      FOR CGA ADAPTER - DO SCREEN SAVE AND RESTORE
  147.     ***********************************************/
  148.     if(sc_adp_== CGA_ADP) {
  149.     sc_setcur(0,23); sc_eeol();
  150.         sc_setcur(2,23);
  151.     sc_puts("Push any key to save current screen");
  152.     kb_getchar();
  153.     gr_getp(pic);           /* save current screen */
  154.     sc_clr();
  155.     gr_wfull();
  156.     sc_setcur(0,23); sc_eeol();
  157.     sc_setcur(0,23);
  158.     sc_puts("Push any key to restore previous screen");
  159.     kb_getchar();
  160.     gr_putp(pic);
  161.     }
  162.  
  163.     /***********************************
  164.      DRAW AND FILL A POLYGON
  165.     ************************************/
  166.     sc_setcur(0,23); sc_eeol();
  167.     sc_setcur(1,23);
  168.     sc_puts("Push any key to draw filled polygon");
  169.     kb_getchar();
  170.     gr_wfull();
  171.  
  172.     gr_windo(70,70,150,150);
  173.     gr_clr();
  174.     gr_pos(80,100);
  175.     gr_scale(shape1,2.75);
  176.     gr_poly(shape1);
  177.     gr_fill(81,101);
  178.  
  179.     sc_setcur(0,23); sc_eeol();
  180.     sc_setcur(9,23);
  181.     sc_puts("Push any key to exit");
  182.     kb_getc();
  183.     co_init(0);
  184.     co_mode(BW80,FWHITE,BBLACK);
  185.     co_clr();
  186.     exit(0);
  187. }
  188.  
  189.