Skip to content

Commit

Permalink
Demos: Add ability to use scroll wheel in starfield
Browse files Browse the repository at this point in the history
This change adds the ability to use the scroll wheel to change
the speed in starfield.
  • Loading branch information
HawDevelopment authored and trflynn89 committed Dec 28, 2022
1 parent e8e1d19 commit a21703f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Userland/Demos/Starfield/Starfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Starfield final : public Desktop::Screensaver {
virtual void paint_event(GUI::PaintEvent&) override;
virtual void timer_event(Core::TimerEvent&) override;
virtual void keydown_event(GUI::KeyEvent&) override;
virtual void mousewheel_event(GUI::MouseEvent&) override;

Vector<Coordinate> m_stars;
int m_sweep_plane = 2000;
Expand Down Expand Up @@ -89,6 +90,16 @@ void Starfield::keydown_event(GUI::KeyEvent& event)
}
}

void Starfield::mousewheel_event(GUI::MouseEvent& event)
{
if (event.wheel_delta_y() == 0)
return;

m_speed += event.wheel_delta_y() > 0 ? -1 : 1;
if (m_speed < 1)
m_speed = 1;
}

void Starfield::paint_event(GUI::PaintEvent& event)
{
GUI::Painter painter(*this);
Expand Down

0 comments on commit a21703f

Please sign in to comment.