From: Andre P. <at...@us...> - 2004-10-19 06:39:54
|
Update of /cvsroot/xine/xine-lib/src/video_out/macosx In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5166/macosx Modified Files: video_window.h video_window.m Log Message: XineOpenGLView for Mac OS X: * Made XineOpenGLViewDelegate formal protocol to avoid compiler warnings * Properly support NSCoders which don't support keyed-coding (yeah, they apparently exist) * Added some logging * Accepts first responder status * Initial mouse tracking support via delegate Index: video_window.h =================================================================== RCS file: /cvsroot/xine/xine-lib/src/video_out/macosx/video_window.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- video_window.h 5 Jul 2004 05:26:12 -0000 1.14 +++ video_window.h 19 Oct 2004 06:39:44 -0000 1.15 @@ -24,13 +24,15 @@ #import <Cocoa/Cocoa.h> +@protocol XineOpenGLViewDelegate; + typedef enum { XINE_FULLSCREEN_OVERSCAN, XINE_FULLSCREEN_CROP } XineVideoWindowFullScreenMode; @interface XineOpenGLView : NSOpenGLView { - IBOutlet id delegate; + IBOutlet id <XineOpenGLViewDelegate> delegate; int video_width, video_height; char *texture_buffer; unsigned long i_texture; @@ -56,6 +58,7 @@ - (char *) getTextureBuffer; - (void) setVideoSize:(NSSize)size; - (void) setViewSizeInMainThread:(NSSize)size; +/* TODO: replace set...Size below with setSize:(double)videoSizeMultiplier */ - (void) setNormalSize; - (void) setHalfSize; - (void) setDoubleSize; Index: video_window.m =================================================================== RCS file: /cvsroot/xine/xine-lib/src/video_out/macosx/video_window.m,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- video_window.m 5 Jul 2004 05:26:12 -0000 1.19 +++ video_window.m 19 Oct 2004 06:39:44 -0000 1.20 @@ -34,11 +34,28 @@ #define DEFAULT_VIDEO_WINDOW_SIZE (NSMakeSize(320, 200)) +/* +#define LOG +*/ +#undef LOG_MOUSE + +@protocol XineOpenGLViewDelegate + +- (void) mouseMoved:(NSEvent *)theEvent inXineView:(XineOpenGLView *)view; +- (BOOL) respondsToSelector:(SEL)selector; +- (NSSize) xineViewWillResize:(NSSize)oldSize toSize:(NSSize)proposedSize; +- (void) xineViewDidResize:(NSNotification *)note; + +@end + @implementation XineVideoWindow - (void) setContentSize: (NSSize) size { +#ifdef LOG + NSLog(@"setContent called with new size w:%d h:%d", size.width, size.height); +#endif [xineView setViewSizeInMainThread:size]; - + [super setContentSize: size]; } @@ -77,6 +94,11 @@ defer: flag screen: aScreen]; +#ifdef LOG + NSLog(@"initWithContentRect called with rect x:%d y:%d w:%d h:%d", + rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); +#endif + xineView = [[XineOpenGLView alloc] initWithFrame:rect]; [xineView setResizeViewOnVideoSizeChange:YES]; @@ -171,6 +193,28 @@ return YES; } +- (void)mouseMoved:(NSEvent *)theEvent +{ + NSPoint point = [self convertPoint:[theEvent locationInWindow] + fromView:nil]; + + NSRect bounds = [self bounds]; + + if (!NSMouseInRect(point, bounds, [self isFlipped])) return; + + /* flip the y axis */ + point.y = bounds.size.height - point.y; +#ifdef LOG_MOUSE + NSLog(@"XineOpenGLView: mouse at x:%f y:%f", point.x, point.y); +#endif + + if ([delegate respondsToSelector:@selector(mouseMoved:inXineView:)]) { + (void) [delegate mouseMoved:theEvent inXineView:self]; + } + + [super mouseMoved:theEvent]; +} + - (NSSize)videoSize { return NSMakeSize(video_width, video_height); } @@ -224,30 +268,50 @@ /* Black background */ glClearColor (0.0, 0.0, 0.0, 0.0); - + +#ifdef LOG + NSLog(@"XineOpenGLView: initWithFrame called"); +#endif + return self; } - (id) initWithCoder:(NSCoder *)coder { - [super initWithCoder:coder]; +#ifdef LOG + NSLog(@"XineOpenGLView: initWithCoder called"); +#endif + + self = [super initWithCoder:coder]; self = [self initWithFrame:[self frame]]; - keepsVideoAspectRatio = [coder decodeBoolForKey:@"keepsVideoAspectRatio"]; - resizeViewOnVideoSizeChange = [coder decodeBoolForKey: - @"resizeViewOnVideoSizeChange"]; + if ([coder allowsKeyedCoding]) { + keepsVideoAspectRatio = [coder decodeBoolForKey:@"keepsVideoAspectRatio"]; + resizeViewOnVideoSizeChange = [coder decodeBoolForKey: + @"resizeViewOnVideoSizeChange"]; + } else { + /* Must decode values in the same order as encodeWithCoder: */ + [coder decodeValueOfObjCType:@encode(BOOL) at:&keepsVideoAspectRatio]; + [coder decodeValueOfObjCType:@encode(BOOL) at:&resizeViewOnVideoSizeChange]; + } return self; } - (void) encodeWithCoder:(NSCoder *)coder { - [coder encodeBool:keepsVideoAspectRatio forKey:@"keepsVideoAspectRatio"]; - [coder encodeBool:resizeViewOnVideoSizeChange - forKey:@"resizeViewOnVideoSizeChange"]; - [super encodeWithCoder:coder]; + + if ([coder allowsKeyedCoding]) { + [coder encodeBool:keepsVideoAspectRatio forKey:@"keepsVideoAspectRatio"]; + [coder encodeBool:resizeViewOnVideoSizeChange + forKey:@"resizeViewOnVideoSizeChange"]; + } else { + [coder encodeValueOfObjCType:@encode(BOOL) at:&keepsVideoAspectRatio]; + [coder encodeValueOfObjCType:@encode(BOOL) at:&resizeViewOnVideoSizeChange]; + } + } - (void) dealloc { @@ -596,6 +660,10 @@ if (resizeViewOnVideoSizeChange) [self setViewSizeInMainThread:size]; +#ifdef LOG + NSLog(@"setVideoSize called"); +#endif + [self initTextures]; } @@ -612,6 +680,10 @@ withObject:sizeWrapper waitUntilDone:NO]; +#ifdef LOG + NSLog(@"setViewSizeInMainThread called"); +#endif + [pool release]; } @@ -665,6 +737,10 @@ delegate = aDelegate; } +- (BOOL)acceptsFirstResponder { + return YES; +} + @end /* XineOpenGLView */ |