home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / raytrace / radiance / simplerd.lha / simplerad / FinalFTP / WalkT / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-22  |  6.5 KB  |  194 lines

  1. /**********************************************************************/
  2. /* help.c :                                                           */
  3. /*                                                                    */
  4. /* Help window for program.                                           */
  5. /*                                                                    */
  6. /* Copyright (C) 1992, Bernard Kwok                                   */
  7. /* All rights reserved.                                               */
  8. /* Revision 1.0                                                       */
  9. /* May, 1992                                                          *
  10. /**********************************************************************/
  11. #include <stdio.h>
  12. #include <fcntl.h>
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15. #include <errno.h>
  16. #include <string.h>
  17. #include <gl/gl.h>
  18. #include <gl/device.h>
  19. #include <fmclient.h>
  20. #ifdef RELEASE3.2
  21. #include <malloc.h>
  22. #else
  23. #include <stdlib.h>
  24. #endif
  25. #define IRIS4D 1
  26. #include "geo.h"
  27. #include "walk.h"
  28.  
  29. /* Text fonts */
  30. extern fmfonthandle FontScreen, FontScreen5, FontScreen8, FontScreen10;
  31. extern fmfontinfo FontScreenInfo, FontScreen5Info, FontScreen8Info, 
  32.     FontScreen10Info;
  33.  
  34. /* Size of help window, window id, and title */
  35. static long HelpYsize;
  36. static long HelpXsize;
  37. long HelpWid = -1;
  38. static char *HelpTitle = "Help for Walk";
  39.  
  40. /* Help text */
  41. static char **Lines = 0;
  42. char HelpText[] = "This program uses the properties of polygons\ninput in order to render the model.\n\nThe following describes the functionality of each mouse button.\n\nLeft              : Rotate the viewer about axis of the camera.\nMiddle            : Translate the viewer about axis of the camera.\nLeft+Right        : Zoom in or out of the model.\nLeft+Middle+Right : Scale in the z plane.\n\nThe following describes the functionality of each button in the main menu.\n\nHelp              : Click the HELP option for this help.\nDebug             : Print or suppress debugging messages.\nScene             : Options menu for scene.\nLog               : Options menu for logging movement.\n\nThe Scene menu allows options for:\n\nSave Image        : Save current image as RGB or black and white.\nGouraud or Flat   : Change to/from Gouraud to flat shading.\nTriangle or\nQuadralateral     : Change to/from quadralateral to trianguler meshed\n                    shading.\nScale             : Scale RGB values of polygons.\n\nThe Log menu allows options for:\n\nClear             : Clear log of movements.\nStart             : Start logging camera movements.\nStop              : Stop logging camera movements.\nSave              : Save current log to output file\nAutomate          : Read and exectute movements saved in file.\n\nCurrently only saving to IRIS imagelib image format is implemented\n";
  43.  
  44. static int NumLines = 0;          /* Number of lines of help */
  45.  
  46. /**********************************************************************/
  47. void InitHelp();
  48. long InitHelpWindow();
  49. void DoEventsHelp();
  50. void DrawHelp();
  51. long CloseHelpWindow();
  52. void DoExitHelp();
  53.  
  54. /**********************************************************************/
  55. /* InitHelpWindow() - Display help window                             */
  56. /**********************************************************************/
  57. long InitHelpWindow(Wname)
  58.      char *Wname;
  59. {
  60.   long Wid;
  61.  
  62.   foreground();
  63.   prefsize(HelpXsize, HelpYsize);
  64.   Wid = winopen(HelpTitle);
  65.   if (Wid == -1) {
  66.     fprintf(stderr, "No additional graphics windows are available\n");
  67.     return -1;
  68.   }
  69.   gconfig();
  70.   return Wid;
  71. }
  72.  
  73. /**********************************************************************/
  74. /* CloseHelpWindow() - Close help window, retrun window down.         */
  75. /**********************************************************************/
  76. long CloseHelpWindow(Wid)
  77.      long Wid;
  78. {
  79.   winclose(Wid);
  80.   return -1;
  81. }
  82.  
  83. /**********************************************************************/
  84. /* Allocate space for help text */
  85. /**********************************************************************/
  86. void InitHelp(Text)
  87.      char Text[];
  88. {
  89.   char *c;
  90.   int line;
  91.   int num_chars, count;
  92.   int file;
  93.   FILE *fptr;
  94.   int length;
  95.   static help_initialized = 0;
  96.  
  97.   if (help_initialized) return;
  98.     
  99.   /* Find number of characters and number of lines, allocate space */
  100.   for(num_chars = 0; Text[num_chars] != 0; num_chars++);
  101.   for (c = Text; *c != 0; c++) {
  102.     if (*c == '\n')
  103.       NumLines++;
  104.   }
  105.   NumLines++;
  106.   
  107.   Lines = (char **) malloc(NumLines * sizeof(char *));
  108.   
  109.   line = 0;
  110.   Lines[line++] = Text;
  111.   
  112.   for (c = Text; *c != 0; c++)
  113.     if (*c == '\n') {
  114.       *c = 0;
  115.       Lines[line++] = c + 1;
  116.     }
  117.   
  118.   /* Calculate x,y window size from text and font size */
  119.   HelpYsize = NumLines * FontScreen10Info.height + 4;
  120.   HelpXsize = 0;
  121.   
  122.   for (line = 0; line < NumLines; line++) {
  123.     length = fmgetstrwidth(FontScreen10, Lines[line]);
  124.     if (HelpXsize < length)
  125.       HelpXsize = length;
  126.   }
  127.   HelpXsize += 4;
  128.  
  129.   help_initialized = 1;
  130. }
  131.  
  132. /**********************************************************************/
  133. /* Draw help text                                                     */
  134. /**********************************************************************/
  135. void DrawHelp()
  136. {
  137.   int line;
  138.   long x, y, space;
  139.  
  140.   color(BLUE); clear();           /* Clear background                 */  
  141.   color(YELLOW);                  /* Draw help text                   */
  142.   fmsetfont(FontScreen10);
  143.   space = FontScreen10Info.height;
  144.   x = 2;
  145.   y = HelpYsize - space;
  146.  
  147.   for (line = 0; line < NumLines; line++) {
  148.     cmov2i(x, y);
  149.     fmprstr(Lines[line]);
  150.     y -= space;
  151.   }
  152. }
  153.  
  154. /**********************************************************************/
  155. /* Exit help window */
  156. /**********************************************************************/
  157. void DoExitHelp(rc)
  158.     int rc;
  159. {
  160.   if (Lines) free(Lines);
  161.   rc = CloseHelpWindow(HelpWid);
  162. }
  163.  
  164. /**********************************************************************/
  165. /* Handle events for help window */
  166. /**********************************************************************/
  167. void DoEventsHelp(dev, val)
  168.      long dev;
  169.      short val;
  170. {
  171.   /* On redraw, redraw help text */
  172.   winset(HelpWid);
  173.   switch(dev) {
  174.   case REDRAW:
  175.     reshapeviewport();
  176.     DrawHelp();
  177.     break;
  178.   default: break;
  179.   }
  180. }
  181.  
  182. /**********************************************************************/
  183. /* Pop/unpop help */
  184. /**********************************************************************/
  185. void DoHelp()
  186. {
  187.   if (HelpWid == -1) {
  188.     InitHelp();
  189.     HelpWid = InitHelpWindow(HelpTitle);
  190.     DrawHelp();
  191.   } else
  192.     HelpWid = CloseHelpWindow(HelpWid);
  193. }
  194.