home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / mgl11 / examples / testgr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-10  |  45.2 KB  |  2,142 lines

  1. /****************************************************************************
  2. *
  3. *                        MegaGraph Graphics Library
  4. *
  5. *                   Copyright (C) 1994 SciTech Software.
  6. *                            All rights reserved.
  7. *
  8. * Filename:        $RCSfile: testgr.c $
  9. * Version:        $Revision: 1.3 $
  10. *
  11. * Language:        ANSI C
  12. * Environment:    IBM PC (MS DOS)
  13. *
  14. * Description:    Set of test programs to test the MegaGraph graphics library
  15. *                routines. You must define which test to compile for when
  16. *                you compile this source file.
  17. *
  18. *                This could have been factorised into separate source files,
  19. *                but having all the tests in one file makes it easy to
  20. *                find code that tests a part of the library using a global
  21. *                text search.
  22. *
  23. * $Id: testgr.c 1.3 1994/03/10 09:25:52 kjb release $
  24. *
  25. ****************************************************************************/
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <time.h>
  30. #include <conio.h>
  31. #include <dos.h>
  32. #include <string.h>
  33. #include <alloc.h>
  34. #include "mgraph.h"
  35. #include "mgldos.h"
  36. #include "ztimer.h"
  37.  
  38. extern    bool smallclip;
  39.  
  40. /* Define the test being compiled. You will need to comment this out when
  41.  * compiling all tests via the makefile.
  42.  */
  43.  
  44. #ifdef    MGL_TEST
  45. #define TEST15
  46. #endif
  47.  
  48. /* Routines in main.c */
  49.  
  50. void four_dots(void);
  51. void init_graphics(char *testname,int argc,char *argv[]);
  52. void exit_graphics(void);
  53. void ReportTime(ulong count);
  54.  
  55. /* Different mouse cursors */
  56.  
  57. cursor CHECK = {
  58.     0xFFF0, 0xFFE0, 0xFFC0, 0xFF81,
  59.     0xFF03, 0x0607, 0x000F, 0x001F,
  60.     0x803F, 0xC07F, 0xE0FF, 0xF1FF,
  61.     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  62.  
  63.     0x0000, 0x0006, 0x000C, 0x0018,
  64.     0x0030, 0x0060, 0x70C0, 0x3980,
  65.     0x1F00, 0x0E00, 0x0400, 0x0000,
  66.     0x0000, 0x0000, 0x0000, 0x0000,
  67.     0x0005, 0x000A };
  68.  
  69. cursor CROSS = {
  70.     0xF01F, 0xE00F, 0xC007, 0x8003,
  71.     0x0441, 0x0C61, 0x0381, 0x0381,
  72.     0x0381, 0x0C61, 0x0441, 0x8003,
  73.     0xC007, 0xE00F, 0xF01F, 0xFFFF,
  74.  
  75.     0x0000, 0x07C0, 0x0920, 0x1110,
  76.     0x2108, 0x4004, 0x4004, 0x783C,
  77.     0x4004, 0x4004, 0x2108, 0x1110,
  78.     0x0920, 0x07C0, 0x0000, 0x0000,
  79.     0x0007, 0x0007 };
  80.  
  81. cursor GLOVE = {
  82.     0xF3FF, 0xE1FF, 0xE1FF, 0xE1FF,
  83.     0xE1FF, 0xE049, 0xE000, 0x8000,
  84.     0x0000, 0x0000, 0x07FC, 0x07F8,
  85.     0x9FF9, 0x8FF1, 0xC003, 0xE007,
  86.  
  87.     0x0C00, 0x1200, 0x1200, 0x1200,
  88.     0x1200, 0x13B6, 0x1249, 0x7249,
  89.     0x9249, 0x9001, 0x9001, 0x8001,
  90.     0x4002, 0x4002, 0x2004, 0x1FF8,
  91.     0x0004, 0x0000 };
  92.  
  93. cursor IBEAM = {
  94.     0xF39F, 0xFD7F, 0xFEFF, 0xFEFF,
  95.     0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF,
  96.     0xFEFF, 0xFEFF, 0xFEFF, 0xFEFF,
  97.     0xFEFF, 0xFEFF, 0xFD7F, 0xF39F,
  98.  
  99.     0x0C60, 0x0280, 0x0100, 0x0100,
  100.     0x0100, 0x0100, 0x0100, 0x0100,
  101.     0x0100, 0x0100, 0x0100, 0x0100,
  102.     0x0100, 0x0100, 0x0280, 0x0C60,
  103.     0x0007, 0x0008 };
  104.  
  105. ulong    count1,count2,count3,count4;
  106.  
  107. long randoml(long max)
  108. /****************************************************************************
  109. *
  110. * Function:        randoml
  111. * Parameters:    max    - Maximum random number value+1
  112. * Returns:        Random long between 0 and max-1.
  113. *
  114. * Description:    Routine to compute random long numbers. We do this simply
  115. *                by expanding a random integer into the correct range,
  116. *                which means some values will never get generated :-(,
  117. *                but hell, it works for what we want (it will also fail
  118. *                for large numbers).
  119. *
  120. ****************************************************************************/
  121. {
  122.     return ((float)rand() * max) / (float)RAND_MAX;
  123. }
  124.  
  125. #ifdef    TEST1
  126.  
  127. /* TEST1    - Initialisation test.
  128.  *
  129.  * Test the initialisation routines. Put system into graphics mode, back
  130.  * into text mode, and then change to a new graphics mode.
  131.  *
  132.  * Note that this routine also tests the functionality of the mouse
  133.  * cursor routines.
  134.  */
  135.  
  136. void cdecl main(int argc,char *argv[])
  137. {
  138.     int driver,chip,memory,dac,mode,err;
  139.  
  140.     dac = grDETECTDAC;
  141.     MGL_detectGraph(&driver,&chip,&memory,&dac,&mode);
  142.  
  143.     _installMouse = true;            /* Install mouse cursor routines    */
  144.     MS_init();
  145.     init_graphics("Initialisation test",argc,argv);
  146.     four_dots();
  147.     MS_show();
  148.     getch();
  149.     MS_hide();
  150.     getch();
  151.     MS_hide();
  152.     getch();
  153.     MS_hide();
  154.     getch();
  155.     MS_show();
  156.     getch();
  157.     MS_show();
  158.     getch();
  159.     MS_show();
  160.     getch();
  161.     MS_show();
  162.     MS_setCursor(&CROSS);
  163.     getch();
  164.     MS_hide();
  165.     MS_setCursor(&DEF_CURSOR);
  166.     MS_show();
  167.     getch();
  168.  
  169.     MS_hide();
  170.     MGL_restoreCRTMode();
  171.     MGL_restoreCRTMode();
  172.     printf("Back in text mode\n");
  173.     MS_show();
  174.     getch();
  175.  
  176.     MS_hide();
  177.     mode = grEGA_640x200x16;
  178.     MGL_exit();
  179.     MGL_init(&driver,&chip,&memory,&dac,&mode,"..\\");
  180.     err = MGL_result();
  181.     if (err != grOK) {
  182.         printf("Graphics error: %s\n",MGL_errorMsg(err));
  183.         printf("Driver: %d, Mode: %d\n",driver,mode);
  184.         exit(1);
  185.         }
  186.     four_dots();
  187.     MS_show();
  188.     getch();
  189.  
  190.     MS_hide();
  191.     mode = grEGA_320x200x16;
  192.     MGL_exit();
  193.     MGL_init(&driver,&chip,&memory,&dac,&mode,"..\\");
  194.     err = MGL_result();
  195.     if (err != grOK) {
  196.         printf("Graphics error: %s\n",MGL_errorMsg(err));
  197.         printf("Driver: %d, Mode: %d\n",driver,mode);
  198.         exit(1);
  199.         }
  200.     four_dots();
  201.     MS_show();
  202.     exit_graphics();
  203.  
  204.     MS_exit();
  205. }
  206.  
  207. #endif
  208.  
  209. #ifdef    TEST2
  210.  
  211. /* TEST2    - Raw pixel speed test.
  212.  *
  213.  * Test the raw pixel drawing speed of the library.
  214.  */
  215.  
  216. void fill_pixel(void)
  217. {
  218.     int        i,j,maxx,maxy;
  219.  
  220.     maxx = MGL_maxx();
  221.     maxy = MGL_maxy();
  222.     MGL_beginPixel();
  223.     for (j = 0; j <= maxy; j++)
  224.         for (i = 0; i <= maxx; i++)
  225.             MGL_pixelCoord(i,j);
  226.     MGL_endPixel();
  227. }
  228.  
  229. void cdecl main(int argc,char *argv[])
  230. {
  231.     color_t    i;
  232.  
  233.     init_graphics("Pixel plotting speed test",argc,argv);
  234.  
  235.     four_dots();
  236.     getch();
  237.     LZTimerOn();
  238.     fill_pixel();
  239.     MGL_setColor(MGL_defaultColor()/3);
  240.     fill_pixel();
  241.     LZTimerOff();
  242.     i = MGL_getPixelCoord(0,0);
  243.  
  244.     exit_graphics();
  245.  
  246.     printf("Value of pixel (0,0) = %ld\n",i);
  247.     ReportTime(LZTimerCount());
  248. }
  249.  
  250. #endif
  251.  
  252. #ifdef    TEST3
  253.  
  254. /* TEST3    - Screen clearing test
  255.  *
  256.  * Test the screen clearing routines of the library
  257.  */
  258.  
  259. void cdecl main(int argc,char *argv[])
  260. {
  261.     int        i;
  262.  
  263.     init_graphics("Screen clearing test",argc,argv);
  264.  
  265.     LZTimerOn();
  266.     for (i = 0; i < 200; i++) {
  267.         MGL_setBackColor(MGL_realColor(i & 15));
  268.         MGL_clearDevice();
  269.         }
  270.     LZTimerOff();
  271.  
  272.     exit_graphics();
  273.     ReportTime(LZTimerCount());
  274. }
  275.  
  276. #endif
  277.  
  278. #ifdef    TEST4
  279.  
  280. /* TEST4    - Simple line drawing/clipping test
  281.  *
  282.  * This simple test draws a simple pattern on the display, and tests the
  283.  * clipping and drawing routines.
  284.  */
  285.  
  286. void cdecl main(int argc,char *argv[])
  287. {
  288.     int        i,maxx,maxy;
  289.     rect    clip2;
  290.  
  291.     init_graphics("Line drawing/clipping test",argc,argv);
  292.  
  293.     LZTimerOn();
  294.     maxx = MGL_maxx();
  295.     maxy = MGL_maxy();
  296.     for (i = 0; i < maxx; i += 10) {
  297.         MGL_lineCoord(maxx/2,maxy/2,i,0);
  298.         MGL_lineCoord(maxx/2,maxy/2,i,maxy);
  299.         }
  300.     for (i = 0; i < maxy; i += 10) {
  301.         MGL_lineCoord(maxx/2,maxy/2,0,i);
  302.         MGL_lineCoord(maxx/2,maxy/2,maxx,i);
  303.         }
  304.  
  305.     clip2.left = maxx/8;
  306.     clip2.top = maxy/8;
  307.     clip2.right = clip2.left * 7;
  308.     clip2.bottom = clip2.top * 7;
  309.     MGL_insetRect(clip2,-1,-1);
  310.     MGL_setColor(MGL_realColor(BLUE));
  311.     MGL_rect(clip2);
  312.     MGL_insetRect(clip2,1,1);
  313.     MGL_setClipRect(clip2);
  314.  
  315.     MGL_setColor(MGL_realColor(YELLOW));
  316.     for (i = 0; i < maxx; i += 10) {
  317.         MGL_lineCoord(maxx/2,maxy/2,i,0);
  318.         MGL_lineCoord(maxx/2,maxy/2,i,maxy);
  319.         }
  320.     for (i = 0; i < maxy; i += 10) {
  321.         MGL_lineCoord(maxx/2,maxy/2,0,i);
  322.         MGL_lineCoord(maxx/2,maxy/2,maxx,i);
  323.         }
  324.     LZTimerOff();
  325.  
  326.     exit_graphics();
  327.     ReportTime(LZTimerCount());
  328. }
  329.  
  330. #endif
  331.  
  332. #ifdef    TEST5
  333.  
  334. /* TEST5    - Line drawing speed test
  335.  *
  336.  * This routine draws a number of random lines at full speed to time
  337.  * how fast the routines are.
  338.  */
  339.  
  340. #define    MAXNUM    1000
  341. #define    LOOPS    5
  342.  
  343. point    p[MAXNUM+1];
  344.  
  345. void cdecl main(int argc,char *argv[])
  346. {
  347.     int        i,j,maxx,maxy;
  348.  
  349.     init_graphics("Line drawing speed test",argc,argv);
  350.  
  351.     maxx = MGL_maxx();
  352.     maxy = MGL_maxy();
  353.  
  354.     srand(1000);
  355.     for (i = 0; i < MAXNUM; i++) {
  356.         p[i].x = random(maxx);
  357.         p[i].y = random(maxy);
  358.         }
  359.  
  360.     LZTimerOn();
  361.     for (j = 0; j < LOOPS; j++) {
  362.         MGL_setColor(MGL_realColor(j+1));
  363.         for (i = 0; i < MAXNUM; i++)
  364.             MGL_line(p[i],p[i+1]);
  365.         }
  366.     LZTimerOff();
  367.     count1 = LZTimerCount();
  368.     getch();
  369.  
  370.     MGL_clearDevice();
  371.  
  372.     MGL_beginDrawing();
  373.     LZTimerOn();
  374.     for (j = 0; j < LOOPS; j++) {
  375.         MGL_setColor(MGL_realColor(j+1));
  376.         for (i = 0; i < MAXNUM; i++)
  377.             MGL_lineFast(p[i],p[i+1]);
  378.         }
  379.     LZTimerOff();
  380.     MGL_endDrawing();
  381.     count2 = LZTimerCount();
  382.  
  383.     exit_graphics();
  384.     printf("Normal line drawing:   ");    ReportTime(count1);
  385.     printf("Fast line drawing:     ");    ReportTime(count2);
  386. }
  387.  
  388. #endif
  389.  
  390. #ifdef    TEST6
  391.  
  392. /* TEST6    - Horizontal/Vertical line drawing test
  393.  *
  394.  * This routine tests the drawing of horizontal and vertical lines, which
  395.  * are faster to draw than general lines.
  396.  */
  397.  
  398. void cdecl main(int argc,char *argv[])
  399. {
  400.     int        i,j,maxx,maxy;
  401.  
  402.     init_graphics("Horizontal/Vertical line test",argc,argv);
  403.  
  404.     maxx = MGL_maxx();
  405.     maxy = MGL_maxy();
  406.  
  407.     LZTimerOn();
  408.     for (j = 1; j < 20; j++) {
  409.         MGL_setColor(MGL_realColor(j & 15));
  410.         for (i = 0; i <= maxy; i += 2) {
  411.             MGL_lineCoord(0,i,maxx,i);
  412.             MGL_lineCoord(maxx,i+1,0,i+1);
  413.             }
  414.         }
  415.     LZTimerOff();
  416.     count1 = LZTimerCount();
  417.  
  418.     getch();
  419.  
  420.     LZTimerOn();
  421.     for (j = 1; j < 20; j++) {
  422.         MGL_setColor(MGL_realColor(j & 15));
  423.         for (i = 0; i <= maxx; i += 2) {
  424.             MGL_lineCoord(i,0,i,maxy);
  425.             MGL_lineCoord(i+1,maxy,i+1,0);
  426.             }
  427.         }
  428.     LZTimerOff();
  429.     count2 = LZTimerCount();
  430.  
  431.     exit_graphics();
  432.     printf("Horizontal lines: ");    ReportTime(count1);
  433.     printf("Vertical lines:   ");    ReportTime(count2);
  434. }
  435.  
  436. #endif
  437.  
  438. #ifdef    TEST7
  439.  
  440. /* TEST7    - Filled rectangle test.
  441.  *
  442.  * This routine tests and times the drawing of filled rectangles.
  443.  */
  444.  
  445. void cdecl main(int argc,char *argv[])
  446. {
  447.     int        j,maxx,maxy;
  448.  
  449.     init_graphics("Filled rectangle test",argc,argv);
  450.  
  451.     maxx = MGL_maxx();
  452.     maxy = MGL_maxy();
  453.  
  454.     MGL_setBackColor(MGL_realColor(MAGENTA));
  455.     MGL_clearDevice();
  456.     MGL_setBackColor(MGL_realColor(BLUE));
  457.  
  458.     LZTimerOn();
  459.     for (j = 1; j < 100; j++) {
  460.         MGL_setColor(MGL_realColor(j & 15));
  461.         MGL_fillRectCoord(5,5,maxx-3,maxy-3);
  462.         }
  463.     LZTimerOff();
  464.  
  465.     exit_graphics();
  466.     ReportTime(LZTimerCount());
  467. }
  468.  
  469. #endif
  470.  
  471. #ifdef    TEST8
  472.  
  473. /* TEST8    - Patterned drawing test.
  474.  *
  475.  * This routine draws a number of pre-defined bitmaps on the display screen.
  476.  */
  477.  
  478. #include "bitmaps.c"
  479.  
  480. void cdecl main(int argc,char *argv[])
  481. {
  482.     int        i;
  483.     char    buf[20];
  484.  
  485.     init_graphics("Bitmap pattern test",argc,argv);
  486.  
  487.     MGL_setTextJustify(CENTER_TEXT,CENTER_TEXT);
  488.  
  489.     MGL_setPenStyle(BITMAP_PATTERN_OPAQUE);
  490.     for (i = 0; i < sizeof(bitpat) / 8; i++) {
  491.         MGL_setPenBitmapPattern(&bitpat[i]);
  492.         MGL_setColor(7);
  493.         MGL_fillRectCoord(0,0,MGL_maxx()+1,MGL_maxy()+1);
  494.         sprintf(buf,"Bitmap number %d",i);
  495.         MGL_setColor(WHITE);
  496.         MGL_drawStrXY(MGL_maxx()/2,MGL_maxy()/2,buf);
  497.         getch();
  498.         }
  499.  
  500.     exit_graphics();
  501. }
  502.  
  503. #endif
  504.  
  505. #ifdef    TEST9
  506.  
  507. /* TEST9    - Polyline drawing test.
  508.  *
  509.  * Tests the polyLine, polyPoint and polyMarker routines.
  510.  */
  511.  
  512. void cdecl main(int argc,char *argv[])
  513. {
  514.     point    vArray[4];
  515.  
  516.     init_graphics("Polyline test",argc,argv);
  517.  
  518.     MGL_setColor(GREEN);
  519.  
  520.     vArray[0].x = 20;    vArray[0].y = 175;
  521.     vArray[1].x = 620;    vArray[1].y = 20;
  522.     vArray[2].x = 590;    vArray[2].y = 330;
  523.     vArray[3].x = 320;    vArray[3].y = 10;
  524.     MGL_polyPoint(4,vArray);
  525.     getch();
  526.     MGL_setColor(RED);
  527.     MGL_polyLine(4,vArray);
  528.     MGL_setColor(BLUE);
  529.     MGL_polyMarker(4,vArray);
  530.  
  531.     exit_graphics();
  532. }
  533.  
  534. #endif
  535.  
  536. #ifdef    TEST10
  537.  
  538. /* TEST10    - Circle drawing speed test.
  539.  *
  540.  * This routine draws a number of random ellipses as fast as possible,
  541.  * timing the result.
  542.  */
  543.  
  544. #define    MAXNUM    1000
  545. #define    LOOPS    5
  546.  
  547. rect    r[MAXNUM];
  548.  
  549. void cdecl main(int argc,char *argv[])
  550. {
  551.     int        i,j,maxx,maxy;
  552.  
  553.     init_graphics("Ellipse speed test",argc,argv);
  554.  
  555.     maxx = MGL_maxx();
  556.     maxy = MGL_maxy();
  557.  
  558.     srand(1000);
  559.     for (i = 0; i < MAXNUM; i++) {
  560.         r[i].left = random(maxx-100);
  561.         r[i].top = random(maxy-100);
  562.         r[i].right = r[i].left + random(100);
  563.         r[i].bottom = r[i].top + random(100);
  564.         }
  565.  
  566.     LZTimerOn();
  567.     for (j = 0; j < LOOPS; j++) {
  568.         MGL_setColor(MGL_realColor(j+1));
  569.         for (i = 0; i < MAXNUM; i++) {
  570.             MGL_ellipse(r[i]);
  571.             }
  572.         }
  573.     LZTimerOff();
  574.  
  575.     exit_graphics();
  576.     ReportTime(LZTimerCount());
  577. }
  578.  
  579. #endif
  580.  
  581. #ifdef    TEST11
  582.  
  583. /* TEST11    - Filled circle drawing speed test.
  584.  *
  585.  * This routine draws a number of random filled ellipses as fast as
  586.  * possible, timing the result.
  587.  */
  588.  
  589. #define    MAXNUM    1000
  590. #define    LOOPS    5
  591.  
  592. rect    r[MAXNUM];
  593.  
  594. void cdecl main(int argc,char *argv[])
  595. {
  596.     int        i,j,maxx,maxy,maxcolor;
  597.  
  598.     init_graphics("Filled ellipse speed test",argc,argv);
  599.  
  600.     maxx = MGL_maxx();
  601.     maxy = MGL_maxy();
  602.     maxcolor = MGL_maxColor();
  603.  
  604.     srand(1000);
  605.     for (i = 0; i < MAXNUM; i++) {
  606.         r[i].left = random(maxx-100);
  607.         r[i].top = random(maxy-100);
  608.         r[i].right = r[i].left + random(100);
  609.         r[i].bottom = r[i].top + random(100);
  610.         }
  611.  
  612.     LZTimerOn();
  613.     for (j = 0; j < LOOPS; j++) {
  614.         for (i = 0; i < MAXNUM; i++) {
  615.             MGL_setColor(i % maxcolor + 1);
  616.             MGL_fillEllipse(r[i]);
  617.             }
  618.         }
  619.     LZTimerOff();
  620.  
  621.     exit_graphics();
  622.     ReportTime(LZTimerCount());
  623. }
  624.  
  625. #endif
  626.  
  627. #ifdef    TEST12
  628.  
  629. /* TEST12    - Elliptical arc speed test.
  630.  *
  631.  * This routine draws a number of random elliptical arcs as fast as
  632.  * possible, timing the result.
  633.  */
  634.  
  635. #define    MAXNUM    1000
  636. #define    LOOPS    5
  637.  
  638. rect    r[MAXNUM];
  639. int        startAng[MAXNUM];
  640. int        endAng[MAXNUM];
  641.  
  642. void cdecl main(int argc,char *argv[])
  643. {
  644.     int        i,j,maxx,maxy;
  645.  
  646.     init_graphics("Elliptical arc speed test",argc,argv);
  647.  
  648.     maxx = MGL_maxx();
  649.     maxy = MGL_maxy();
  650.  
  651.     srand(100);
  652.     for (i = 0; i < MAXNUM; i++) {
  653.         r[i].left = random(maxx-100);
  654.         r[i].top = random(maxy-100);
  655.         r[i].right = r[i].left + random(100);
  656.         r[i].bottom = r[i].top + random(100);
  657.         startAng[i] = random(360);
  658.         endAng[i] = random(360);
  659.         }
  660.  
  661.     LZTimerOn();
  662.     for (j = 0; j < LOOPS; j++) {
  663.         MGL_setColor(MGL_realColor(j+1));
  664.         for (i = 0; i < MAXNUM; i++)
  665.             MGL_ellipseArc(r[i],startAng[i],endAng[i]);
  666.         }
  667.     LZTimerOff();
  668.  
  669.     exit_graphics();
  670.     ReportTime(LZTimerCount());
  671. }
  672.  
  673. #endif
  674.  
  675. #ifdef    TEST13
  676.  
  677. /* TEST13    - Filled elliptical arc speed test.
  678. *
  679. * This routine draws a number of random elliptical arcs as fast as
  680. * possible, timing the result.
  681. */
  682.  
  683. #define    MAXNUM    1000
  684. #define    LOOPS    5
  685.  
  686. rect    r[MAXNUM];
  687. int        startAng[MAXNUM];
  688. int        endAng[MAXNUM];
  689.  
  690. void cdecl main(int argc,char *argv[])
  691. {
  692.    int        i,j,maxx,maxy,maxcolor;
  693.  
  694.    init_graphics("Filled elliptical arc speed test",argc,argv);
  695.  
  696.    maxx = MGL_maxx();
  697.    maxy = MGL_maxy();
  698.    maxcolor = MGL_maxColor();
  699.  
  700.    srand(100);
  701.    for (i = 0; i < MAXNUM; i++) {
  702.        r[i].left = random(maxx-100);
  703.        r[i].top = random(maxy-100);
  704.        r[i].right = r[i].left + random(100);
  705.        r[i].bottom = r[i].top + random(100);
  706.        startAng[i] = random(360);
  707.        endAng[i] = random(360);
  708.        }
  709.  
  710.    LZTimerOn();
  711.    for (j = 0; j < LOOPS; j++) {
  712.        for (i = 0; i < MAXNUM; i++) {
  713.            MGL_setColor(i % maxcolor + 1);
  714.            MGL_fillEllipseArc(r[i],startAng[i],endAng[i]);
  715.            }
  716.        }
  717.    LZTimerOff();
  718.  
  719.    exit_graphics();
  720.    ReportTime(LZTimerCount());
  721. }
  722.  
  723. #endif
  724.  
  725. #ifdef TEST14
  726.  
  727. /* TEST14    - Palette programming test routine.
  728.  *
  729.  * This routine draws a number of colors rectangles on the display, and
  730.  * tests the palette programming routines.
  731.  */
  732.  
  733. void cdecl main(int argc,char *argv[])
  734. {
  735.     int        color,maxcolor,width,height,x,y,i,j,palsize;
  736.     palette    pal[256],temppal[256];
  737.     palette    oldpal[256];
  738.  
  739.     init_graphics("Color demonstration",argc,argv);
  740.  
  741.     maxcolor = MGL_maxColor();
  742.     palsize = MGL_getPaletteSize();
  743.  
  744.     if (maxcolor <= 15) {
  745.         /* Simple color demonstration for 16 color displays */
  746.  
  747.         width = 2 * ((MGL_maxx()+1) / 16);
  748.         height = 2 * ((MGL_maxy()-10)  / 10);
  749.  
  750.         x = width / 2;
  751.         y = height / 2;
  752.         color = 1;
  753.         for (j = 0; j < 3; j++) {
  754.             for (i = 0; i < 5; i++) {
  755.                 MGL_setColor(color++);
  756.                 MGL_fillRectCoord(x,y,x+width,y+height);
  757.                 x += (width/2) * 3;
  758.                 }
  759.             y += (height / 2) * 3;
  760.             x = width / 2;
  761.             }
  762.         }
  763.     else {
  764.         /* Color demonstration for large numbers of colors */
  765.  
  766.         width = 2 * ((MGL_maxx()+1) / 46);
  767.         height = 2 * ((MGL_maxy()-10)  / 47);
  768.  
  769.         x = width / 2;
  770.         y = height / 2;
  771.         color = 1;
  772.         for (j = 0; j < 16; j++) {
  773.             for (i = 0; i < 16; i++) {
  774.                 MGL_setColor(color++);
  775.                 MGL_fillRectCoord(x,y,x+width,y+height);
  776.                 x += (width/2) * 3;
  777.                 }
  778.             y += (height / 2) * 3;
  779.             x = width / 2;
  780.             }
  781.         }
  782.  
  783.     getch();
  784.  
  785.     MGL_getPalette(oldpal,palsize,0);
  786.     MGL_getPalette(pal,palsize,0);
  787.  
  788.     pal[0].red = 0;        pal[0].green = 0;    pal[0].blue = 0;    // Black
  789.     pal[1].red = 255;    pal[1].green = 255;    pal[1].blue = 255;    // White
  790.     pal[2].red = 204;    pal[2].green = 204;    pal[2].blue = 204;    // LightGray
  791.     pal[3].red = 128;    pal[3].green = 128;    pal[3].blue = 128;    // DarkGray
  792.     pal[4].red = 0;        pal[4].green = 0;    pal[4].blue = 128;    // Blue
  793.     pal[5].red = 0;        pal[5].green = 128;    pal[5].blue = 128;    // Jade
  794.     pal[6].red = 255;    pal[6].green = 255;    pal[6].blue = 128;    // Yellow
  795.     pal[7].red = 255;    pal[7].green = 255;    pal[7].blue = 204;    // LightYellow
  796.  
  797.     MGL_setPalette(pal,palsize,0);
  798. /*
  799.     maxcolor++;
  800.     for (i = 0; i < maxcolor; i++) {
  801.         pal[i].red = i * ((PALMAX+1) / maxcolor);
  802.         pal[i].green = 0;
  803.         pal[i].blue = 0;
  804.         MGL_setPaletteEntry(i,pal[i].red,pal[i].green,pal[i].blue);
  805.         }
  806.  
  807.     getch();
  808.     for (i = 0; i < maxcolor; i++) {
  809.         pal[i].red = 0;
  810.         pal[i].green = i * ((PALMAX+1) / maxcolor);
  811.         pal[i].blue = 0;
  812.         }
  813.     MGL_setPalette(pal,palsize,0);
  814.  
  815.     getch();
  816.     for (i = 0; i < maxcolor; i++) {
  817.         pal[i].red = 0;
  818.         pal[i].green = 0;
  819.         pal[i].blue = i * ((PALMAX+1) / maxcolor);
  820.         }
  821.     MGL_setPalette(pal,palsize,0);
  822.  
  823.     getch();
  824.     for (i = 0; i < maxcolor; i++) {
  825.         pal[i].red = (i * ((PALMAX+1) / maxcolor)) / 2;
  826.         pal[i].green = (i * ((PALMAX+1) / maxcolor)) / 2;
  827.         pal[i].blue = i * ((PALMAX+1) / maxcolor);
  828.         }
  829.     MGL_setPalette(pal,palsize,0);
  830.     getch();
  831.  
  832.     MGL_setPalette(oldpal,palsize,0);
  833.     MGL_getPalette(pal,palsize,0);
  834.  
  835.     if (MGL_maxColor() > 15) {
  836.         // Palette rotations
  837.  
  838.         while (!kbhit()) {
  839.             MGL_rotatePalette(pal+1,palsize-1,PAL_ROTATE_UP);
  840.             MGL_setPalette(pal+1,palsize-1,1);
  841.             }
  842.         getch();
  843.  
  844.         while (!kbhit()) {
  845.             MGL_rotatePalette(pal+1,palsize-1,PAL_ROTATE_DOWN);
  846.             MGL_setPalette(pal+1,palsize-1,1);
  847.             }
  848.         getch();
  849.  
  850.         // Palette fade out
  851.  
  852.         temppal[0] = pal[0];
  853.         for (i = 63; i >= 0; i--) {
  854.             MGL_fadePalette(temppal+1,pal+1,palsize-1,i*4);
  855.             MGL_setPalette(temppal+1,palsize-1,1);
  856.             }
  857.  
  858.         for (i = 0; i <= 63; i++) {
  859.             MGL_fadePalette(temppal+1,pal+1,palsize-1,i*4);
  860.             MGL_setPalette(temppal+1,palsize-1,1);
  861.             }
  862.         getch();
  863.         }
  864.  
  865.     for (i = 0; i < 200; i++)
  866.         MGL_setPalette(oldpal,palsize,0);
  867. */
  868.     exit_graphics();
  869. }
  870.  
  871. #endif
  872.  
  873. #ifdef    TEST15
  874.  
  875. /* TEST15    - Polygon drawing speed test.
  876.  *
  877.  * This routine tests the speed of the polygon drawing routines. It tests
  878.  * both the complex and convex polygon drawing routines.
  879.  */
  880.  
  881. #define MaxPts        6        /* Maximum # of pts in polygon    */
  882. #define    NUM            40
  883.  
  884. typedef    struct {
  885.     point    poly[MaxPts];
  886.     int        color;
  887.     } entry;
  888.  
  889. entry    table[NUM];
  890.  
  891. void cdecl main(int argc,char *argv[])
  892. {
  893.     color_t maxcolor;
  894.     int        maxx,maxy,backcolor;
  895.     point    tri1[3];
  896.     int     i,j;
  897.     rect    clip,view;
  898.  
  899.     init_graphics("Polygon speed test",argc,argv);
  900.  
  901.     maxcolor = MGL_maxColor();
  902.     maxx = MGL_maxx();
  903.     maxy = MGL_maxy();
  904.  
  905.     MGL_getClipRect(&clip);
  906.     srand(100);
  907. #if 0
  908.     /* Create the array of polygons */
  909.  
  910.     for (j = 0; j < NUM; j++) {
  911.         table[j].color = 1 + randoml(maxcolor-1);
  912.  
  913.         for (i = 0; i < (MaxPts-1); i++) {
  914.             table[j].poly[i].x = random(maxx);
  915.             table[j].poly[i].y = random(maxy);
  916.             }
  917.         table[j].poly[i] = table[j].poly[0];
  918.         }
  919.  
  920.     MGL_setPolygonType(COMPLEX_POLYGON);
  921.     LZTimerOn();
  922.     for (j = 0; j < NUM; j++) {
  923.         MGL_setColor(table[j].color);
  924.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  925.         }
  926.     LZTimerOff();
  927.     count1 = LZTimerCount();
  928.     getch();
  929. #endif
  930. //    MGL_setActivePage(1);
  931. //    MGL_setVisualPage(1);
  932.  
  933. /*
  934.     backcolor = MGL_getBackColor();
  935.     MGL_setBackColor(BLACK);
  936.     MGL_clearDevice();
  937.     MGL_setBackColor(backcolor);
  938.     MGL_getViewport(&view);
  939.     MGL_setClipRect(view);
  940.     MGL_setColor(1);
  941.     MGL_insetRect(clip,-1,-1);
  942.     MGL_rect(clip);
  943.     MGL_insetRect(clip,1,1);
  944.     MGL_setClipRect(clip);
  945. */
  946.  
  947.     /* Create the array of triangular convex polygons */
  948.  
  949.     for (j = 0; j < NUM; j++) {
  950.         table[j].color = 1 + random(maxcolor-1);
  951.  
  952.         for (i = 0; i < 3; i++) {
  953.             table[j].poly[i].x = random(maxx);
  954.             table[j].poly[i].y = random(maxy);
  955.             }
  956.         table[j].poly[i] = table[j].poly[0];
  957.         }
  958.  
  959.     for (i = 0; i < maxx/2; i++) {
  960.         clip.left = i;
  961.         clip.right = maxx-i;
  962.         MGL_setClipRect(clip);
  963.         MGL_setPolygonType(CONVEX_POLYGON);
  964.         MGL_clearDevice();
  965.         for (j = 0; j < NUM; j++) {
  966.             MGL_setColor(table[j].color);
  967.             MGL_fillPolygon(3,table[j].poly,0,0);
  968.             }
  969.         }
  970. #if 0
  971.     MGL_setPolygonType(CONVEX_POLYGON);
  972.     LZTimerOn();
  973.     for (j = 0; j < NUM; j++) {
  974.         MGL_setColor(table[j].color);
  975.         MGL_fillPolygon(3,table[j].poly,0,0);
  976.         }
  977.     LZTimerOff();
  978.     count2 = LZTimerCount();
  979. #endif
  980. #if 0
  981.     getch();
  982.     backcolor = MGL_getBackColor();
  983.     MGL_setBackColor(BLACK);
  984.     MGL_clearDevice();
  985.     MGL_setBackColor(backcolor);
  986.     MGL_getViewport(&view);
  987.     MGL_setClipRect(view);
  988.     MGL_setColor(1);
  989.     MGL_insetRect(clip,-1,-1);
  990.     MGL_rect(clip);
  991.     MGL_insetRect(clip,1,1);
  992.     MGL_setClipRect(clip);
  993.  
  994.     /* Create a single 24x24 pixel triangle */
  995.  
  996.     tri1[0].x = 10;    tri1[0].y = 0;
  997.     tri1[1].x = 1;    tri1[1].y = 24;
  998.     tri1[2].x = 23;    tri1[2].y = 24;
  999.  
  1000.     /* Now draw 10,000 of them. */
  1001.  
  1002.     MGL_beginDrawing();
  1003.     LZTimerOn();
  1004.     for (i = 0; i < 100; i++)
  1005.         for (j = 0; j < 100; j++) {
  1006.             MGL_setColor(((i+j)%15)+1);
  1007.             MGL_fillPolygonFast(3,tri1,i,j);
  1008.             }
  1009.     LZTimerOff();
  1010.     MGL_endDrawing();
  1011.     count3 = LZTimerCount();
  1012.  
  1013.     /* Create a single sliver triangles */
  1014.  
  1015.     tri1[0].x = 10;    tri1[0].y = 0;
  1016.     tri1[1].x = 0;    tri1[1].y = 4;
  1017.     tri1[2].x = 5;    tri1[2].y = 4;
  1018.  
  1019.     /* Now draw 10,000 of them. */
  1020.  
  1021.     MGL_clearDevice();
  1022.     MGL_beginDrawing();
  1023.     LZTimerOn();
  1024.     for (i = 0; i < 100; i++)
  1025.         for (j = 0; j < 100; j++) {
  1026.             MGL_setColor(((i+j)%15)+1);
  1027.             MGL_fillPolygonFast(3,tri1,i,j);
  1028.             }
  1029.     LZTimerOff();
  1030.     MGL_endDrawing();
  1031.     count4 = LZTimerCount();
  1032. #endif
  1033.     exit_graphics();
  1034.     printf("Complex polygons with %d vertices:\n    ",MaxPts);
  1035.     ReportTime(count1);
  1036.     printf("Convex Triangular polygons:\n    ");
  1037.     ReportTime(count2);
  1038.     printf("10,000 24x24 triangular polygons:\n    ");
  1039.     ReportTime(count3);
  1040.     printf("    Speed:      %.0f polys/sec\n", (10000000000.0) / count3);
  1041.     printf("10,000 sliver triangular polygons:\n    ");
  1042.     ReportTime(count4);
  1043.     printf("    Speed:      %.0f polys/sec\n", (10000000000.0) / count4);
  1044. }
  1045.  
  1046. #endif
  1047.  
  1048. #ifdef    TEST16
  1049.  
  1050. /* TEST16    - Page flip animation test
  1051.  *
  1052.  * This routine tests the page flipping routines, but drawing polygons
  1053.  * into the off-screen image and then displaying it.
  1054.  */
  1055.  
  1056. #define MaxPts        6        /* Maximum # of pts in polygon    */
  1057. #define    NUM            100
  1058.  
  1059. typedef    struct {
  1060.     point    poly[MaxPts];
  1061.     int        color;
  1062.     } entry;
  1063.  
  1064. entry    table[NUM];
  1065.  
  1066. void cdecl main(int argc,char *argv[])
  1067. {
  1068.     int     maxcolor,maxx,maxy;
  1069.     int     i,j;
  1070.     int        vpage,apage,maxPage;
  1071.  
  1072.     init_graphics("Page flip animation test",argc,argv);
  1073.  
  1074.     maxcolor = MGL_maxColor();
  1075.     maxx = MGL_maxx();
  1076.     maxy = MGL_maxy();
  1077.     maxPage = MGL_maxPage() + 1;
  1078.     if (maxPage == 1) {
  1079.         MGL_exit();
  1080.         printf("Mode does not support page flipping...\n");
  1081.         exit(1);
  1082.         }
  1083.  
  1084.     srand(100);
  1085.  
  1086.     /* Create the array of polygons */
  1087.  
  1088.     for (j = 0; j < NUM; j++) {
  1089.         table[j].color = 1 + random(maxcolor-1);
  1090.  
  1091.         for (i = 0; i < (MaxPts-1); i++) {
  1092.             table[j].poly[i].x = random(maxx);
  1093.             table[j].poly[i].y = random(maxy);
  1094.             }
  1095.         table[j].poly[i] = table[j].poly[0];
  1096.         }
  1097.  
  1098.     vpage = 0;
  1099.     apage = 1;
  1100.  
  1101.     /* Make sure we initially clear the display, as the top few pages
  1102.      * of SuperVGA's will not be cleared when the video mode is set.
  1103.      */
  1104.  
  1105.     MGL_setActivePage(apage);
  1106.     MGL_clearDevice();
  1107.  
  1108.     LZTimerOn();
  1109.     for (j = 0; j < NUM; j++) {
  1110.         MGL_setActivePage(apage);
  1111.         MGL_setColor(table[j].color);
  1112.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  1113.         vpage = ++vpage % maxPage;
  1114.         MGL_setVisualPage(vpage);
  1115.         apage = ++apage % maxPage;
  1116.         MGL_copyPage(apage,vpage);
  1117.         }
  1118.     LZTimerOff();
  1119.  
  1120.     exit_graphics();
  1121.     ReportTime(LZTimerCount());
  1122. }
  1123.  
  1124. #endif
  1125.  
  1126. #ifdef    TEST17
  1127.  
  1128. /* TEST17    - Bit block transfer test.
  1129.  *
  1130.  * Tests the MGL_getImage and MGL_putImage bit block transfer routines.
  1131.  */
  1132.  
  1133. #define MaxPts        6        /* Maximum # of pts in polygon    */
  1134. #define    NUM            10
  1135.  
  1136. typedef    struct {
  1137.     point    poly[MaxPts];
  1138.     int        color;
  1139.     } entry;
  1140.  
  1141. entry    table[NUM];
  1142.  
  1143. void cdecl main(int argc,char *argv[])
  1144. {
  1145.     int        maxx,maxy;
  1146.     int     i,j;
  1147.     long    size;
  1148.     rect    r;
  1149.     char    *image;
  1150.  
  1151.     init_graphics("MGL_getImage/MGL_putImage test",argc,argv);
  1152.  
  1153.     maxx = MGL_maxx();
  1154.     maxy = MGL_maxy();
  1155.  
  1156.     srand(100);
  1157.  
  1158.     /* Create the array of polygons */
  1159.  
  1160.     for (j = 0; j < NUM; j++) {
  1161.         table[j].color = 1 + random(15);
  1162.  
  1163.         for (i = 0; i < (MaxPts-1); i++) {
  1164.             table[j].poly[i].x = random(maxx);
  1165.             table[j].poly[i].y = random(maxy);
  1166.             }
  1167.         table[j].poly[i] = table[j].poly[0];
  1168.         }
  1169.  
  1170.     for (j = 0; j < NUM; j++) {
  1171.         MGL_setColor(MGL_realColor(table[j].color));
  1172.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  1173.         }
  1174.  
  1175.     getch();
  1176.  
  1177.     r.left = 50;
  1178.     r.top = 50;
  1179.     r.right = maxx - 50;
  1180.     r.bottom = maxy/2 - 50;
  1181.     size = MGL_imageSize(r);
  1182.  
  1183.     image = farmalloc(size);
  1184.  
  1185.     MGL_getImage(r,image);
  1186.     MGL_setColor(MGL_realColor(BLACK));
  1187.     MGL_fillRectCoord(r.left-1,r.top-1,r.right+1,r.bottom+1);
  1188.  
  1189.     LZTimerOn();
  1190.     MGL_putImage(r,image,REPLACE_MODE);
  1191.     LZTimerOff();
  1192.  
  1193.     getch();
  1194.  
  1195.     LZTimerOn();
  1196.     MGL_putImage(r,image, XOR_MODE);
  1197.     LZTimerOff();
  1198.     getch();
  1199.     MGL_putImage(r,image, OR_MODE);
  1200.     getch();
  1201.     MGL_putImage(r,image, AND_MODE);
  1202.  
  1203.     getch();
  1204.  
  1205.     for (i = 0; i < 100; i += 2) {
  1206.         MGL_putImageCoord(r.left,i,r.right,r.bottom+i,image,REPLACE_MODE);
  1207.         }
  1208.  
  1209.     exit_graphics();
  1210.     ReportTime(LZTimerCount());
  1211. }
  1212.  
  1213. #endif
  1214.  
  1215. #ifdef    TEST18
  1216.  
  1217. /* TEST18    - Divot save/restore test.
  1218.  *
  1219.  * This routine tests the byte aligned divot save/restore routines.
  1220.  */
  1221.  
  1222. #define MaxPts        6        /* Maximum # of pts in polygon    */
  1223. #define    NUM            10
  1224.  
  1225. typedef    struct {
  1226.     point    poly[MaxPts];
  1227.     int        color;
  1228.     } entry;
  1229.  
  1230. entry    table[NUM];
  1231.  
  1232. void cdecl main(int argc,char *argv[])
  1233. {
  1234.     int     maxx,maxy;
  1235.     int     i,j;
  1236.     long    size;
  1237.     rect    r;
  1238.     void    far *divot;
  1239.  
  1240.     init_graphics("Divot save/restore test",argc,argv);
  1241.  
  1242.     maxx = MGL_maxx();
  1243.     maxy = MGL_maxy();
  1244.  
  1245.     srand(100);
  1246.  
  1247.     /* Create the array of polygons */
  1248.  
  1249.     for (j = 0; j < NUM; j++) {
  1250.         table[j].color = 1 + random(15);
  1251.  
  1252.         for (i = 0; i < (MaxPts-1); i++) {
  1253.             table[j].poly[i].x = random(maxx);
  1254.             table[j].poly[i].y = random(maxy);
  1255.             }
  1256.         table[j].poly[i] = table[j].poly[0];
  1257.         }
  1258.  
  1259.     for (j = 0; j < NUM; j++) {
  1260.         MGL_setColor(MGL_realColor(table[j].color));
  1261.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  1262.         }
  1263.  
  1264.     r.left = 101;
  1265.     r.top = 100;
  1266.     r.right = r.left + 200;
  1267.     r.bottom = r.top + 100;
  1268.     size = MGL_divotSize(r);
  1269.  
  1270.     divot = malloc(size);
  1271.  
  1272.     LZTimerOn();
  1273.     MGL_getDivot(r,divot);
  1274.     LZTimerOff();
  1275.     count1 = LZTimerCount();
  1276.     MGL_setColor(MGL_realColor(BLACK));
  1277.     MGL_fillRectCoord(r.left-1,r.top-1,r.right+1,r.bottom+1);
  1278.  
  1279.     getch();
  1280.  
  1281.     MGL_setActivePage(1);
  1282.     MGL_setVisualPage(1);
  1283.  
  1284.     LZTimerOn();
  1285.     MGL_putDivot(divot);
  1286.     LZTimerOff();
  1287.     count2 = LZTimerCount();
  1288.  
  1289.     exit_graphics();
  1290.     printf("Save:    ");    ReportTime(count1);
  1291.     printf("Restore: ");    ReportTime(count2);
  1292. }
  1293.  
  1294. #endif
  1295.  
  1296. #ifdef    TEST19
  1297.  
  1298. /* TEST19    - Mouse interface test.
  1299.  *
  1300.  * This routines test the integrity of the mouse interface routines.
  1301.  */
  1302.  
  1303. #define MaxPts        6        /* Maximum # of pts in polygon    */
  1304. #define    NUM            10
  1305.  
  1306. typedef    struct {
  1307.     point    poly[MaxPts];
  1308.     int        color;
  1309.     } entry;
  1310.  
  1311. entry    table[NUM];
  1312.  
  1313. void cdecl main(int argc,char *argv[])
  1314. {
  1315.     int         maxx,maxy;
  1316.     int         i,j;
  1317.     color_t        oldColor;
  1318.     void        *state;
  1319.     ms_status    pos;
  1320.  
  1321.     _installMouse = true;
  1322.     init_graphics("Mouse interface test",argc,argv);
  1323.     MS_init();
  1324.  
  1325.     maxx = MGL_maxx();
  1326.     maxy = MGL_maxy();
  1327.  
  1328.     srand(100);
  1329.  
  1330.     /* Create the array of polygons */
  1331.  
  1332.     for (j = 0; j < NUM; j++) {
  1333.         table[j].color = 1 + random(15);
  1334.  
  1335.         for (i = 0; i < (MaxPts-1); i++) {
  1336.             table[j].poly[i].x = random(maxx);
  1337.             table[j].poly[i].y = random(maxy);
  1338.             }
  1339.         table[j].poly[i] = table[j].poly[0];
  1340.         }
  1341.  
  1342.     for (j = 0; j < NUM; j++) {
  1343.         MGL_setColor(MGL_realColor(table[j].color));
  1344.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  1345.         }
  1346.     MGL_setColor(MGL_realColor(BLUE));
  1347.     MGL_rectCoord(0,0,maxx+1,maxy+1);
  1348.  
  1349.     MGL_setActivePage(0);            /* Active page possibly different to
  1350.                                      * visual page
  1351.                                      */
  1352.     MS_show();
  1353.     MS_moveTo(maxx/4,3*maxy/4);
  1354.     getch();
  1355.  
  1356.     MS_pos(&pos);
  1357.     printf("(%d,%d) ",pos.x,pos.y);
  1358.  
  1359.     state = malloc(i = MS_stateSize());
  1360.     MS_saveState(state);
  1361.     MS_setCursor(&CROSS);
  1362.     getch();
  1363.  
  1364.     MS_restoreState(state);
  1365.     getch();
  1366.  
  1367.     oldColor = MGL_getCursorColor();
  1368.     MGL_setCursorColor(MGL_realColor(BLUE));
  1369.     MS_hide();    MS_show();
  1370.     getch();
  1371.  
  1372.     MGL_setCursorColor(oldColor);
  1373.     MS_hide();    MS_show();
  1374.     getch();
  1375.  
  1376.     exit_graphics();
  1377.     MS_exit();
  1378. }
  1379.  
  1380. #endif
  1381.  
  1382. #ifdef    TEST20
  1383.  
  1384. /* TEST20    - Text direction drawing test.
  1385.  *
  1386.  * This routine tests the text drawing routines for a specified font.
  1387.  */
  1388.  
  1389. void cdecl main(int argc,char *argv[])
  1390. {
  1391.     int     maxx,maxy;
  1392.     int     horiz,vert,err;
  1393.     char    *str,fontfile[80];
  1394.     font    far *font = NULL;
  1395.  
  1396.     char    buf[80];
  1397.     int        i;
  1398.  
  1399.     fontfile[0] = '\0';
  1400.     if (argc > 1 && argv[1][0] != '-') {
  1401.         strcpy(fontfile,argv[1]);
  1402.         argc--;
  1403.         argv++;
  1404.         }
  1405.     init_graphics("Text direction drawing test",argc,argv);
  1406.  
  1407.     maxx = MGL_maxx();
  1408.     maxy = MGL_maxy();
  1409.  
  1410.     if (strlen(fontfile) != 0) {
  1411.         MGL_availableFont(fontfile);
  1412.         if ((err = MGL_result()) != grOK) {
  1413.             MGL_exit();
  1414.             printf("Graphics error: %s\n",MGL_errorMsg(err));
  1415.             exit(1);
  1416.             }
  1417.         font = MGL_loadFont(fontfile);
  1418.         }
  1419.     else
  1420.         font = DEFAULT_FONT;
  1421.  
  1422.     MGL_setTextSize(1,1,1,1);
  1423.  
  1424.     for (horiz = LEFT_TEXT; horiz <= RIGHT_TEXT; horiz++)
  1425.         for (vert = TOP_TEXT; vert <= BASELINE_TEXT; vert++) {
  1426.             MGL_clearDevice();
  1427.             MGL_setColor(RED);
  1428.             MGL_lineCoord(0,maxy/2,maxx,maxy/2);
  1429.             MGL_lineCoord(maxx/2,0,maxx/2,maxy);
  1430.             MGL_setTextJustify(LEFT_TEXT,TOP_TEXT);
  1431.             MGL_setTextDirection(RIGHT_DIR);
  1432.             MGL_useFont(DEFAULT_FONT);
  1433.             MGL_setColor(GREEN);
  1434.             MGL_moveToCoord(0,0);
  1435.             MGL_drawStr("horiz: ");
  1436.             switch (horiz) {
  1437.                 case LEFT_TEXT:
  1438.                     str = "LEFT";
  1439.                     break;
  1440.                 case CENTER_TEXT:
  1441.                     str = "CENTER";
  1442.                     break;
  1443.                 case RIGHT_TEXT:
  1444.                     str = "RIGHT";
  1445.                 }
  1446.             MGL_drawStr(str);
  1447.             MGL_moveToCoord(0,MGL_textHeight());
  1448.             MGL_drawStr("vert:  ");
  1449.             switch (vert) {
  1450.                 case TOP_TEXT:
  1451.                     str = "TOP";
  1452.                     break;
  1453.                 case CENTER_TEXT:
  1454.                     str = "CENTER";
  1455.                     break;
  1456.                 case BOTTOM_TEXT:
  1457.                     str = "BOTTOM";
  1458.                     break;
  1459.                 case BASELINE_TEXT:
  1460.                     str = "BASELINE";
  1461.                     break;
  1462.                 }
  1463.             MGL_drawStr(str);
  1464.  
  1465.             MGL_setTextJustify(horiz,vert);
  1466.             MGL_useFont(font);
  1467.  
  1468.             MGL_setColor(BLUE);
  1469.             MGL_lineCoord(0,maxy/2+MGL_textHeight()-1,maxx,maxy/2+MGL_textHeight()-1);
  1470.             MGL_lineCoord(maxx/2+MGL_textHeight()-1,0,maxx/2+MGL_textHeight()-1,maxy);
  1471.  
  1472.             MGL_setColor(WHITE);
  1473.             MGL_setTextDirection(LEFT_DIR);
  1474.             MGL_drawStrXY(maxx/2,maxy/2,"This text goes left");
  1475.  
  1476.             MGL_setTextDirection(DOWN_DIR);
  1477.             MGL_drawStrXY(maxx/2,maxy/2,"This text goes down");
  1478.  
  1479.             MGL_setTextDirection(UP_DIR);
  1480.             MGL_drawStrXY(maxx/2,maxy/2,"This text goes up");
  1481.  
  1482.             MGL_setTextDirection(RIGHT_DIR);
  1483.             MGL_drawStrXY(maxx/2,maxy/2,"This text goes right");
  1484.  
  1485.             getch();
  1486.             }
  1487.  
  1488.     MGL_clearDevice();
  1489.  
  1490.     MGL_useFont(font);
  1491.     MGL_setColor(RED);
  1492.     MGL_lineCoord(0,maxy/2,maxx,maxy/2);
  1493.     MGL_setColor(BLUE);
  1494.     MGL_lineCoord(0,maxy/2-font->ascent,maxx,maxy/2-font->ascent);
  1495.     MGL_lineCoord(0,maxy/2-font->descent,maxx,maxy/2-font->descent);
  1496.     MGL_setColor(GREEN);
  1497.     MGL_lineCoord(0,maxy/2-font->descent+font->leading,maxx,maxy/2-font->descent+font->leading);
  1498.     MGL_lineCoord(0,maxy/2+MGL_textHeight()-1,maxx,maxy/2+MGL_textHeight()-1);
  1499.  
  1500.     MGL_setTextJustify(CENTER_TEXT,TOP_TEXT);
  1501.     MGL_setTextDirection(RIGHT_DIR);
  1502.     MGL_setColor(WHITE);
  1503.  
  1504.     strcpy(buf,"ABCDefgj");
  1505.     for (i = 140; i < 150; i++)
  1506.         buf[i-132] = i;
  1507.     buf[i-132] = 0;
  1508.     MGL_drawStrXY(maxx/2,maxy/2,buf);
  1509.  
  1510.     if (strlen(fontfile) != 0)
  1511.         MGL_unloadFont(font);
  1512.  
  1513.     exit_graphics();
  1514.     ReportTime(count1);
  1515. }
  1516.  
  1517. #endif
  1518.  
  1519. #ifdef    TEST21
  1520.  
  1521. /* TEST21    - Font drawing test.
  1522.  *
  1523.  * This routine displays all of the characters in a specified font file.
  1524.  */
  1525.  
  1526. void cdecl main(int argc,char *argv[])
  1527. {
  1528.     int     i,x,maxx,err;
  1529.     char    *str;
  1530.     font    far *font;
  1531.     uchar    buf[10];
  1532.     char    fontfile[80];
  1533.     rect    r;
  1534.  
  1535.     fontfile[0] = '\0';
  1536.     if (argc > 1 && argv[1][0] != '-') {
  1537.         strcpy(fontfile,argv[1]);
  1538.         argc--;
  1539.         argv++;
  1540.         }
  1541.     init_graphics("Font drawing test",argc,argv);
  1542.  
  1543.     maxx = MGL_maxx();
  1544.  
  1545.     if (strlen(fontfile) != 0) {
  1546.         MGL_availableFont(fontfile);
  1547.         if ((err = MGL_result()) != grOK) {
  1548.             MGL_exit();
  1549.             printf("Graphics error: %s\n",MGL_errorMsg(err));
  1550.             exit(1);
  1551.             }
  1552.         font = MGL_loadFont(fontfile);
  1553.         }
  1554.     else
  1555.         font = DEFAULT_FONT;
  1556.  
  1557.     MGL_useFont(font);
  1558.     MGL_setTextSize(1,1,1,1);
  1559.  
  1560.     buf[1] = '\0';
  1561.     str = (char*)buf;
  1562.     LZTimerOn();
  1563.     x = 1;
  1564.     MGL_moveToCoord(0,0);
  1565.     for (i = 1; i < 256; i++) {
  1566.         buf[0] = i;
  1567.         MGL_drawStr(str);
  1568.         if (MGL_getX() + MGL_maxCharWidth() > maxx)
  1569.             MGL_moveToCoord(x++,MGL_getY() + MGL_textHeight());
  1570.         }
  1571.     LZTimerOff();
  1572.  
  1573.     if (smallclip) {
  1574.         r.left = (MGL_maxx()+1)/4;
  1575.         r.right = r.left * 3;
  1576.         r.top = (MGL_maxy()+1)/4;
  1577.         r.bottom = r.top * 3;
  1578.         MGL_setColor(1);
  1579.         MGL_insetRect(r,-1,-1);
  1580.         MGL_rect(r);
  1581.         MGL_insetRect(r,1,1);
  1582.         MGL_setColor(YELLOW);
  1583.         MGL_setClipRect(r);
  1584.         MGL_setClipMode(CLIPON);
  1585.  
  1586.         x = 1;
  1587.         MGL_moveToCoord(0,0);
  1588.         for (i = 1; i < 256; i++) {
  1589.             buf[0] = i;
  1590.             MGL_drawStr(str);
  1591.             if (MGL_getX() + MGL_maxCharWidth() > maxx)
  1592.                 MGL_moveToCoord(x++,MGL_getY() + MGL_textHeight());
  1593.             }
  1594.         }
  1595.  
  1596.     if (strlen(fontfile) != 0)
  1597.         MGL_unloadFont(font);
  1598.  
  1599.     exit_graphics();
  1600.     ReportTime(LZTimerCount());
  1601. }
  1602.  
  1603. #endif
  1604.  
  1605. #ifdef    TEST22
  1606.  
  1607. /* TEST22    - Border drawing tests.
  1608.  *
  1609.  * This routine tests the border drawing routines, which allow you to
  1610.  * draw Window and OS/2 2.0 style borders and buttons.
  1611.  */
  1612.  
  1613. #define    THICKNESS    2
  1614.  
  1615. void cdecl main(int argc,char *argv[])
  1616. {
  1617.     int     maxx,maxy;
  1618.     rect    r;
  1619.  
  1620.     _installMouse = true;
  1621.     init_graphics("Border drawing tests",argc,argv);
  1622.     MS_init();
  1623.  
  1624.     maxx = MGL_maxx();
  1625.     maxy = MGL_maxy();
  1626.  
  1627.     MGL_setBackColor(MGL_realColor(LIGHTGRAY));
  1628.     MGL_clearDevice();
  1629.     MGL_setColor(MGL_realColor(RED));
  1630.  
  1631.     r.left = 10;
  1632.     r.top = 10;
  1633.     r.right = maxx/2 - 10;
  1634.     r.bottom = maxy/2 - 10;
  1635.     MGL_drawBorder(r,BDR_INSET,THICKNESS);
  1636.  
  1637.     r.left = maxx/2 + 10;
  1638.     r.top = 10;
  1639.     r.right = maxx - 10;
  1640.     r.bottom = maxy/2 - 10;
  1641.     MGL_drawBorder(r,BDR_OUTSET,THICKNESS);
  1642.  
  1643.     r.left = 10;
  1644.     r.top = maxy/2 + 10;
  1645.     r.right = maxx/2 - 10;
  1646.     r.bottom = maxy - 10;
  1647.     MGL_drawBorder(r,BDR_OUTLINE,THICKNESS);
  1648.  
  1649.     r.left = maxx/2 + 10;
  1650.     r.top = maxy/2 + 10;
  1651.     r.right = maxx - 10;
  1652.     r.bottom = maxy - 10;
  1653.     MGL_drawBorder(r,BDR_OUTLINE,THICKNESS);
  1654.  
  1655.     MGL_drawVDivider((r.right+r.left)/2,r.top+3,(r.top+r.bottom)/2 - 2);
  1656.     MGL_drawHDivider((r.top+r.bottom)/2,r.left+3,r.right - 4);
  1657.  
  1658.     MS_show();
  1659.  
  1660.     exit_graphics();
  1661.     MS_exit();
  1662. }
  1663.  
  1664. #endif
  1665.  
  1666. #ifdef    TEST23
  1667.  
  1668. /* TEST23    - Gouraud shaded polygon drawing speed test.
  1669.  *
  1670.  * This routine tests the speed of the shaded polygon drawing routines.
  1671.  */
  1672.  
  1673. #define MaxPts        3        /* Maximum # of pts in polygon    */
  1674. #define    NUM            100
  1675.  
  1676. typedef    struct {
  1677.     point    poly[MaxPts];
  1678.     color_t    colors[MaxPts];
  1679.     } entry;
  1680.  
  1681. entry    table[NUM];
  1682.  
  1683. void cdecl main(int argc,char *argv[])
  1684. {
  1685.     int     maxcolor,maxx,maxy,backcolor;
  1686.     int     i,j;
  1687.     rect    view,clip;
  1688.     point    tri1[3];
  1689.     color_t    colors[3];
  1690.     palette    pal[256];
  1691.     char    buf[40];
  1692.  
  1693.     init_graphics("Gouraud shaded polygon speed test",argc,argv);
  1694.  
  1695.     maxcolor = MGL_maxColor();
  1696.     maxx = MGL_maxx();
  1697.     maxy = MGL_maxy();
  1698.     MGL_getClipRect(&clip);
  1699.  
  1700. /*    if (maxcolor < 255) {
  1701.         MGL_exit();
  1702.         printf("Gouraud shading not supported in this video mode\n");
  1703.         exit(1);
  1704.         }*/
  1705.  
  1706.     /* Setup the palette to show smooth shading between bright red and
  1707.      * bright blue. Note that we leave color 0 as black.
  1708.      */
  1709.  
  1710.     pal[0].red = pal[0].green = pal[0].blue = 0;
  1711.     for (i = 1; i <= maxcolor; i++) {
  1712.         pal[i].red = ((long)PALMAX * i) / maxcolor;
  1713.         pal[i].green = 0;
  1714.         pal[i].blue = ((long)PALMAX * (maxcolor - i)) / maxcolor;
  1715.         }
  1716.     MGL_setPalette(pal,MGL_getPaletteSize(),0);
  1717.  
  1718.     srand(100);
  1719.  
  1720.     /* Create the array of polygons */
  1721.  
  1722.     for (j = 0; j < NUM; j++) {
  1723.         for (i = 0; i < MaxPts; i++) {
  1724.             table[j].poly[i].x = random(maxx);
  1725.             table[j].poly[i].y = random(maxy);
  1726.             table[j].colors[i] = 1 + random(maxcolor-1);
  1727.             }
  1728.         }
  1729.  
  1730.     LZTimerOn();
  1731.     for (j = 4; j < NUM; j++) {
  1732.         MGL_fillGouraudPolygon(MaxPts,table[j].poly,table[j].colors,0,0);
  1733.  
  1734.         // Label the vertice for the polygon
  1735.  
  1736.         MGL_setTextJustify(CENTER_TEXT,CENTER_TEXT);
  1737.         for (i = 0; i < MaxPts; i++) {
  1738.             sprintf(buf,"%d",table[j].colors[i]);
  1739.             MGL_drawStrXY(table[j].poly[i].x,table[j].poly[i].y,buf);
  1740.             }
  1741.         getch();
  1742.         }
  1743.     LZTimerOff();
  1744.     count1 = LZTimerCount();
  1745.     getch();
  1746.  
  1747.     backcolor = MGL_getBackColor();
  1748.     MGL_setBackColor(BLACK);
  1749.     MGL_clearDevice();
  1750.     MGL_setBackColor(backcolor);
  1751.     MGL_getViewport(&view);
  1752.     MGL_setClipRect(view);
  1753.     MGL_setColor(1);
  1754.     MGL_insetRect(clip,-1,-1);
  1755.     MGL_rect(clip);
  1756.     MGL_insetRect(clip,1,1);
  1757.     MGL_setClipRect(clip);
  1758.  
  1759.     /* Create a single 24x24 pixel triangle */
  1760.  
  1761.     tri1[0].x = 10;    tri1[0].y = 0;        colors[0] = 1;
  1762.     tri1[1].x = 1;    tri1[1].y = 24;        colors[1] = maxcolor;
  1763.     tri1[2].x = 23;    tri1[2].y = 24;        colors[2] = maxcolor;
  1764.  
  1765.     /* Now draw 49,300 of them. */
  1766.  
  1767.     MGL_beginDrawing();
  1768.     LZTimerOn();
  1769.     for (i = 0; i < 290; i++)
  1770.         for (j = 0; j < 170; j++) {
  1771.             colors[0] = ((i+j)%15)+1;
  1772.             MGL_fillGouraudPolygon(3,tri1,colors,i,j);
  1773.             }
  1774.     LZTimerOff();
  1775.     MGL_endDrawing();
  1776.     count2 = LZTimerCount();
  1777.  
  1778.     exit_graphics();
  1779.     printf("Shaded polygons:\n    ");
  1780.     ReportTime(count1);
  1781.     printf("49,300 24x24 polygons:\n    ");
  1782.     ReportTime(count2);
  1783. }
  1784.  
  1785. #endif
  1786.  
  1787. #ifdef    TEST24
  1788.  
  1789. /* TEST24    - Bit Block copy test
  1790.  *
  1791.  * Tests the MGL_copyImage routine for scrolling the display.
  1792.  */
  1793.  
  1794. #define MaxPts        6        /* Maximum # of pts in polygon    */
  1795. #define    NUM            10
  1796.  
  1797. typedef    struct {
  1798.     point    poly[MaxPts];
  1799.     int        color;
  1800.     } entry;
  1801.  
  1802. entry    table[NUM];
  1803.  
  1804. void cdecl main(int argc,char *argv[])
  1805. {
  1806.     int     maxcolor,maxx,maxy,maxpage;
  1807.     int     i,j,page;
  1808.     rect    r;
  1809.  
  1810.     init_graphics("MGL_copyImage test",argc,argv);
  1811.  
  1812.     maxcolor = MGL_maxColor();
  1813.     maxx = MGL_maxx();
  1814.     maxy = MGL_maxy();
  1815.     maxpage = MGL_maxPage();
  1816.     page = MGL_getActivePage();
  1817.  
  1818.     srand(100);
  1819.  
  1820.     /* Create the array of polygons */
  1821.  
  1822.     for (j = 0; j < NUM; j++) {
  1823.         table[j].color = 1 + random(maxcolor-1);
  1824.  
  1825.         for (i = 0; i < (MaxPts-1); i++) {
  1826.             table[j].poly[i].x = random(maxx);
  1827.             table[j].poly[i].y = random(maxy);
  1828.             }
  1829.         table[j].poly[i] = table[j].poly[0];
  1830.         }
  1831.  
  1832.     /* Scroll upwards */
  1833.  
  1834.     MGL_clearDevice();
  1835.     for (j = 0; j < NUM; j++) {
  1836.         MGL_setColor(table[j].color);
  1837.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  1838.         }
  1839.  
  1840.     r.left = 0;
  1841.     r.top = 5;
  1842.     r.right = maxx+1;
  1843.     r.bottom = maxy+1;
  1844.  
  1845.     getch();
  1846.     LZTimerOn();
  1847.     for (i = 0; i < maxy; i += 8)
  1848.         MGL_copyImage(r,0,0,page,page);
  1849.     LZTimerOff();
  1850.     count1 = LZTimerCount();
  1851.  
  1852.     getch();
  1853.  
  1854.     /* Scroll downwards */
  1855.  
  1856.     MGL_clearDevice();
  1857.     for (j = 0; j < NUM; j++) {
  1858.         MGL_setColor(table[j].color);
  1859.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  1860.         }
  1861.  
  1862.     r.left = 0;
  1863.     r.top = 0;
  1864.     r.right = maxx+1;
  1865.     r.bottom = maxy-4;
  1866.  
  1867.     getch();
  1868.     LZTimerOn();
  1869.     for (i = 0; i < maxy; i += 8)
  1870.         MGL_copyImage(r,0,5,page,page);
  1871.     LZTimerOff();
  1872.     count2 = LZTimerCount();
  1873.  
  1874.     getch();
  1875.  
  1876.     /* Scroll right */
  1877.  
  1878.     MGL_clearDevice();
  1879.     for (j = 0; j < NUM; j++) {
  1880.         MGL_setColor(table[j].color);
  1881.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  1882.         }
  1883.  
  1884.     r.left = 0;
  1885.     r.top = 0;
  1886.     r.right = maxx-3;
  1887.     r.bottom = maxy+1;
  1888.  
  1889.     getch();
  1890.     LZTimerOn();
  1891.     for (i = 0; i < maxx; i += 8)
  1892.         MGL_copyImage(r,4,0,page,page);
  1893.     LZTimerOff();
  1894.     count3 = LZTimerCount();
  1895.  
  1896.     getch();
  1897.  
  1898.     /* Scroll left */
  1899.  
  1900.     MGL_clearDevice();
  1901.     for (j = 0; j < NUM; j++) {
  1902.         MGL_setColor(table[j].color);
  1903.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  1904.         }
  1905.  
  1906.     r.left = 4;
  1907.     r.top = 0;
  1908.     r.right = maxx+1;
  1909.     r.bottom = maxy+1;
  1910.  
  1911.     getch();
  1912.     LZTimerOn();
  1913.     for (i = 0; i < maxx; i += 8)
  1914.         MGL_copyImage(r,0,0,page,page);
  1915.     LZTimerOff();
  1916.     count4 = LZTimerCount();
  1917.  
  1918.     getch();
  1919.  
  1920.     /* Scroll right and down */
  1921.  
  1922.     MGL_clearDevice();
  1923.     for (j = 0; j < NUM; j++) {
  1924.         MGL_setColor(table[j].color);
  1925.         MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  1926.         }
  1927.  
  1928.     r.left = 0;
  1929.     r.top = 0;
  1930.     r.right = maxx-4;
  1931.     r.bottom = maxy-4;
  1932.     for (i = 0; i < maxy; i += 8)
  1933.         MGL_copyImage(r,5,5,page,page);
  1934.  
  1935.     /* Copy between video pages */
  1936.  
  1937.     if (maxpage > 0) {
  1938.         MGL_setActivePage(1);
  1939.         MGL_setVisualPage(1);
  1940.         MGL_clearDevice();
  1941.         for (j = 0; j < NUM; j++) {
  1942.             MGL_setColor(table[j].color);
  1943.             MGL_fillPolygon(MaxPts,table[j].poly,0,0);
  1944.             }
  1945.  
  1946.         getch();
  1947.         MGL_setActivePage(0);
  1948.         MGL_setVisualPage(0);
  1949.         MGL_clearDevice();
  1950.         getch();
  1951.         MGL_copyImageCoord(0,0,
  1952.                            maxx+1,maxy+1,
  1953.                            0,0,
  1954.                            1,0);
  1955.         getch();
  1956.         MGL_setActivePage(1);
  1957.         MGL_setVisualPage(1);
  1958.         MGL_clearDevice();
  1959.         getch();
  1960.         MGL_copyImageCoord(maxx/2-100,0,
  1961.                            maxx/2+100,maxy+1,
  1962.                            maxx/2-100,0,
  1963.                            0,1);
  1964.         }
  1965.  
  1966.     exit_graphics();
  1967.     printf("Up:    ");    ReportTime(count1);
  1968.     printf("Down:  ");    ReportTime(count2);
  1969.     printf("Right: ");    ReportTime(count3);
  1970.     printf("Left:  ");    ReportTime(count4);
  1971. }
  1972.  
  1973. #endif
  1974.  
  1975. #ifdef    TEST25
  1976.  
  1977. /* TEST25    - Text underline test
  1978.  *
  1979.  * This routine tests the text underline calculation routines.
  1980.  */
  1981.  
  1982. void cdecl main(int argc,char *argv[])
  1983. {
  1984.     int     maxx,maxy,x,y;
  1985.     int     horiz,vert,err;
  1986.     char    *str,fontfile[80];
  1987.     font    far *font = NULL;
  1988.  
  1989.     fontfile[0] = '\0';
  1990.     if (argc > 1 && argv[1][0] != '-') {
  1991.         strcpy(fontfile,argv[1]);
  1992.         argc--;
  1993.         argv++;
  1994.         }
  1995.  
  1996.     init_graphics("Text direction drawing test",argc,argv);
  1997.  
  1998.     maxx = MGL_maxx();
  1999.     maxy = MGL_maxy();
  2000.  
  2001.     if (strlen(fontfile) != 0) {
  2002.         MGL_availableFont(fontfile);
  2003.         if ((err = MGL_result()) != grOK) {
  2004.             MGL_exit();
  2005.             printf("Graphics error: %s\n",MGL_errorMsg(err));
  2006.             exit(1);
  2007.             }
  2008.         font = MGL_loadFont(fontfile);
  2009.         }
  2010.     else
  2011.         font = DEFAULT_FONT;
  2012.  
  2013.     MGL_setTextSize(1,1,1,1);
  2014.  
  2015.     for (horiz = LEFT_TEXT; horiz <= RIGHT_TEXT; horiz++)
  2016.         for (vert = TOP_TEXT; vert <= BASELINE_TEXT; vert++) {
  2017.             MGL_clearDevice();
  2018.             MGL_setColor(RED);
  2019.             MGL_lineCoord(0,maxy/2,maxx,maxy/2);
  2020.             MGL_lineCoord(maxx/2,0,maxx/2,maxy);
  2021.             MGL_setTextJustify(LEFT_TEXT,TOP_TEXT);
  2022.             MGL_setTextDirection(RIGHT_DIR);
  2023.             MGL_useFont(DEFAULT_FONT);
  2024.             MGL_setColor(GREEN);
  2025.             MGL_moveToCoord(0,0);
  2026.             MGL_drawStr("horiz: ");
  2027.             switch (horiz) {
  2028.                 case LEFT_TEXT:
  2029.                     str = "LEFT";
  2030.                     break;
  2031.                 case CENTER_TEXT:
  2032.                     str = "CENTER";
  2033.                     break;
  2034.                 case RIGHT_TEXT:
  2035.                     str = "RIGHT";
  2036.                 }
  2037.             MGL_drawStr(str);
  2038.             MGL_moveToCoord(0,MGL_textHeight());
  2039.             MGL_drawStr("vert:  ");
  2040.             switch (vert) {
  2041.                 case TOP_TEXT:
  2042.                     str = "TOP";
  2043.                     break;
  2044.                 case CENTER_TEXT:
  2045.                     str = "CENTER";
  2046.                     break;
  2047.                 case BOTTOM_TEXT:
  2048.                     str = "BOTTOM";
  2049.                 }
  2050.             MGL_drawStr(str);
  2051.  
  2052.             MGL_setTextJustify(horiz,vert);
  2053.             MGL_useFont(font);
  2054.  
  2055.             MGL_setColor(WHITE);
  2056.             MGL_setTextDirection(LEFT_DIR);
  2057.             MGL_drawStrXY(maxx/2,maxy/2,"This text goes left");
  2058.             x = maxx/2; y = maxy/2;
  2059.             MGL_underScoreLocation(&x,&y,"This text goes left");
  2060.             MGL_setColor(BLUE);
  2061.             MGL_lineCoord(x,y,x-MGL_textWidth("This text goes left"),y);
  2062.  
  2063.             MGL_setColor(WHITE);
  2064.             MGL_setTextDirection(DOWN_DIR);
  2065.             MGL_drawStrXY(maxx/2,maxy/2,"This text goes down");
  2066.             x = maxx/2; y = maxy/2;
  2067.             MGL_underScoreLocation(&x,&y,"This text goes down");
  2068.             MGL_setColor(BLUE);
  2069.             MGL_lineCoord(x,y,x,y+MGL_textWidth("This text goes down"));
  2070.  
  2071.             MGL_setColor(WHITE);
  2072.             MGL_setTextDirection(UP_DIR);
  2073.             MGL_drawStrXY(maxx/2,maxy/2,"This text goes up");
  2074.             x = maxx/2; y = maxy/2;
  2075.             MGL_underScoreLocation(&x,&y,"This text goes up");
  2076.             MGL_setColor(BLUE);
  2077.             MGL_lineCoord(x,y,x,y-MGL_textWidth("This text goes up"));
  2078.  
  2079.             MGL_setColor(WHITE);
  2080.             MGL_setTextDirection(RIGHT_DIR);
  2081.             MGL_drawStrXY(maxx/2,maxy/2,"This text goes right");
  2082.             x = maxx/2; y = maxy/2;
  2083.             MGL_underScoreLocation(&x,&y,"This text goes right");
  2084.             MGL_setColor(BLUE);
  2085.             MGL_lineCoord(x,y,x+MGL_textWidth("This text goes right"),y);
  2086.  
  2087.             getch();
  2088.             }
  2089.  
  2090.     if (strlen(fontfile) != 0)
  2091.         MGL_unloadFont(font);
  2092.  
  2093.     exit_graphics();
  2094.     ReportTime(count1);
  2095. }
  2096.  
  2097. #endif
  2098.  
  2099. #ifdef    TEST26
  2100.  
  2101. /* TEST26    - Monochrome image drawing routines
  2102.  *
  2103.  * Tests the MGL_putMonoImage routine for drawing monochrome bitmaps.
  2104.  */
  2105.  
  2106. uchar image[] = {
  2107.     0xFF, 0xDE, 0x7B, 0xFE,        /* 11111111 11011110 01111011 11111110    */
  2108.     0xFF, 0xCC, 0x31, 0xFE,        /* 11111111 11001100 00110001 11111110    */
  2109.     0x8C, 0x4C, 0x31, 0x82,        /* 10001100 01001100 00110001 10000010    */
  2110.     0x0C, 0x0C, 0x31, 0x80,        /* 00001100 00001100 00110001 10000000    */
  2111.     0x0C, 0x0C, 0x31, 0x90,        /* 00001100 00001100 00110001 10010000    */
  2112.     0x0C, 0x0F, 0xF1, 0xF0,        /* 00001100 00001111 11110001 11110000    */
  2113.     0x0C, 0x0F, 0xF1, 0xF0,        /* 00001100 00001111 11110001 11110000    */
  2114.     0x0C, 0x0C, 0x31, 0x90,        /* 00001100 00001100 00110001 10010000    */
  2115.     0x0C, 0x0C, 0x31, 0x80,        /* 00001100 00001100 00110001 10000000    */
  2116.     0x0C, 0x0C, 0x31, 0x82,        /* 00001100 00001100 00110001 10000010    */
  2117.     0x0C, 0x0C, 0x31, 0xFE,        /* 00001100 00001100 00110001 11111110    */
  2118.     0x1E, 0x1E, 0x7B, 0xFE,        /* 00011110 00011110 01111011 11111110    */
  2119.     };
  2120.  
  2121. void cdecl main(int argc,char *argv[])
  2122. {
  2123.     int        maxx,maxy,x,y;
  2124.     color_t    maxcolor;
  2125.  
  2126.     init_graphics("MGL_putMonoImage test",argc,argv);
  2127.  
  2128.     maxx = MGL_maxx();
  2129.     maxy = MGL_maxy();
  2130.     maxcolor = MGL_maxColor();
  2131.  
  2132.     for (x = 0; x < maxx; x += 40)
  2133.         for (y = 0; y < maxy; y += sizeof(image)/4 + 2) {
  2134.             MGL_setColor((x + y) % (maxcolor+1));
  2135.             MGL_putMonoImage(x,y,4,sizeof(image)/4,image);
  2136.             }
  2137.  
  2138.     exit_graphics();
  2139. }
  2140.  
  2141. #endif
  2142.