-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawcontext.go
84 lines (70 loc) · 2.35 KB
/
drawcontext.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package ifs
import (
"image/color"
eimage "github.com/ebitenui/ebitenui/image"
"github.com/ebitenui/ebitenui/widget"
"github.com/hajimehoshi/ebiten/v2"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
)
// DrawContext contains various structures that are useful during Draw calls.
type DrawContext struct {
Txt *TextRenderer
Screen *ebiten.Image
UI *DrawContextUI
Game *GameContext
}
// DrawContextUI is a structure containing the UI styling and data.
type DrawContextUI struct {
Width, Height int
//
HeadlineFace font.Face
BodyCopyFace font.Face
ButtonImage *widget.ButtonImage
ButtonTextColor *widget.ButtonTextColor
ButtonPadding widget.Insets
TextInputColor *widget.TextInputColor
TextInputImage *widget.TextInputImage
TextInputPadding widget.Insets
//
ItemInfoBackgroundImage *eimage.NineSlice
}
// Init sets up the necessary data structuers, such as fonts, styling, images, etc.
func (ui *DrawContextUI) Init(txt *TextRenderer) {
ui.HeadlineFace, _ = opentype.NewFace(txt.Renderer.GetFont(), &opentype.FaceOptions{
Size: 16,
DPI: 72,
Hinting: font.HintingNone,
})
ui.BodyCopyFace, _ = opentype.NewFace(txt.Renderer.GetFont(), &opentype.FaceOptions{
Size: 16,
DPI: 72,
Hinting: font.HintingNone,
})
ui.ButtonImage = &widget.ButtonImage{
Idle: eimage.NewNineSliceColor(color.NRGBA{R: 40, G: 30, B: 40, A: 255}),
Hover: eimage.NewNineSliceColor(color.NRGBA{R: 50, G: 40, B: 50, A: 255}),
Pressed: eimage.NewNineSliceColor(color.NRGBA{R: 60, G: 50, B: 60, A: 255}),
}
ui.ButtonPadding = widget.Insets{
Left: 30,
Right: 30,
Top: 5,
Bottom: 5,
}
ui.ButtonTextColor = &widget.ButtonTextColor{
Idle: color.NRGBA{0xdf, 0xf4, 0xff, 0xff},
}
ui.TextInputImage = &widget.TextInputImage{
Idle: eimage.NewNineSliceColor(color.NRGBA{R: 60, G: 50, B: 60, A: 255}),
Disabled: eimage.NewNineSliceColor(color.NRGBA{R: 100, G: 100, B: 100, A: 255}),
}
ui.TextInputPadding = widget.NewInsetsSimple(5)
ui.TextInputColor = &widget.TextInputColor{
Idle: color.NRGBA{254, 255, 255, 255},
Disabled: color.NRGBA{R: 200, G: 200, B: 200, A: 255},
Caret: color.NRGBA{254, 255, 255, 255},
DisabledCaret: color.NRGBA{R: 200, G: 200, B: 200, A: 255},
}
ui.ItemInfoBackgroundImage = eimage.NewNineSliceColor(color.NRGBA{R: 20, G: 20, B: 20, A: 255})
}