From 6f5bd910c8ca06923d8f15cbae38beda0d9f6684 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 12 Sep 2021 14:42:39 -0700 Subject: [PATCH] Zoom Progress: Actor/Link Tool Hitboxes * When the Actor Tool or Link Tool is active, mouse-over hitboxes on the level's actors now works correctly while zoomed and scrolling in the level. * Regression: Level chunks don't appear outside a certain range from origin while zoomed in. * Regression: Actors don't draw their sprite while zoomed in, but do when zoomed out. --- pkg/uix/canvas_editable.go | 29 +++++++++++++++++++++++++---- pkg/uix/canvas_present.go | 13 ++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/pkg/uix/canvas_editable.go b/pkg/uix/canvas_editable.go index 85dc527..edd20d9 100644 --- a/pkg/uix/canvas_editable.go +++ b/pkg/uix/canvas_editable.go @@ -304,9 +304,20 @@ func (w *Canvas) loopEditable(ev *event.State) error { var deleteActors = []*level.Actor{} for _, actor := range w.actors { + + // Compute the bounding box on screen where this doodad + // visually appears. + var scrollBias = render.Point{ + X: w.Scroll.X, + Y: w.Scroll.Y, + } + if w.Zoom != 0 { + scrollBias.X = w.ZoomDivide(scrollBias.X) + scrollBias.Y = w.ZoomDivide(scrollBias.Y) + } box := render.Rect{ - X: actor.Actor.Point.X - P.X - w.Scroll.X, - Y: actor.Actor.Point.Y - P.Y - w.Scroll.Y, + X: actor.Actor.Point.X - P.X - scrollBias.X, + Y: actor.Actor.Point.Y - P.Y - scrollBias.Y, W: actor.Canvas.Size().W, H: actor.Canvas.Size().H, } @@ -356,9 +367,19 @@ func (w *Canvas) loopEditable(ev *event.State) error { continue } + // Compute the bounding box on screen where this doodad + // visually appears. + var scrollBias = render.Point{ + X: w.Scroll.X, + Y: w.Scroll.Y, + } + if w.Zoom != 0 { + scrollBias.X = w.ZoomDivide(scrollBias.X) + scrollBias.Y = w.ZoomDivide(scrollBias.Y) + } box := render.Rect{ - X: actor.Actor.Point.X - P.X - w.Scroll.X, - Y: actor.Actor.Point.Y - P.Y - w.Scroll.Y, + X: actor.Actor.Point.X - P.X - scrollBias.X, + Y: actor.Actor.Point.Y - P.Y - scrollBias.Y, W: actor.Canvas.Size().W, H: actor.Canvas.Size().H, } diff --git a/pkg/uix/canvas_present.go b/pkg/uix/canvas_present.go index 82b1b99..9a801f9 100644 --- a/pkg/uix/canvas_present.go +++ b/pkg/uix/canvas_present.go @@ -69,15 +69,10 @@ func (w *Canvas) Present(e render.Engine, p render.Point) { // (0, 0) = (0,0, 127,127) chunk A // (1, 0) = (128,128, 255,255) chunk B // At 2x zoom, Chunk A is still half on screen at -128 scroll - if w.Zoom > 0 { - // Since disappearing chunks happens on Zoom In the most? - // Grow the viewport's X and Y offsets back the other - // way, so chunks sliding off the screen don't unload early. - // This kinda thing makes no difference at all? - // var orig = Viewport - // Viewport.X = w.ZoomDivide(w.chunks.Size) - // Viewport.Y = w.ZoomDivide(w.chunks.Size) - } + // if w.Zoom > 0 { + // Viewport.X = w.ZoomDivide(w.chunks.Size) + // Viewport.Y = w.ZoomDivide(w.chunks.Size) + // } // Get the chunks in the viewport and cache their textures. for coord := range w.chunks.IterViewportChunks(Viewport) {