Annotation of Examples/AppKit/BackspaceViews/SlidingImage/SlidingImageView.m, revision 1.1.1.1

1.1       root        1: //
                      2: //  SlidingImageView.m
                      3: //
                      4: //  Implements a sliding image screen saver view.
                      5: //
                      6: //  Lennart Lovstrand, August 1991.
                      7: //     small modifications by sam 910904
                      8: //
                      9: //  You may freely copy, distribute, and reuse the code in this example.
                     10: //  NeXT disclaims any warranty of any kind, expressed or  implied, as to its
                     11: //  fitness for any particular use.
                     12: 
                     13: #import "SlidingImageView.h"
                     14: #import "Thinker.h"
                     15: #import <appkit/NXImage.h>
                     16: #import <appkit/Panel.h>               // for NXRunAlertPanel()
                     17: #import <dpsclient/wraps.h>
                     18: #import <libc.h>
                     19: #import <math.h>
                     20: 
                     21: @implementation SlidingImageView
                     22: 
                     23: - drawSelf:(const NXRect *)rects :(int)rectCount
                     24: {
                     25:        NXPoint p;
                     26:        if (!rects || !rectCount) return self;
                     27: 
                     28:        [super drawSelf:rects :rectCount];
                     29:        
                     30:        p.x = floor(imageRect.origin.x);
                     31:        p.y = floor(imageRect.origin.y);
                     32: 
                     33:     [image composite: NX_SOVER toPoint: &p];
                     34: 
                     35:        return self;
                     36: }
                     37: 
                     38: - oneStep
                     39: {
                     40:        NXPoint p;
                     41:     PSsetgray(0);
                     42:     NXRectFill(&imageRect);
                     43:     
                     44:        usleep((1*1000000)/68);                                 //sleep a few vblanks
                     45:     imageRect.origin.x += delta.x;
                     46:     imageRect.origin.y += delta.y;
                     47: 
                     48:     if (imageRect.origin.x < 0)
                     49:        {
                     50:                imageRect.origin.x = 0;
                     51:                delta.x = randBetween(.8,1.3);
                     52:     }
                     53:        else if (imageRect.origin.x > maxCoord.x)
                     54:        {
                     55:                imageRect.origin.x = maxCoord.x;
                     56:                delta.x = -randBetween(.8,1.3);
                     57:     }
                     58: 
                     59:     if (imageRect.origin.y < 0)
                     60:        {
                     61:                imageRect.origin.y = 0;
                     62:                delta.y = randBetween(.8,1.3);
                     63:     }
                     64:        else if (imageRect.origin.y > maxCoord.y)
                     65:        {
                     66:                imageRect.origin.y = maxCoord.y;
                     67:                delta.y = -randBetween(.8,1.3);
                     68:     }
                     69: 
                     70:        p.x = floor(imageRect.origin.x);
                     71:        p.y = floor(imageRect.origin.y);
                     72: 
                     73:     [image composite: NX_SOVER toPoint: &p];
                     74: 
                     75:     return self;
                     76: }
                     77: 
                     78: - setImageConstraints
                     79: {
                     80:     [super setImageConstraints];
                     81: 
                     82:        if (imageRect.origin.x > maxCoord.x ||
                     83:                imageRect.origin.y > maxCoord.y)
                     84:        {
                     85:                imageRect.origin.x = randBetween(0, maxCoord.x);
                     86:                imageRect.origin.y = randBetween(0, maxCoord.y);
                     87:        }
                     88: 
                     89:        delta.x = randBetween(-1,1);
                     90:        delta.y = randBetween(-1,1);
                     91: 
                     92:     return self;
                     93: }
                     94: 
                     95: - inspector:sender
                     96: {
                     97:        return [sender commonImageInspector];
                     98: }
                     99: 
                    100: @end

unix.superglobalmegacorp.com

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