AaronCameron.net
Because you all make me very, very tired.
Not a Member? - Login or Create an Account
Wednesday the 23rd of May 2012 @ 09:58am
Front Page Journal Projects Your Profile About
[]

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

cGuiSEAutoscroll.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library
00003 Copyright (C) 2002  Aaron Cameron
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation; either
00008 version 2.1 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 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 
00019 A copy of the GNU Lesser General Public License has been provided with
00020 this library in the file 'COPYING'.
00021 
00022 Contact information for the author of this library has been provided
00023 with this library in the file 'AUTHOR'.
00024 ************************************************************************/
00025 #include "gui/cGuiSEAutoscroll.h"
00026 
00027 #include "gui/cGuiTextDisplay.h"
00028 
00029 namespace n2l
00030 {
00031     /**************************************************************************/
00032     cGuiSEAutoscroll::cGuiSEAutoscroll()
00033     {
00034         init();
00035     }
00036 
00037     /**************************************************************************/
00038     cGuiSEAutoscroll::cGuiSEAutoscroll( const cDynVar &iDef )
00039     {
00040         init();
00041         load( iDef );
00042     }
00043 
00044     /**************************************************************************/
00045     cGuiSEAutoscroll::cGuiSEAutoscroll( const tString &iName ) :
00046         cGuiSEInt( iName )
00047     {
00048         init();
00049     }
00050 
00051     /**************************************************************************/
00052     cGuiSEAutoscroll::~cGuiSEAutoscroll()
00053     {
00054     }
00055 
00056     /**************************************************************************/
00057     void cGuiSEAutoscroll::load( const cDynVar &iDef )
00058     {
00059         cGuiSEInt::load( iDef );
00060     }
00061 
00062     /**************************************************************************/
00063     void cGuiSEAutoscroll::lifespan( const tUint &iLifespan )
00064     {
00065         mLifespan = iLifespan;
00066     }
00067 
00068     /**************************************************************************/
00069     void cGuiSEAutoscroll::textToScroll( const tString &iText )
00070     {
00071         tUint words(0);
00072         tUint lastWordOffset = 0;
00073         while (tString::npos !=
00074             (lastWordOffset = iText.find(' ',lastWordOffset)))
00075         {
00076             ++words;
00077             ++lastWordOffset;
00078         }
00079         mSlideTime = n2lMax(tUint(3000),484 * words);
00080         mLifespan = mStartWait + mSlideTime;
00081     }
00082 
00083     /**************************************************************************/
00084     const tBool cGuiSEAutoscroll::actOn( cGuiElement *const ioElement,
00085         const tUint iTimePassed )
00086     {
00087         if (!alive()) return false;
00088 
00089         cGuiTextDisplay *tmp = dynamic_cast<cGuiTextDisplay *>(ioElement);
00090         if (!tmp) throw cBadDataUseException( "cGuiSEAutoscroll::actOn",
00091             "Special effect attached to incompatible element." );
00092 
00093         if (!mLifespan)
00094             textToScroll( tmp->text() );
00095 
00096         mLifespan -= n2lMin( mLifespan, iTimePassed );
00097         mStartWait -= n2lMin( mStartWait, iTimePassed );
00098 
00099         if (mStartWait) return alive();
00100 
00101         mSlideTime -= n2lMin( mSlideTime, iTimePassed );
00102 
00103         if (!mSlideTime) return alive();
00104 
00105         const tFloat Seconds = iTimePassed/1000.0f;
00106 
00107         mSlideVal += mSlideRate*Seconds;
00108         tmp->lineOffset( tUint(mSlideVal) );
00109 
00110         return alive(mLifespan);
00111     }
00112 
00113     /**************************************************************************/
00114     const cAutoPtr<cGuiSEInt> cGuiSEAutoscroll::clone() const
00115     {
00116         cAutoPtr<cGuiSEAutoscroll> tmp = new cGuiSEAutoscroll;
00117         cloneInto( tmp );
00118         return tmp;
00119     }
00120     
00121     /**************************************************************************/
00122     void cGuiSEAutoscroll::cloneInto(
00123         const cAutoPtr<cGuiSEAutoscroll> &ioElement ) const
00124     {
00125         cGuiSEInt::cloneInto( ioElement );
00126 
00127         ioElement->mLifespan = mLifespan;
00128         ioElement->mStartWait = mStartWait;
00129         ioElement->mSlideTime = mSlideTime;
00130         ioElement->mSlideRate = mSlideRate;
00131         ioElement->mSlideVal = mSlideVal;
00132     }
00133 
00134     /**************************************************************************/
00135     void cGuiSEAutoscroll::init()
00136     {
00137         mLifespan = 0;
00138         mStartWait = 3000;
00139         mSlideTime = 10000;
00140         mSlideRate = .5f;
00141         mSlideVal = .0f;
00142     }
00143 
00144 } // namespace n2l
©2012 Aaron Cameron