forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowCocoaWrappers.m
More file actions
78 lines (60 loc) · 1.79 KB
/
WindowCocoaWrappers.m
File metadata and controls
78 lines (60 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// Copyright Contributors to the MaterialX Project
// SPDX-License-Identifier: Apache-2.0
//
#if defined (__APPLE__)
#ifndef TARGET_OS_IPHONE
#import <Cocoa/Cocoa.h>
#import <AppKit/NSApplication.h>
#import <MaterialXRenderHw/WindowCocoaWrappers.h>
void* NSUtilGetView(void* pWindow)
{
NSWindow* window = (NSWindow*)pWindow;
NSView* view = [window contentView];
return (void*)view;
}
void* NSUtilCreateWindow(unsigned int width, unsigned int height, const char* title, bool batchMode)
{
// In batch mode, ensure that Cocoa is initialized
if (batchMode)
{
NSApplicationLoad();
}
// Create local autorelease pool for any objects that need to be autoreleased.
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, height)
styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable
backing:NSBackingStoreBuffered defer:NO];
NSString *string = [NSString stringWithUTF8String:title];
[window setTitle:string];
[window setAlphaValue:0.0];
// Free up memory
[pool release];
return (void*)window;
}
void NSUtilShowWindow(void* pWindow)
{
NSWindow* window = (NSWindow*) pWindow;
[window orderFront:window];
}
void NSUtilHideWindow(void* pWindow)
{
NSWindow* window = (NSWindow*)pWindow;
[window orderOut:window];
}
void NSUtilSetFocus(void* pWindow)
{
NSWindow* window = (NSWindow*)pWindow;
[window makeKeyAndOrderFront:window];
}
void NSUtilDisposeWindow(void* pWindow)
{
// Create local autorelease pool for any objects that need to be autoreleased.
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow* window = (NSWindow*)pWindow;
[window close];
// Free up memory
[pool release];
}
#endif
#endif