]> git.vomp.tv Git - vompclient.git/blob - vscreensaver.cc
German updates
[vompclient.git] / vscreensaver.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "vscreensaver.h"
22
23 #include "defines.h"
24 #include "log.h"
25 #include "remote.h"
26 #include "colour.h"
27 #include "video.h"
28 #include "surface.h"
29
30 VScreensaver::VScreensaver()
31 {
32   setPosition(0, 0);
33   Video* video = Video::getInstance();
34   screenWidth = video->getScreenWidth();
35   screenHeight = video->getScreenHeight();
36   area.w = screenWidth;
37   area.h = screenHeight;
38   surface = Surface::getScreen();
39 }
40
41 VScreensaver::~VScreensaver()
42 {
43   surface = NULL; // it's the screen. stop view base from killing it.
44   threadCancel();
45 }
46
47 void VScreensaver::draw()
48 {
49   fillColour(Colour::BLACK);
50   threadStart();
51 }
52
53 int VScreensaver::handleCommand(int command)
54 {
55   threadCancel();
56   return 4;
57 }
58
59 void VScreensaver::threadMethod()
60 {
61   srand(time(NULL));
62
63   threadSetKillable();
64
65   // Config
66   const int h = 50;  // length of line
67   float deviation = 0.2;  // how quickly can it change direction
68
69
70
71   int x[h];
72   int y[h];
73   int i;
74   int head = -1;
75   int tail;
76   float direction = 0;
77   float fx, fy, dd;
78   const float pi2 = 6.28318;
79   float halfdeviation = deviation / 2;
80
81   for(i = 0; i < h; i++) x[i] = -1;
82
83   fx = x[0] = 50;
84   fy = y[0] = 50;
85
86   while(1)
87   {
88     if (++head == h) head = 0;
89
90     tail = head + 1;
91     if (tail == h) tail = 0;
92
93     // Undraw oldest pixel
94     if (x[tail] != -1) surface->drawPixel(x[tail], y[tail], Colour::BLACK.rgba());
95
96     dd = ((rand() / (double)RAND_MAX) * deviation) - halfdeviation;
97     direction += dd;
98
99     if (direction >= pi2) direction -= pi2;
100     if (direction < 0) direction += pi2;
101
102     fx += sin(direction);
103     fy += cos(direction);
104
105     if (fx < 0) fx += screenWidth;
106     if (fx >= screenWidth) fx -= screenWidth;
107     if (fy < 0) fy += screenHeight;
108     if (fy >= screenHeight) fy -= screenHeight;
109
110     x[head] = (int)fx;
111     y[head] = (int)fy;
112
113     surface->drawPixel(x[head], y[head], Colour::SELECTHIGHLIGHT.rgba());
114     MILLISLEEP(10);
115   }
116 }