From f0e36ca8459a9b9aab19f7c1a279acf557c83f95 Mon Sep 17 00:00:00 2001 From: penguindark <57967770+penguindark@users.noreply.github.com> Date: Sat, 27 Mar 2021 16:28:09 +0100 Subject: [PATCH] examples: fix fireworks exiting when minimized on windows (issue: #9485) (#9487) --- examples/fireworks/fireworks.v | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/examples/fireworks/fireworks.v b/examples/fireworks/fireworks.v index 871ce085bd..a7017110e8 100644 --- a/examples/fireworks/fireworks.v +++ b/examples/fireworks/fireworks.v @@ -12,9 +12,13 @@ mut: frames [][]objects.Rocket // i thought about using a fixed fifo queue for the frames but the array // seemed to work fine, if you'd like a challenge try implementing it with the queue :) + draw_flag bool = true } fn on_frame(mut app App) { + if !app.draw_flag { + return + } app.gg.begin() // drawing previous frames @@ -57,22 +61,35 @@ fn on_frame(mut app App) { fn on_event(e &gg.Event, mut app App) { match e.typ { - .resized, .restored, .resumed { app.resize() } - else {} + .resized, .resumed { app.resize() } + .iconified { app.draw_flag = false } + .restored { + app.draw_flag = true + app.resize() + } + else { + //println("Type ${e.typ}") + } } } fn (mut app App) resize() { + size := gg.window_size() + // avoid calls when minimized + if size.width < 2 && size.height < 2 { + return + } mut s := gg.dpi_scale() + if s == 0.0 { s = 1.0 - } - size := gg.window_size() + } app.ui.dpi_scale = s app.ui.width = size.width app.ui.height = size.height } +[console] // is needed for easier diagnostics on windows fn main() { mut font_path := os.resource_abs_path(os.join_path('../assets/fonts/', 'RobotoMono-Regular.ttf')) $if android {