home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / VOGLE / EXAMPLES / MORETXT.C < prev    next >
C/C++ Source or Header  |  2000-02-11  |  3KB  |  186 lines

  1. #include <stdio.h>
  2. #include "vogle.h"
  3.  
  4. /*
  5.  * drawgrid
  6.  *
  7.  *    draw a grid in the middle of the screen
  8.  */
  9. drawgrid()
  10. {
  11.     float    x;
  12.     int    i;
  13.  
  14.     color(GREEN);
  15.  
  16.     rect(0.1, 0.4, 0.9, 0.6);
  17.  
  18.     x = 0.2;
  19.     for (i = 0; i < 8; i++) {
  20.         move2(x, 0.4);
  21.         draw2(x, 0.6);
  22.         x += 0.1;
  23.     }
  24.     move2(0.1, 0.5);
  25.     draw2(0.9, 0.5);
  26.  
  27.     color(YELLOW);
  28. }
  29.  
  30. /*
  31.  * demonstrate some more features of text
  32.  */
  33. main(argc, argv)
  34.     int    argc;
  35.     char    **argv;
  36. {
  37.     char    dev[20];
  38.     int    i;
  39.     float    x;
  40.     
  41.     fprintf(stderr, "Enter device: ");
  42.     gets(dev);
  43.  
  44.     vinit(dev);
  45.  
  46.     color(BLACK);
  47.     clear();
  48.  
  49.     if (argc == 2)
  50.         font(argv[1]);
  51.  
  52.     ortho2(0.0, 1.0, 0.0, 1.0);
  53.  
  54.     drawgrid();
  55.  
  56.     /*
  57.      * show some scaled text on the grid (In the bottom part)
  58.      */
  59.     boxtext(0.1, 0.4, 0.8, 0.1, "{This is Some text] | $");
  60.  
  61.     getkey();
  62.  
  63.     color(BLACK);
  64.     clear();
  65.  
  66.     drawgrid();
  67.  
  68.     /*
  69.      * centertext causes text to be centered around the current graphics
  70.      * position this is especially usefull if you want your text to come
  71.      * out centered on a line, or a character to be centered on a point
  72.      * in a graph. A non-zero argument turns centertext on.
  73.      *
  74.      * show a string centered on the center line
  75.      */
  76.     centertext(1);
  77.  
  78.     boxtext(0.5, 0.5, 0.8, 0.1, "{This is Some Centered text] | $");
  79.  
  80.     /*
  81.      * turn centertext off. We use an argument with the value zero.
  82.      */
  83.     centertext(0);
  84.  
  85.     getkey();
  86.  
  87.     color(BLACK);
  88.     clear();
  89.  
  90.     /*
  91.      * rotate the grid so that it is the same angle as the text after
  92.      * textang for text ang.
  93.      */
  94.     pushmatrix();
  95.         translate(0.5, 0.5, 0.0);
  96.         rotate(90.0, 'z');
  97.         translate(-0.5, -0.5, 0.0);
  98.  
  99.         drawgrid();
  100.     popmatrix();
  101.  
  102.     /*
  103.      * turn on centered text again
  104.      */
  105.     centertext(1);
  106.  
  107.     /*
  108.      * set the angle to 90.
  109.      */
  110.     textang(90.0);
  111.  
  112.     /*
  113.      * draw the string
  114.      */
  115.     boxtext(0.5, 0.5, 0.8, 0.1, "{This is Some Rotated Centered text] | $");
  116.  
  117.     /*
  118.      * turn off center text
  119.      */
  120.     centertext(0);
  121.  
  122.     /*
  123.      * set text angle back to 90
  124.      */
  125.     textang(0.0);
  126.  
  127.     getkey();
  128.  
  129.     color(BLACK);
  130.     clear();
  131.  
  132.     drawgrid();
  133.  
  134.     /*
  135.      * as all the software fonts are proportionally spaced we use
  136.      * the fixedwidth call to make each character take the same amount
  137.      * of horizontal space. As with centertext this is done by passing
  138.      * fixedwidth a non-zero argument.
  139.      */
  140.     fixedwidth(1);
  141.  
  142.     boxtext(0.1, 0.5, 0.8, 0.1, "{This is Some Fixedwidth text] | $");
  143.  
  144.     getkey();
  145.  
  146.     color(BLACK);
  147.     clear();
  148.  
  149.     drawgrid();
  150.  
  151.     /*
  152.      * now try centered and fixewidth at the same time
  153.      */
  154.     centertext(1);
  155.  
  156.     move2(0.5, 0.5);
  157.     drawstr("{This is Some Cent.Fixedwidth text] | $");
  158.  
  159.     centertext(0);
  160.     
  161.     getkey();
  162.     color(BLACK);
  163.     clear();
  164.  
  165.     drawgrid();
  166.  
  167.     /*
  168.      * scale the text so tha a character is the size of a box in
  169.      * the grid.
  170.      */
  171.     boxfit(0.8, 0.1, 8);
  172.  
  173.     /*
  174.      * draw the two strings fixedwidth (it is still turned on)
  175.      */
  176.     move2(0.1, 0.4);
  177.     drawstr("ABCDefgh");
  178.  
  179.     move2(0.1, 0.5);
  180.     drawstr("IJKLmnop");
  181.  
  182.     getkey();
  183.  
  184.     vexit();
  185. }
  186.