-
Notifications
You must be signed in to change notification settings - Fork 2
/
shadow.go
63 lines (57 loc) · 2.03 KB
/
shadow.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package rendercard
import (
"image/color"
"github.com/FloatTech/gg"
"github.com/disintegration/imaging"
)
// DrawRoundShadowedRectangle 绘制带阴影的圆角矩形
func DrawRoundShadowedRectangle(canvas *gg.Context, x, y, w, h, r, sr, sigma float64, ox, oy int, rectanglecolor, shadowcolor color.Color) {
DrawShadowedRectangle(canvas, x, y, w, h, sr, sigma, ox, oy, shadowcolor)
canvas.DrawRoundedRectangle(x, y, w, h, r)
canvas.SetColor(rectanglecolor)
canvas.Fill()
}
// DrawShadowedRectangle 绘制阴影
func DrawShadowedRectangle(canvas *gg.Context, x, y, w, h, r, sigma float64, ox, oy int, shadowcolor color.Color) {
one := gg.NewContextForImage(Transparency(canvas.Image(), 0))
one.DrawRoundedRectangle(x, y, w, h, r)
one.SetColor(shadowcolor)
one.Fill()
canvas.DrawImage(imaging.Blur(one.Image(), sigma), ox, oy)
}
// DrawShadowedString 绘制带阴影的文字
func DrawShadowedString(canvas *gg.Context, s string, fontdata []byte, x, y, point, sigma float64, ox, oy int, stringcolor, shadowcolor color.Color) (err error) {
one := gg.NewContext(canvas.W(), canvas.H())
err = one.ParseFontFace(fontdata, point)
if err != nil {
return
}
one.SetColor(shadowcolor)
one.DrawString(s, x, y)
canvas.DrawImage(imaging.Blur(one.Image(), sigma), ox, oy)
err = canvas.ParseFontFace(fontdata, point)
if err != nil {
return
}
canvas.SetColor(stringcolor)
canvas.DrawString(s, x, y)
return
}
// DrawShadowedStringAnchored 在锚点上绘制带阴影的文字
func DrawShadowedStringAnchored(canvas *gg.Context, s string, fontdata []byte, x, y, point, sigma float64, ox, oy int, stringcolor, shadowcolor color.Color, ax, ay float64) (err error) {
one := gg.NewContext(canvas.W(), canvas.H())
err = one.ParseFontFace(fontdata, point)
if err != nil {
return
}
one.SetColor(shadowcolor)
one.DrawStringAnchored(s, x, y, ax, ay)
canvas.DrawImage(imaging.Blur(one.Image(), sigma), ox, oy)
err = canvas.ParseFontFace(fontdata, point)
if err != nil {
return
}
canvas.SetColor(stringcolor)
canvas.DrawStringAnchored(s, x, y, ax, ay)
return
}