-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2d.go
75 lines (60 loc) · 1.75 KB
/
2d.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
package main
import (
"image"
g143 "github.com/bankole7782/graphics143"
"github.com/fogleman/gg"
)
type Ctx struct {
WindowWidth int
WindowHeight int
ggCtx *gg.Context
}
func New2dCtx(wWidth, wHeight int) Ctx {
// frame buffer
ggCtx := gg.NewContext(wWidth, wHeight)
// background rectangle
ggCtx.DrawRectangle(0, 0, float64(wWidth), float64(wHeight))
ggCtx.SetHexColor("#ffffff")
ggCtx.Fill()
// load font
fontPath := getDefaultFontPath()
err := ggCtx.LoadFontFace(fontPath, 20)
if err != nil {
panic(err)
}
ctx := Ctx{WindowWidth: wWidth, WindowHeight: wHeight, ggCtx: ggCtx}
return ctx
}
func Continue2dCtx(img image.Image) Ctx {
ggCtx := gg.NewContextForImage(img)
// load font
fontPath := getDefaultFontPath()
err := ggCtx.LoadFontFace(fontPath, 20)
if err != nil {
panic(err)
}
ctx := Ctx{WindowWidth: img.Bounds().Dx(), WindowHeight: img.Bounds().Dy(), ggCtx: ggCtx}
return ctx
}
func (ctx *Ctx) drawButtonA(btnId, originX, originY int, text, textColor, bgColor string) g143.Rect {
// draw bounding rect
width, height := toolBoxW, toolBoxH
ctx.ggCtx.SetHexColor(bgColor)
ctx.ggCtx.DrawRectangle(float64(originX), float64(originY), float64(width), float64(height))
ctx.ggCtx.Fill()
// draw text
ctx.ggCtx.SetHexColor(textColor)
ctx.ggCtx.DrawString(text, float64(originX)+10, float64(originY)+fontSize+10)
// save dimensions
btnARect := g143.NewRect(originX, originY, int(width), int(height))
objCoords[btnId] = btnARect
return btnARect
}
func (ctx *Ctx) windowRect() g143.Rect {
return g143.NewRect(0, 0, ctx.WindowWidth, ctx.WindowHeight)
}
func nextVerticalCoords(aRect g143.Rect, margin int) (int, int) {
nextOriginX := margin
nextOriginY := aRect.OriginY + aRect.Height + margin
return nextOriginX, nextOriginY
}