2 Copyright 2004-2020 Chris Tallon
4 This file is part of VOMP.
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.
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.
16 You should have received a copy of the GNU General Public License
17 along with VOMP. If not, see <https://www.gnu.org/licenses/>.
32 #include "vscreensaver.h"
34 VScreensaver::VScreensaver()
37 Video* video = Video::getInstance();
38 screenWidth = video->getScreenWidth();
39 screenHeight = video->getScreenHeight();
41 area.h = screenHeight;
42 surface = Surface::getScreen();
45 VScreensaver::~VScreensaver()
48 surface = NULL; // it's the screen. stop view base from killing it.
51 void VScreensaver::draw()
53 fillColour(DrawStyle::BLACK);
55 ssThreadStartProtect.lock();
56 ssThread = std::thread([this]
58 ssThreadStartProtect.lock();
59 ssThreadStartProtect.unlock();
62 ssThreadStartProtect.unlock();
65 int VScreensaver::handleCommand(int /*command*/)
71 void VScreensaver::stopThread()
74 if (ssThread.joinable()) ssThread.join();
77 void VScreensaver::threadMethod()
82 const int h = 50; // length of line
83 double deviation = 0.2; // how quickly can it change direction
93 const double pi2 = 6.28318;
94 double halfdeviation = deviation / 2;
96 for(i = 0; i < h; i++) x[i] = -1;
101 DrawStyle &black=DrawStyle::BLACK;
102 DrawStyle &light=DrawStyle::SELECTHIGHLIGHT;
106 if (++head == h) head = 0;
109 if (tail == h) tail = 0;
111 // Undraw oldest point
112 if (x[tail] != -1) surface->drawPoint(x[tail], y[tail], black);// was rgba
114 dd = ((rand() / (double)RAND_MAX) * deviation) - halfdeviation;
117 if (direction >= pi2) direction -= pi2;
118 if (direction < 0) direction += pi2;
120 fx += sin(direction);
121 fy += cos(direction);
123 if (fx < 0) fx += screenWidth;
124 if (fx >= screenWidth) fx -= screenWidth;
125 if (fy < 0) fy += screenHeight;
126 if (fy >= screenHeight) fy -= screenHeight;
128 x[head] = static_cast<int>(fx);
129 y[head] = static_cast<int>(fy);
131 surface->drawPoint(x[head], y[head], light); // was rgba
133 if (threadReqStop) return;