ns_darwin.go (2644B)
1 // Copyright 2018 The Ebiten Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package ns provides access to Apple's AppKit API (https://developer.apple.com/documentation/appkit). 16 // 17 // This package is in very early stages of development. 18 // It's a minimal implementation with scope limited to 19 // supporting the movingtriangle example. 20 package ns 21 22 import ( 23 "unsafe" 24 25 "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/ca" 26 ) 27 28 // #cgo !ios CFLAGS: -mmacosx-version-min=10.12 29 // 30 // #include "ns_darwin.h" 31 import "C" 32 33 // Window is a window that an app displays on the screen. 34 // 35 // Reference: https://developer.apple.com/documentation/appkit/nswindow. 36 type Window struct { 37 window uintptr 38 } 39 40 // NewWindow returns a Window that wraps an existing NSWindow * pointer. 41 func NewWindow(window uintptr) Window { 42 return Window{window} 43 } 44 45 // ContentView returns the window's content view, the highest accessible View 46 // in the window's view hierarchy. 47 // 48 // Reference: https://developer.apple.com/documentation/appkit/nswindow/1419160-contentview. 49 func (w Window) ContentView() View { 50 return View{C.Window_ContentView(C.uintptr_t(w.window))} 51 } 52 53 // View is the infrastructure for drawing, printing, and handling events in an app. 54 // 55 // Reference: https://developer.apple.com/documentation/appkit/nsview. 56 type View struct { 57 view unsafe.Pointer 58 } 59 60 // SetLayer sets v.layer to l. 61 // 62 // Reference: https://developer.apple.com/documentation/appkit/nsview/1483298-layer. 63 func (v View) SetLayer(l ca.Layer) { 64 C.View_SetLayer(v.view, l.Layer()) 65 } 66 67 // SetWantsLayer sets v.wantsLayer to wantsLayer. 68 // 69 // Reference: https://developer.apple.com/documentation/appkit/nsview/1483695-wantslayer. 70 func (v View) SetWantsLayer(wantsLayer bool) { 71 if wantsLayer { 72 C.View_SetWantsLayer(v.view, 1) 73 } else { 74 C.View_SetWantsLayer(v.view, 0) 75 } 76 } 77 78 // IsInFullScreenMode returns a boolean value indicating whether the view is in full screen mode. 79 // 80 // Reference: https://developer.apple.com/documentation/appkit/nsview/1483337-infullscreenmode. 81 func (v View) IsInFullScreenMode() bool { 82 return C.View_IsInFullScreenMode(v.view) != 0 83 }