Check if user wants to quit app 2

This commit is contained in:
Michał 2024-01-29 12:53:12 +00:00
parent 3740187ee2
commit 51a6bf959c
2 changed files with 20 additions and 14 deletions

View file

@ -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,
}
}

17
main.go
View file

@ -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)