[chronojump] MovingBar after simple jump/run, animates according elapsed time



commit 9b9514b72c882d5d9302b43bc225cf9e29564460
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Apr 30 19:05:24 2021 +0200

    MovingBar after simple jump/run, animates according elapsed time

 src/gui/eventExecute.cs  | 13 +++++++------
 src/gui/usefulObjects.cs | 36 ++++++++++++++++++++++++++++++++++--
 2 files changed, 41 insertions(+), 8 deletions(-)
---
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index f211dd45..85dd4ddc 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -1298,8 +1298,9 @@ public partial class ChronoJumpWindow
                if(isLast && animate) {
                        timerBar = true;
                        movingBar = new MovingBar(x, alto - bottomMargin, barWidth, y, alto - bottomMargin,
-                                       pen_bar_bg, result, layout);
-                       GLib.Timeout.Add(1, new GLib.TimeoutHandler(OnTimerBar));
+                                       pen_bar_bg, result, 250, layout);
+                       movingBar.Start();
+                       GLib.Timeout.Add(10, new GLib.TimeoutHandler(OnTimerBar));
                }
                else {
                        Rectangle rect = new Rectangle(x, y, barWidth, alto-bottomMargin-y-1);
@@ -1317,9 +1318,9 @@ public partial class ChronoJumpWindow
        { 
                if (!timerBar) 
                        return false;
-               
-               movingBar.Next();
-               Rectangle rect = new Rectangle(movingBar.X, movingBar.Y, movingBar.Width, movingBar.Step);
+
+               int yNew = movingBar.NextByDuration();
+               Rectangle rect = new Rectangle(movingBar.X, yNew, movingBar.Width, movingBar.YStart - yNew);
 
                //paint the 0 line
                event_execute_pixmap.DrawLine(pen_black_90,
@@ -1327,7 +1328,7 @@ public partial class ChronoJumpWindow
                                movingBar.X + movingBar.Width, movingBar.AltoTop -1);
 
                event_execute_pixmap.DrawRectangle(movingBar.Pen_bar_bg, true, rect);
-               event_execute_drawingarea.QueueDrawArea(movingBar.X, movingBar.Y, movingBar.Width, 
movingBar.Step);
+               event_execute_drawingarea.QueueDrawArea(movingBar.X, yNew, movingBar.Width, movingBar.YStart 
- yNew);
 
                if(movingBar.Y <= movingBar.YTop)
                {
diff --git a/src/gui/usefulObjects.cs b/src/gui/usefulObjects.cs
index c4bac1d0..4b7a4373 100644
--- a/src/gui/usefulObjects.cs
+++ b/src/gui/usefulObjects.cs
@@ -20,6 +20,7 @@
 
 using System;
 using System.Data;
+using System.Diagnostics; //Stopwatch
 using Gtk;
 using System.Collections; //ArrayList
 using System.Collections.Generic; //List<T>
@@ -435,10 +436,11 @@ public class MovingBar
        public Gdk.GC Pen_bar_bg;
        public double Result;
        public int Step;
+       public int DurationMS; //Step will depend on current time and durationMS (milliseconds)
        public Pango.Layout Layout;
 
        public MovingBar(int x, int y, int width, int yTop, int altoTop, 
-                       Gdk.GC pen_bar_bg, double result, Pango.Layout layout)
+                       Gdk.GC pen_bar_bg, double result, int durationMS, Pango.Layout layout)
        {
                this.X = x;
                this.Y = y;
@@ -447,13 +449,43 @@ public class MovingBar
                this.AltoTop = altoTop;
                this.Pen_bar_bg = pen_bar_bg;
                this.Result = result;
+               this.DurationMS = durationMS;
                this.Layout = layout;
        } 
-       
+
+       /*
        public void Next() {
                Step = Convert.ToInt32(Math.Ceiling((Y-YTop)/100.0));
                Y = Y - Step;
        }
+       */
+
+       Stopwatch sw;
+       public int YStart;
+
+       public void Start()
+       {
+               YStart = Y;
+               sw = new Stopwatch();
+               sw.Start();
+       }
+
+       //creates new Y and also returns it
+       public int NextByDuration()
+       {
+               long elapsedMS = sw.ElapsedMilliseconds;
+               if(elapsedMS >= DurationMS)
+                       Y = YTop;
+               else {
+                       /*
+                       LogB.Information(string.Format("YStart: {0}, YTop: {1}, elapsed: {2}, duration: {3}, 
y will be: {4}",
+                                               YStart, YTop, sw.ElapsedMilliseconds, DurationMS,
+                                               YStart - Convert.ToInt32( UtilAll.DivideSafe(elapsedMS, 
DurationMS) * (YStart - YTop) )));
+                       */
+                       Y = YStart - Convert.ToInt32( UtilAll.DivideSafe(elapsedMS, DurationMS) * (YStart - 
YTop) );
+               }
+               return Y;
+       }
 
        ~MovingBar() {}
 }


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