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

  1. /*
  2.  * Copyright 1991, 1992, 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 "demograph.h"
  20. #include "kurtfont.h"
  21.  
  22. #define MARGIN 3
  23. #define FPSSTRING "Frames per second: "
  24. #define FPSCHARS 5    /* number of characters for float */
  25. #define FPSLEN (strlen(FPSSTRING) + MARGIN * 2 + FPSCHARS)
  26.  
  27. #define DATASTR "Data: "
  28. #define DATASTRLEN 6
  29.  
  30. extern WINREC winrec;
  31. extern CATEGORY *curcategory;
  32.  
  33. FONTREC title;
  34. FONTREC fps;
  35. FONTREC curdate;
  36.  
  37.  
  38. void writetitle(str)
  39. char *str;
  40. {
  41.     static char datastr[MAXDATA+DATASTRLEN+1];
  42.  
  43.     /* clear the old title string */
  44.     setcolor(0xbb,0xbb,0xbb);
  45.     sboxfi ((int)(title.xoffset),(int)(title.yoffset),
  46.     (int)(title.xoffset + title.xscale * strlen(str) * 6.0),
  47.     (int)(title.yoffset + title.yscale * 9.0));
  48.  
  49.     /* draw the new title string */
  50.     setcolor(0,0,0);
  51.     linewidth(title.lwid);
  52.     sprintf(datastr,"%s%s",DATASTR,str);
  53.     stroke(title.xoffset,title.yoffset,0.0,title.xscale, title.yscale, 1.0, 
  54.     datastr);
  55.     linewidth(1);
  56. }
  57.  
  58.  
  59. void writefps(frames_per_sec)
  60. float frames_per_sec;
  61. {
  62.     static char fpsstr[32];
  63.  
  64.     sprintf(fpsstr,"%1.3f",frames_per_sec);
  65.  
  66.     frontbuffer(TRUE);
  67.  
  68.     /* clear old frames_per_second string */
  69.     setcolor(0xbb,0xbb,0xbb);
  70.     sboxfi ((int)(fps.xoffset),(int)(fps.yoffset),
  71.     (int)(fps.xoffset + fps.xscale * strlen(fpsstr) * 6.0),
  72.     (int)(fps.yoffset + fps.yscale * 9.0));
  73.  
  74.     /* draw the new text */
  75.     setcolor(0,0,0);
  76.     linewidth(fps.lwid);
  77.     stroke(fps.xoffset,fps.yoffset,0.0,fps.xscale, fps.yscale, 1.0, fpsstr);
  78.     linewidth(1);
  79.     frontbuffer(FALSE);
  80. }
  81.  
  82.  
  83. void writesliderdate(sliderdate, x)
  84. char *sliderdate;
  85. float x;
  86. {
  87.     linewidth(curdate.lwid);
  88.  
  89.     setcolor(0,0,0);
  90.     stroke(x+curdate.xoffset, curdate.yoffset, 0.0, curdate.xscale,
  91.     curdate.yscale, 1.0, sliderdate);
  92.     linewidth(1);
  93. }
  94.  
  95.  
  96. void init_text()
  97. {
  98.     register float sizex;
  99.     register int nchars;
  100.  
  101.     /* get font info for button */
  102.     curdate.xscale = winrec.scale;
  103.     curdate.yscale = winrec.scale;
  104.     curdate.xoffset = -(DATECHARS * 6.0)/2.0 * curdate.xscale;
  105.     curdate.yoffset =
  106.     ((winrec.sliderminy+winrec.slidermaxy)/2.0)-(3.5 * winrec.scale);
  107.  
  108.     /* get font info for title */
  109.     nchars = DATASTRLEN + MAXTITLE + (MARGIN * 2);
  110.     if (FPSLEN > nchars && winrec.fps) {
  111.     nchars = FPSLEN;
  112.     }
  113.     sizex = (winrec.statmaxx - winrec.statminx + winrec.scale) / 2.0;
  114.     title.xscale = sizex / (nchars * 6.0);
  115.     title.yscale = winrec.scale;
  116.     title.yoffset = (winrec.statmaxy+winrec.statminy)/2.0 - title.yscale * 3.5;
  117.     if (!winrec.fps) { /* center justified */
  118.     title.xoffset = (sizex - winrec.scale) - 
  119.         ((((strlen(curcategory->title) + DATASTRLEN)*6.0)/ 2.0) * title.xscale);
  120.     } else { /* left justified */
  121.     title.xoffset = MARGIN * 6.0 * title.xscale;
  122.  
  123.     /* set up frames_per_second text structure */
  124.     fps.xscale = title.xscale;
  125.     fps.yscale = title.yscale;
  126.     fps.yoffset = title.yoffset;
  127.     fps.xoffset = (winrec.statmaxx - sizex - winrec.scale) 
  128.         + MARGIN * 6.0 * fps.xscale;
  129.     fps.lwid = (int)(winrec.scale);
  130.     /* draw permanent text now and update leater */
  131.     linewidth(fps.lwid);
  132.     setcolor(0,0,0);
  133.     stroke(fps.xoffset,fps.yoffset,0.0,
  134.         fps.xscale,fps.yscale,1.0,FPSSTRING);
  135.     fps.xoffset += (float)(strlen(FPSSTRING)) * 6.0 * fps.xscale;
  136.     linewidth(1);
  137.     }
  138.     curdate.lwid = title.lwid = (int)(winrec.scale);
  139. }
  140.  
  141.  
  142. stroke(tx,ty,tz,sx,sy,sz,str)
  143. float tx,ty,tz,sx,sy,sz;
  144. char *str;
  145. {
  146.     register int i, mode;
  147.  
  148.     pushmatrix();
  149.     translate(tx,ty,tz);
  150.     scale(sx,sy,sz);
  151.     for (; *str; str++) {
  152.     if (chrtbl[*str][0][0]) {
  153.         for (i=0; mode = chrtbl[*str][i][0]; i++) {
  154.         switch (mode) {
  155.         case 1:
  156.             translate(
  157.               (float)chrtbl[*str][i][1],
  158.               (float)chrtbl[*str][i][2],
  159.               0.0);
  160.             break;
  161.         case 2:
  162.             bgnline();
  163.             v2i(&chrtbl[*str][i][1]);
  164.             break;
  165.         case 3:
  166.             v2i(&chrtbl[*str][i][1]);
  167.             break;
  168.         case 4:
  169.             v2i(&chrtbl[*str][i][1]);
  170.             endline();
  171.             break;
  172.         }
  173.         }
  174.     }
  175.     }
  176.     popmatrix();
  177. }
  178.