/
box.go
40 lines (34 loc) · 1.14 KB
/
box.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
package main
import (
"code.google.com/p/freetype-go/freetype"
"image"
"image/color"
"image/draw"
)
type Box struct {
Content string
Color color.RGBA
TypeColor color.RGBA
}
func (box *Box) Render(context *Context, x int, y int, w int) {
rectangle := image.Rect(x, y, x+w, y+box.GetHeight())
draw.Draw(context.Img, rectangle, &image.Uniform{&box.Color}, image.ZP, draw.Src)
rectangle = image.Rect(x, y, x+10, y+box.GetHeight())
draw.Draw(context.Img, rectangle, &image.Uniform{&color.RGBA{0, 0, 0, 255}}, image.ZP, draw.Src)
rectangle = image.Rect(x+2, y, x+8, y+box.GetHeight())
draw.Draw(context.Img, rectangle, &image.Uniform{&box.TypeColor}, image.ZP, draw.Src)
box.RenderText(context, x+10, y)
}
func (box *Box) RenderText(context *Context, x int, y int) {
pt := freetype.Pt(x, y)
pt.Y += context.FontContext.PointToFix32(18.0)
context.FontContext.SetSrc(&image.Uniform{color.RGBA{255, 255, 255, 255}})
for _, s := range box.Content {
context.FontContext.DrawString(string(s), pt)
pt.X += context.FontContext.PointToFix32(18.0)
}
context.FontContext.SetClip(context.Img.Bounds())
}
func (box *Box) GetHeight() int {
return 20
}