• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Drawing while handling events (was Re: scribbling)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing while handling events (was Re: scribbling)


  • Subject: Re: Drawing while handling events (was Re: scribbling)
  • From: John Randolph <email@hidden>
  • Date: Wed, 13 Aug 2003 13:48:48 -0700

On Wednesday, August 13, 2003, at 12:32 PM, Fritz Anderson wrote:

On Wednesday, 13 August 2003, at 1:56 PM, John Randolph wrote:

First suggestion: don't do any drawing in an event-handling method, and don't call -lockFocus yourself. Just update the info you need to do the drawing, and call -setNeedsDisplayInRect:.

May I ask you to explore this more closely? This seems to contradict the example in the tasks-and-concepts documentation for mouse-event handling in NSViews, "Handling Mouse Events in Views," <file:///Developer/Documentation/Cocoa/TasksAndConcepts/ ProgrammingTopics/BasicEventHandling/Tasks/HandlingMouseEvents.html>

That topic describes the way we used to handle mouse tracking in NeXTSTEP. It could probably use some updating.

The document says, "NSViews that handle mouse clicks as a single event, from mouse down, through dragging, to mouse up, must usually short-circuit the applications normal event loop, entering a modal event loop to catch and process only events of interest." It then provides an example of a mouseDown: handler implementing a loop on -[NSWindow nextEventMatchingMask:], which calls drawing methods. I could see how the equivalent program mode could be handled by state-sensitive mouseUp: and mouseDragged: methods, but it would be a lot uglier.

Not necessarily. You just need an ivar to keep track of your mode, as I've done in the Cropped Image example.

Are you disagreeing, or are you saying it's OK to draw in that case where the state from mouse-down to mouse-up amounts to a unique, modal event? But if the latter is the case, why isn't "scribbling" with the mouse the same sort of state?

I'm not arguing; I want to learn.

It's largely a matter of taste. I make a point of returning control as soon as possible in any mouse-event method, so that anything else that may be going on (timer animation, etc) isn't impaired. Also, if you ever subclass a control like NSSlider, you'll notice that as soon as you call [super mouseDown:], your own -mouseDragged: method never gets called.

-jcr
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: scribbling (From: Richard Chamberlain <email@hidden>)
 >Re: scribbling (From: John Randolph <email@hidden>)
 >Drawing while handling events (was Re: scribbling) (From: Fritz Anderson <email@hidden>)

  • Prev by Date: Additional Library problem
  • Next by Date: Re: Additional Library problem
  • Previous by thread: Drawing while handling events (was Re: scribbling)
  • Next by thread: Re: scribbling
  • Index(es):
    • Date
    • Thread