mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/uidriver/glfw: Native macOS implementation for setting cursor shape (#1624)
Updates #1624
This commit is contained in:
parent
7adf6aac27
commit
bea5ab3335
@ -35,4 +35,6 @@ const (
|
||||
CursorShapeText CursorShapeType = CursorShapeType(driver.CursorShapeText)
|
||||
CursorShapeCrosshair CursorShapeType = CursorShapeType(driver.CursorShapeCrosshair)
|
||||
CursorShapePointer CursorShapeType = CursorShapeType(driver.CursorShapePointer)
|
||||
CursorShapeEWResize CursorShapeType = CursorShapeType(driver.CursorShapeEWResize)
|
||||
CursorShapeNSResize CursorShapeType = CursorShapeType(driver.CursorShapeNSResize)
|
||||
)
|
||||
|
@ -61,6 +61,10 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
ebitenutil.DebugPrint(screen, "CursorShape: Crosshair")
|
||||
case ebiten.CursorShapePointer:
|
||||
ebitenutil.DebugPrint(screen, "CursorShape: Pointer")
|
||||
case ebiten.CursorShapeEWResize:
|
||||
ebitenutil.DebugPrint(screen, "CursorShape: EW Resize")
|
||||
case ebiten.CursorShapeNSResize:
|
||||
ebitenutil.DebugPrint(screen, "CursorShape: NS Resize")
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,22 +75,21 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
||||
func main() {
|
||||
g := &Game{
|
||||
grids: map[image.Rectangle]ebiten.CursorShapeType{
|
||||
image.Rect(100, 100, 200, 300): ebiten.CursorShapeDefault,
|
||||
image.Rect(200, 100, 300, 300): ebiten.CursorShapeText,
|
||||
image.Rect(300, 100, 400, 300): ebiten.CursorShapeCrosshair,
|
||||
image.Rect(400, 100, 500, 300): ebiten.CursorShapePointer,
|
||||
image.Rect(100, 100, 200, 200): ebiten.CursorShapeDefault,
|
||||
image.Rect(200, 100, 300, 200): ebiten.CursorShapeText,
|
||||
image.Rect(300, 100, 400, 200): ebiten.CursorShapeCrosshair,
|
||||
image.Rect(100, 200, 200, 300): ebiten.CursorShapePointer,
|
||||
image.Rect(200, 200, 300, 300): ebiten.CursorShapeEWResize,
|
||||
image.Rect(300, 200, 400, 300): ebiten.CursorShapeNSResize,
|
||||
},
|
||||
gridColors: map[image.Rectangle]color.Color{},
|
||||
}
|
||||
for rect, c := range g.grids {
|
||||
clr := color.RGBA{0x40, 0x40, 0x40, 0xff}
|
||||
switch c % 3 {
|
||||
case 0:
|
||||
if c%2 == 0 {
|
||||
clr.R = 0x80
|
||||
case 1:
|
||||
} else {
|
||||
clr.G = 0x80
|
||||
case 2:
|
||||
clr.B = 0x80
|
||||
}
|
||||
g.gridColors[rect] = clr
|
||||
}
|
||||
|
@ -29,4 +29,6 @@ const (
|
||||
CursorShapeText
|
||||
CursorShapeCrosshair
|
||||
CursorShapePointer
|
||||
CursorShapeEWResize
|
||||
CursorShapeNSResize
|
||||
)
|
||||
|
@ -190,6 +190,8 @@ func initialize() error {
|
||||
glfwSystemCursors[driver.CursorShapeText] = glfw.CreateStandardCursor(glfw.IBeamCursor)
|
||||
glfwSystemCursors[driver.CursorShapeCrosshair] = glfw.CreateStandardCursor(glfw.CrosshairCursor)
|
||||
glfwSystemCursors[driver.CursorShapePointer] = glfw.CreateStandardCursor(glfw.HandCursor)
|
||||
glfwSystemCursors[driver.CursorShapeEWResize] = glfw.CreateStandardCursor(glfw.HResizeCursor)
|
||||
glfwSystemCursors[driver.CursorShapeNSResize] = glfw.CreateStandardCursor(glfw.VResizeCursor)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -651,7 +653,7 @@ func (u *UserInterface) SetCursorShape(shape driver.CursorShape) {
|
||||
return
|
||||
}
|
||||
_ = u.t.Call(func() error {
|
||||
u.window.SetCursor(glfwSystemCursors[shape])
|
||||
u.setNativeCursor(shape)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
@ -43,9 +43,35 @@ package glfw
|
||||
// return [[NSApplication sharedApplication] currentSystemPresentationOptions] &
|
||||
// NSApplicationPresentationFullScreen;
|
||||
// }
|
||||
//
|
||||
// static void setNativeCursor(int cursorID) {
|
||||
// id cursor = [[NSCursor class] performSelector:@selector(arrowCursor)];
|
||||
// switch (cursorID) {
|
||||
// case 0:
|
||||
// cursor = [[NSCursor class] performSelector:@selector(arrowCursor)];
|
||||
// break;
|
||||
// case 1:
|
||||
// cursor = [[NSCursor class] performSelector:@selector(IBeamCursor)];
|
||||
// break;
|
||||
// case 2:
|
||||
// cursor = [[NSCursor class] performSelector:@selector(crosshairCursor)];
|
||||
// break;
|
||||
// case 3:
|
||||
// cursor = [[NSCursor class] performSelector:@selector(pointingHandCursor)];
|
||||
// break;
|
||||
// case 4:
|
||||
// cursor = [[NSCursor class] performSelector:@selector(_windowResizeEastWestCursor)];
|
||||
// break;
|
||||
// case 5:
|
||||
// cursor = [[NSCursor class] performSelector:@selector(_windowResizeNorthSouthCursor)];
|
||||
// break;
|
||||
// }
|
||||
// [cursor push];
|
||||
// }
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/glfw"
|
||||
)
|
||||
|
||||
@ -91,3 +117,7 @@ func (u *UserInterface) nativeWindow() uintptr {
|
||||
func (u *UserInterface) isNativeFullscreen() bool {
|
||||
return bool(C.isNativeFullscreen())
|
||||
}
|
||||
|
||||
func (u *UserInterface) setNativeCursor(shape driver.CursorShape) {
|
||||
C.setNativeCursor(C.int(shape))
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package glfw
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/glfw"
|
||||
)
|
||||
|
||||
@ -67,3 +68,8 @@ func (u *UserInterface) nativeWindow() uintptr {
|
||||
func (u *UserInterface) isNativeFullscreen() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (u *UserInterface) setNativeCursor(shape driver.CursorShape) {
|
||||
// TODO: Use native API in the future (#1571)
|
||||
u.window.SetCursor(glfwSystemCursors[shape])
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/glfw"
|
||||
)
|
||||
|
||||
@ -186,3 +187,8 @@ func (u *UserInterface) nativeWindow() uintptr {
|
||||
func (u *UserInterface) isNativeFullscreen() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (u *UserInterface) setNativeCursor(shape driver.CursorShape) {
|
||||
// TODO: Use native API in the future (#1571)
|
||||
u.window.SetCursor(glfwSystemCursors[shape])
|
||||
}
|
||||
|
@ -41,6 +41,10 @@ func driverCursorShapeToCSSCursor(cursor driver.CursorShape) string {
|
||||
return "crosshair"
|
||||
case driver.CursorShapePointer:
|
||||
return "pointer"
|
||||
case driver.CursorShapeEWResize:
|
||||
return "ew-resize"
|
||||
case driver.CursorShapeNSResize:
|
||||
return "ns-resize"
|
||||
}
|
||||
return "auto"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user