Text Animation

  • Hi all;

    Any quick pointers on how to animate a block of text that is manually
    drawn in a custom view?  I'm drawing the text using -[NSString
    drawWithRect:options:attributes:].  I've tried running an NSAnimation
    but my drawing in the -animation:didReachProgressMark: method doesn't
    seem to ever reach the screen even though I'm locking/unlocking focus.

    Any thoughts?

    Thanks,
    ->Ben
    --
    "Pinky, you've left the lens cap of your mind on again." - The Brain
  • On 01.09.2007, at 08:44, Ben Lachman wrote:
    > Any quick pointers on how to animate a block of text that is
    > manually drawn in a custom view?  I'm drawing the text using -
    > [NSString drawWithRect:options:attributes:].  I've tried running an
    > NSAnimation but my drawing in the -animation:didReachProgressMark:
    > method doesn't seem to ever reach the screen even though I'm
    > locking/unlocking focus.

      There are only a few places where you're ever allowed to draw in
    Cocoa: Either between a lockFocus/unlockFocus on an NSImage/
    NSImageRep, or from inside the drawRect method of an NSView subclass
    (that's pure Cocoa, i.e. AppKit -- if you use OpenGL directly or
    CoreImage or so, there may be other places). You're not supposed to
    lock focus on a view manually and draw just at any old time. If you
    want to use NSAnimation, use an NSView that draws what you want to
    draw, and then send it setNeedsDisplay:. -
    animation:didReachProgressMark: is supposed to be used to change the
    view's properties (e.g. move it, call setNeedsDisplay: etc.), not to
    do the actual drawing.

      Does that clear up the confusion?

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
  • On Sep 1, 2007, at 6:38 AM, Uli Kusterer wrote:

    > There are only a few places where you're ever allowed to draw in
    > Cocoa: Either between a lockFocus/unlockFocus on an NSImage/
    > NSImageRep, or from inside the drawRect method of an NSView subclass
    > (that's pure Cocoa, i.e. AppKit -- if you use OpenGL directly or
    > CoreImage or so, there may be other places). You're not supposed to
    > lock focus on a view manually and draw just at any old time.

    that's probably a bit strong.

    there are cases where locking focus, drawing, and then unlocking focus
    outside of these cases are useful (in the AppKit domain) .  I believe
    at least one common case is creating selection rectangles/indicators.
  • > On Sep 1, 2007, at 6:38 AM, Uli Kusterer wrote:
    >
    >> There are only a few places where you're ever allowed to draw in
    >> Cocoa: Either between a lockFocus/unlockFocus on an NSImage/
    >> NSImageRep, or from inside the drawRect method of an NSView
    >> subclass (that's pure Cocoa, i.e. AppKit -- if you use OpenGL
    >> directly or CoreImage or so, there may be other places). You're
    >> not supposed to lock focus on a view manually and draw just at any
    >> old time.
    >
    > that's probably a bit strong.
    >
    > there are cases where locking focus, drawing, and then unlocking
    > focus outside of these cases are useful (in the AppKit domain) .  I
    > believe at least one common case is creating selection rectangles/
    > indicators.
    For selection for ex. I make the rect or something but then
    setNeedsDisplay and draw the selection in the drawRect... I thought
    the same as Uli... that's only 'save' to draw at the righ time!?

    Regards,
    Dominik
  • On Sep 1, 2007, at 3:48 PM, Scott Anguish wrote:

    >
    > On Sep 1, 2007, at 6:38 AM, Uli Kusterer wrote:
    >
    >> There are only a few places where you're ever allowed to draw in
    >> Cocoa: Either between a lockFocus/unlockFocus on an NSImage/
    >> NSImageRep, or from inside the drawRect method of an NSView
    >> subclass (that's pure Cocoa, i.e. AppKit -- if you use OpenGL
    >> directly or CoreImage or so, there may be other places). You're not
    >> supposed to lock focus on a view manually and draw just at any old
    >> time.
    >
    > that's probably a bit strong.
    >
    > there are cases where locking focus, drawing, and then unlocking
    > focus outside of these cases are useful (in the AppKit domain) .  I
    > believe at least one common case is creating selection rectangles/
    > indicators.

    I will point out though, that drawing selection indicators can be done
    without going outside of the normal view update machinery.

    http://developer.apple.com/samplecode/Cropped_Image/index.html

    -jcr
  • On Sep 1, 2007, at 08:44 , Ben Lachman wrote:

    > my drawing in the -animation:didReachProgressMark: method doesn't
    > seem to ever reach the screen even though I'm locking/unlocking focus.
    >
    > Any thoughts?
    >
    > Thanks,
    > ->Ben

    maybe you need to explicitly mark the new drawn area(s) as 'needs
    display'.
    setNeedsDisplay / setNeedsDisplayInRect:

    also note that the drawRect: method often gets called with as
    argument an NSRect that just covers a part of the view (depening on
    what/where the software -thinks- needs to be updated.)

    .a
  • On Aug 31, 2007, at 11:44 PM, Ben Lachman wrote:

    > Any quick pointers on how to animate a block of text that is
    > manually drawn in a custom view?  I'm drawing the text using -
    > [NSString drawWithRect:options:attributes:].  I've tried running an
    > NSAnimation but my drawing in the -animation:didReachProgressMark:
    > method doesn't seem to ever reach the screen even though I'm
    > locking/unlocking focus.

    You might want to take a look at the CircleView and Worm examples in /
    Developer/Examples/AppKit.

    Douglas Davidson
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today