home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 (1993) / nebula.bin / SourceCode / MiniExamples / ZooView / RightSubView.m < prev    next >
Encoding:
Text File  |  1991-10-10  |  1.3 KB  |  61 lines

  1.  
  2. /* 
  3.  * RightSubView.m
  4.  *
  5.  * Purpose:
  6.  *        This object simply blasts an image to itself. Knows the name of the
  7.  *        image, too.
  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.  * Written by: Mary McNabb
  14.  * Created: Apr 91
  15.  *
  16.  */
  17.  
  18. #import "RightSubView.h"
  19. #import <dpsclient/psops.h>
  20. #import <appkit/NXImage.h>
  21. #import <string.h>
  22.  
  23. @implementation RightSubView
  24.  
  25. - drawSelf:(const NXRect *)r :(int)c
  26. {
  27.     NXPoint position;
  28.     NXSize animalSize;
  29.     
  30.     id image = [NXImage findImageNamed:animalName];
  31.         
  32.         /* figure out the position of the lower left hand corner */
  33.     [image getSize:&animalSize];
  34.     position.x = bounds.size.width / 2.0 - animalSize.width / 2.0;
  35.     position.y = bounds.size.height / 2.0 - animalSize.height / 2.0;
  36.     if (position.x < 0) position.x = bounds.origin.x;
  37.     if (position.y < 0) position.y = bounds.origin.y;
  38.     
  39.         /* draw background first to cover up old image */
  40.     PSsetgray(NX_LTGRAY);
  41.     NXRectFill(r);
  42.     [image composite:NX_SOVER toPoint:&position];
  43.     [image free];
  44.     PSsetgray(NX_DKGRAY);
  45.     NXFrameRect(r);
  46.     
  47.     return self;
  48. }
  49.  
  50. /*
  51.  * just remember the name of the picture
  52.  */
  53. - setAnimalPicture:(char *) path
  54. {
  55.     strcpy(animalName, path);
  56.     [self display];
  57.     return self;
  58. }
  59.  
  60. @end
  61.