-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathcursor.go
More file actions
56 lines (47 loc) · 1.27 KB
/
cursor.go
File metadata and controls
56 lines (47 loc) · 1.27 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
package cursor
import (
"image"
"path/filepath"
"github.com/linuxdeepin/dde-api/theme_thumb/common"
)
const (
Version = 1
basePadding = 12
baseIconSize = 24
)
func Gen(descFile string, width, height int, scaleFactor float64, out string) error {
dir := filepath.Join(filepath.Dir(descFile), "cursors")
iconSize := int(baseIconSize * scaleFactor)
padding := int(basePadding * scaleFactor)
width = int(float64(width) * scaleFactor)
height = int(float64(height) * scaleFactor)
images := getCursorIcons(dir, iconSize)
ret := common.CompositeIcons(images, width, height, iconSize, padding)
return common.SavePngFile(ret, out)
}
var presentCursors = [][]string{
{"left_ptr"},
{"left_ptr_watch"},
{"x-cursor", "X_cursor"},
{"hand2", "hand1"},
{"grab", "grabbing", "closedhand"},
{"fleur", "move"},
{"sb_v_double_arrow"},
{"sb_h_double_arrow"},
{"watch", "wait"},
}
func getCursorIcons(dir string, size int) (images []image.Image) {
for _, cursors := range presentCursors {
for _, cursor := range cursors {
img, err := loadXCursor(filepath.Join(dir, cursor), size)
if err == nil {
images = append(images, img)
break
}
}
}
return
}