Преглед изворни кода

Starfield: Modify speed by Plus or Minus keypresses

Although this is supposed to be a screensaver, it makes all the sense in
the world that it should support modifying the speed interactively. :^)
Pedro Pereira пре 3 година
родитељ
комит
efe5f37b04
1 измењених фајлова са 12 додато и 2 уклоњено
  1. 12 2
      Userland/Demos/Starfield/Starfield.cpp

+ 12 - 2
Userland/Demos/Starfield/Starfield.cpp

@@ -85,9 +85,19 @@ void Starfield::mousedown_event(GUI::MouseEvent&)
     GUI::Application::the()->quit();
     GUI::Application::the()->quit();
 }
 }
 
 
-void Starfield::keydown_event(GUI::KeyEvent&)
+void Starfield::keydown_event(GUI::KeyEvent& event)
 {
 {
-    GUI::Application::the()->quit();
+    switch (event.key()) {
+    case Key_Plus:
+        m_speed++;
+        break;
+    case Key_Minus:
+        if (--m_speed < 1)
+            m_speed = 1;
+        break;
+    default:
+        GUI::Application::the()->quit();
+    }
 }
 }
 
 
 void Starfield::paint_event(GUI::PaintEvent& event)
 void Starfield::paint_event(GUI::PaintEvent& event)