xineopenglview.m
来自「linux下的MPEG1」· M 代码 · 共 771 行 · 第 1/2 页
M
771 行
[mutex unlock];}- (void)setHalfSize{ NSSize size; [mutex lock]; if (!isFullScreen) { size.width = trunc(videoSize.width / 2); size.height = trunc(videoSize.height / 2); [self setViewSizeInMainThread:size]; } [mutex unlock];}- (void)setDoubleSize{ NSSize size; [mutex lock]; if (!isFullScreen) { size.width = videoSize.width * 2; size.height = videoSize.height * 2; [self setViewSizeInMainThread:size]; } [mutex unlock];}- (NSSize)videoSize{ return videoSize;}- (BOOL)keepsVideoAspectRatio{ return keepsVideoAspectRatio;}- (void)setKeepsVideoAspectRatio:(BOOL)flag{ keepsVideoAspectRatio = flag;}- (BOOL)resizeViewOnVideoSizeChange{ return resizeViewOnVideoSizeChange;}- (void)setResizeViewOnVideoSizeChange:(BOOL)flag{ resizeViewOnVideoSizeChange = flag;}- (void)setViewSize:(NSValue *)sizeWrapper{ NSSize currentSize, newSize, proposedSize; [sizeWrapper getValue:&proposedSize]; newSize = proposedSize; currentSize = [self frame].size; if (proposedSize.width == currentSize.width && proposedSize.height == currentSize.height) { return; } // If our controller handles xineViewWillResize:toSize:, send the // message to him first. Note that the delegate still has a chance // to override the controller's resize preference ... if ([controller respondsToSelector:@selector(xineViewWillResize:toSize:)]) { NSSize oldSize = [self frame].size; newSize = [controller xineViewWillResize:oldSize toSize:proposedSize]; } // If our delegate handles xineViewWillResize:toSize:, send the // message to him; otherwise, just resize ourselves if ([delegate respondsToSelector:@selector(xineViewWillResize:toSize:)]) { NSSize oldSize = [self frame].size; newSize = [delegate xineViewWillResize:oldSize toSize:proposedSize]; } [self setFrameSize:newSize]; [self setBoundsSize:newSize]; /* Post a notification that we resized and also notify our controller */ /* and delegate */ NSNotification *note = [NSNotification notificationWithName:XineViewDidResizeNotification object:self]; [[NSNotificationCenter defaultCenter] postNotification:note]; if ([controller respondsToSelector:@selector(xineViewDidResize:)]) { [controller xineViewDidResize:note]; } if ([delegate respondsToSelector:@selector(xineViewDidResize:)]) { [delegate xineViewDidResize:note]; } [mutex lock]; [[self openGLContext] makeCurrentContext]; if (isFullScreen) { [self calcFullScreenAspect]; } [self initTextures]; [mutex unlock];}- (void)setViewSizeInMainThread:(NSSize)size{ // Create an autorelease pool, since we're running in a xine thread that // may not have a pool of its own NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSValue *sizeWrapper = [NSValue valueWithBytes:&size objCType:@encode(NSSize)]; [self performSelectorOnMainThread:@selector(setViewSize:) withObject:sizeWrapper waitUntilDone:NO]; #ifdef LOG NSLog(@"setViewSizeInMainThread called");#endif [pool release];}- (NSCursor *)currentCursor{ return currentCursor;}- (void)setCurrentCursor:(NSCursor *)cursor{ [currentCursor autorelease]; currentCursor = [cursor retain]; [self resetCursorRectsInMainThread];}- (BOOL)isFullScreen{ return isFullScreen;}- (void)goFullScreen:(XineVideoWindowFullScreenMode)mode{ NSOpenGLPixelFormat *pixelFormat; if (!(pixelFormat = [[self class] fullScreenPixelFormat])) { NSLog(@"Cannot create NSOpenGLPixelFormat for full screen mode"); return; } if (!(fullScreenContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil])) { NSLog(@"Cannot create NSOpenGLContext for full screen mode"); return; } if (CGCaptureAllDisplays() != CGDisplayNoErr) { [fullScreenContext release], fullScreenContext = nil; NSLog(@"CGCaptureAllDisplays() failed"); return; } [mutex lock]; fullScreenMode = mode; isFullScreenPrepared = NO; [fullScreenContext setFullScreen]; [[self openGLContext] makeCurrentContext]; // Redraw the last picture [self setNeedsDisplay:YES]; isFullScreen = YES; [mutex unlock];}- (void)exitFullScreen{ NSOpenGLContext *context; [mutex lock]; if (isFullScreen) { context = fullScreenContext; fullScreenContext = nil; [[self openGLContext] makeCurrentContext]; [context clearDrawable]; [context release]; [self reshape]; [self initTextures]; CGReleaseAllDisplays(); [self setNeedsDisplay:YES]; isFullScreen = NO; } [mutex unlock];}- (id)delegate{ return [[delegate retain] autorelease];}- (void)setDelegate:(id)aDelegate{ [delegate autorelease]; delegate = [aDelegate retain];}- (id)xineController{ return controller;}- (void)setXineController:(id)aController{ [controller autorelease]; controller = [aController retain];}- (char *)textureBuffer{ return textureBuffer;}- (void)setVideoSize:(NSSize)size{ [mutex lock]; videoSize = size; if (resizeViewOnVideoSizeChange) { [self setViewSizeInMainThread:size]; } if (initDone) { [[self openGLContext] makeCurrentContext]; [self initTextures]; } [mutex unlock];}- (void)resetCursorRects{ [mutex lock]; [self discardCursorRects]; [self addCursorRect:[self visibleRect] cursor:currentCursor]; [currentCursor set]; [mutex unlock];}- (void)resetCursorRectsInMainThread{ [self performSelectorOnMainThread:@selector(resetCursorRects) withObject:nil waitUntilDone:NO];}- (void)releaseInMainThread{ [self performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];}- (void)calcFullScreenAspect{ float fs_height, fs_width, h, w, x, y; // Feh, should go to main or should go to current display of window? fs_width = CGDisplayPixelsWide(kCGDirectMainDisplay); fs_height = CGDisplayPixelsHigh(kCGDirectMainDisplay); switch (fullScreenMode) { case XINE_FULLSCREEN_OVERSCAN: if ((fs_width / fs_height) > (videoSize.width / videoSize.height)) { w = videoSize.width * (fs_height / videoSize.height); h = fs_height; x = (fs_width - w) / 2; y = 0; } else { w = fs_width; h = videoSize.height * (fs_width / videoSize.width); x = 0; y = (fs_height - h) / 2; } break; case XINE_FULLSCREEN_CROP: if ((fs_width / fs_height) > (videoSize.width / videoSize.height)) { w = fs_width; h = videoSize.height * (fs_width / videoSize.width); x = 0; y = (fs_height - h) / 2; } else { w = videoSize.width * (fs_height / videoSize.height); h = fs_height; x = (fs_width - w) / 2; y = 0; } break; default: NSLog(@"Mac OS X fullscreen mode unrecognized: %d", fullScreenMode); return; } #ifdef LOG NSLog(@"Mac OS X fullscreen mode: %fx%f => %fx%f @ %f,%f\n", videoSize.width, videoSize.height, w, h, x, y);#endif // Assumes locked and current context set glViewport(x, y, w, h);}- (void)passEventToDelegate:(NSEvent *)theEvent withSelector:(SEL)selector{ NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil]; if (NSMouseInRect(point, [self bounds], [self isFlipped])) { if ([delegate respondsToSelector:selector]) { [delegate performSelector:selector withObject:theEvent withObject:self]; } else if ([controller respondsToSelector:selector]) { [controller performSelector:selector withObject:theEvent withObject:self]; } }}- (void)mouseMoved:(NSEvent *)theEvent{ [self passEventToDelegate:theEvent withSelector:@selector(mouseMoved:inXineView:)]; [super mouseMoved:theEvent];}- (void)mouseDown:(NSEvent *)theEvent{ [self passEventToDelegate:theEvent withSelector:@selector(mouseDown:inXineView:)]; [super mouseDown:theEvent];}- (void)rightMouseDown:(NSEvent *)theEvent{ [self passEventToDelegate:theEvent withSelector:@selector(rightMouseDown:inXineView:)]; [super rightMouseDown:theEvent];}- (void)otherMouseDown:(NSEvent *)theEvent{ [self passEventToDelegate:theEvent withSelector:@selector(otherMouseDown:inXineView:)]; [super otherMouseDown:theEvent];}- (BOOL)acceptsFirstResponder{ return YES;}- (BOOL)mouseDownCanMoveWindow{ return YES;}@end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?