diff options
author | gregory guy <gregory-tde@laposte.net> | 2021-04-26 18:17:21 +0200 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2021-05-21 12:18:46 +0900 |
commit | 038e20a6bb9c2adfeb54e5c98ee475969575f39f (patch) | |
tree | 7052c9031a8b067f1311d2d0bff0785db25c195d /asciiquarium/src/sprite.cpp | |
parent | e3a9c9e680ad33d28923091a881b9eca5ad78368 (diff) | |
download | tdeartwork-038e20a6bb9c2adfeb54e5c98ee475969575f39f.tar.gz tdeartwork-038e20a6bb9c2adfeb54e5c98ee475969575f39f.zip |
Import original source code KDE3 Asciiquarium-0.3.2 from https://store.kde.org/p/1124051.
KDE Asciiquarium is a screensaver based off Kirk Baucom's asciiquarium program (http://www.robobunny.com/projects/asciiquarium/).
Code is GPL licensed, https://robobunny.com/projects/asciiquarium/gpl.txt
Signed-off-by: gregory guy <gregory-tde@laposte.net>
(cherry picked from commit 66605c73afda749d19dac310d41f7a7241d6d00b)
Diffstat (limited to 'asciiquarium/src/sprite.cpp')
-rw-r--r-- | asciiquarium/src/sprite.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/asciiquarium/src/sprite.cpp b/asciiquarium/src/sprite.cpp new file mode 100644 index 00000000..85e946ed --- /dev/null +++ b/asciiquarium/src/sprite.cpp @@ -0,0 +1,94 @@ +/* + * Asciiquarium - Native KDE Screensaver based on the Asciiquarium program + * (c) Kirk Baucom <kbaucom@schizoid.com>, which you can find at + * http://www.robobunny.com/projects/asciiquarium/ + * + * Ported to KDE by Maksim Orlovich <maksim@kde.org> and + * Michael Pyne <michael.pyne@kdemail.net>. + * + * Copyright (c) 2003 Kirk Baucom <kbaucom@schizoid.com> + * Copyright (c) 2005 Maksim Orlovich <maksim@kde.org> + * Copyright (c) 2005 Michael Pyne <michael.pyne@kdemail.net> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "sprite.h" + +Sprite::Sprite(Screen* screen, int x, int y, int z, int frameDelay): + m_screen(screen), m_currentFrame(0), m_x(x), m_y(y), m_z(z), + m_isKilled(false), m_killAfterLastFrame(false), + m_ticksSinceFrameChange(0), m_frameDelay(frameDelay) +{ +} + +void Sprite::addFrame(const Frame& frame) +{ + m_frames.append(frame); +} + +void Sprite::erase() +{ + m_frames[m_currentFrame].erase(m_screen, m_x, m_y); +} + +void Sprite::paint() +{ + m_frames[m_currentFrame].paint(m_screen, m_x, m_y); +} + +bool Sprite::timerTick() +{ + ++m_ticksSinceFrameChange; + if (m_ticksSinceFrameChange * m_screen->msPerTick() < m_frameDelay) + return false; + + //Ring! Ring! + m_ticksSinceFrameChange = 0; + return true; +} + +bool Sprite::tickUpdate() +{ + if (m_frames.size() == 1) + return false; + + if (!timerTick()) + return false; + + erase(); + + ++m_currentFrame; + if (m_currentFrame == m_frames.size()) + { + m_currentFrame = 0; + + if(m_killAfterLastFrame) + { + erase(); + kill(); + } + } + + return true; +} + +QRect Sprite::geom() const +{ + return QRect(m_x, m_y, m_frames[0].width(), m_frames[0].height()); +} + + +// vim: set et ts=8 sw=4: |