Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!samsung!uunet!rosie!NeXT.COM From: Peter_King@NeXT.COM (Peter King) Newsgroups: comp.sys.next Subject: Re: How do you draw lines into the current view for Rubberbanding Message-ID: <758@rosie.NeXT.COM> Date: 17 May 91 19:27:29 GMT References: <1004@nddsun1.sps.mot.com> Sender: news@NeXT.COM Lines: 122 Nntp-Posting-Host: palantir.next.com In article <1004@nddsun1.sps.mot.com> leivian@axon.sps.mot.com (Bob Leivian) writes: > > ... > > I would like to draw lines into the current view in XOR mode to do > rubberbanding, I can't find anything on this except composite, which > has an XOR mode but do I need to have two full window rectangles and > clear one and draw into it and then composite them? > I would like to do something like this > Check out instance drawing. Here's a little snippet of code that does temporary line drawing in response to a mouse-down method. -mouseDown:(NXEvent *)theEvent { int looping; /* Flag for while in modal loop */ int oldMask; /* Old event mask */ NXPoint startPoint; /* Location of mouseDown */ NXPoint currentPoint; /* Location of mouseDragged/mouseUp */ /* Allow mouseDragged events */ oldMask = [window addToEventMask:NX_MOUSEDRAGGEDMASK]; /* Get the location of the mouseDown in view coordinates */ startPoint = theEvent->location; [self convertPoint:&startPoint fromView:nil]; /* Initialize the drawing context */ [self lockFocus]; PSsetgray(0.0); /* Turn on instance drawing */ PSsetinstance (YES); /* Run modal loop until mouse up */ looping = YES; while (looping) { /* Get the next mouseDragged/mouseUp event */ theEvent=[NXApp getNextEvent:NX_MOUSEUPMASK|NX_MOUSEDRAGGEDMASK]; /* Convert location to view coordinates */ currentPoint = theEvent->location; [self convertPoint:¤tPoint fromView:nil]; /* Erase all previous instance drawing */ PSnewinstance(); /* Handle the event */ if (theEvent->type==NX_MOUSEDRAGGED) { /* * On mouseDragged, instance draw a line * from starting point to current point. */ PSmoveto(startPoint.x, startPoint.y); PSlineto(currentPoint.x, currentPoint.y); PSstroke(); } else { /* * On mouse up, we stop the modal loop and draw * a real line from starting point to current * point. */ looping = NO; PSsetinstance(NO); /* Turn off instance drawing */ PSmoveto(startPoint.x, startPoint.y); PSlineto(currentPoint.x, currentPoint.y); PSstroke(); /* * Since we're not called from display, flush the * window buffer. */ [window flushWindow]; } } /* Release the drawing context and restore the event mask */ [self unlockFocus]; [window setEventMask:oldMask]; return self; } This causes a little bit of flicker (acceptable when rubber-banding). If you want to avoid the flicker, then you'd need to do double-buffering with off-screen windows and compositing. I'll leave this as an exercise for the reader. > In IB I created a .nib that has a controlPanel (subclass of panel) > that has the buttons and sliders set up to control an instance of > an object that is dynamically created by the program. However when I > 'new' the panel (with a loadNibSection in the +new method) I still > just get an empty panel, no buttons or sliders, even though the loadNib > comes back without an error -- any hints of where to look > You never need to "new" the panel; loadNibSection:owner: will instantiate it for you. What you want to do is add an outlet to your "custom object that is instantiated programmatically" which points to the control panel. In the nib file, set the File's Owner object to be the same class as your custom object, and drag a connection from the outlet you just created to your panel. When instantiating -->your custom object<--, call loadNibSection:owner: and pass in the id of the new custom object as the argument to owner:. When loadNibSection:owner: returns, the outlet in the custom object will have been initialized to point to the new panel (with buttons and all). Peter ----------Disclaimers? No such thing. Everything's the truth---------- Peter F. King Developer Trainer NeXT Computer, Inc. USPS: 900 Chesapeake Dr. Redwood City, CA 94063 Internet: Peter_King@NeXT.COM