summaryrefslogtreecommitdiff
path: root/Demos
diff options
context:
space:
mode:
authorBrendan Coles <bcoles@gmail.com>2020-04-28 00:00:44 +0000
committerAndreas Kling <kling@serenityos.org>2020-04-28 09:36:28 +0200
commit24b9e57b150ec03c6cfc60cb3492959460f381cb (patch)
tree6657222d423e238f0353d855bc9e16d5b8371d49 /Demos
parent8f2300afb5cae00595126ee9119a6f47c6e20b17 (diff)
downloadserenity-24b9e57b150ec03c6cfc60cb3492959460f381cb.zip
Screensaver: Draw screen before first timer iteration and seed srand()
Diffstat (limited to 'Demos')
-rw-r--r--Demos/Screensaver/Screensaver.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/Demos/Screensaver/Screensaver.cpp b/Demos/Screensaver/Screensaver.cpp
index e63005f53a..be6c6ca89a 100644
--- a/Demos/Screensaver/Screensaver.cpp
+++ b/Demos/Screensaver/Screensaver.cpp
@@ -26,13 +26,13 @@
#include <LibCore/ElapsedTimer.h>
#include <LibGfx/Bitmap.h>
-#include <LibGUI/Application.h>
#include <LibGUI/Action.h>
+#include <LibGUI/Application.h>
#include <LibGUI/Event.h>
#include <LibGUI/Painter.h>
#include <LibGUI/Widget.h>
#include <LibGUI/Window.h>
-#include <math.h>
+#include <time.h>
#include <stdio.h>
#define WIDTH 64
@@ -48,6 +48,7 @@ private:
Screensaver();
RefPtr<Gfx::Bitmap> m_bitmap;
+ void draw();
virtual void paint_event(GUI::PaintEvent&) override;
virtual void timer_event(Core::TimerEvent&) override;
virtual void keydown_event(GUI::KeyEvent&) override;
@@ -58,8 +59,10 @@ private:
Screensaver::Screensaver()
{
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { WIDTH, HEIGHT });
+ srand(time(nullptr));
stop_timer();
start_timer(INTERVAL);
+ draw();
}
Screensaver::~Screensaver()
@@ -75,6 +78,7 @@ void Screensaver::mousedown_event(GUI::MouseEvent&)
{
::exit(0);
}
+
void Screensaver::keydown_event(GUI::KeyEvent&)
{
::exit(0);
@@ -90,7 +94,11 @@ void Screensaver::timer_event(Core::TimerEvent&)
{
Core::ElapsedTimer timer;
timer.start();
+ draw();
+}
+void Screensaver::draw()
+{
const Color colors[] {
Color::Blue,
Color::Cyan,
@@ -106,7 +114,6 @@ void Screensaver::timer_event(Core::TimerEvent&)
Gfx::Orientation::Vertical
};
-
int start_color_index = 0;
int end_color_index = 0;
while (start_color_index == end_color_index) {