ui: Replace the native window's type (unsafe.Pointer) with uintptr

Updates #1306
This commit is contained in:
Hajime Hoshi 2020-09-04 00:43:51 +09:00
parent 55f0c983ba
commit a3b41515a9
13 changed files with 24 additions and 38 deletions

View File

@ -14,10 +14,6 @@
package glfw
import (
"unsafe"
)
func (w *Window) GetCocoaWindow() unsafe.Pointer {
return w.w.GetCocoaWindow()
func (w *Window) GetCocoaWindow() uintptr {
return uintptr(w.w.GetCocoaWindow())
}

View File

@ -14,12 +14,8 @@
package glfw
import (
"unsafe"
)
func (w *Window) GetWin32Window() unsafe.Pointer {
func (w *Window) GetWin32Window() uintptr {
r := glfwDLL.call("glfwGetWin32Window", w.w)
panicError()
return unsafe.Pointer(r)
return r
}

View File

@ -362,7 +362,7 @@ func (g *Graphics) End() {
})
}
func (g *Graphics) SetWindow(window unsafe.Pointer) {
func (g *Graphics) SetWindow(window uintptr) {
g.t.Call(func() error {
// Note that [NSApp mainWindow] returns nil when the window is borderless.
// Then the window is needed to be given explicitly.

View File

@ -36,11 +36,11 @@ import "C"
//
// Reference: https://developer.apple.com/documentation/appkit/nswindow.
type Window struct {
window unsafe.Pointer
window uintptr
}
// NewWindow returns a Window that wraps an existing NSWindow * pointer.
func NewWindow(window unsafe.Pointer) Window {
func NewWindow(window uintptr) Window {
return Window{window}
}
@ -49,7 +49,7 @@ func NewWindow(window unsafe.Pointer) Window {
//
// Reference: https://developer.apple.com/documentation/appkit/nswindow/1419160-contentview.
func (w Window) ContentView() View {
return View{C.Window_ContentView(w.window)}
return View{C.Window_ContentView(C.uintptr_t(w.window))}
}
// View is the infrastructure for drawing, printing, and handling events in an app.

View File

@ -14,7 +14,9 @@
// +build darwin
void *Window_ContentView(void *window);
#include "stdint.h"
void *Window_ContentView(uintptr_t window);
void View_SetLayer(void *view, void *layer);
void View_SetWantsLayer(void *view, unsigned char wantsLayer);

View File

@ -17,7 +17,7 @@
#include "ns.h"
#import <Cocoa/Cocoa.h>
void *Window_ContentView(void *window) {
void *Window_ContentView(uintptr_t window) {
return ((NSWindow *)window).contentView;
}

View File

@ -18,14 +18,13 @@ package metal
import (
"sync"
"unsafe"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/ca"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl"
)
type view struct {
window unsafe.Pointer
window uintptr
uiview uintptr
windowChanged bool

View File

@ -39,7 +39,7 @@ import (
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl"
)
func (v *view) setWindow(window unsafe.Pointer) {
func (v *view) setWindow(window uintptr) {
panic("metal: setWindow is not available on iOS")
}

View File

@ -18,13 +18,11 @@
package metal
import (
"unsafe"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/ns"
)
func (v *view) setWindow(window unsafe.Pointer) {
func (v *view) setWindow(window uintptr) {
// NSView can be updated e.g., fullscreen-state is switched.
v.window = window
v.windowChanged = true

View File

@ -26,7 +26,6 @@ import (
"runtime"
"sync"
"time"
"unsafe"
"github.com/hajimehoshi/ebiten/internal/devicescale"
"github.com/hajimehoshi/ebiten/internal/driver"
@ -768,12 +767,12 @@ func (u *UserInterface) run() error {
return nil
})
var w unsafe.Pointer
var w uintptr
_ = u.t.Call(func() error {
w = u.nativeWindow()
return nil
})
if g, ok := u.Graphics().(interface{ SetWindow(unsafe.Pointer) }); ok {
if g, ok := u.Graphics().(interface{ SetWindow(uintptr) }); ok {
g.SetWindow(w)
}
return u.loop()
@ -1066,7 +1065,7 @@ func (u *UserInterface) setWindowSize(width, height int, fullscreen bool) {
})
if windowRecreated {
if g, ok := u.Graphics().(interface{ SetWindow(unsafe.Pointer) }); ok {
if g, ok := u.Graphics().(interface{ SetWindow(uintptr) }); ok {
g.SetWindow(u.nativeWindow())
}
}

View File

@ -22,7 +22,7 @@ package glfw
//
// #import <AppKit/AppKit.h>
//
// static void currentMonitorPos(void* windowPtr, int* x, int* y) {
// static void currentMonitorPos(uintptr_t windowPtr, int* x, int* y) {
// NSScreen* screen = [NSScreen mainScreen];
// if (windowPtr) {
// NSWindow* window = (NSWindow*)windowPtr;
@ -42,8 +42,6 @@ package glfw
import "C"
import (
"unsafe"
"github.com/hajimehoshi/ebiten/internal/glfw"
)
@ -60,7 +58,7 @@ func currentMonitorByOS(w *glfw.Window) *glfw.Monitor {
y := C.int(0)
// Note: [NSApp mainWindow] is nil when it doesn't have its border. Use w here.
win := w.GetCocoaWindow()
C.currentMonitorPos(win, &x, &y)
C.currentMonitorPos(C.uintptr_t(win), &x, &y)
for _, m := range glfw.GetMonitors() {
mx, my := m.GetPos()
if int(x) == mx && int(y) == my {
@ -70,6 +68,6 @@ func currentMonitorByOS(w *glfw.Window) *glfw.Monitor {
return nil
}
func (u *UserInterface) nativeWindow() unsafe.Pointer {
func (u *UserInterface) nativeWindow() uintptr {
return u.window.GetCocoaWindow()
}

View File

@ -19,8 +19,6 @@
package glfw
import (
"unsafe"
"github.com/hajimehoshi/ebiten/internal/glfw"
)
@ -37,7 +35,7 @@ func currentMonitorByOS(_ *glfw.Window) *glfw.Monitor {
return nil
}
func (u *UserInterface) nativeWindow() unsafe.Pointer {
func (u *UserInterface) nativeWindow() uintptr {
// TODO: Implement this.
return nil
return 0
}

View File

@ -165,6 +165,6 @@ func currentMonitorByOS(_ *glfw.Window) *glfw.Monitor {
return nil
}
func (u *UserInterface) nativeWindow() unsafe.Pointer {
func (u *UserInterface) nativeWindow() uintptr {
return u.window.GetWin32Window()
}