displayintro.cpp

Go to the documentation of this file.
00001 /*
00002    This file is part of the KDE games kwin4 program
00003    Copyright (c) 2006 Martin Heni <kde@heni-online.de>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 // Standard includes
00022 #include <math.h>
00023 
00024 // Qt includes
00025 #include <QFont>
00026 #include <QColor>
00027 #include <QPixmap>
00028 #include <QPoint>
00029 
00030 // KDE includes
00031 #include <klocale.h>
00032 #include <kdebug.h>
00033 
00034 // Local includes
00035 #include "displayintro.h"
00036 #include "introsprite.h"
00037 
00038 
00039 
00040 // Constructor for the intro display
00041 DisplayIntro::DisplayIntro(int advancePeriod, QGraphicsScene* scene, ThemeManager* theme, QObject* parent)
00042           : Themable("introdisplay",theme), QObject(parent)
00043 {
00044   // Choose a background color
00045   scene->setBackgroundBrush(QColor(0,0,128));
00046   
00047   // Store the theme manager and other attributes
00048   mTheme         = theme;
00049   mScene         = scene;
00050   mAdvancePeriod = advancePeriod;
00051 
00052   // Storage of all sprites
00053   mSprites.clear();
00054 
00055   // Create all sprites used for intro
00056   for (int i=0; i<42; i++)
00057   {
00058     IntroSprite* sprite = new IntroSprite("intro_piece", mTheme, mAdvancePeriod, i, mScene);
00059     if (!sprite) kFatal() << "Cannot load sprite " << "intro_piece" << endl;
00060     mSprites.append(sprite);
00061     if ((i/2)%2==0) sprite->setFrame(0);
00062     else  sprite->setFrame(1);
00063     sprite->setZValue(i);
00064     sprite->hide();
00065   }
00066 
00067 
00068   // Animation timer
00069   mTimer = new QTimer(this);
00070   connect(mTimer, SIGNAL(timeout()), this, SLOT(advance()));
00071 
00072   // Draw us
00073   theme->updateTheme(this);
00074 }
00075 
00076 
00077 // Desctruct the intro and all sprites
00078 DisplayIntro::~DisplayIntro()
00079 {
00080   delete mTimer;
00081   while (!mSprites.isEmpty())
00082   {
00083     delete mSprites.takeFirst();
00084   }
00085 }
00086 
00087 
00088 // Master theme change function. Redraw the display
00089 void DisplayIntro::changeTheme()
00090 {
00091    // Nothing to do here as the sprites handles this by themselves
00092 }
00093 
00094 
00095 // Start the animation
00096 void DisplayIntro::start()
00097 {
00098   // Begin with the first state
00099   mIntroState = IntroMoveIn;
00100 
00101   // Tun the timer
00102   mTimer->setSingleShot(true);
00103   mTimer->start(0);
00104 }
00105 
00106 
00107 // Animation main routine to advance the aniamtion. Called
00108 // by a timer
00109 void DisplayIntro::advance()
00110 {
00111         // Local variables
00112   double dura, delay, rad;
00113   QPointF start, end;
00114 
00115   // First part of intro animation. Move sprites into window
00116   if (mIntroState == IntroMoveIn)
00117   {
00118         // Loop all sprites
00119     for (int i = 0; i < mSprites.size(); ++i) 
00120     {
00121         // Move only intro sprites
00122       if (mSprites.at(i)->type() != QGraphicsItem::UserType+1) continue;
00123       
00124       IntroSprite* sprite = (IntroSprite*)mSprites.at(i);
00125       int no = sprite->number();
00126       {
00127         if (no%2==0)
00128         {
00129           start = QPointF(1.05, 0.5);
00130           end   = QPointF(0.35 + no/300.0, 105.0/800.0+no/125.0);
00131           dura  = 3000.0;
00132           delay = 80.0*no;
00133           rad   = 0.1;
00134         }
00135         else
00136         {
00137           start = QPointF(-0.05, 0.5);
00138           end   = QPointF(0.65-(no-1)/300.0, 105.0/800.0+(no-1)/125.0);
00139           dura  = 3000.0;
00140           delay = 80.0*(no-1);
00141           rad   = 0.1;
00142         }
00143         sprite->setZValue(no);
00144         sprite->startIntro(start, end, rad, dura, delay);
00145       }
00146     }// end list loop
00147 
00148     // Continue with next intro state
00149     mIntroState = IntroCollapse;
00150     mTimer->start(9000); // [ms]
00151     return;
00152   }// end IntroMoveIn
00153 
00154   // Second part of intro animation. Move sprites inwards
00155   if (mIntroState == IntroCollapse)
00156   {
00157         // Loop all sprites
00158     for (int i = 0; i < mSprites.size(); ++i) 
00159     {
00160         // Move only intro sprites
00161       if (mSprites.at(i)->type() != QGraphicsItem::UserType+1) continue;
00162       
00163       IntroSprite* sprite = (IntroSprite*)mSprites.at(i);
00164       sprite->startLinear(QPointF(0.5, 0.3), 200);
00165     }// end for
00166 
00167     // Continue with next intro state
00168     mIntroState = IntroExplode;
00169     mTimer->start(500);  // [ms]
00170     return;
00171   }// end IntroCollapse
00172 
00173   // Third part of intro animation. Move sprites outwards
00174   if (mIntroState == IntroExplode)
00175   {
00176         // Loop all sprites
00177     for (int i = 0; i < mSprites.size(); ++i) 
00178     {
00179         // Move only intro sprites
00180       if (mSprites.at(i)->type() != QGraphicsItem::UserType+1) continue;
00181       
00182       IntroSprite* sprite = (IntroSprite*)mSprites.at(i);
00183       int no = sprite->number();
00184       double x = 0.5 + 1.50*cos(no/42.0*2.0*M_PI);
00185       double y = 0.3 + 1.50*sin(no/42.0*2.0*M_PI);
00186       sprite->startLinear(QPointF(x,y), 800);
00187     }// end for
00188 
00189     // Start again with first intro state
00190     mIntroState = IntroMoveIn;
00191     mTimer->start(1900);  // [ms]
00192     return;
00193   }// end IntroCollapse
00194 }
00195 
00196 
00197 #include "displayintro.moc"

Generated on Sun Mar 4 10:56:43 2007 for KWin4 by  doxygen 1.4.6