diff --git a/pkg/editor_ui_menubar.go b/pkg/editor_ui_menubar.go index d6fa5fe..e7c50c7 100644 --- a/pkg/editor_ui_menubar.go +++ b/pkg/editor_ui_menubar.go @@ -203,7 +203,7 @@ func (u *EditorUI) SetupMenuBar(d *Doodle) *ui.MenuBar { }) if u.Scene.DrawingType == enum.LevelDrawing { - toolMenu.AddItemAccel("Doodads", "d", func() { + toolMenu.AddItemAccel("Doodads", "q", func() { log.Info("Open the DoodadDropper") u.doodadWindow.Show() }) diff --git a/pkg/keybind/keybind.go b/pkg/keybind/keybind.go index 211e96f..9af66b9 100644 --- a/pkg/keybind/keybind.go +++ b/pkg/keybind/keybind.go @@ -198,7 +198,7 @@ func EraserTool(ev *event.State) bool { // DoodadDropper (D) opens the doodad dropper in the editor. func DoodadDropper(ev *event.State) bool { - return ev.KeyDown("d") + return ev.KeyDown("q") } // ShellKey (`) opens the developer console. diff --git a/pkg/shell.go b/pkg/shell.go index 2a72048..b2013cb 100644 --- a/pkg/shell.go +++ b/pkg/shell.go @@ -274,7 +274,14 @@ func (s *Shell) Draw(d *Doodle, ev *event.State) error { } else { s.Text += key } - ev.SetKeyDown(key, false) + // HACK: I wanted to do: + // ev.SetKeyDown(key, false) + // But, ev.KeysDown(shifted=true) returns letter keys + // like 'M' when the key we wanted to unset was 'm', + // or we got '$' when we want to unset '5'... so all + // shifted chars got duplicated 3+ times on key press! + // So, just reset ALL key press states to work around it: + ev.ResetKeyDown() } // How tall is the box? diff --git a/pkg/uix/canvas_present.go b/pkg/uix/canvas_present.go index 699e283..57f4681 100644 --- a/pkg/uix/canvas_present.go +++ b/pkg/uix/canvas_present.go @@ -39,13 +39,43 @@ func (w *Canvas) Present(e render.Engine, p render.Point) { } // Scale the viewport to account for zoom level. - if w.Zoom < 0 { + if w.Zoom != 0 { // 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.H = w.ZoomDivide(Viewport.W) } + // Disappearing chunks issue: + // When at the top-left corner of a bounded level, + // And Zoom=2 (200% zoom), Level Chunk Size=128, + // When you scroll down exactly -128 pixels, the whole row + // of chunks along the top edge of the viewport unload. + // At -256, the next row of chunks unloads. + // At -383, another row - it's creeping down the page with + // the top 1/3 of the level editor showing blank wallpaper + // At -768, about 3/4 the level editor is blank + // + // It must think the upper 128px of chunks had left the + // viewport when in fact the bottom half of them was still + // in view, not respecting the 2X zoom level. + // + // Viewport is like: Rect<128,0,1058,721> + // Level chunks would be: + // (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 = render.NewPoint(Viewport.X, Viewport.Y) + // Viewport.X -= 256 //w.ZoomMultiply(w.chunks.Size) + // Viewport.Y -= 256 //w.ZoomMultiply(w.chunks.Size) + // log.Info("Viewport: %s was: %s", Viewport, orig) + } + // Get the chunks in the viewport and cache their textures. for coord := range w.chunks.IterViewportChunks(Viewport) { if chunk, ok := w.chunks.GetChunk(coord); ok { diff --git a/pkg/uix/canvas_scrolling.go b/pkg/uix/canvas_scrolling.go index 8815405..ac45354 100644 --- a/pkg/uix/canvas_scrolling.go +++ b/pkg/uix/canvas_scrolling.go @@ -5,6 +5,7 @@ import ( "fmt" "git.kirsle.net/apps/doodle/pkg/balance" + "git.kirsle.net/apps/doodle/pkg/keybind" "git.kirsle.net/apps/doodle/pkg/level" "git.kirsle.net/apps/doodle/pkg/shmem" "git.kirsle.net/go/render" @@ -29,16 +30,25 @@ func (w *Canvas) loopEditorScroll(ev *event.State) error { } // Arrow keys to scroll the view. - scrollBy := render.Point{} - if ev.Right { - scrollBy.X -= balance.CanvasScrollSpeed - } else if ev.Left { - scrollBy.X += balance.CanvasScrollSpeed + // Shift key to scroll very slowly. + var ( + scrollBy = render.Point{} + scrollSpeed = balance.CanvasScrollSpeed + ) + if keybind.Shift(ev) { + scrollSpeed = 1 } - if ev.Down { - scrollBy.Y -= balance.CanvasScrollSpeed - } else if ev.Up { - scrollBy.Y += balance.CanvasScrollSpeed + + // Arrow key handlers. + if keybind.Right(ev) { + scrollBy.X -= scrollSpeed + } else if keybind.Left(ev) { + scrollBy.X += scrollSpeed + } + if keybind.Down(ev) { + scrollBy.Y -= scrollSpeed + } else if keybind.Up(ev) { + scrollBy.Y += scrollSpeed } if !scrollBy.IsZero() { w.ScrollBy(scrollBy) diff --git a/pkg/windows/settings.go b/pkg/windows/settings.go index 448cade..45558cb 100644 --- a/pkg/windows/settings.go +++ b/pkg/windows/settings.go @@ -394,7 +394,7 @@ func (c Settings) makeControlsTab(Width, Height int) *ui.Frame { Label: "Scroll to origin", }, { - Shortcut: "d", + Shortcut: "q", Label: "Doodads", }, {