diff options
author | 2011-06-16 14:46:26 +0000 | |
---|---|---|
committer | 2011-06-16 14:46:26 +0000 | |
commit | 6c4cd265e368531f6c73f4bbb0cf073d3899e10c (patch) | |
tree | 5fdccc1b83af1363827ccb7a7e18952283a86ab9 /experimental/SimpleCocoaApp/SkNSWindow.mm | |
parent | e67bd3fbc9bcd0929033635d546544527784b4c0 (diff) |
Added SimpleCocoaApp to the experimental directory
http://codereview.appspot.com/4576059/
git-svn-id: http://skia.googlecode.com/svn/trunk@1614 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental/SimpleCocoaApp/SkNSWindow.mm')
-rw-r--r-- | experimental/SimpleCocoaApp/SkNSWindow.mm | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/experimental/SimpleCocoaApp/SkNSWindow.mm b/experimental/SimpleCocoaApp/SkNSWindow.mm new file mode 100644 index 0000000000..5f4d65e315 --- /dev/null +++ b/experimental/SimpleCocoaApp/SkNSWindow.mm @@ -0,0 +1,60 @@ +#import "SkNSWindow.h" +#import "SkEvent.h" +#define SkEventClass @"SkEvent" +@implementation SkNSWindow + +-(id) initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle + backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag { + self = [super initWithContentRect:contentRect styleMask:aStyle + backing:bufferingType defer:flag]; + if (self) { + //Register as an observer for SkEventClass events and call + //receiveSkEvent: upon receiving the event + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(receiveSkEvent:) name:SkEventClass object:nil]; + } + return self; +} + +-(void) dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; +} + +-(void) installSkViews { + //to be overwritten by subclass +} + +-(BOOL) acceptsFirstResponder { + return YES; +} + +-(void) receiveSkEvent:(NSNotification *)notification { + if(SkEvent::ProcessEvent()) + SkEvent::SignalNonEmptyQueue(); +} + ++(void) postTimedEvent:(NSTimeInterval)ti { + [NSTimer scheduledTimerWithTimeInterval:ti target:self + selector:@selector(timerFireMethod:) + userInfo:nil repeats:NO]; +} + ++(void) timerFireMethod:(NSTimer*)theTimer { + SkEvent::ServiceQueueTimer(); +} +@end +//////////////////////////////////////////////////////////////////////////////// +void SkEvent::SignalNonEmptyQueue() { + //post a SkEventClass event to the default notification center + [[NSNotificationCenter defaultCenter] postNotificationName:SkEventClass + object:nil]; +} + +void SkEvent::SignalQueueTimer(SkMSec delay) { + if (delay) { + //Convert to seconds + NSTimeInterval ti = delay/(float)SK_MSec1; + [SkNSWindow postTimedEvent:ti]; + } +}
\ No newline at end of file |