Thank you 2011/10/19 Fritz Anderson <fri...@manoverboard.org>
> On 19 Oct 2011, at 12:41 PM, Nick wrote: > > > Could you advice me how to get rid of blinking in the following code? > > This is an NSView's subclass, I am trying to draw a rectangle for zooming > > (theoretically a user is supposed to be able to zoom in a piece of a > view, > > by selecting a rectangle area to zoom. > > The problem is that when the mouse is being dragged, the rectangle that's > > being drawn is blinking. > > What would be the write approach to make it behave like other software > where > > a user can select things with a rectangle? > > You're fighting the framework. Calling -display yourself or drawing outside > of drawRect: are powerful code smells. This is a tangle: > > ===== > [self display]; > // Forces an immediate call to drawRect:. > > [self lockFocus]; > [self drawRectUsingTwoPoints:lastMouseDownPos:locationOnCanvas]; > [self unlockFocus]; > // Draw over what drawRect: drew. > > [self displayIfNeeded]; //show the currect "rectangle" > // Force _another_ drawRect:, again without drawing the selection > rectangle. > // If your first drawRect:, via -display, cleared your selection > rectangle, this > // repeated call to drawRect: will erase it _again_. > ===== > > If you're using mouseUp/Dragged/Down methods, you'll be returning to the > event loop, and thus to the built-in redrawing through drawRect:, anyway. > And, Quartz will schedule it so everything is coalesced and won't flicker. > > In your tracking methods, just save the selection rectangle in an instance > variable (which can be NSZeroRect if you don't have a selection). When the > rectangle changes, send -setNeedsDisplay (not displayIfNeeded) to the view > and let the scheduling take care of itself. drawRect: can check for a > non-NSZeroRect selection, and you can draw the rectangle if there's one to > draw. > > — F > > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com