From 51a6bf959c0d407062b12001415097a2a0d572e5 Mon Sep 17 00:00:00 2001 From: Fluffy <michal-gdula@protonmail.com> Date: Mon, 29 Jan 2024 12:53:12 +0000 Subject: [PATCH] Check if user wants to quit app 2 --- canvas.go | 17 +++++++++-------- main.go | 17 +++++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/canvas.go b/canvas.go index 90557bd..746c6c6 100644 --- a/canvas.go +++ b/canvas.go @@ -121,14 +121,15 @@ func (c *Canvas) Save() { func NewCanvas(name string, size, offset raylib.Vector2, background raylib.Texture2D) *Canvas { return &Canvas{ - Name: name, - Size: size, - Offset: offset, - Target: raylib.LoadRenderTexture(int32(size.X), int32(size.Y)), - Background: background, - Strokes: []raylib.Texture2D{}, - UndoneStrokes: []raylib.Texture2D{}, - Refresh: true, + Name: name, + Size: size, + Offset: offset, + Target: raylib.LoadRenderTexture(int32(size.X), int32(size.Y)), + Background: background, + Strokes: []raylib.Texture2D{}, + UndoneStrokes: []raylib.Texture2D{}, + UnsavedChanges: false, + Refresh: true, } } diff --git a/main.go b/main.go index 0ae5c8a..d8a8d6d 100644 --- a/main.go +++ b/main.go @@ -43,11 +43,7 @@ func main() { for !applicationShouldQuit { // Update default loop values if raylib.WindowShouldClose() { - if canvas.UnsavedChanges { - applicationState = StateWindowWantsToDie - } else { - applicationShouldQuit = true - } + applicationState = StateWindowWantsToDie } if raylib.IsWindowResized() { applicationWindowWidth = int32(raylib.GetScreenWidth()) @@ -287,7 +283,6 @@ func main() { } } } - raylib.EndScissorMode() case StateNewCanvas: if !canvas.UnsavedChanges { @@ -311,6 +306,16 @@ func main() { AddToast("Created New Canvas: " + canvas.Name) } case StateWindowWantsToDie: + if !canvas.UnsavedChanges { + applicationShouldQuit = true + break + } + if !canvas.UnsavedChanges { + applicationState = StateNormal + shouldCreateNewCanvas = true + AddToast("Created New Canvas: " + canvas.Name) + break + } gui.Unlock() raylib.DrawRectangle(0, 0, applicationWindowWidth, applicationWindowHeight, raylib.Fade(raylib.Black, 0.5)) windowPos := raylib.NewRectangle(float32((applicationWindowWidth/2)-200), float32((applicationWindowHeight/2)-75), 400, 150)