Home

Download

Features

Screenshots

Handbook

Browse Source

Authors

SourceForge.net Logo
Hosted by SourceForge.net

OSI Certified


Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages   Search  

animator.cpp

00001 /***************************************************************************
00002                           animator.cpp  -  description
00003                              -------------------
00004     begin                : Sat Mar 29 2003
00005     copyright            : (C) 2003 by Fungmeista
00006     email                : mizunoami44@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "animator.h"
00019 
00020 #include <qobject.h>
00021 #include <qtimer.h>
00022 
00023 Animator::Animator()
00024 {
00025     min = 0;
00026     max = 10;
00027     step = 0.1;
00028     speed = 40;
00029 
00030     _displayNValue = true;
00031 
00032     current = min;
00033 }
00034 
00035 Animator::~Animator()
00036 {
00037 }
00038 
00039 void Animator::initializeAnimator( QObject *parent )
00040 {
00041     _timer = new QTimer( parent ); //auto-deleted
00042 
00043     parent->connect( _timer, SIGNAL(timeout()), parent, SLOT(slotNextFrame()) );
00044 }
00045 
00046 void Animator::load_key( const char *key, const char *value )
00047 {
00048     if (strcmp(key,"animationMin=") == 0)
00049     {
00050         setAnimationMin(QString(value).toDouble());
00051     }
00052     else if (strcmp(key,"animationMax=") == 0)
00053     {
00054         setAnimationMax(QString(value).toDouble());
00055     }
00056     else if (strcmp(key,"animationStep=") == 0)
00057     {
00058         setAnimationStep(QString(value).toDouble());
00059     }
00060     else if (strcmp(key,"animationSpeed=") == 0)
00061     {
00062         setAnimationSpeed(QString(value).toInt());
00063     }
00064     else if (strcmp(key,"animatorValue=") == 0)
00065     {
00066         setAnimationFrame(QString(value).toDouble());
00067     }
00068 }
00069 
00070 void Animator::play()
00071 {
00072     _save = true;
00073     _timer->start( speed, FALSE );
00074 }
00075 
00076 void Animator::stop()
00077 {
00078     _timer->stop();
00079 
00080     current = min;
00081     nextFrameReady();
00082 }
00083 
00084 void Animator::pause()
00085 {
00086     if ( _timer->isActive() )
00087         _timer->stop();
00088     else
00089         play();
00090 }
00091 
00092 int Animator::setAnimationSpeed(int ms)
00093 {
00094     if ( ms > 0 )
00095     {
00096         bool is_active = _timer->isActive(); /* calling changeInterval() will play the graph... record this to set it back how it was */
00097     
00098         speed = ms;
00099         _timer->changeInterval(speed);
00100         if (!is_active) _timer->stop();
00101         
00102         return 0;
00103     }
00104     else
00105         return 1;
00106     
00107 }
00108 
00109 int Animator::setAnimationMin(double d)
00110 {
00111     if ( d < max )
00112     {
00113         min = d;
00114         return 0;
00115     }
00116     else
00117         return 1;
00118 }
00119 
00120 int Animator::setAnimationMax(double d)
00121 {
00122     if ( d > min )
00123     {
00124         max = d;
00125         return 0;
00126     }
00127     else
00128         return 1;
00129 }
00130 
00131 int Animator::setAnimationStep(double d)
00132 {
00133     if ( d > 0 )
00134     {
00135         step = d;
00136         return 0;
00137     }
00138     else
00139         return 1;
00140 }
00141 
00142 void Animator::nextFrame()
00143 {
00144     if ( current >= max )
00145     {
00146         current = min; // loop back around
00147         _save = false; //stop saving if currently are
00148     }
00149     else
00150     {
00151         current += step;
00152         if ( current > max )
00153             current = max;
00154     }
00155     
00156     nextFrameReady();
00157 }
00158 
00159 void Animator::saveAsMovie()
00160 {
00161     _save = true;
00162 }
00163 
00164