-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcursor_darwin.go
37 lines (31 loc) · 1.19 KB
/
cursor_darwin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright ©2021-2022 by Richard A. Wilkes. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, version 2.0.
package unison
import (
"image"
"github.com/ddkwork/golibrary/mylog"
"github.com/ddkwork/toolbox/errs"
"github.com/ddkwork/unison/internal/glfw"
"golang.org/x/image/draw"
)
// NewCursor creates a new custom cursor from an image.
func NewCursor(img *Image, hotSpot Point) *Cursor {
nrgba := mylog.Check2(img.ToNRGBA())
// glfw doesn't take the high resolution cursors properly, so scale them down, if needed
logicalSize := img.LogicalSize()
size := img.Size()
if logicalSize != size {
dstRect := image.Rect(0, 0, int(logicalSize.Width), int(logicalSize.Height))
dst := image.NewNRGBA(dstRect)
draw.CatmullRom.Scale(dst, dstRect, nrgba, image.Rect(0, 0, int(size.Width), int(size.Height)),
draw.Over, nil)
nrgba = dst
}
return glfw.CreateCursor(nrgba, int(hotSpot.X), int(hotSpot.Y))
}