Zoom Improvements
* Doodad outline while dragging is now sized properly for the zoom level * Make doodad hitboxes for Actor/Link Tool more accurate while zoomed * Fix chunks low on the level not loading while zoomed in * Fix Link lines drawn between doodads while zoomed - they point to the correct position and their DrawLine calls have been optimized so they don't lag out the level when lots of them are drawn at once.
This commit is contained in:
parent
6f5bd910c8
commit
fd730483b0
14
go.mod
14
go.mod
|
@ -16,22 +16,10 @@ require (
|
||||||
github.com/robertkrimen/otto v0.0.0-20200922221731-ef014fd054ac
|
github.com/robertkrimen/otto v0.0.0-20200922221731-ef014fd054ac
|
||||||
github.com/tomnomnom/xtermcolor v0.0.0-20160428124646-b78803f00a7e // indirect
|
github.com/tomnomnom/xtermcolor v0.0.0-20160428124646-b78803f00a7e // indirect
|
||||||
github.com/urfave/cli/v2 v2.3.0
|
github.com/urfave/cli/v2 v2.3.0
|
||||||
github.com/veandco/go-sdl2 v0.4.8
|
github.com/veandco/go-sdl2 v0.4.10
|
||||||
github.com/vmihailenco/msgpack v3.3.3+incompatible
|
github.com/vmihailenco/msgpack v3.3.3+incompatible
|
||||||
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
|
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
|
||||||
google.golang.org/appengine v1.6.7 // indirect
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||||
gopkg.in/sourcemap.v1 v1.0.5 // indirect
|
gopkg.in/sourcemap.v1 v1.0.5 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
// replace git.kirsle.net/go/render => /home/kirsle/SketchyMaze/deps/render
|
|
||||||
|
|
||||||
// replace git.kirsle.net/go/ui => /home/kirsle/SketchyMaze/deps/ui
|
|
||||||
|
|
||||||
// replace git.kirsle.net/go/audio => /home/kirsle/SketchyMaze/deps/audio
|
|
||||||
|
|
||||||
// replace git.kirsle.net/go/render => /run/build/sketchymaze/deps/render
|
|
||||||
|
|
||||||
// replace git.kirsle.net/go/ui => /run/build/sketchymaze/deps/ui
|
|
||||||
|
|
||||||
// replace git.kirsle.net/go/audio => /run/build/sketchymaze/deps/audio
|
|
||||||
|
|
|
@ -39,10 +39,16 @@ func (u *EditorUI) startDragActor(doodad *doodads.Doodad, actor *level.Actor) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size and scale this doodad according to the zoom level.
|
||||||
|
size := doodad.Rect()
|
||||||
|
size.W = u.Canvas.ZoomMultiply(size.W)
|
||||||
|
size.H = u.Canvas.ZoomMultiply(size.H)
|
||||||
|
|
||||||
// Create the canvas to render on the mouse cursor.
|
// Create the canvas to render on the mouse cursor.
|
||||||
drawing := uix.NewCanvas(doodad.Layers[0].Chunker.Size, false)
|
drawing := uix.NewCanvas(doodad.Layers[0].Chunker.Size, false)
|
||||||
drawing.LoadDoodad(doodad)
|
drawing.LoadDoodad(doodad)
|
||||||
drawing.Resize(doodad.Rect())
|
drawing.Resize(size)
|
||||||
|
drawing.Zoom = u.Canvas.Zoom
|
||||||
drawing.SetBackground(render.RGBA(0, 0, 1, 0)) // TODO: invisible becomes white
|
drawing.SetBackground(render.RGBA(0, 0, 1, 0)) // TODO: invisible becomes white
|
||||||
drawing.MaskColor = balance.DragColor // blueprint effect
|
drawing.MaskColor = balance.DragColor // blueprint effect
|
||||||
u.DraggableActor = &DraggableActor{
|
u.DraggableActor = &DraggableActor{
|
||||||
|
|
|
@ -316,8 +316,8 @@ func (w *Canvas) loopEditable(ev *event.State) error {
|
||||||
scrollBias.Y = w.ZoomDivide(scrollBias.Y)
|
scrollBias.Y = w.ZoomDivide(scrollBias.Y)
|
||||||
}
|
}
|
||||||
box := render.Rect{
|
box := render.Rect{
|
||||||
X: actor.Actor.Point.X - P.X - scrollBias.X,
|
X: actor.Actor.Point.X - scrollBias.X - w.ZoomDivide(P.X),
|
||||||
Y: actor.Actor.Point.Y - P.Y - scrollBias.Y,
|
Y: actor.Actor.Point.Y - scrollBias.Y - w.ZoomDivide(P.Y),
|
||||||
W: actor.Canvas.Size().W,
|
W: actor.Canvas.Size().W,
|
||||||
H: actor.Canvas.Size().H,
|
H: actor.Canvas.Size().H,
|
||||||
}
|
}
|
||||||
|
@ -378,8 +378,8 @@ func (w *Canvas) loopEditable(ev *event.State) error {
|
||||||
scrollBias.Y = w.ZoomDivide(scrollBias.Y)
|
scrollBias.Y = w.ZoomDivide(scrollBias.Y)
|
||||||
}
|
}
|
||||||
box := render.Rect{
|
box := render.Rect{
|
||||||
X: actor.Actor.Point.X - P.X - scrollBias.X,
|
X: actor.Actor.Point.X - scrollBias.X - w.ZoomDivide(P.X),
|
||||||
Y: actor.Actor.Point.Y - P.Y - scrollBias.Y,
|
Y: actor.Actor.Point.Y - scrollBias.Y - w.ZoomDivide(P.Y),
|
||||||
W: actor.Canvas.Size().W,
|
W: actor.Canvas.Size().W,
|
||||||
H: actor.Canvas.Size().H,
|
H: actor.Canvas.Size().H,
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,10 +43,12 @@ func (w *Canvas) Present(e render.Engine, p render.Point) {
|
||||||
// Zoomed out (level go tiny)
|
// Zoomed out (level go tiny)
|
||||||
// TODO: seems unstable as shit on Zoom In??
|
// TODO: seems unstable as shit on Zoom In??
|
||||||
Viewport.W = w.ZoomDivide(Viewport.W)
|
Viewport.W = w.ZoomDivide(Viewport.W)
|
||||||
Viewport.H = w.ZoomDivide(Viewport.W)
|
Viewport.H = w.ZoomDivide(Viewport.H)
|
||||||
if w.Zoom > 0 {
|
if w.Zoom > 0 {
|
||||||
Viewport.X = w.ZoomDivide(w.chunks.Size)
|
// Viewport.X = w.ZoomDivide(w.chunks.Size)
|
||||||
Viewport.Y = w.ZoomDivide(w.chunks.Size)
|
// Viewport.Y = w.ZoomDivide(w.chunks.Size)
|
||||||
|
Viewport.X = w.ZoomDivide(Viewport.X)
|
||||||
|
Viewport.Y = w.ZoomDivide(Viewport.Y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +75,7 @@ func (w *Canvas) Present(e render.Engine, p render.Point) {
|
||||||
// Viewport.X = w.ZoomDivide(w.chunks.Size)
|
// Viewport.X = w.ZoomDivide(w.chunks.Size)
|
||||||
// Viewport.Y = w.ZoomDivide(w.chunks.Size)
|
// Viewport.Y = w.ZoomDivide(w.chunks.Size)
|
||||||
// }
|
// }
|
||||||
|
// Seems resolved now?
|
||||||
|
|
||||||
// Get the chunks in the viewport and cache their textures.
|
// Get the chunks in the viewport and cache their textures.
|
||||||
for coord := range w.chunks.IterViewportChunks(Viewport) {
|
for coord := range w.chunks.IterViewportChunks(Viewport) {
|
||||||
|
|
|
@ -186,9 +186,14 @@ func (w *Canvas) presentActorLinks(e render.Engine) {
|
||||||
bS = actorMap[linkID].Size()
|
bS = actorMap[linkID].Size()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Adapt actor positions per the zoom level.
|
||||||
|
aP.X = w.ZoomMultiply(aP.X)
|
||||||
|
aP.Y = w.ZoomMultiply(aP.Y)
|
||||||
|
bP.X = w.ZoomMultiply(bP.X)
|
||||||
|
bP.Y = w.ZoomMultiply(bP.Y)
|
||||||
|
|
||||||
// Draw a line connecting the centers of each actor together.
|
// Draw a line connecting the centers of each actor together.
|
||||||
stroke := drawtool.NewStroke(drawtool.Line, color)
|
stroke := drawtool.NewStroke(drawtool.Line, color)
|
||||||
stroke.Thickness = 1
|
|
||||||
stroke.PointA = render.Point{
|
stroke.PointA = render.Point{
|
||||||
X: aP.X + (aS.W / 2),
|
X: aP.X + (aS.W / 2),
|
||||||
Y: aP.Y + (aS.H / 2),
|
Y: aP.Y + (aS.H / 2),
|
||||||
|
@ -275,13 +280,36 @@ func (w *Canvas) DrawStrokes(e render.Engine, strokes []*drawtool.Stroke) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
var color = stroke.Color
|
||||||
|
if balance.DebugCanvasStrokeColor != render.Invisible {
|
||||||
|
color = balance.DebugCanvasStrokeColor
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: iterating all the points is very costly!
|
||||||
|
// Strokes don't properly render your Pattern anyway (glitchy mess),
|
||||||
|
// so let them just be simple DrawLine etc. calls.
|
||||||
|
// This optimization specifically speeds up the Actor Link Lines.
|
||||||
|
if stroke.Shape == drawtool.Line {
|
||||||
|
var (
|
||||||
|
pointA = render.Point{
|
||||||
|
X: P.X + w.Scroll.X + w.BoxThickness(1) + stroke.PointA.X,
|
||||||
|
Y: P.Y + w.Scroll.Y + w.BoxThickness(1) + stroke.PointA.Y,
|
||||||
|
}
|
||||||
|
pointB = render.Point{
|
||||||
|
X: P.X + w.Scroll.X + w.BoxThickness(1) + stroke.PointB.X,
|
||||||
|
Y: P.Y + w.Scroll.Y + w.BoxThickness(1) + stroke.PointB.Y,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
e.DrawLine(color, pointA, pointB)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
for point := range stroke.IterPoints() {
|
for point := range stroke.IterPoints() {
|
||||||
if !point.Inside(VP) {
|
if !point.Inside(VP) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Does the swatch have a pattern to sample?
|
// Does the swatch have a pattern to sample?
|
||||||
color := stroke.Color
|
|
||||||
if stroke.Pattern != "" {
|
if stroke.Pattern != "" {
|
||||||
color = pattern.SampleColor(stroke.Pattern, color, point)
|
color = pattern.SampleColor(stroke.Pattern, color, point)
|
||||||
}
|
}
|
||||||
|
@ -291,11 +319,7 @@ func (w *Canvas) DrawStrokes(e render.Engine, strokes []*drawtool.Stroke) {
|
||||||
Y: P.Y + w.Scroll.Y + w.BoxThickness(1) + point.Y,
|
Y: P.Y + w.Scroll.Y + w.BoxThickness(1) + point.Y,
|
||||||
}
|
}
|
||||||
|
|
||||||
if balance.DebugCanvasStrokeColor != render.Invisible {
|
e.DrawPoint(color, dest)
|
||||||
e.DrawPoint(balance.DebugCanvasStrokeColor, dest)
|
|
||||||
} else {
|
|
||||||
e.DrawPoint(color, dest)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user