Shift to scroll slowly + Doodads on Q

* Holding Shift while pressing arrow keys in the editor will scroll by
  just 1 pixel per tick to aid in precise debugging with the Zoom In/Out
  feature.
* The keybinds used in canvas_editable.go to catch the arrow keys are
  updated to use our nice keybind package. As a consequence, the WASD
  keys will also scroll the level.
* The "d for Doodads" keybind is renamed "q" so as not to open the
  Doodads window whenever scrolling right using the WASD keys.
This commit is contained in:
Noah 2021-07-12 22:19:36 -07:00
parent 37f6177a17
commit 26b1ac88dd
6 changed files with 62 additions and 15 deletions

View File

@ -203,7 +203,7 @@ func (u *EditorUI) SetupMenuBar(d *Doodle) *ui.MenuBar {
}) })
if u.Scene.DrawingType == enum.LevelDrawing { if u.Scene.DrawingType == enum.LevelDrawing {
toolMenu.AddItemAccel("Doodads", "d", func() { toolMenu.AddItemAccel("Doodads", "q", func() {
log.Info("Open the DoodadDropper") log.Info("Open the DoodadDropper")
u.doodadWindow.Show() u.doodadWindow.Show()
}) })

View File

@ -198,7 +198,7 @@ func EraserTool(ev *event.State) bool {
// DoodadDropper (D) opens the doodad dropper in the editor. // DoodadDropper (D) opens the doodad dropper in the editor.
func DoodadDropper(ev *event.State) bool { func DoodadDropper(ev *event.State) bool {
return ev.KeyDown("d") return ev.KeyDown("q")
} }
// ShellKey (`) opens the developer console. // ShellKey (`) opens the developer console.

View File

@ -274,7 +274,14 @@ func (s *Shell) Draw(d *Doodle, ev *event.State) error {
} else { } else {
s.Text += key 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? // How tall is the box?

View File

@ -39,13 +39,43 @@ func (w *Canvas) Present(e render.Engine, p render.Point) {
} }
// Scale the viewport to account for zoom level. // Scale the viewport to account for zoom level.
if w.Zoom < 0 { if w.Zoom != 0 {
// 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.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. // Get the chunks in the viewport and cache their textures.
for coord := range w.chunks.IterViewportChunks(Viewport) { for coord := range w.chunks.IterViewportChunks(Viewport) {
if chunk, ok := w.chunks.GetChunk(coord); ok { if chunk, ok := w.chunks.GetChunk(coord); ok {

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"git.kirsle.net/apps/doodle/pkg/balance" "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/level"
"git.kirsle.net/apps/doodle/pkg/shmem" "git.kirsle.net/apps/doodle/pkg/shmem"
"git.kirsle.net/go/render" "git.kirsle.net/go/render"
@ -29,16 +30,25 @@ func (w *Canvas) loopEditorScroll(ev *event.State) error {
} }
// Arrow keys to scroll the view. // Arrow keys to scroll the view.
scrollBy := render.Point{} // Shift key to scroll very slowly.
if ev.Right { var (
scrollBy.X -= balance.CanvasScrollSpeed scrollBy = render.Point{}
} else if ev.Left { scrollSpeed = balance.CanvasScrollSpeed
scrollBy.X += balance.CanvasScrollSpeed )
if keybind.Shift(ev) {
scrollSpeed = 1
} }
if ev.Down {
scrollBy.Y -= balance.CanvasScrollSpeed // Arrow key handlers.
} else if ev.Up { if keybind.Right(ev) {
scrollBy.Y += balance.CanvasScrollSpeed 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() { if !scrollBy.IsZero() {
w.ScrollBy(scrollBy) w.ScrollBy(scrollBy)

View File

@ -394,7 +394,7 @@ func (c Settings) makeControlsTab(Width, Height int) *ui.Frame {
Label: "Scroll to origin", Label: "Scroll to origin",
}, },
{ {
Shortcut: "d", Shortcut: "q",
Label: "Doodads", Label: "Doodads",
}, },
{ {