mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:07:34 +00:00
Screensaver: Draw screen before first timer iteration and seed srand()
This commit is contained in:
parent
8f2300afb5
commit
24b9e57b15
1 changed files with 10 additions and 3 deletions
|
@ -26,13 +26,13 @@
|
||||||
|
|
||||||
#include <LibCore/ElapsedTimer.h>
|
#include <LibCore/ElapsedTimer.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGUI/Application.h>
|
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/Event.h>
|
#include <LibGUI/Event.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGUI/Widget.h>
|
#include <LibGUI/Widget.h>
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <math.h>
|
#include <time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define WIDTH 64
|
#define WIDTH 64
|
||||||
|
@ -48,6 +48,7 @@ private:
|
||||||
Screensaver();
|
Screensaver();
|
||||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||||
|
|
||||||
|
void draw();
|
||||||
virtual void paint_event(GUI::PaintEvent&) override;
|
virtual void paint_event(GUI::PaintEvent&) override;
|
||||||
virtual void timer_event(Core::TimerEvent&) override;
|
virtual void timer_event(Core::TimerEvent&) override;
|
||||||
virtual void keydown_event(GUI::KeyEvent&) override;
|
virtual void keydown_event(GUI::KeyEvent&) override;
|
||||||
|
@ -58,8 +59,10 @@ private:
|
||||||
Screensaver::Screensaver()
|
Screensaver::Screensaver()
|
||||||
{
|
{
|
||||||
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { WIDTH, HEIGHT });
|
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { WIDTH, HEIGHT });
|
||||||
|
srand(time(nullptr));
|
||||||
stop_timer();
|
stop_timer();
|
||||||
start_timer(INTERVAL);
|
start_timer(INTERVAL);
|
||||||
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
Screensaver::~Screensaver()
|
Screensaver::~Screensaver()
|
||||||
|
@ -75,6 +78,7 @@ void Screensaver::mousedown_event(GUI::MouseEvent&)
|
||||||
{
|
{
|
||||||
::exit(0);
|
::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screensaver::keydown_event(GUI::KeyEvent&)
|
void Screensaver::keydown_event(GUI::KeyEvent&)
|
||||||
{
|
{
|
||||||
::exit(0);
|
::exit(0);
|
||||||
|
@ -90,7 +94,11 @@ void Screensaver::timer_event(Core::TimerEvent&)
|
||||||
{
|
{
|
||||||
Core::ElapsedTimer timer;
|
Core::ElapsedTimer timer;
|
||||||
timer.start();
|
timer.start();
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Screensaver::draw()
|
||||||
|
{
|
||||||
const Color colors[] {
|
const Color colors[] {
|
||||||
Color::Blue,
|
Color::Blue,
|
||||||
Color::Cyan,
|
Color::Cyan,
|
||||||
|
@ -106,7 +114,6 @@ void Screensaver::timer_event(Core::TimerEvent&)
|
||||||
Gfx::Orientation::Vertical
|
Gfx::Orientation::Vertical
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int start_color_index = 0;
|
int start_color_index = 0;
|
||||||
int end_color_index = 0;
|
int end_color_index = 0;
|
||||||
while (start_color_index == end_color_index) {
|
while (start_color_index == end_color_index) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue