]> git.vomp.tv Git - vompclient.git/blob - vscreensaver.cc
fd5d4eaeaec01cb859ca0166088c5a2386360332
[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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 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(DrawStyle::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   DrawStyle &black=DrawStyle::BLACK;
87   DrawStyle &light=DrawStyle::SELECTHIGHLIGHT;
88
89   while(1)
90   {
91     if (++head == h) head = 0;
92
93     tail = head + 1;
94     if (tail == h) tail = 0;
95
96     // Undraw oldest point
97     if (x[tail] != -1) surface->drawPoint(x[tail], y[tail], black);// was rgba
98
99     dd = ((rand() / (double)RAND_MAX) * deviation) - halfdeviation;
100     direction += dd;
101
102     if (direction >= pi2) direction -= pi2;
103     if (direction < 0) direction += pi2;
104
105     fx += sin(direction);
106     fy += cos(direction);
107
108     if (fx < 0) fx += screenWidth;
109     if (fx >= screenWidth) fx -= screenWidth;
110     if (fy < 0) fy += screenHeight;
111     if (fy >= screenHeight) fy -= screenHeight;
112
113     x[head] = (int)fx;
114     y[head] = (int)fy;
115
116     surface->drawPoint(x[head], y[head], light); // was rgba
117     MILLISLEEP(10);
118   }
119 }