ColouringApp/penTool.go

46 lines
1.3 KiB
Go
Raw Permalink Normal View History

2024-01-25 15:57:10 +00:00
package main
import (
raylib "github.com/gen2brain/raylib-go/raylib"
)
type penTool struct {
2024-01-25 20:02:20 +00:00
Size float32
2024-01-26 00:55:21 +00:00
Color raylib.Color
2024-01-25 20:02:20 +00:00
Points []raylib.Vector2
2024-01-25 15:57:10 +00:00
}
2024-01-26 00:55:21 +00:00
func (p *penTool) Render() raylib.Texture2D {
offset := raylib.Vector2Scale(canvas.Offset, -1)
texture := raylib.LoadRenderTexture(int32(canvas.Size.X), int32(canvas.Size.Y))
raylib.BeginTextureMode(texture)
raylib.ClearBackground(raylib.Fade(raylib.Black, 0))
2024-01-25 15:57:10 +00:00
for i := 0; i < len(p.Points)-1; i++ {
startPoint := raylib.Vector2Add(p.Points[i], offset)
endPoint := raylib.Vector2Add(p.Points[i+1], offset)
raylib.DrawLineEx(startPoint, endPoint, p.Size, p.Color)
raylib.DrawCircle(int32(startPoint.X), int32(startPoint.Y), p.Size/2, p.Color)
}
if len(p.Points) > 0 {
endPoint := raylib.Vector2Add(p.Points[len(p.Points)-1], offset)
raylib.DrawCircle(int32(endPoint.X), int32(endPoint.Y), p.Size/2, p.Color)
}
2024-01-26 00:55:21 +00:00
raylib.EndTextureMode()
return texture.Texture
}
func (p *penTool) Draw() {
for i := 0; i < len(p.Points)-1; i++ {
startPoint := p.Points[i]
endPoint := p.Points[i+1]
raylib.DrawLineEx(startPoint, endPoint, p.Size, p.Color)
raylib.DrawCircle(int32(startPoint.X), int32(startPoint.Y), p.Size/2, p.Color)
}
if len(p.Points) > 0 {
endPoint := p.Points[len(p.Points)-1]
raylib.DrawCircle(int32(endPoint.X), int32(endPoint.Y), p.Size/2, p.Color)
}
2024-01-25 15:57:10 +00:00
}