ns.go (2366B)
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 // +build darwin 16 17 // Package ns provides access to Apple's AppKit API (https://developer.apple.com/documentation/appkit). 18 // 19 // This package is in very early stages of development. 20 // It's a minimal implementation with scope limited to 21 // supporting the movingtriangle example. 22 package ns 23 24 import ( 25 "unsafe" 26 27 "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/ca" 28 ) 29 30 // #cgo !ios CFLAGS: -mmacosx-version-min=10.12 31 // 32 // #include "ns.h" 33 import "C" 34 35 // Window is a window that an app displays on the screen. 36 // 37 // Reference: https://developer.apple.com/documentation/appkit/nswindow. 38 type Window struct { 39 window uintptr 40 } 41 42 // NewWindow returns a Window that wraps an existing NSWindow * pointer. 43 func NewWindow(window uintptr) Window { 44 return Window{window} 45 } 46 47 // ContentView returns the window's content view, the highest accessible View 48 // in the window's view hierarchy. 49 // 50 // Reference: https://developer.apple.com/documentation/appkit/nswindow/1419160-contentview. 51 func (w Window) ContentView() View { 52 return View{C.Window_ContentView(C.uintptr_t(w.window))} 53 } 54 55 // View is the infrastructure for drawing, printing, and handling events in an app. 56 // 57 // Reference: https://developer.apple.com/documentation/appkit/nsview. 58 type View struct { 59 view unsafe.Pointer 60 } 61 62 // SetLayer sets v.layer to l. 63 // 64 // Reference: https://developer.apple.com/documentation/appkit/nsview/1483298-layer. 65 func (v View) SetLayer(l ca.Layer) { 66 C.View_SetLayer(v.view, l.Layer()) 67 } 68 69 // SetWantsLayer sets v.wantsLayer to wantsLayer. 70 // 71 // Reference: https://developer.apple.com/documentation/appkit/nsview/1483695-wantslayer. 72 func (v View) SetWantsLayer(wantsLayer bool) { 73 if wantsLayer { 74 C.View_SetWantsLayer(v.view, 1) 75 } else { 76 C.View_SetWantsLayer(v.view, 0) 77 } 78 }