home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Audio / LPCView / Source / LPCView.m < prev    next >
Encoding:
Text File  |  1992-03-07  |  3.3 KB  |  189 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "LPCView.h"
  5. #import "LPCPlot.h"
  6. #import <appkit/Window.h>
  7. #import <appkit/Application.h>
  8. #import <dpsclient/wraps.h>
  9. #import <dpsclient/dpsclient.h>
  10.  
  11. /* 
  12.  *  Shorthand for drawing a hairline cursor
  13.  */
  14. #define CURSORL(w) PScompositerect(cursorloc, 0, w, NX_HEIGHT(&frame), NX_HIGHLIGHT);
  15.  
  16. @implementation LPCView
  17.  
  18. + newFrame:(const NXRect *)frameRect
  19. {
  20.     self = [super newFrame:frameRect];
  21.     width = 0.0;
  22.     cursorloc = 0.0;
  23.     [self setCursor:NO];
  24.     [self setCursorType:HAIRLINE];
  25.     return self;
  26. }
  27.  
  28. - drawSelf:(const NXRect *)rects :(int)rectCount
  29. {    
  30.     PSsetgray(NX_WHITE);
  31.     [self lockFocus];
  32.     [self unlockFocus];
  33.     [self setCursor:NO];
  34.     width = 0.0;
  35.     if (parent)
  36.         [parent drawData];
  37.     [self drawCurs];
  38.     return self;
  39. }
  40.  
  41. #define DRAG_MASK (NX_MOUSEUPMASK|NX_MOUSEDRAGGEDMASK)
  42.  
  43. - mouseDown:(NXEvent *)event
  44. {
  45.     int    oldMask;
  46.     NXPoint    p;
  47.     
  48.     [self lockFocus];
  49.     
  50.     oldMask = [[self window] addToEventMask:DRAG_MASK];
  51.     
  52.     if ([self cursorOn]) {
  53.         CURSORL(width);    // off
  54.     }
  55.     cursorloc = -1.0;
  56.     width = 1.0;
  57.     [self setCursor:YES];
  58.     p = event->location;
  59.     [self convertPoint:&p fromView:nil];
  60.     p.x = (p.x < 0.0) ? 0.0 : p.x;
  61.     p.x = (p.x > NX_WIDTH(&bounds)) ? NX_WIDTH(&bounds) : p.x;
  62.     cursorloc = p.x;
  63.     CURSORL(width);        // on
  64.     for (;;) {
  65.         event = [NXApp getNextEvent:DRAG_MASK];
  66.         switch (event->type) {
  67.            case NX_MOUSEDRAGGED :
  68.             switch([self cursorType]) {
  69.                case SELECTION :
  70.                    p = event->location;
  71.                 [self convertPoint:&p fromView:nil];
  72.                 p.x = (p.x < 0.0) ? 0.0 : p.x;
  73.                 p.x = (p.x > NX_WIDTH(&bounds)) ? NX_WIDTH(&bounds) : p.x;
  74.                 CURSORL(width); // off
  75.                 width = (p.x - cursorloc);
  76.                 CURSORL(width); // on
  77.                 break;
  78.                case HAIRLINE :
  79.                    p = event->location;
  80.                 [self convertPoint:&p fromView:nil];
  81.                 p.x = (p.x < 0.0) ? 0.0 : p.x;
  82.                 p.x = (p.x > NX_WIDTH(&bounds)) ? NX_WIDTH(&bounds) : p.x;
  83.                 CURSORL(width);    // off
  84.                 
  85.                 width = 1.0;
  86.                 cursorloc = p.x;
  87.                 CURSORL(width);    // on
  88.                 break;
  89.             }
  90.             break;
  91.            case NX_MOUSEUP :
  92.                goto done;
  93.                break;
  94.         }
  95.         [parent updateCursor:self];
  96.         [[self window] flushWindow];
  97.         NXPing();  // use only if there is a speed problem
  98.     }
  99. done:    [[self window] setEventMask:oldMask];
  100.     [self unlockFocus];
  101.     [parent updateCursor:self];
  102.     return self;
  103. }
  104.  
  105. - drawCurs
  106. {
  107.     [self lockFocus];
  108.     CURSORL(width);
  109.     [[self window] flushWindow];
  110.     [self unlockFocus];
  111.     [self setCursor:YES];
  112.     return self;
  113. }
  114.  
  115. - changeCurs:(float)loc:(float)wid
  116. {
  117.     [self lockFocus];
  118.     if ([self cursorOn]) {
  119.         CURSORL(width);    // off
  120.     }
  121.     cursorloc = loc;
  122.     width = wid;
  123.     CURSORL(width);
  124.     [[self window] flushWindow];
  125.     NXPing();
  126.     [self unlockFocus];
  127.     return self;
  128. }
  129.  
  130. - drawPlot:(float *)data :(char *)ops :(float *)bbox :(int) num :(float) scale
  131. {
  132.     if (!num) 
  133.         return self;
  134.     [self lockFocus];
  135.     PSsetgray(scale);
  136.     DPSDoUserPath((void *)data, num*4, dps_float, ops, num*2, (void *)bbox, dps_ustroke);
  137.     [self unlockFocus];
  138.     return self;
  139.         
  140. }
  141. - setCursor:(BOOL)val
  142. {
  143.     displayCursor = val;
  144.     return self;
  145. }
  146.  
  147. - (BOOL) cursorOn
  148. {
  149.     return displayCursor;
  150. }
  151.  
  152. - (BOOL) acceptsFirstResponder
  153. {
  154.     return YES;
  155. }
  156.  
  157. - setDelegate:anObject
  158. {
  159.     delegate = anObject;
  160.     return self;
  161. }
  162.  
  163. - setParent:par
  164. {
  165.     parent = par;
  166.     return self;
  167. }
  168. - (int) getcurPos
  169. {
  170.     return cursorloc;
  171. }
  172. - (int) getWidth
  173. {
  174.     return width;
  175. }
  176.  
  177. - setCursorType:(int)type
  178. {
  179.     cursortype = type;
  180.     return self;
  181. }
  182.  
  183. - (int)cursorType
  184. {
  185.     return cursortype;
  186. }
  187.  
  188. @end
  189.