mirror of
https://github.com/Fluffy-Bean/ColouringApp.git
synced 2025-05-19 01:44:55 +00:00
Convert pen strokes to texture
This commit is contained in:
parent
9cfdd651b7
commit
f2d2a539ea
4 changed files with 83 additions and 27 deletions
29
canvas.go
29
canvas.go
|
@ -1,6 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
raylib "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
|
@ -12,8 +14,8 @@ type Canvas struct {
|
|||
|
||||
Target raylib.RenderTexture2D
|
||||
|
||||
Strokes []penTool
|
||||
UndoneStrokes []penTool
|
||||
Strokes []raylib.Texture2D
|
||||
UndoneStrokes []raylib.Texture2D
|
||||
|
||||
Refresh bool
|
||||
}
|
||||
|
@ -24,8 +26,15 @@ func (c *Canvas) Update() {
|
|||
|
||||
raylib.BeginTextureMode(c.Target)
|
||||
raylib.ClearBackground(raylib.White)
|
||||
for _, mark := range c.Strokes {
|
||||
mark.Draw(raylib.Vector2Scale(c.Offset, -1))
|
||||
for _, stroke := range c.Strokes {
|
||||
raylib.DrawTexturePro(
|
||||
stroke,
|
||||
raylib.NewRectangle(0, 0, c.Size.X, -c.Size.Y),
|
||||
raylib.NewRectangle(0, 0, c.Size.X, c.Size.Y),
|
||||
raylib.Vector2Zero(),
|
||||
0,
|
||||
raylib.White,
|
||||
)
|
||||
}
|
||||
raylib.EndTextureMode()
|
||||
|
||||
|
@ -33,6 +42,12 @@ func (c *Canvas) Update() {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *Canvas) AddStroke(stroke raylib.Texture2D) {
|
||||
c.Strokes = append(c.Strokes, stroke)
|
||||
c.UndoneStrokes = []raylib.Texture2D{}
|
||||
c.Refresh = true
|
||||
}
|
||||
|
||||
func (c *Canvas) Undo() {
|
||||
if len(c.Strokes) > 0 {
|
||||
c.UndoneStrokes = append(c.UndoneStrokes, c.Strokes[len(c.Strokes)-1])
|
||||
|
@ -65,6 +80,8 @@ func (c *Canvas) Draw() {
|
|||
}
|
||||
|
||||
func (c *Canvas) Save() {
|
||||
c.Name = strings.Trim(c.Name, " ")
|
||||
|
||||
if c.Name == "" {
|
||||
AddToast("Please enter a file name!")
|
||||
} else {
|
||||
|
@ -85,8 +102,8 @@ func NewCanvas(name string, size, offset raylib.Vector2) *Canvas {
|
|||
Size: size,
|
||||
Offset: offset,
|
||||
Target: raylib.LoadRenderTexture(int32(size.X), int32(size.Y)),
|
||||
Strokes: []penTool{},
|
||||
UndoneStrokes: []penTool{},
|
||||
Strokes: []raylib.Texture2D{},
|
||||
UndoneStrokes: []raylib.Texture2D{},
|
||||
Refresh: true,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue