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/>.
31 #include "vscreensaver.h"
33 VScreensaver::VScreensaver()
36 Video* video = Video::getInstance();
37 screenWidth = video->getScreenWidth();
38 screenHeight = video->getScreenHeight();
40 area.h = screenHeight;
41 surface = Surface::getScreen();
44 VScreensaver::~VScreensaver()
47 surface = NULL; // it's the screen. stop view base from killing it.
50 void VScreensaver::draw()
52 fillColour(DrawStyle::BLACK);
54 ssThreadStartProtect.lock();
55 ssThread = std::thread([this]
57 ssThreadStartProtect.lock();
58 ssThreadStartProtect.unlock();
61 ssThreadStartProtect.unlock();
64 int VScreensaver::handleCommand(int /*command*/)
70 void VScreensaver::stopThread()
73 if (ssThread.joinable()) ssThread.join();
76 void VScreensaver::threadMethod()
81 const int h = 50; // length of line
82 double deviation = 0.2; // how quickly can it change direction
92 const double pi2 = 6.28318;
93 double halfdeviation = deviation / 2;
95 for(i = 0; i < h; i++) x[i] = -1;
102 if (++head == h) head = 0;
105 if (tail == h) tail = 0;
107 // Undraw oldest point
108 if (x[tail] != -1) surface->drawPoint(x[tail], y[tail], DrawStyle::BLACK);// was rgba
110 dd = ((rand() / (double)RAND_MAX) * deviation) - halfdeviation;
113 if (direction >= pi2) direction -= pi2;
114 if (direction < 0) direction += pi2;
116 fx += sin(direction);
117 fy += cos(direction);
119 if (fx < 0) fx += screenWidth;
120 if (fx >= screenWidth) fx -= screenWidth;
121 if (fy < 0) fy += screenHeight;
122 if (fy >= screenHeight) fy -= screenHeight;
124 x[head] = static_cast<int>(fx);
125 y[head] = static_cast<int>(fy);
127 surface->drawPoint(x[head], y[head], DrawStyle::SELECTHIGHLIGHT); // was rgba
129 if (threadReqStop) return;