mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:37:35 +00:00
Demos+LibDesktop: Centralize screensaver logic
We have 3 demos with pretty similar window logic and quitting behavior on user activity, so centralize that into `Desktop::Screensaver`.
This commit is contained in:
parent
379e4a2432
commit
18b6bdb563
11 changed files with 108 additions and 99 deletions
|
@ -16,7 +16,6 @@
|
|||
#include <LibGfx/Bitmap.h>
|
||||
|
||||
constexpr size_t grid_resolution = 15;
|
||||
constexpr int mouse_max_distance_move = 10;
|
||||
constexpr int reset_every_ticks = 900;
|
||||
constexpr double rotation_range = 35.;
|
||||
constexpr u8 tube_maximum_count = 12;
|
||||
|
@ -78,6 +77,7 @@ static IntVector3 vector_for_direction(Direction direction)
|
|||
Tubes::Tubes(int interval)
|
||||
: m_grid(MUST(FixedArray<u8>::try_create(grid_resolution * grid_resolution * grid_resolution)))
|
||||
{
|
||||
on_screensaver_exit = []() { GUI::Application::the()->quit(); };
|
||||
start_timer(interval);
|
||||
}
|
||||
|
||||
|
@ -149,25 +149,6 @@ void Tubes::set_grid(IntVector3 position, u8 value)
|
|||
m_grid[position.z() * grid_resolution * grid_resolution + position.y() * grid_resolution + position.x()] = value;
|
||||
}
|
||||
|
||||
void Tubes::mousemove_event(GUI::MouseEvent& event)
|
||||
{
|
||||
if (m_mouse_origin.is_null()) {
|
||||
m_mouse_origin = event.position();
|
||||
} else if (event.position().distance_from(m_mouse_origin) > mouse_max_distance_move) {
|
||||
GUI::Application::the()->quit();
|
||||
}
|
||||
}
|
||||
|
||||
void Tubes::mousedown_event(GUI::MouseEvent&)
|
||||
{
|
||||
GUI::Application::the()->quit();
|
||||
}
|
||||
|
||||
void Tubes::keydown_event(GUI::KeyEvent&)
|
||||
{
|
||||
GUI::Application::the()->quit();
|
||||
}
|
||||
|
||||
void Tubes::paint_event(GUI::PaintEvent& event)
|
||||
{
|
||||
GUI::Painter painter(*this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue