home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Utilities / Fiend-1.4.1-src / BackView.m < prev    next >
Encoding:
Text File  |  1994-10-21  |  2.3 KB  |  107 lines

  1. //  BackView.m
  2. //
  3. //  a View that provides some functionality that some screen savers might
  4. //  find useful; you can subclass this class if you like.
  5. //
  6. //  You may freely copy, distribute, and reuse the code in this example.
  7. //  NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  8. //  fitness for any particular use.
  9.  
  10. #import "BackView.h"
  11. #import "Thinker.h"
  12. #import <mach/mach.h>
  13. #import <appkit/NXImage.h>
  14. #import <dpsclient/wraps.h>
  15. #import <libc.h>
  16.  
  17. @implementation BackView
  18.  
  19. - (BOOL) timePassed: (BStimeval) delay
  20. {
  21.     BStimeval now, msec;
  22.     BOOL result;
  23.     
  24.     now = currentTimeInMs();
  25.     if (BVthen == 0)        // added by shou-h@nexus.or.jp
  26.         BVthen = now;        // added by shou-h@nexus.or.jp
  27.     msec = now - BVthen;
  28.  
  29.     //so as not to suck too many cycles, if I'm waiting for some
  30.     // time more than a tenth of a second in the future, I sleep
  31.     // a while.  This interval is short enough that the app shouldn't
  32.     // seem unresponsive to user actions.
  33.     
  34.     // ok, so you'd never pull this trick if the user had to type.
  35.     // A better solution would be to coordinate the timed entry better,
  36.     // but I get slightly better performance from spinning in my
  37.     // timed entry (a bad idea for most apps...)
  38.     
  39.     if ((msec + 120) < delay)    {
  40.         thread_switch(THREAD_NULL, SWITCH_OPTION_WAIT, 110);
  41. //        usleep(110000);
  42.         return NO;
  43.     }
  44.     
  45.     result = (msec > delay);
  46.     if (result) BVthen = now;
  47.  
  48.     return result;
  49. }
  50.  
  51. - initFrame:(const NXRect *)frameRect
  52. {
  53.     [super initFrame:frameRect];
  54.     [self allocateGState];        // For faster lock/unlockFocus
  55.  
  56.     srandom(time(0));
  57.  
  58.     [self setImageConstraints];
  59.     return self;
  60. }
  61.  
  62. - sizeTo:(NXCoord)width :(NXCoord)height
  63. {
  64.     [super sizeTo:width :height];
  65.     [self setImageConstraints];
  66.     return self;
  67. }
  68.  
  69. - drawSelf:(const NXRect *)rects :(int)rectCount
  70. {
  71.     if (!rects || !rectCount) return self;
  72.  
  73.     PSsetgray(0);
  74.     NXRectFill(rects);
  75.  
  76.     return self;
  77. }
  78.  
  79. - setImageConstraints
  80. {
  81.     maxCoord.x = bounds.size.width - imageRect.size.width;
  82.     maxCoord.y = bounds.size.height - imageRect.size.height;
  83.     if (maxCoord.x < 0) maxCoord.x = 0;
  84.     if (maxCoord.y < 0) maxCoord.y = 0;
  85.  
  86.     return self;
  87. }
  88.  
  89.  
  90. - setImage: newImage
  91. {
  92.     image = newImage;
  93.     [image getSize: &imageRect.size];
  94.  
  95.     [self setImageConstraints];
  96.     [self display];
  97.  
  98.     return self;
  99. }
  100.  
  101. - (BOOL) useBufferedWindow
  102. {
  103.     return YES; // by default; can be overridden in subclasses
  104. }
  105.  
  106. @end
  107.