From 4289a744bf6698ef54181508fbe5d8d25f833605 Mon Sep 17 00:00:00 2001 From: Andre Pang Date: Tue, 19 Oct 2004 06:39:44 +0000 Subject: 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 CVS patchset: 7051 CVS date: 2004/10/19 06:39:44 --- src/video_out/macosx/video_window.h | 5 +- src/video_out/macosx/video_window.m | 96 +++++++++++++++++++++++++++++++++---- 2 files changed, 90 insertions(+), 11 deletions(-) diff --git a/src/video_out/macosx/video_window.h b/src/video_out/macosx/video_window.h index 5f2cad55e..4d4dba37c 100644 --- a/src/video_out/macosx/video_window.h +++ b/src/video_out/macosx/video_window.h @@ -24,13 +24,15 @@ #import +@protocol XineOpenGLViewDelegate; + typedef enum { XINE_FULLSCREEN_OVERSCAN, XINE_FULLSCREEN_CROP } XineVideoWindowFullScreenMode; @interface XineOpenGLView : NSOpenGLView { - IBOutlet id delegate; + IBOutlet id delegate; int video_width, video_height; char *texture_buffer; unsigned long i_texture; @@ -56,6 +58,7 @@ typedef enum { - (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; diff --git a/src/video_out/macosx/video_window.m b/src/video_out/macosx/video_window.m index 8381dfaea..6aa189ba0 100644 --- a/src/video_out/macosx/video_window.m +++ b/src/video_out/macosx/video_window.m @@ -34,11 +34,28 @@ NSString *XineViewDidResizeNotification = @"XineViewDidResizeNotification"; #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 @@ NSString *XineViewDidResizeNotification = @"XineViewDidResizeNotification"; 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 @@ NSString *XineViewDidResizeNotification = @"XineViewDidResizeNotification"; 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 @@ NSString *XineViewDidResizeNotification = @"XineViewDidResizeNotification"; /* 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 @@ NSString *XineViewDidResizeNotification = @"XineViewDidResizeNotification"; if (resizeViewOnVideoSizeChange) [self setViewSizeInMainThread:size]; +#ifdef LOG + NSLog(@"setVideoSize called"); +#endif + [self initTextures]; } @@ -612,6 +680,10 @@ NSString *XineViewDidResizeNotification = @"XineViewDidResizeNotification"; withObject:sizeWrapper waitUntilDone:NO]; +#ifdef LOG + NSLog(@"setViewSizeInMainThread called"); +#endif + [pool release]; } @@ -665,6 +737,10 @@ NSString *XineViewDidResizeNotification = @"XineViewDidResizeNotification"; delegate = aDelegate; } +- (BOOL)acceptsFirstResponder { + return YES; +} + @end /* XineOpenGLView */ -- cgit v1.2.3