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*/)
68 return BoxStack::DELETE_ME;
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;
103 if (++head == h) head = 0;
106 if (tail == h) tail = 0;
108 // Undraw oldest point
109 if (x[tail] != -1) surface->drawPoint(x[tail], y[tail], DrawStyle::BLACK);// was rgba
111 dd = ((rand() / (double)RAND_MAX) * deviation) - halfdeviation;
114 if (direction >= pi2) direction -= pi2;
115 if (direction < 0) direction += pi2;
117 fx += sin(direction);
118 fy += cos(direction);
120 if (fx < 0) fx += screenWidth;
121 if (fx >= screenWidth) fx -= screenWidth;
122 if (fy < 0) fy += screenHeight;
123 if (fy >= screenHeight) fy -= screenHeight;
125 x[head] = static_cast<int>(fx);
126 y[head] = static_cast<int>(fy);
128 surface->drawPoint(x[head], y[head], DrawStyle::SELECTHIGHLIGHT); // was rgba
130 if (threadReqStop) return;