home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / demobook / text3d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.0 KB  |  139 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18. #include <gl.h>
  19. #include "screenfont.h"
  20. #include "exglobals.h"
  21. #include "exbookglo.h"
  22.  
  23. extern int find_blank(char *s);
  24.  
  25. /***********************************************************************
  26. *
  27. * draw_demoname draws the name of each icon.  If a name is more
  28. * than 10 characters long, it is chopped at the first blank and
  29. * drawn on two lines.  Before draw_demoname is called, we are
  30. * translated to the left side of the box where the name will be drawn.
  31. *
  32. ***********************************************************************/
  33. void draw_demoname(struct icntmpltstruct *iconptr)
  34. {
  35.    float x_offset;
  36.    int len;
  37.    char *s1, *s2, *s3;
  38.    int blankpos1, blankpos2;
  39.    
  40.    c3s(morecolors[Black]);
  41.  
  42.    len = strlen(iconptr->nameptr->string);
  43. /* A square on the page = 2 inches.  10 characters fit inside
  44.    the highlight box. Each highlight box is scaled .9 in x & y.
  45.    = 1.8 inches = .18 units per character */
  46.    if (len < 11)
  47.       {
  48.       x_offset = 1.0 - (float)len/2.0 *.18;
  49.       stroke(x_offset, 0.0, 0.0, .02, .02, .02, iconptr->nameptr->string);
  50.       }
  51.    else
  52.       {
  53.       blankpos1 = find_blank(iconptr->nameptr->string);
  54.       if (blankpos1 >= 0)
  55.          {
  56.          blankpos2 = find_blank(&(iconptr->nameptr->string[blankpos1+1]));
  57.          if (blankpos2 > 0 && blankpos1 + blankpos2 < 12)
  58.             blankpos1 = blankpos2 + blankpos1+1;
  59.          s1 = (char *)malloc(blankpos1+1);
  60.          strncpy(s1, iconptr->nameptr->string, blankpos1);
  61.          s1[blankpos1] = '\0';
  62.          s2 = (char *)malloc(len - blankpos1);
  63.          strcpy(s2, &(iconptr->nameptr->string[blankpos1+1]) );
  64.          x_offset = 1.0 - (float)(blankpos1-1)/2.0 *.18;
  65.          stroke(x_offset, 0.28, 0.0, .017, .017, .017, s1);
  66.  
  67.          len = strlen(s2);
  68.          if (len > 11)
  69.             {
  70.             s2[7] = '.';
  71.             s2[8] = '.';
  72.             s2[9] = '.';
  73.             s2[10] = '\0';
  74.             len = 10;
  75.             }
  76.          x_offset = 1.0 - (float)(len-1)/2.0 *.18;
  77.          stroke(x_offset, 0.0, 0.0, .017, .017, .017, s2);
  78.          free(s1);
  79.          free(s2);
  80.          }
  81.       else  /* no blanks in the name */
  82.          {
  83.          s1 = (char *)malloc(11);
  84.          strncpy(s1, iconptr->nameptr->string, 7);
  85.          s1[7] = '.';
  86.          s1[8] = '.';
  87.          s1[9] = '.';
  88.          s1[10] = '\0';
  89.          x_offset = 1.0 - 10.0/2.0 *.18;
  90.          stroke(x_offset, 0.0, 0.0, .02, .02, .02, s1);
  91.          }
  92.       }
  93. }
  94.  
  95. stroke(tx,ty,tz,sx,sy,sz,str)
  96. float tx,ty,tz,sx,sy,sz;
  97. char *str;
  98. {
  99.     register int i, mode;
  100.  
  101.     pushmatrix();
  102.     translate(tx,ty,tz);
  103.     scale(sx,sy,sz);
  104.     for (; *str; str++) {
  105.     if (chrtbl[*str][0][0]) {
  106.         for (i=0; mode = chrtbl[*str][i][0]; i++) {
  107.         switch (mode) {
  108.         case 1:
  109.             translate(
  110.               (float)chrtbl[*str][i][1],
  111.               (float)chrtbl[*str][i][2],
  112.               0.0);
  113.             break;
  114.         case 2:
  115.             bgnline();
  116.             v2i(&chrtbl[*str][i][1]);
  117.             break;
  118.         case 3:
  119.             v2i(&chrtbl[*str][i][1]);
  120.             break;
  121.         case 4:
  122.             v2i(&chrtbl[*str][i][1]);
  123.             endline();
  124.             break;
  125.                 case 5:
  126.                     bgnpolygon();
  127.                     v2i(&chrtbl[*str][i][1]);
  128.                     break;
  129.                 case 6:
  130.                     v2i(&chrtbl[*str][i][1]);
  131.                     endpolygon();
  132.                     break;
  133.         }
  134.         }
  135.     }
  136.     }
  137.     popmatrix();
  138. }
  139.