From 61ca37f97e79806ceb769b86948e5fdabf20fca4 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Wed, 28 Mar 2007 22:46:09 +0000 Subject: [PATCH] A _very_ simple screensaver. --- objects.mk | 2 +- vscreensaver.cc | 118 ++++++++++++++++++++++++++++++++++++++++++++++++ vscreensaver.h | 61 +++++++++++++++++++++++++ vwelcome.cc | 5 ++ vwelcome.h | 1 + 5 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 vscreensaver.cc create mode 100644 vscreensaver.h diff --git a/objects.mk b/objects.mk index f86dcaa..8e4bef7 100644 --- a/objects.mk +++ b/objects.mk @@ -10,7 +10,7 @@ OBJECTS1 = command.o log.o tcp.o dsock.o thread.o timers.o i18n.o mutex.o \ vtimerlist.o vtimeredit.o voptionsmenu.o vrecordingmenu.o \ vchannellist.o vwelcome.o vvideolive.o vvideorec.o vepgsettimer.o \ vchannelselect.o vserverselect.o vconnect.o vepg.o vrecmove.o \ - vradiorec.o vaudioselector.o \ + vradiorec.o vaudioselector.o vscreensaver.o \ vtabsviewman.o vremoteconfig.o \ widget.o wselectlist.o wjpeg.o wsymbol.o wbutton.o \ woptionbox.o wtextbox.o wwss.o \ diff --git a/vscreensaver.cc b/vscreensaver.cc new file mode 100644 index 0000000..c51b714 --- /dev/null +++ b/vscreensaver.cc @@ -0,0 +1,118 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "vscreensaver.h" + +VScreensaver::VScreensaver() +{ + setScreenPos(0, 0); + Video* video = Video::getInstance(); + screenWidth = video->getScreenWidth(); + screenHeight = video->getScreenHeight(); + area.w = screenWidth; + area.h = screenHeight; + surface = Surface::getScreen(); +} + +VScreensaver::~VScreensaver() +{ + surface = NULL; // it's the screen. stop view base from killing it. + threadCancel(); +} + +void VScreensaver::draw() +{ + setBackgroundColour(Colour::BLACK); + View::draw(); + threadStart(); +} + +int VScreensaver::handleCommand(int command) +{ + threadCancel(); + + return 4; +} + +void VScreensaver::threadMethod() +{ + threadSetKillable(); + + // Config + int h = 50; // length of line + float deviation = 0.2; // how quickly can it change direction + + + + int x[h]; + int y[h]; + int i; + float direction = 0; + float fx; + float fy; + float dd; + const float pi = 3.14159; + const float pi2 = 6.28318; + float halfdeviation = deviation / 2; + + for(i = 1; i < h; i++) + { + x[i] = -1; + y[i] = -1; + } + + fx = x[0] = 50; + fy = y[0] = 50; + + while(1) + { + // Undraw oldest pixel + if ((x[h-1] != -1) && (y[h-1] != -1)) + { + surface->drawPixel(x[h-1], y[h-1], Colour::BLACK.rgba()); + } + + for(i = h - 1; i > 0; i--) + { + x[i] = x[i-1]; + y[i] = y[i-1]; + } + + dd = ((rand() / (double)RAND_MAX) * deviation) - halfdeviation; + direction += dd; + + if (direction >= pi2) direction -= pi2; + if (direction < 0) direction += pi2; + + fx += sin(direction); + fy += cos(direction); + + if (fx < 0){ printf("AAA\n"); fx += screenWidth; } + if (fx >= screenWidth){ printf("BBB\n"); fx -= screenWidth; } + if (fy < 0){ printf("CCC\n"); fy += screenHeight; } + if (fy >= screenHeight){ printf("DDD\n"); fy -= screenHeight; } + + x[0] = (int)fx; + y[0] = (int)fy; + + surface->drawPixel(x[0], y[0], Colour::SELECTHIGHLIGHT.rgba()); + MILLISLEEP(10); + } +} diff --git a/vscreensaver.h b/vscreensaver.h new file mode 100644 index 0000000..4d3330e --- /dev/null +++ b/vscreensaver.h @@ -0,0 +1,61 @@ +/* + Copyright 2007 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef VSCREENSAVER_H +#define VSCREENSAVER_H + +#include +#include +#include + +#include "defines.h" +#include "log.h" +#include "view.h" +#include "remote.h" +#include "colour.h" +#include "video.h" +#include "video.h" + +#ifdef WIN32 +#include "threadwin.h" +#else +#include "threadp.h" +#endif + + +class VScreensaver : public View, public Thread_TYPE +{ + public: + VScreensaver(); + ~VScreensaver(); + + int handleCommand(int command); + void draw(); + + private: + + virtual void threadMethod(); + virtual void threadPostStopCleanup() {}; + + int screenHeight; + int screenWidth; +}; + +#endif diff --git a/vwelcome.cc b/vwelcome.cc index dd4d334..7bfd9cb 100644 --- a/vwelcome.cc +++ b/vwelcome.cc @@ -192,6 +192,11 @@ int VWelcome::handleCommand(int command) #ifdef DEV case Remote::NINE: { + VScreensaver* vscreensaver = new VScreensaver(); + viewman->add(vscreensaver); + vscreensaver->draw(); +// viewman->updateView(vscreensaver); + return 2; } #endif diff --git a/vwelcome.h b/vwelcome.h index 3f8be28..320cc0f 100644 --- a/vwelcome.h +++ b/vwelcome.h @@ -40,6 +40,7 @@ #include "voptionsmenu.h" #include "i18n.h" #include "timers.h" +#include "vscreensaver.h" class VWelcome : public View, public TimerReceiver { -- 2.39.5