Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_WindowCocoa.mm
| Context not available. | |||||
| #include "GHOST_SystemCocoa.h" | #include "GHOST_SystemCocoa.h" | ||||
| #include "GHOST_ContextNone.h" | #include "GHOST_ContextNone.h" | ||||
| #include "GHOST_Debug.h" | #include "GHOST_Debug.h" | ||||
| #include "GHOST_UtilsCocoa.h" | |||||
| #if defined(WITH_GL_EGL) | #if defined(WITH_GL_EGL) | ||||
| # include "GHOST_ContextEGL.h" | # include "GHOST_ContextEGL.h" | ||||
| Context not available. | |||||
| return NSNotFound; | return NSNotFound; | ||||
| } | } | ||||
| - (NSArray*)validAttributesForMarkedText | - (NSArray *)validAttributesForMarkedText | ||||
| { | { | ||||
| return [NSArray array]; // XXX does this leak? | return [NSArray array]; // XXX does this leak? | ||||
| } | } | ||||
| Context not available. | |||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||||
| //Creates the window | // Create the window | ||||
| NSRect rect; | NSSize minSize = CGSizeMake(MINIMUM_WINDOW_WIDTH, MINIMUM_WINDOW_HEIGHT); | ||||
| NSSize minSize; | |||||
| // find window screen | |||||
| rect.origin.x = left; | NSRect rect = CGRectMake(left, bottom - height, width, height); | ||||
| rect.origin.y = bottom; | NSScreen *windowScreen = nil; | ||||
| rect.size.width = width; | for (NSScreen *screen in [NSScreen screens]) { | ||||
| rect.size.height = height; | NSRect screenFrame = screen.frame; | ||||
| if (NSContainsRect(screenFrame, rect)) { | |||||
| m_window = [[CocoaWindow alloc] initWithContentRect:rect | windowScreen = screen; | ||||
| styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask | //NSLog(@"cocoa: found containing screen: %@", screen); | ||||
| backing:NSBackingStoreBuffered defer:NO]; | // adjust rect origin to be relative to the origin of this screen | ||||
| rect.origin.x -= screenFrame.origin.x; | |||||
| rect.origin.y -= screenFrame.origin.y; | |||||
| break; | |||||
| } | |||||
| } | |||||
| if (windowScreen == nil) { | |||||
| windowScreen = [GHOST_UtilsCocoa mainScreen]; | |||||
| } | |||||
| int mask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask; | |||||
| m_window = [[CocoaWindow alloc] initWithContentRect:rect styleMask:mask | |||||
| backing:NSBackingStoreBuffered | |||||
| defer:NO screen:windowScreen]; | |||||
| if (m_window == nil) { | if (m_window == nil) { | ||||
| [pool drain]; | [pool drain]; | ||||
| return; | return; | ||||
| Context not available. | |||||
| [m_window setSystemAndWindowCocoa:systemCocoa windowCocoa:this]; | [m_window setSystemAndWindowCocoa:systemCocoa windowCocoa:this]; | ||||
| //Forbid to resize the window below the blender defined minimum one | // Forbid to resize the window below the blender defined minimum one | ||||
| minSize.width = 320; | |||||
| minSize.height = 240; | |||||
| [m_window setContentMinSize:minSize]; | [m_window setContentMinSize:minSize]; | ||||
| //Creates the OpenGL View inside the window | // Creates the OpenGL View inside the window | ||||
| m_openGLView = [[CocoaOpenGLView alloc] initWithFrame:rect]; | m_openGLView = [[CocoaOpenGLView alloc] init]; //WithFrame:rect]; | ||||
| if (m_systemCocoa->m_nativePixel) { | if (m_systemCocoa->m_nativePixel) { | ||||
| // Needs to happen early when building with the 10.14 SDK, otherwise | // Needs to happen early when building with the 10.14 SDK, otherwise | ||||
| // has no effect until resizeing the window. | // has no effect until resizing the window. | ||||
| if ([m_openGLView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) { | if ([m_openGLView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) { | ||||
| [m_openGLView setWantsBestResolutionOpenGLSurface:YES]; | [m_openGLView setWantsBestResolutionOpenGLSurface:YES]; | ||||
| } | } | ||||
| Context not available. | |||||
| [m_window setInitialFirstResponder:m_openGLView]; | [m_window setInitialFirstResponder:m_openGLView]; | ||||
| [m_window makeKeyAndOrderFront:nil]; | [m_window makeKeyAndOrderFront:nil]; | ||||
| setDrawingContextType(type); | setDrawingContextType(type); | ||||
| updateDrawingContext(); | updateDrawingContext(); | ||||
| activateDrawingContext(); | activateDrawingContext(); | ||||
| Context not available. | |||||
| void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect& bounds) const | void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect& bounds) const | ||||
| { | { | ||||
| NSRect rect; | |||||
| GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getWindowBounds(): window invalid"); | GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getWindowBounds(): window invalid"); | ||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||||
| NSRect screenSize = [[m_window screen] visibleFrame]; | |||||
| rect = [m_window frame]; | NSRect frame = m_window.frame; | ||||
| NSRect contentFrame = m_window.contentView.frame; | |||||
| // use size of content frame for sizing, because window initWithContentRect | |||||
| // requires the content area of the window. | |||||
| bounds.m_l = frame.origin.x; | |||||
| bounds.m_t = frame.origin.y; | |||||
| bounds.m_r = frame.origin.x + contentFrame.size.width; | |||||
| bounds.m_b = frame.origin.y + contentFrame.size.height; | |||||
| bounds.m_b = screenSize.size.height - (rect.origin.y -screenSize.origin.y); | |||||
| bounds.m_l = rect.origin.x -screenSize.origin.x; | |||||
| bounds.m_r = rect.origin.x-screenSize.origin.x + rect.size.width; | |||||
| bounds.m_t = screenSize.size.height - (rect.origin.y + rect.size.height -screenSize.origin.y); | |||||
| [pool drain]; | [pool drain]; | ||||
| } | } | ||||
| void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const | void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const | ||||
| { | { | ||||
| NSRect rect; | |||||
| GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getClientBounds(): window invalid"); | GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getClientBounds(): window invalid"); | ||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||||
| NSRect screenSize = [[m_window screen] visibleFrame]; | NSRect screenSize = [[m_window screen] visibleFrame]; | ||||
| //Max window contents as screen size (excluding title bar...) | // Max window contents as screen size (excluding title bar...) | ||||
| NSRect contentRect = [CocoaWindow contentRectForFrameRect:screenSize | NSRect contentRect = [CocoaWindow contentRectForFrameRect:screenSize | ||||
| styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)]; | styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)]; | ||||
| rect = [m_window contentRectForFrameRect:[m_window frame]]; | NSRect rect = [m_window contentRectForFrameRect:[m_window frame]]; | ||||
| bounds.m_b = contentRect.size.height - (rect.origin.y -contentRect.origin.y); | bounds.m_b = contentRect.size.height - (rect.origin.y - contentRect.origin.y); | ||||
| bounds.m_l = rect.origin.x -contentRect.origin.x; | bounds.m_l = rect.origin.x - contentRect.origin.x; | ||||
| bounds.m_r = rect.origin.x-contentRect.origin.x + rect.size.width; | bounds.m_r = rect.origin.x - contentRect.origin.x + rect.size.width; | ||||
| bounds.m_t = contentRect.size.height - (rect.origin.y + rect.size.height -contentRect.origin.y); | bounds.m_t = contentRect.size.height - (rect.origin.y + rect.size.height -contentRect.origin.y); | ||||
| [pool drain]; | [pool drain]; | ||||
| } | } | ||||
| Context not available. | |||||