traverso-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Traverso-commit] traverso/src/traverso/songcanvas Cursors.cpp Cu...


From: Remon Sijrier
Subject: [Traverso-commit] traverso/src/traverso/songcanvas Cursors.cpp Cu...
Date: Wed, 30 May 2007 18:04:18 +0000

CVSROOT:        /sources/traverso
Module name:    traverso
Changes by:     Remon Sijrier <r_sijrier>       07/05/30 18:04:18

Modified files:
        src/traverso/songcanvas: Cursors.cpp Cursors.h 

Log message:
        Make animation time independent of scrolled pixels... (and use 1 second 
animation, seems rather common)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/songcanvas/Cursors.cpp?cvsroot=traverso&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/songcanvas/Cursors.h?cvsroot=traverso&r1=1.14&r2=1.15

Patches:
Index: Cursors.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/songcanvas/Cursors.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- Cursors.cpp 30 May 2007 16:14:47 -0000      1.22
+++ Cursors.cpp 30 May 2007 18:04:18 -0000      1.23
@@ -32,6 +32,8 @@
 // in case we run with memory leak detection enabled!
 #include "Debugger.h"
 
+#define ANIME_DURATION 1000
+
 PlayHead::PlayHead(SongView* sv, Song* song, ClipsViewPort* vp)
        : ViewItem(0, song)
        , m_song(song)
@@ -42,7 +44,7 @@
        connect(&(config()), SIGNAL(configChanged()), this, 
SLOT(check_config()));
        
        // TODO: Make duration scale with scalefactor? (nonlinerly?)
-       m_animation.setDuration(800);
+       m_animation.setDuration(ANIME_DURATION);
        m_animation.setCurveShape(QTimeLine::SineCurve);
        
        connect(m_song, SIGNAL(transferStarted()), this, SLOT(play_start()));
@@ -152,15 +154,18 @@
                // If the playhead is _not_ in the viewports range, center it 
in the middle!
                horizontalScrollbar->setValue((int) ((int)scenePos().x() - (0.5 
* vpWidth)) );
        
-       } else if (vppoint.x() > ( vpWidth * 0.82) ) {
+       } else if (vppoint.x() > ( vpWidth * 0.85) ) {
                
                // If the playhead is in the viewports range, and is nearing 
the end
                // either start the animated flip page, or flip the page and 
place the 
                // playhead cursor ~ 1/10 from the left viewport border
                if (m_mode == ANIMATED_FLIP_PAGE) {
                        if (m_animation.state() != QTimeLine::Running) {
-                               m_animation.setFrameRange(0, (int)(vpWidth * 
0.75));
-                               m_animationScrollPosition = 
horizontalScrollbar->value();
+                               m_animFrameRange = (int)(vpWidth * 0.7);
+                               m_totalAnimValue = 0;
+                               m_animation.setFrameRange(0, m_animFrameRange);
+                               calculate_total_anim_frames();
+                               m_animationScrollStartPos = 
horizontalScrollbar->value();
                                //during the animation, we stop the play update 
timer
                                // to avoid unnecessary update/paint events
                                play_stop();
@@ -179,20 +184,26 @@
        // calculate the motion distance of the playhead.
        qreal deltaX = newPos.x() - pos().x();
 
-       // 16 seems to be the division factor with a QTimeLine running for
-       // 1300 ms, and 3/4 of the viewport width. Don't ask me why :-) 
-       // Due the playhead moves as well during the animation, we have to 
-       // compensate for this, by adding it's delta x to the animation 
-       // 'scroll' position
-       //
-       // And with the duration changed to 800, 9 is a good division factor
-       m_animationScrollPosition += (int)(value/9 + deltaX);
+       // calculate the animation x diff.
+       int diff = float(int(0.5 + ((float)(value) / m_totalAnimFrames) * 
m_animFrameRange));
+       m_totalAnimValue += (diff + deltaX);
+       int newXPos = m_animationScrollStartPos + m_totalAnimValue;
        
        if (newPos != pos()) {
                setPos(newPos);
        }
        
-       m_vp->horizontalScrollBar()->setValue(m_animationScrollPosition);
+       m_vp->horizontalScrollBar()->setValue(newXPos);
+}
+
+void PlayHead::calculate_total_anim_frames()
+{
+       int count = (ANIME_DURATION / 40) / 2;
+       m_totalAnimFrames = 0;
+       for (int i=0; i<count; ++i) {
+               m_totalAnimFrames += m_animation.frameForTime(i*40);
+       }
+       m_totalAnimFrames *= 2;
 }
 
 

Index: Cursors.h
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/songcanvas/Cursors.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- Cursors.h   30 May 2007 06:05:06 -0000      1.14
+++ Cursors.h   30 May 2007 18:04:18 -0000      1.15
@@ -61,7 +61,12 @@
         bool           m_follow;
        bool            m_followDisabled;
         PlayHeadMode   m_mode;
-        int            m_animationScrollPosition;
+        int            m_animationScrollStartPos;
+       int             m_animFrameRange;
+       int             m_totalAnimFrames;
+       int             m_totalAnimValue;
+       
+       void calculate_total_anim_frames();
 
 private slots:
        void check_config();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]