mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
ui: Replace the native window's type (unsafe.Pointer) with uintptr
Updates #1306
This commit is contained in:
parent
55f0c983ba
commit
a3b41515a9
@ -14,10 +14,6 @@
|
|||||||
|
|
||||||
package glfw
|
package glfw
|
||||||
|
|
||||||
import (
|
func (w *Window) GetCocoaWindow() uintptr {
|
||||||
"unsafe"
|
return uintptr(w.w.GetCocoaWindow())
|
||||||
)
|
|
||||||
|
|
||||||
func (w *Window) GetCocoaWindow() unsafe.Pointer {
|
|
||||||
return w.w.GetCocoaWindow()
|
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,8 @@
|
|||||||
|
|
||||||
package glfw
|
package glfw
|
||||||
|
|
||||||
import (
|
func (w *Window) GetWin32Window() uintptr {
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (w *Window) GetWin32Window() unsafe.Pointer {
|
|
||||||
r := glfwDLL.call("glfwGetWin32Window", w.w)
|
r := glfwDLL.call("glfwGetWin32Window", w.w)
|
||||||
panicError()
|
panicError()
|
||||||
return unsafe.Pointer(r)
|
return r
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
g.t.Call(func() error {
|
||||||
// Note that [NSApp mainWindow] returns nil when the window is borderless.
|
// Note that [NSApp mainWindow] returns nil when the window is borderless.
|
||||||
// Then the window is needed to be given explicitly.
|
// Then the window is needed to be given explicitly.
|
||||||
|
@ -36,11 +36,11 @@ import "C"
|
|||||||
//
|
//
|
||||||
// Reference: https://developer.apple.com/documentation/appkit/nswindow.
|
// Reference: https://developer.apple.com/documentation/appkit/nswindow.
|
||||||
type Window struct {
|
type Window struct {
|
||||||
window unsafe.Pointer
|
window uintptr
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWindow returns a Window that wraps an existing NSWindow * pointer.
|
// NewWindow returns a Window that wraps an existing NSWindow * pointer.
|
||||||
func NewWindow(window unsafe.Pointer) Window {
|
func NewWindow(window uintptr) Window {
|
||||||
return Window{window}
|
return Window{window}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ func NewWindow(window unsafe.Pointer) Window {
|
|||||||
//
|
//
|
||||||
// Reference: https://developer.apple.com/documentation/appkit/nswindow/1419160-contentview.
|
// Reference: https://developer.apple.com/documentation/appkit/nswindow/1419160-contentview.
|
||||||
func (w Window) ContentView() View {
|
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 is the infrastructure for drawing, printing, and handling events in an app.
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
|
|
||||||
// +build darwin
|
// +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_SetLayer(void *view, void *layer);
|
||||||
void View_SetWantsLayer(void *view, unsigned char wantsLayer);
|
void View_SetWantsLayer(void *view, unsigned char wantsLayer);
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#include "ns.h"
|
#include "ns.h"
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
void *Window_ContentView(void *window) {
|
void *Window_ContentView(uintptr_t window) {
|
||||||
return ((NSWindow *)window).contentView;
|
return ((NSWindow *)window).contentView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,14 +18,13 @@ package metal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/ca"
|
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/ca"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl"
|
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl"
|
||||||
)
|
)
|
||||||
|
|
||||||
type view struct {
|
type view struct {
|
||||||
window unsafe.Pointer
|
window uintptr
|
||||||
uiview uintptr
|
uiview uintptr
|
||||||
|
|
||||||
windowChanged bool
|
windowChanged bool
|
||||||
|
@ -39,7 +39,7 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl"
|
"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")
|
panic("metal: setWindow is not available on iOS")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,13 +18,11 @@
|
|||||||
package metal
|
package metal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl"
|
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/ns"
|
"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.
|
// NSView can be updated e.g., fullscreen-state is switched.
|
||||||
v.window = window
|
v.window = window
|
||||||
v.windowChanged = true
|
v.windowChanged = true
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/devicescale"
|
"github.com/hajimehoshi/ebiten/internal/devicescale"
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||||
@ -768,12 +767,12 @@ func (u *UserInterface) run() error {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
var w unsafe.Pointer
|
var w uintptr
|
||||||
_ = u.t.Call(func() error {
|
_ = u.t.Call(func() error {
|
||||||
w = u.nativeWindow()
|
w = u.nativeWindow()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if g, ok := u.Graphics().(interface{ SetWindow(unsafe.Pointer) }); ok {
|
if g, ok := u.Graphics().(interface{ SetWindow(uintptr) }); ok {
|
||||||
g.SetWindow(w)
|
g.SetWindow(w)
|
||||||
}
|
}
|
||||||
return u.loop()
|
return u.loop()
|
||||||
@ -1066,7 +1065,7 @@ func (u *UserInterface) setWindowSize(width, height int, fullscreen bool) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if windowRecreated {
|
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())
|
g.SetWindow(u.nativeWindow())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ package glfw
|
|||||||
//
|
//
|
||||||
// #import <AppKit/AppKit.h>
|
// #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];
|
// NSScreen* screen = [NSScreen mainScreen];
|
||||||
// if (windowPtr) {
|
// if (windowPtr) {
|
||||||
// NSWindow* window = (NSWindow*)windowPtr;
|
// NSWindow* window = (NSWindow*)windowPtr;
|
||||||
@ -42,8 +42,6 @@ package glfw
|
|||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/glfw"
|
"github.com/hajimehoshi/ebiten/internal/glfw"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -60,7 +58,7 @@ func currentMonitorByOS(w *glfw.Window) *glfw.Monitor {
|
|||||||
y := C.int(0)
|
y := C.int(0)
|
||||||
// Note: [NSApp mainWindow] is nil when it doesn't have its border. Use w here.
|
// Note: [NSApp mainWindow] is nil when it doesn't have its border. Use w here.
|
||||||
win := w.GetCocoaWindow()
|
win := w.GetCocoaWindow()
|
||||||
C.currentMonitorPos(win, &x, &y)
|
C.currentMonitorPos(C.uintptr_t(win), &x, &y)
|
||||||
for _, m := range glfw.GetMonitors() {
|
for _, m := range glfw.GetMonitors() {
|
||||||
mx, my := m.GetPos()
|
mx, my := m.GetPos()
|
||||||
if int(x) == mx && int(y) == my {
|
if int(x) == mx && int(y) == my {
|
||||||
@ -70,6 +68,6 @@ func currentMonitorByOS(w *glfw.Window) *glfw.Monitor {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) nativeWindow() unsafe.Pointer {
|
func (u *UserInterface) nativeWindow() uintptr {
|
||||||
return u.window.GetCocoaWindow()
|
return u.window.GetCocoaWindow()
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
package glfw
|
package glfw
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/glfw"
|
"github.com/hajimehoshi/ebiten/internal/glfw"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,7 +35,7 @@ func currentMonitorByOS(_ *glfw.Window) *glfw.Monitor {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) nativeWindow() unsafe.Pointer {
|
func (u *UserInterface) nativeWindow() uintptr {
|
||||||
// TODO: Implement this.
|
// TODO: Implement this.
|
||||||
return nil
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -165,6 +165,6 @@ func currentMonitorByOS(_ *glfw.Window) *glfw.Monitor {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) nativeWindow() unsafe.Pointer {
|
func (u *UserInterface) nativeWindow() uintptr {
|
||||||
return u.window.GetWin32Window()
|
return u.window.GetWin32Window()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user