If you're "writing" with the mouse the following might help. It isn't done, 
still needs some sort of check in the drawRect method to know when you've drawn 
all the segments and you;ll need to adjust x/y values to the view you're 
drawing in, but it will get you started.

- (void) mouseDown:(NSEvent *) inEvent
{
        // allocate a mutable data to store event points and times
        dragPoints              = [[NSMutableData alloc] init];

        // save fetch time and location of click and store in dragPoints
        NSTimeInterval  timestamp       = [inEvent timestamp];
        NSPoint                 clickPoint      = [inEvent locationInWindow];
        
        [dragPoints appendBytes: &timestamp length: sizeof(NSTimeInterval)];
        [dragPoints appendBytes: &dragPoint length: sizeof(NSPoint)];
}

- (void) mouseDragged:(NSEvent *) inEvent
{
        NSTimeInterval  timestamp       = [inEvent timestamp];
        NSPoint                 dragPoint       = [inEvent locationInWindow];
        
        // write interval and point to dragPoints mutable data object
        [dragPoints appendBytes: &timestamp length: sizeof(NSTimeInterval)];
        [dragPoints appendBytes: &dragPoint length: sizeof(NSPoint)];
}

- (void) mouseUp:(NSEvent *) inEvent
{
        // save the recording, either in memory or to a file
        [dragPoints writeToFile: @"/path/to/some/file.bin"];
        
        [dragPoints release];
}


// In your draw method, you could fetch a timestamp/NSPoint pair from the 
recording like so

- (void) drawRect:(NSRect) inRect
{
        CGContextRef            context                 = [[NSGraphicsContext 
currentContext] graphicsPort];
        
        // some instance variable indicating where you are in the recording
        int                                     frameOffset             = 
currentIncrement * (sizeof(NSTimeInterval) + sizeof(NSPoint));
        NSTimeInterval          time                            = 
*(NSTimeInterval*)[dragPoints bytes] + frameOffset;
        NSPoint                         point                   = 
*(NSPoint*)[dragPoints bytes] + frameOffset + sizeof(NSTimeInterval);
        
        // draw line
        CGContextAddLineToPoint(context, point.x, point.y);
        
        // create a new NSTimer with the delay from "time" variable
        [NSTimer scheduledTimerWithTimeInterval: time 
                        target: self 
                        selector: @selector(dearRect:) 
                        userInfo: nil 
                        repeats: NO];
        
        // increment placeholder
        currentIncrement++;
}

On Jun 23, 2011, at 5:21 AM, Gustavo Adolfo Pizano wrote:

> Hello all.
> 
> Im wondering if animating handwriting  is somehow possible to do, I
> have been looking but I find only how to do it in flash.
> 
> Can somebody give me some headlights in the right direction so I can
> start digging into?
> 
> Thanks a lot.
> 
> Gustavo
> _______________________________________________
> 
> 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/kentozier%40comcast.net
> 
> This email sent to kentoz...@comcast.net

_______________________________________________

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

Reply via email to