home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / OOP_Course / Examples / DragDemo_1.1 / DragTester.m < prev    next >
Encoding:
Text File  |  1993-01-19  |  1.5 KB  |  63 lines

  1. #import "DemoDiagram.h"
  2. #import "DiagramCell.h"
  3. #import "DragTester.h"
  4.  
  5. /* DragTester - This is just a test object to fit between the user interface
  6. and the diagram objects. */
  7.  
  8. @implementation DragTester
  9.  
  10. /* Just set up a gray background for the view.  However, in other
  11. situations this could be a more complicated background. */
  12.  
  13. - appDidInit:sender
  14. {
  15.     NXRect rect;
  16.     [diagram getBounds:&rect];
  17.     diagramBg=[[NXImage alloc] initSize:&rect.size];
  18.     [diagramBg lockFocus];
  19.         PSsetgray(0.5);
  20.         NXRectFill(&rect);
  21.     [diagramBg unlockFocus];
  22.     [diagram setBackground:diagramBg];
  23.     [diagram display];
  24.     return self;
  25. }
  26.  
  27. /* Creates an image as requested, instantiates a new diagram item, gives
  28. the image to the new item, then adds the item to the diagram. */
  29.  
  30. - addItem:sender
  31. {
  32.     id image,item;
  33.     NXRect r;
  34.     /* Get an image for the new item */
  35.     NXSetRect(&r,0.0,0.0,(float)[sideInput intValue],(float)[sideInput intValue]);
  36.     image = [[NXImage alloc] initSize:&r.size];
  37.     [self drawImage:image :&r];
  38.     
  39.     /* Get an item and set the image */
  40.     item=[[DiagramCell alloc] init];
  41.     [item setImage:image];
  42.     
  43.     /* Give the new item to the diagram */
  44.     [diagram addItem:item];
  45.     return self;
  46. }
  47.  
  48. /* Draws the image for the new item as specified at the user interface. */
  49.  
  50. - drawImage:(NXImage *)image :(NXRect *)r
  51. {
  52.     [image lockFocus];
  53.         [image composite:NX_CLEAR fromRect:r toPoint:&(r->origin)];
  54.         PSsetgray([grayInput floatValue]);
  55.         if ([filledSwitch intValue])
  56.             NXRectFill(r);
  57.         else
  58.             NXFrameRectWithWidth(r,5.0);
  59.     [image unlockFocus];
  60.     return self;
  61. }
  62.  
  63. @end