Bugfix: Don't draw in the level behind open windows

* With the Window Manager update you can open the Level Settings window
  while editing a level, to change its wallpaper or page type. But you
  could "draw" in the level "through" the opened window. This bug is now
  fixed: if the cursor is on top of a managed UI window, the Canvas loop
  is not called.
This commit is contained in:
Noah 2020-04-08 18:21:29 -07:00
parent f0101ba048
commit d615619aba
2 changed files with 9 additions and 12 deletions

View File

@ -273,7 +273,8 @@ func (u *EditorUI) Loop(ev *event.State) error {
u.ToolBar.Compute(u.d.Engine) u.ToolBar.Compute(u.d.Engine)
// Only forward events to the Canvas if the UI hasn't stopped them. // Only forward events to the Canvas if the UI hasn't stopped them.
if !stopPropagation { // Also ignore events if a managed ui.Window is overlapping the canvas.
if !(stopPropagation || u.Supervisor.IsPointInWindow(u.cursor)) {
u.Canvas.Loop(ev) u.Canvas.Loop(ev)
} }
return nil return nil

View File

@ -29,15 +29,18 @@ func NewAddEditLevel(config AddEditLevel) *ui.Window {
newPageType = level.Bounded.String() newPageType = level.Bounded.String()
newWallpaper = "notebook.png" newWallpaper = "notebook.png"
isNewLevel = config.EditLevel == nil isNewLevel = config.EditLevel == nil
title = "New Drawing"
) )
// Given a level to edit? // Given a level to edit?
if config.EditLevel != nil { if config.EditLevel != nil {
newPageType = config.EditLevel.PageType.String() newPageType = config.EditLevel.PageType.String()
newWallpaper = config.EditLevel.Wallpaper newWallpaper = config.EditLevel.Wallpaper
title = "Page Settings"
} }
window := ui.NewWindow("New Drawing") window := ui.NewWindow(title)
window.SetButtons(ui.CloseButton)
window.Configure(ui.Config{ window.Configure(ui.Config{
Width: 540, Width: 540,
Height: 350, Height: 350,
@ -119,8 +122,7 @@ func NewAddEditLevel(config AddEditLevel) *ui.Window {
******************/ ******************/
label2 := ui.NewLabel(ui.Label{ label2 := ui.NewLabel(ui.Label{
// Text: "Wallpaper", Text: "Wallpaper",
TextVariable: &newWallpaper,
Font: balance.LabelFont, Font: balance.LabelFont,
}) })
frame.Pack(label2, ui.Pack{ frame.Pack(label2, ui.Pack{
@ -170,12 +172,6 @@ func NewAddEditLevel(config AddEditLevel) *ui.Window {
******************/ ******************/
bottomFrame := ui.NewFrame("Button Frame") bottomFrame := ui.NewFrame("Button Frame")
// bottomFrame.Configure(ui.Config{
// BorderSize: 1,
// BorderStyle: ui.BorderSunken,
// BorderColor: render.Black,
// })
// bottomFrame.SetBackground(render.Grey)
frame.Pack(bottomFrame, ui.Pack{ frame.Pack(bottomFrame, ui.Pack{
Side: ui.N, Side: ui.N,
FillX: true, FillX: true,
@ -221,7 +217,7 @@ func NewAddEditLevel(config AddEditLevel) *ui.Window {
} }
for _, t := range buttons { for _, t := range buttons {
// If we're editing settings on an existing level, skip the Continue. // If we're editing settings on an existing level, skip the Continue.
if isNewLevel && t.Label == "OK" { if (isNewLevel && t.Label == "OK") || (!isNewLevel && t.Label != "OK") {
continue continue
} }
btn := ui.NewButton(t.Label, ui.NewLabel(ui.Label{ btn := ui.NewButton(t.Label, ui.NewLabel(ui.Label{