home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / Concentration / Help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-24  |  2.1 KB  |  100 lines  |  [TEXT/KAHL]

  1. # include    "TransSkel.h"
  2. # include    "TransDisplay.h"
  3.  
  4. # include    "Concentration.h"
  5.  
  6.  
  7.  
  8. static WindowPtr    helpWind = nil;
  9.  
  10.  
  11. /* ---------------------------------------------------------------- */
  12. /*                    General Display Window Routines                    */
  13. /* ---------------------------------------------------------------- */
  14.  
  15.  
  16. static pascal void
  17. DWindActivate (Boolean active)
  18. {
  19. WindowPeek    w;
  20.  
  21.     if (!active)    /* deactivated - was it closed? */
  22.     {
  23.         GetPort ((GrafPtr *) &w);
  24.         if (w->visible == 0)
  25.         {
  26.             SkelRmveWind ((WindowPtr) w);    /* yes - remove it */
  27.             if ((WindowPtr) w == helpWind)
  28.                 helpWind = nil;
  29.         }
  30.     }
  31. }
  32.  
  33.  
  34. /*
  35.  * Build a display window.  NewDWindow makes it the current output
  36.  * window for display output.
  37.  */
  38.  
  39. static void
  40. DisplayWindow (StringPtr title, Boolean visible)
  41. {
  42. WindowPtr    w;
  43. Rect                r;
  44. static int            i = 0;
  45. int        h, v;
  46.  
  47.     if (i < 1)
  48.         i = 1;
  49.     h = i * 23 + 5;
  50.     v = h + 65;
  51.     SetRect (&r, h, v, h + 350, v + 200);
  52.     SetDWindowNotify (nil, DWindActivate);
  53.     w = NewDWindow (&r, title, visible, (WindowPtr) -1L, true, 0L);
  54.     if (++i == 4)
  55.         i = 0;
  56. }
  57.  
  58.  
  59. /* ---------------------------------------------------------------- */
  60. /*                        Help Window Routines                        */
  61. /* ---------------------------------------------------------------- */
  62.  
  63.  
  64. /*
  65.  * Create help window, unless it already exists - in which case 
  66.  * simply pull it to the front.
  67.  */
  68.  
  69.  
  70. void
  71. HelpWindow (void)
  72. {
  73. WindowPtr    curDispWind;
  74. Rect    r;
  75. Handle    h;
  76.  
  77.     if (helpWind == nil)
  78.     {
  79.         curDispWind = GetDWindow ();    /* get current display window */
  80.         SetRect (&r, 40, 50, 450, 280);
  81.         helpWind = NewDWindow (&r, "\pHelp Window", false, (WindowPtr) -1L, true, 0L);
  82.         SetDWindowNotify (helpWind, DWindActivate);
  83.         SetDWindowStyle (helpWind, 0, 0, 1, teJustLeft);
  84.  
  85.         h = GetResource ('TEXT', helpTextNum);    /* read help text */
  86.         HLock (h);                            /* lock it and write to window */
  87.         DisplayText (*h, GetHandleSize (h));
  88.         HUnlock (h);
  89.         ReleaseResource (h);            /* done with it, so goodbye */
  90.         SetDWindowPos (helpWind, 0);    /* scroll back to top */
  91.         SetDWindow (curDispWind);        /* restore previous help window */
  92.     }
  93.     if (helpWind != nil)
  94.     {
  95.         SelectWindow (helpWind);
  96.         ShowWindow (helpWind);
  97.         SkelDoEvents (updateEvt + activateEvt);
  98.     }
  99. }
  100.