display_intro.cpp

Go to the documentation of this file.
00001 /*
00002    This file is part of the KDE games lskat 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 // General includes
00022 #include <math.h>
00023 
00024 // Qt includes
00025 #include <QSize>
00026 #include <QPoint>
00027 
00028 // KDE includes
00029 #include <klocale.h>
00030 #include <kdebug.h>
00031 
00032 // Local includes
00033 #include "display_intro.h"
00034 #include "cardsprite.h"
00035 #include "textsprite.h"
00036 
00037 #define WAIT_CNT       100  /* Wait this [ms] before clearing board */
00038 
00039 // Constructor for the display
00040 DisplayIntro::DisplayIntro(Deck* deck, QGraphicsScene* theScene, ThemeManager* theme,
00041                            int advancePeriod, QGraphicsView* parent)
00042             : Themable("display_intro",theme), AbstractDisplay(deck, theScene, theme, advancePeriod, parent)
00043 {
00044   // Choose a background color
00045   scene()->setBackgroundBrush(QColor(0,0,128));
00046 
00047   mTimer = new QTimer(this);
00048   connect(mTimer, SIGNAL(timeout()), this, SLOT(loop()));
00049   mTimer->stop();
00050 
00051    // Redraw
00052   if (theme) theme->updateTheme(this);
00053 }
00054 
00055 
00056 // Called by thememanager when theme or theme geometry changes. Redraw and resize
00057 // this display.
00058 void DisplayIntro::changeTheme()
00059 {
00060   // Retrieve theme data
00061   KConfigGroup config = thememanager()->config(id());
00062   
00063   // Retrieve background pixmap
00064   QString bgsvgid = config.readEntry("background-svgid");
00065   QPixmap pixmap  = thememanager()->getPixmap(bgsvgid, scene()->sceneRect().size().toSize());
00066   scene()->setBackgroundBrush(pixmap);
00067   mView->update();
00068 }
00069 
00070 
00071 // Start the intro.
00072 void DisplayIntro::start()
00073 {
00074   mAnimCnt = 0;
00075   mState   = Putting;
00076   mTimer->start(50);
00077 
00078   QString s1 = i18nc("Title of the game - line 1", "Lieutenant Skat");
00079   QString s2 = i18nc("Title of the game - line 2", "for");
00080   QString s3 = i18nc("Title of the game - line 3", "K D E");
00081 
00082   // Text sprite title foreground
00083   TextSprite* text1a = new TextSprite(s1, "name-front", mTheme, scene());
00084   mSprites.append(text1a);
00085   text1a->show();
00086 
00087   // Text sprite title background
00088   TextSprite* text1b = new TextSprite(s1, "name-back", mTheme, scene());
00089   mSprites.append(text1b);
00090   text1b->show();
00091 
00092   // Text sprite title foreground
00093   TextSprite* text2a = new TextSprite(s2, "for-front", mTheme, scene());
00094   mSprites.append(text2a);
00095   text2a->show();
00096 
00097   // Text sprite title background
00098   TextSprite* text2b = new TextSprite(s2, "for-back", mTheme, scene());
00099   mSprites.append(text2b);
00100   text2b->show();
00101 
00102   // Text sprite title foreground
00103   TextSprite* text3a = new TextSprite(s3, "kde-front", mTheme, scene());
00104   mSprites.append(text3a);
00105   text3a->show();
00106 
00107   // Text sprite title background
00108   TextSprite* text3b = new TextSprite(s3, "kde-back", mTheme, scene());
00109   mSprites.append(text3b);
00110   text3b->show();
00111 
00112   // Stop all card sprites
00113   for (int i=0; i<mCards.size(); i++)
00114   {
00115     mCards[i]->stop();
00116   }
00117 }
00118 
00119 
00120 // Animation loop
00121 void DisplayIntro::loop()
00122 {
00123   int no = mCards.size();
00124   // Catch no card error
00125   if (no<1) return;
00126 
00127   // Retrieve theme data
00128   KConfigGroup cardconfig = thememanager()->config("card");
00129   double card_width       = cardconfig.readEntry("width", 1.0);
00130   KConfigGroup config     = thememanager()->config(id());
00131   QPointF start_shift     = config.readEntry("start-shift", QPointF(1.0,1.0));
00132   QPointF start_pos       = config.readEntry("start-pos", QPointF(1.0,1.0));
00133   double time_clear_in    = config.readEntry("time-clear-in", 1.0);
00134   double time_clear_out   = config.readEntry("time-clear-out", 1.0);
00135   double aspectRatio      = thememanager()->aspectRatio();
00136 
00137   // Display a card
00138   if (mAnimCnt < no && mState == Putting)
00139   {
00140     double factor = double(mAnimCnt)/double(no-1);
00141     double fsin = sin(factor*M_PI);
00142 
00143     CardSprite* sprite = mCards[mAnimCnt];
00144 
00145     QPointF pos;
00146     if (mAnimCnt %2 == 0) 
00147     {
00148       pos  = QPointF(start_pos.x(), start_pos.y());
00149       pos += QPointF(start_shift.x() * fsin, start_shift.y() * factor);
00150     }
00151     else
00152     {
00153       pos  = QPointF(1.0-start_pos.x()-card_width, start_pos.y());
00154       pos += QPointF(-start_shift.x() * fsin, start_shift.y() * factor);
00155     }
00156     sprite->setBackside();
00157     sprite->setPosition(pos);
00158     sprite->setZValue(50+mAnimCnt);
00159     sprite->show();
00160     mAnimCnt++;
00161   }
00162   // Change state to turning
00163   else if (mState == Putting)
00164   {
00165     mState   = Turning;
00166     mAnimCnt = 0;
00167   }
00168   // Turn cards
00169   else if (mAnimCnt < no && mState == Turning)
00170   {
00171     CardSprite* sprite = mCards[mAnimCnt];
00172     sprite->setTurning(true);
00173     mAnimCnt++;
00174   }
00175   // Change state to waiting
00176   else if (mState == Turning)
00177   {
00178     mState   = Waiting;
00179     mAnimCnt = 0;
00180   }
00181   // Wait
00182   else if (mAnimCnt < WAIT_CNT && mState == Waiting)
00183   {
00184     mAnimCnt++;
00185   }
00186   // Change state to clearing the board
00187   else if (mState == Waiting)
00188   {
00189     mState   = Clearing;
00190     mAnimCnt = 0;
00191   }
00192   // Clear the board, step 1
00193   else if (mAnimCnt == 0 && mState == Clearing)
00194   {
00195     for (int i=0; i<no; i++)
00196     {
00197       CardSprite* sprite = mCards[i];
00198       sprite->setMove(QPointF((1.0-card_width)/2.0, (1.0/aspectRatio-card_width)/2.0), time_clear_in);
00199     }
00200     mAnimCnt++;
00201   }
00202   // Clear the board, step 2
00203   else if (mAnimCnt < 30 && mState == Clearing)
00204   {
00205     mAnimCnt++;
00206   }
00207   // Clear the board, step 3 and change state to waiting
00208   else if (mState == Clearing)
00209   {
00210     for (int i=0; i<no; i++)
00211     {
00212       double r = 1.0;
00213       double x = r*cos(double(i)/double(no-1)*M_PI*2.0) + 0.5;
00214       double y = r*sin(double(i)/double(no-1)*M_PI*2.0) + 0.5;
00215       CardSprite* sprite = mCards[i];
00216       sprite->setMove(QPointF(x,y/aspectRatio), time_clear_out);
00217     }
00218     mState = Waiting2;
00219     mAnimCnt = 0;
00220   }
00221   // Wait
00222   else if (mAnimCnt < WAIT_CNT && mState == Waiting2)
00223   {
00224     mAnimCnt++;
00225   }
00226   // Restart cycle
00227   else if (mState == Waiting2)
00228   {
00229     for (int i=0; i<no; i++)
00230     {
00231       CardSprite* sprite = mCards[i];
00232       sprite->stop();
00233     }
00234 
00235     mState   = Putting;
00236     mAnimCnt = 0;
00237   }
00238 
00239 }
00240 
00241 
00242 #include "display_intro.moc"

Generated on Tue May 1 09:34:40 2007 for LSkat by  doxygen 1.4.6