Annotation of Examples/AppKit/Backspace/BackView.m, revision 1.1.1.1

1.1       root        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 <appkit/NXImage.h>
                     13: #import <dpsclient/wraps.h>
                     14: #import <libc.h>
                     15: 
                     16: @implementation BackView
                     17: 
                     18: - (BOOL) timePassed: (BStimeval) delay
                     19: {
                     20:        BStimeval now, msec;
                     21:        BOOL result;
                     22:        
                     23:        now = currentTimeInMs();
                     24:        if (BVthen == 0)                // added by [email protected]
                     25:            BVthen = now;               // added by [email protected]
                     26:        msec = now - BVthen;
                     27: 
                     28:        //so as not to suck too many cycles, if I'm waiting for some
                     29:        // time more than a tenth of a second in the future, I sleep
                     30:        // a while.  This interval is short enough that the app shouldn't
                     31:        // seem unresponsive to user actions.
                     32:        
                     33:        // ok, so you'd never pull this trick if the user had to type.
                     34:        // A better solution would be to coordinate the timed entry better,
                     35:        // but I get slightly better performance from spinning in my
                     36:        // timed entry (a bad idea for most apps...)
                     37:        
                     38:        if ((msec + 120) < delay)
                     39:        {       usleep(110000);
                     40:                return NO;
                     41:        }
                     42:        
                     43:        result = (msec > delay);
                     44:        if (result) BVthen = now;
                     45: 
                     46:        return result;
                     47: }
                     48: 
                     49: - initFrame:(const NXRect *)frameRect
                     50: {
                     51:        [super initFrame:frameRect];
                     52:        [self allocateGState];          // For faster lock/unlockFocus
                     53: 
                     54:        srandom(time(0));
                     55: 
                     56:        [self setImageConstraints];
                     57:        return self;
                     58: }
                     59: 
                     60: - sizeTo:(NXCoord)width :(NXCoord)height
                     61: {
                     62:        [super sizeTo:width :height];
                     63:        [self setImageConstraints];
                     64:        return self;
                     65: }
                     66: 
                     67: - drawSelf:(const NXRect *)rects :(int)rectCount
                     68: {
                     69:        if (!rects || !rectCount) return self;
                     70: 
                     71:        PSsetgray(0);
                     72:        NXRectFill(rects);
                     73: 
                     74:        return self;
                     75: }
                     76: 
                     77: - setImageConstraints
                     78: {
                     79:        maxCoord.x = bounds.size.width - imageRect.size.width;
                     80:        maxCoord.y = bounds.size.height - imageRect.size.height;
                     81:        if (maxCoord.x < 0) maxCoord.x = 0;
                     82:        if (maxCoord.y < 0) maxCoord.y = 0;
                     83: 
                     84:        return self;
                     85: }
                     86: 
                     87: 
                     88: - setImage: newImage
                     89: {
                     90:        image = newImage;
                     91:        [image getSize: &imageRect.size];
                     92: 
                     93:        [self setImageConstraints];
                     94:        [self display];
                     95: 
                     96:        return self;
                     97: }
                     98: 
                     99: - (BOOL) useBufferedWindow
                    100: {
                    101:        return YES; // by default; can be overridden in subclasses
                    102: }
                    103: 
                    104: @end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.