home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / avogl.tar.gz / avogl.tar / vogl / examples / moretxt.c < prev    next >
C/C++ Source or Header  |  1992-09-22  |  3KB  |  195 lines

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