Line data Source code
1 : package hud
2 :
3 : import (
4 : "image"
5 : "image/color"
6 :
7 : "github.com/hajimehoshi/ebiten/v2/text/v2"
8 : theme "github.com/kijimaD/ruins/internal/widgets/theme"
9 : "github.com/kijimaD/ruins/internal/widgets/uicore"
10 : )
11 :
12 : // OutlinedText は枠線付きテキストを描く。8方向へずらして枠を描いてから本体を重ねる。
13 : // 世界の上に文字を置くので、背景の明暗によらず読めるようにする
14 : func OutlinedText(cv uicore.Canvas, str string, face text.Face, pos image.Point, textColor, outlineColor color.Color) {
15 1 : offsets := []image.Point{
16 1 : {X: -1, Y: -1}, {X: 0, Y: -1}, {X: 1, Y: -1},
17 1 : {X: -1, Y: 0}, {X: 1, Y: 0},
18 1 : {X: -1, Y: 1}, {X: 0, Y: 1}, {X: 1, Y: 1},
19 1 : }
20 1 : for _, off := range offsets {
21 1 : cv.DrawText(pos.Add(off), str, face, outlineColor)
22 1 : }
23 1 : cv.DrawText(pos, str, face, textColor)
24 : }
25 :
26 : // drawOutlinedText は共通の縁色で枠線付きテキストを描く。HUD の文字はすべてこれを通す
27 : func drawOutlinedText(cv uicore.Canvas, textStr string, face text.Face, pos image.Point, textColor color.Color) {
28 1 : OutlinedText(cv, textStr, face, pos, textColor, theme.HUDTextOutline)
29 1 : }
|