Middle-click to Pan + Remember Scroll Position
In the editor, clicking and dragging with the middle mouse button will scroll the view of the editor in place of the arrow keys. When entering Play Mode, the original scroll position in the level editor is remembered for when you come back - no more having to scroll from 0,0 each time to get back to where you were working!
This commit is contained in:
parent
489a43ea8c
commit
c2c91e45a9
|
@ -29,6 +29,7 @@ type EditorScene struct {
|
|||
OpenFile bool
|
||||
Filename string
|
||||
DoodadSize int
|
||||
RememberScrollPosition render.Point // Play mode remembers it for us
|
||||
|
||||
UI *EditorUI
|
||||
d *Doodle
|
||||
|
@ -209,6 +210,11 @@ func (s *EditorScene) setupAsync(d *Doodle) error {
|
|||
// Recompute the UI Palette window for the level's palette.
|
||||
s.UI.FinishSetup(d)
|
||||
|
||||
// Scroll the level to the remembered position from when we went
|
||||
// to Play Mode and back. If no remembered position, this is zero
|
||||
// anyway.
|
||||
s.UI.Canvas.ScrollTo(s.RememberScrollPosition)
|
||||
|
||||
d.Flash("Editor Mode.")
|
||||
if s.DrawingType == enum.LevelDrawing {
|
||||
d.Flash("Press 'P' to playtest this level.")
|
||||
|
@ -224,6 +230,7 @@ func (s *EditorScene) Playtest() {
|
|||
Filename: s.filename,
|
||||
Level: s.Level,
|
||||
CanEdit: true,
|
||||
RememberScrollPosition: s.UI.Canvas.Scroll,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -244,3 +244,8 @@ func Down(ev *event.State) bool {
|
|||
func Use(ev *event.State) bool {
|
||||
return ev.Space || ev.KeyDown("q")
|
||||
}
|
||||
|
||||
// MiddleClick of the mouse for panning the level.
|
||||
func MiddleClick(ev *event.State) bool {
|
||||
return ev.Button2
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ type PlayScene struct {
|
|||
Level *level.Level
|
||||
CanEdit bool // i.e. you came from the Editor Mode
|
||||
HasNext bool // has a next level to load next
|
||||
RememberScrollPosition render.Point // for the Editor quality of life
|
||||
|
||||
// Private variables.
|
||||
d *Doodle
|
||||
|
@ -296,6 +297,7 @@ func (s *PlayScene) EditLevel() {
|
|||
s.d.Goto(&EditorScene{
|
||||
Filename: s.Filename,
|
||||
Level: s.Level,
|
||||
RememberScrollPosition: s.RememberScrollPosition,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -96,6 +96,9 @@ type Canvas struct {
|
|||
|
||||
// We inherit the ui.Widget which manages the width and height.
|
||||
Scroll render.Point // Scroll offset for which parts of canvas are visible.
|
||||
scrollDragging bool // Middle-click to pan scroll
|
||||
scrollStartAt render.Point // Cursor point at beginning of pan
|
||||
scrollWasAt render.Point // copy of Scroll at beginning of pan
|
||||
}
|
||||
|
||||
// NewCanvas initializes a Canvas widget.
|
||||
|
|
|
@ -54,6 +54,24 @@ func (w *Canvas) loopEditorScroll(ev *event.State) error {
|
|||
w.ScrollBy(scrollBy)
|
||||
}
|
||||
|
||||
// Middle click of the mouse to pan the level.
|
||||
// NOTE: returns are below!
|
||||
if keybind.MiddleClick(ev) {
|
||||
if !w.scrollDragging {
|
||||
w.scrollDragging = true
|
||||
w.scrollStartAt = shmem.Cursor
|
||||
w.scrollWasAt = w.Scroll
|
||||
} else {
|
||||
delta := shmem.Cursor.Compare(w.scrollStartAt)
|
||||
w.Scroll = w.scrollWasAt
|
||||
w.Scroll.Subtract(delta)
|
||||
}
|
||||
} else {
|
||||
if w.scrollDragging {
|
||||
w.scrollDragging = false
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user