more code cleanup
This commit is contained in:
@@ -12,17 +12,63 @@ type Graphics struct {
|
||||
Bounds Rect
|
||||
}
|
||||
|
||||
func CreateGraphics(bounds Rect) *Graphics {
|
||||
return &Graphics {
|
||||
Bounds: bounds,
|
||||
Style: Style {
|
||||
Fill: false,
|
||||
FillColor: rl.RayWhite,
|
||||
Stroke: true,
|
||||
StrokeColor: rl.Black,
|
||||
StrokeWeight: 1.0,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type Style struct {
|
||||
StrokeColor, FillColor color.RGBA
|
||||
StrokeWeight float32
|
||||
Stroke, Fill bool
|
||||
}
|
||||
|
||||
func (g *Graphics) GetGraphicsWidth() int32 {
|
||||
func (g *Graphics) Center() Point {
|
||||
return g.Bounds.Center()
|
||||
}
|
||||
|
||||
func (g *Graphics) Begin() {
|
||||
rl.BeginBlendMode(rl.BlendAlphaPremultiply)
|
||||
g.PushMatrix()
|
||||
g.Translate(g.Bounds.UL())
|
||||
g.BeginClip(g.Bounds)
|
||||
}
|
||||
|
||||
func (g *Graphics) Clear() {
|
||||
rl.ClearBackground(rl.Blank)
|
||||
}
|
||||
|
||||
func (g *Graphics) Background(c color.RGBA) {
|
||||
rl.ClearBackground(c)
|
||||
}
|
||||
|
||||
func (g *Graphics) End() {
|
||||
g.EndBlend()
|
||||
g.EndClip()
|
||||
g.PopMatrix()
|
||||
}
|
||||
|
||||
func (g *Graphics) Width() float32 {
|
||||
return g.Bounds.Width
|
||||
}
|
||||
|
||||
func (g *Graphics) Height() float32 {
|
||||
return g.Bounds.Height
|
||||
}
|
||||
|
||||
func (g *Graphics) WidthInt32() int32 {
|
||||
return int32(g.Bounds.Width)
|
||||
}
|
||||
|
||||
func (g *Graphics) GetGraphicsHeight() int32 {
|
||||
func (g *Graphics) HeightInt32() int32 {
|
||||
return int32(g.Bounds.Height)
|
||||
}
|
||||
|
||||
@@ -33,11 +79,11 @@ func (g *Graphics) PushStyle() {
|
||||
func (g *Graphics) PopStyle() {
|
||||
}
|
||||
|
||||
func (g *Graphics) SetStrokeColor(c Color) {
|
||||
func (g *Graphics) SetStrokeColor(c color.RGBA) {
|
||||
g.Style.StrokeColor = color.RGBA { R: c.R, G: c.G, B: c.B, A: c.A }
|
||||
}
|
||||
|
||||
func (g *Graphics) SetFillColor(c Color) {
|
||||
func (g *Graphics) SetFillColor(c color.RGBA) {
|
||||
g.Style.FillColor = color.RGBA { R: c.R, G: c.G, B: c.B, A: c.A }
|
||||
}
|
||||
|
||||
@@ -87,6 +133,16 @@ func (g *Graphics) BeginTexture(t rl.RenderTexture2D) {
|
||||
rl.BeginTextureMode(t)
|
||||
}
|
||||
|
||||
|
||||
func (g *Graphics) DrawTexture(t rl.Texture2D, p Point, c color.RGBA) {
|
||||
rl.DrawTexture(t, int32(p.X), int32(p.Y), c)
|
||||
}
|
||||
|
||||
|
||||
func (g *Graphics) TransferTexture(t rl.Texture2D, src Rect, dst Rect, tint color.RGBA) {
|
||||
rl.DrawTexturePro(t, src.ToRL(), dst.ToRL(), rl.Vector2{}, 0, tint)
|
||||
}
|
||||
|
||||
func (g *Graphics) EndTexture() {
|
||||
rl.EndTextureMode()
|
||||
}
|
||||
@@ -114,22 +170,25 @@ func (g *Graphics) DrawLine(a, b Point) {
|
||||
rl.SetLineWidth(saveLineWidth)
|
||||
}
|
||||
|
||||
type Color color.RGBA
|
||||
|
||||
func RGBA(r, g, b, a uint8) Color {
|
||||
return Color { R: r, G: g, B: b, A: a }
|
||||
}
|
||||
|
||||
type HSBA struct {
|
||||
H uint
|
||||
S, B float32
|
||||
A uint8
|
||||
}
|
||||
|
||||
var Origin = Point { X: 0, Y: 0, Z: 0 }
|
||||
|
||||
type Point rl.Vector3
|
||||
type Vec rl.Vector3
|
||||
type Rect rl.Rectangle
|
||||
|
||||
func (r *Rect) Center() Point {
|
||||
return Point {
|
||||
X: r.X + r.Width / 2,
|
||||
Y: r.X + r.Height / 2,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Point) Add(v Vec) Point {
|
||||
return Point { X: p.X + v.X, Y: p.Y + v.Y, Z: p.Z + v.Z }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user