automated snapshot
This commit is contained in:
65
sketch.go
65
sketch.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
@@ -23,27 +24,55 @@ func (s *Sketch) CreateLayer(name string, layer Layer, sourceWidth int32, source
|
||||
}
|
||||
}
|
||||
|
||||
func LayerViewRect(ctx *RenderCtx) rl.Rectangle {
|
||||
|
||||
z := ctx.Cam.Zoom
|
||||
|
||||
// get the viewport width in texture space
|
||||
viewportWidth := float32(ctx.TargetWidth) / z
|
||||
viewportHeight := float32(ctx.TargetHeight) / z
|
||||
|
||||
x := rl.Clamp(ctx.Cam.Target.X - viewportWidth/2, 0, float32(ctx.SourceWidth) - viewportWidth/2.0)
|
||||
y := rl.Clamp(ctx.Cam.Target.Y - viewportHeight/2, 0, float32(ctx.SourceHeight) - viewportHeight/2.0)
|
||||
|
||||
return rl.Rectangle{
|
||||
X: x,
|
||||
Y: y,
|
||||
Width: viewportWidth,
|
||||
Height: viewportHeight,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Sketch) Draw(ctx *RenderCtx) {
|
||||
// render onto all layer textures
|
||||
for _, instance := range s.layerTools {
|
||||
layer := instance.layer
|
||||
rl.BeginTextureMode(*instance.texture)
|
||||
rl.ClearBackground(rl.Blank)
|
||||
layer.Draw(ctx)
|
||||
rl.EndTextureMode()
|
||||
}
|
||||
// composite all layers to screen
|
||||
|
||||
//ClampCameraToLayer(ctx)
|
||||
|
||||
//view := LayerViewRect(ctx)
|
||||
src := rl.Rectangle {
|
||||
X: 0, Y: 0,
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: float32(ctx.SourceWidth),
|
||||
Height: -float32(ctx.SourceHeight),
|
||||
}
|
||||
|
||||
dst := rl.Rectangle {
|
||||
X: 0, Y: 0,
|
||||
X: 0,
|
||||
Y: 0,
|
||||
Width: float32(ctx.TargetWidth),
|
||||
Height: float32(ctx.TargetHeight),
|
||||
}
|
||||
|
||||
fmt.Printf("src = %v, dst %v\n", src, dst)
|
||||
|
||||
for _, instance := range s.layerTools {
|
||||
rl.DrawTexturePro(instance.texture.Texture, src, dst, rl.Vector2{}, 0, rl.White)
|
||||
}
|
||||
@@ -56,7 +85,6 @@ type LayerTools struct {
|
||||
texture *rl.RenderTexture2D
|
||||
}
|
||||
|
||||
|
||||
/** Layer **/
|
||||
|
||||
type Layer interface {
|
||||
@@ -65,11 +93,36 @@ type Layer interface {
|
||||
|
||||
type TestPattern struct { }
|
||||
|
||||
func DrawGrid(spacing int32, halfExtent int32) {
|
||||
col := rl.Color{R: 220, G: 220, B: 220, A: 255}
|
||||
|
||||
for x := -halfExtent; x <= halfExtent; x += spacing {
|
||||
rl.DrawLine(x, -halfExtent, x, halfExtent, col)
|
||||
}
|
||||
for y := -halfExtent; y <= halfExtent; y += spacing {
|
||||
rl.DrawLine(-halfExtent, y, halfExtent, y, col)
|
||||
}
|
||||
}
|
||||
|
||||
func (tp *TestPattern) Draw(ctx *RenderCtx) {
|
||||
rl.DrawRectangle(0, 0, int32(ctx.SourceWidth), int32(ctx.SourceHeight), rl.Magenta)
|
||||
|
||||
rl.ClearBackground(rl.Black)
|
||||
centerX := float32(ctx.SourceWidth)/2
|
||||
centerY := float32(ctx.SourceHeight)/2
|
||||
|
||||
rl.DrawRectangleRec(rl.Rectangle { X: 0, Y: 0, Width: centerX, Height: centerY }, rl.Red)
|
||||
rl.DrawRectangleRec(rl.Rectangle { X: centerX, Y: 0, Width: centerX, Height: centerY }, rl.Green)
|
||||
rl.DrawRectangleRec(rl.Rectangle { X: 0, Y: centerY, Width: centerX, Height: centerY }, rl.Blue)
|
||||
rl.DrawRectangleRec(rl.Rectangle { X: centerX, Y: centerY, Width: centerX, Height: centerY }, rl.White)
|
||||
|
||||
rl.DrawLine(0, 0, ctx.SourceWidth, ctx.SourceHeight, rl.Black)
|
||||
|
||||
rl.PushMatrix()
|
||||
rl.Translatef(float32(ctx.SourceWidth)/2.0, float32(ctx.SourceHeight)/2.0, 0.0)
|
||||
rl.DrawRectangle(-100, -100, 200, 200, rl.Green)
|
||||
rl.Translatef(centerX, centerY, 0)
|
||||
rl.SetLineWidth(4.0)
|
||||
rl.DrawLine(-10000, 0, 10000, 0, rl.Red)
|
||||
rl.DrawLine(0, -10000, 0, 10000, rl.Green)
|
||||
rl.DrawRectangleLines(-50, -50, 100, 100, rl.Magenta)
|
||||
rl.PopMatrix()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user