refactoring progress
This commit is contained in:
@@ -8,45 +8,152 @@ import (
|
||||
)
|
||||
|
||||
type Graphics struct {
|
||||
layout Layout
|
||||
style Style
|
||||
Style Style
|
||||
Bounds Rect
|
||||
}
|
||||
|
||||
type Layout struct {
|
||||
// total monitor bounds
|
||||
Monitor Rect
|
||||
// bounds of the application window
|
||||
Window Rect
|
||||
// bounds of the ui controls area
|
||||
Controls Rect
|
||||
// bounds of the region of the app window reserved for rendering the graphics buffer
|
||||
Viewport Rect
|
||||
// bounds of the off screen graphics buffer where rendering happens
|
||||
Graphics Rect
|
||||
type Style struct {
|
||||
StrokeColor, FillColor color.RGBA
|
||||
StrokeWeight float32
|
||||
Stroke, Fill bool
|
||||
}
|
||||
|
||||
func (g *Graphics) GetGraphicsWidth() int32 {
|
||||
return int32(g.Bounds.Width)
|
||||
}
|
||||
|
||||
func (g *Graphics) GetGraphicsHeight() int32 {
|
||||
return int32(g.Bounds.Height)
|
||||
}
|
||||
|
||||
|
||||
func (g *Graphics) PushStyle() {
|
||||
}
|
||||
|
||||
func (g *Graphics) PopStyle() {
|
||||
}
|
||||
|
||||
func (g *Graphics) SetStrokeColor(c Color) {
|
||||
g.Style.StrokeColor = color.RGBA { R: c.R, G: c.G, B: c.B, A: c.A }
|
||||
}
|
||||
|
||||
func (g *Graphics) SetFillColor(c Color) {
|
||||
g.Style.FillColor = color.RGBA { R: c.R, G: c.G, B: c.B, A: c.A }
|
||||
}
|
||||
|
||||
func (g *Graphics) SetStrokeWeight(w float32) {
|
||||
g.Style.StrokeWeight = w
|
||||
}
|
||||
|
||||
func (g *Graphics) SetStroke(b bool) {
|
||||
g.Style.Stroke = b
|
||||
}
|
||||
|
||||
func (g *Graphics) SetFill(b bool) {
|
||||
g.Style.Fill = b
|
||||
}
|
||||
|
||||
func (g *Graphics) PushMatrix() {
|
||||
rl.PushMatrix()
|
||||
}
|
||||
|
||||
func (g *Graphics) Translate(p Point) {
|
||||
rl.Translatef(p.X, p.Y, 0)
|
||||
}
|
||||
|
||||
func (g *Graphics) PopMatrix() {
|
||||
rl.PopMatrix()
|
||||
}
|
||||
|
||||
func (g *Graphics) BeginClip(r Rect) {
|
||||
rlRect := r.ToRL()
|
||||
rint := (&rlRect).ToInt32()
|
||||
rl.BeginScissorMode(rint.X, rint.Y, rint.Width, rint.Height)
|
||||
}
|
||||
|
||||
func (g *Graphics) EndClip() {
|
||||
rl.EndScissorMode()
|
||||
}
|
||||
|
||||
func (g *Graphics) BeginAdditiveBlend() {
|
||||
rl.BeginBlendMode(rl.BlendAdditive)
|
||||
}
|
||||
|
||||
func (g *Graphics) EndBlend() {
|
||||
rl.EndBlendMode()
|
||||
}
|
||||
|
||||
func (g *Graphics) BeginTexture(t rl.RenderTexture2D) {
|
||||
rl.BeginTextureMode(t)
|
||||
}
|
||||
|
||||
func (g *Graphics) EndTexture() {
|
||||
rl.EndTextureMode()
|
||||
}
|
||||
|
||||
func (g *Graphics) DrawRect(r Rect) {
|
||||
if g.Style.Fill {
|
||||
rl.DrawRectangleRec(r.ToRL(), g.Style.FillColor)
|
||||
}
|
||||
if g.Style.Stroke {
|
||||
saveLineWidth := rl.GetLineWidth()
|
||||
rl.SetLineWidth(g.Style.StrokeWeight)
|
||||
rl.DrawRectangleLines(
|
||||
int32(r.X), int32(r.Y),
|
||||
int32(r.Width), int32(r.Height),
|
||||
g.Style.StrokeColor,
|
||||
)
|
||||
rl.SetLineWidth(saveLineWidth)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Graphics) DrawLine(a, b Point) {
|
||||
saveLineWidth := rl.GetLineWidth()
|
||||
rl.SetLineWidth(g.Style.StrokeWeight)
|
||||
rl.DrawLineV(a.ToRL(), b.ToRL(), g.Style.StrokeColor)
|
||||
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
|
||||
}
|
||||
|
||||
type Style struct {
|
||||
StrokeColor Color
|
||||
StrokeWeight float32
|
||||
FillColor Color
|
||||
type Point rl.Vector3
|
||||
type Vec rl.Vector3
|
||||
type Rect rl.Rectangle
|
||||
|
||||
func (p *Point) Add(v Vec) Point {
|
||||
return Point { X: p.X + v.X, Y: p.Y + v.Y, Z: p.Z + v.Z }
|
||||
}
|
||||
|
||||
type Rect rl.Rectangle
|
||||
func (p Point) ToRL() rl.Vector2 {
|
||||
return rl.Vector2 { X: p.X, Y: p.Y }
|
||||
}
|
||||
|
||||
func (p Point) ToRL3() rl.Vector3 {
|
||||
return rl.Vector3 { X: p.X, Y: p.Y, Z: p.Z }
|
||||
}
|
||||
|
||||
/**
|
||||
* scale the given rect down to the target rect
|
||||
* maintaining the aspect ratio of the original rect
|
||||
*/
|
||||
func (r Rect) ToRL() *rl.Rectangle {
|
||||
return &rl.Rectangle { X: r.X, Y: r.Y, Width: r.Width, Height: r.Height }
|
||||
|
||||
func (r Rect) UL() Point {
|
||||
return Point { X: r.X, Y: r.Y }
|
||||
}
|
||||
|
||||
|
||||
func (r Rect) ToRL() rl.Rectangle {
|
||||
return rl.Rectangle { X: r.X, Y: r.Y, Width: r.Width, Height: r.Height }
|
||||
}
|
||||
|
||||
func (r Rect) ScaleTo(tgt Rect) Rect {
|
||||
|
||||
Reference in New Issue
Block a user