home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Examples / Robby / Starter.m < prev   
Encoding:
Text File  |  1995-11-27  |  3.3 KB  |  136 lines

  1. /*
  2.  
  3. Starter.m
  4. Robby
  5. Sean Luke
  6. August 14, 1995
  7. MiscKit Example
  8.  
  9. Permission to use, copy, modify, and distribute this material 
  10. for any purpose and without fee, under the restrictions as noted 
  11. in the MiscKit copyright notice, is hereby granted, provided that
  12. the MiscKit copyright notice and this permission notice 
  13. appear in all source copies, and that the author's name shall not
  14. be used in advertising or publicity pertaining to this 
  15. material without the specific, prior written permission 
  16. of the author.  SEAN O. LUKE  MAKES NO REPRESENTATIONS ABOUT THE
  17. ACCURACY OR SUITABILITY OF THIS MATERIAL FOR ANY PURPOSE.  
  18. IT IS PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  19.  
  20. */
  21.  
  22.  
  23. #import "Starter.h"
  24. #import <misckit/MiscVolumeLight.h>
  25. #import <misckit/MiscTapper.h>
  26. #include <misckit/MiscAppIcon.h>
  27. //#include "MiscAppIcon.h"
  28. #include <stdio.h>
  29. #include <string.h>
  30.  
  31. @implementation Starter
  32.  
  33. /*
  34. Starter is the main object of Robby.  It does four things, basically:
  35.  
  36. 0)  init sets up the MiscTapper
  37. 1)  appDidInit sets up the MiscVolumeLight (which is in an off-screen window)
  38. 2)  meterWillUpdateOnOwn is a delegate method of the MiscVolumeLight, which
  39.     is called _before_ the MiscVolumeLight locks focus and redraws itself.  
  40.     This gives Starter a chance to spit a blank app tile in the background for 
  41.     the Volume Light to draw on top of.  If you launch Robby from the
  42.     Workspace, this isn't necessary since the Workspace owns the app icon
  43.     and makes sure there's a nice background for it.  But if you launch Robby
  44.     from the Terminal (calling, say, Robby.app/Robby) then Robby owns the
  45.     app icon and you have to draw the little beveled, shaded-gray look
  46.     yourself.  cleanTileToWindow: does this for you.
  47. 3)  meterDidUpdate, another delegate method of MiscVolumeLight, tells Starter
  48.     that the meter has finished drawing itself in the window.  So Starter
  49.     then procedes to splat the resultant window image onto the app icon by
  50.     calling windowToAppIcon:.
  51.  
  52. Modifications
  53. January 1993:  Created original version of Robby
  54. August 14, 1995:  Ported Robby to be a MiscKit example
  55.  
  56. */
  57.  
  58. - init
  59.     {
  60.     tapper=[[MiscTapper alloc] init];
  61.     return [super init];
  62.     }
  63.     
  64.  
  65. - appDidInit:sender
  66.     {
  67.     const NXDefaultsVector TheDefaults = {{"Output","YES"},{NULL,NULL}};
  68.     NXRegisterDefaults ([NXApp appName], TheDefaults);
  69.     
  70.     if (!strcmp(NXGetDefaultValue ([NXApp appName],"Output"), "NO"))
  71.         {
  72.         [volume_light setToInput];
  73.         [toggle_menu setTitle:"Listening"];
  74.         [tapper run:self];
  75.         output=NO;
  76.         } 
  77.     else 
  78.         {
  79.         [volume_light setToOutput];
  80.         [toggle_menu setTitle:"Talking    "];
  81.         [tapper stop:self];
  82.         output=YES;
  83.         }
  84.         
  85.     [volume_light setBezeled:YES];
  86.     [volume_light setDelegate:self];
  87.  
  88.     [volume_light run];
  89.     return self;
  90.     }
  91.  
  92.  
  93. - meterWillUpdateOnOwn:sender
  94.     {
  95.     return [NXApp cleanTileToWindow:hidden_window];    
  96.         // A MiscAppIcon category method
  97.     }
  98.  
  99.  
  100. - meterDidUpdate:sender
  101.     {
  102.     return [NXApp windowToAppIcon:hidden_window];    
  103.         // A MiscAppIcon category method
  104.     }
  105.  
  106.  
  107. - toggleInputOutput:sender
  108.     {
  109.     if (output) 
  110.         {
  111.         [volume_light setToInput];
  112.         [toggle_menu setTitle:"Listening"];
  113.         [tapper run:self];
  114.         output=NO;
  115.         }
  116.     else
  117.         {
  118.         [volume_light setToOutput];
  119.         [toggle_menu setTitle:"Talking    "];
  120.         [tapper stop:self];
  121.         output=YES;
  122.         }
  123.     NXWriteDefault([NXApp appName],
  124.         "Output", output? "YES":"NO");
  125.     return self;
  126.     }
  127.     
  128. - free
  129.     {
  130.     [tapper stop:self];
  131.     [tapper free];
  132.     return [super free];
  133.     }
  134.  
  135. @end
  136.