17cupsofcoffee / tetra

🎮 A simple 2D game framework written in Rust
MIT License
909 stars 63 forks source link

Add events related to the display state of the window #248

Closed sumibi-yakitori closed 3 years ago

sumibi-yakitori commented 3 years ago

I am currently working on a tool that displays images from a large number of external files.

I need these events to unload textures from VRAM when the window is minimized. (This requires that tetra::graphics::present is called at least once in the tetra lifecycle after the user has released textures)

17cupsofcoffee commented 3 years ago

Thank you for the PR!

17cupsofcoffee commented 3 years ago

I noticed after merging that Shown and Hidden can't currently be triggered via Tetra's public API (other than Shown getting fired once automatically at startup) - however, I needed to expose window visibility for #119, so I've done so in a seperate commit.

sumibi-yakitori commented 3 years ago

I'm not sure if I'm understanding what you're saying correctly, but on MacOS, minimizing and unminimizing a window seems to cause SDL_WINDOWEVENT_SHOWN and SDL_WINDOWEVENT_HIDDEN.

17cupsofcoffee commented 3 years ago

Ugh, that must be platform-specific, then, because it doesn't happen on Windows. I'll document that.

sumibi-yakitori commented 3 years ago

Ok. I haven't checked how it works on Linux, but I think I can remove Shown and Hidden since my desire seems to be achieved if I can detect the minimization of a window and its unminimization.

Restored, Maximized, Minimized These three events also occur on MacOS.

17cupsofcoffee commented 3 years ago

Yeah, I think I might remove them for now - the only consistent way to trigger them on all platforms seems to be to call SDL_ShowWindow/SDL_HideWindow (now exposed via tetra::window::set_visible), but you don't need events to run code in response to that. The minimize/maximize/etc events are still super useful though 😄

And yep, those other three events work fine on Windows.