[longomatch] Support seeking from the timeline
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Support seeking from the timeline
- Date: Tue, 28 Oct 2014 09:52:04 +0000 (UTC)
commit d52705507f22b7c43b28a268120034e2702325eb
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Wed Oct 22 20:24:52 2014 +0200
Support seeking from the timeline
LongoMatch.Core/Common/EventsBroker.cs | 8 ++
LongoMatch.Core/Handlers/Multimedia.cs | 1 +
LongoMatch.Drawing/CanvasObjects/NeedleObject.cs | 104 ++++++++++++++++++++++
LongoMatch.Drawing/LongoMatch.Drawing.csproj | 1 +
LongoMatch.Drawing/Makefile.am | 1 +
LongoMatch.Drawing/Widgets/PlaysTimeline.cs | 9 ++
LongoMatch.Drawing/Widgets/Timerule.cs | 90 +++++++++++++------
LongoMatch.Services/Services/PlaylistManager.cs | 13 +++
8 files changed, 197 insertions(+), 30 deletions(-)
---
diff --git a/LongoMatch.Core/Common/EventsBroker.cs b/LongoMatch.Core/Common/EventsBroker.cs
index 14a4f19..412a33f 100644
--- a/LongoMatch.Core/Common/EventsBroker.cs
+++ b/LongoMatch.Core/Common/EventsBroker.cs
@@ -91,6 +91,7 @@ namespace LongoMatch.Core.Common
public event DetachPlayerHandler Detach;
public event PlaybackRateChangedHandler PlaybackRateChanged;
public event SeekEventHandler SeekEvent;
+ public event TogglePlayEventHandler TogglePlayEvent;
public void EmitNewTag (EventType eventType, List<Player> players = null, Team team =
Team.NONE,
List<Tag> tags = null, Time start = null, Time stop = null,
@@ -400,6 +401,13 @@ namespace LongoMatch.Core.Common
}
}
+ public void EmitTogglePlayEvent (bool playing)
+ {
+ if (TogglePlayEvent != null) {
+ TogglePlayEvent (playing);
+ }
+ }
+
public void EmitMigrateDB ()
{
if (MigrateDB != null) {
diff --git a/LongoMatch.Core/Handlers/Multimedia.cs b/LongoMatch.Core/Handlers/Multimedia.cs
index 9cce712..4011f33 100644
--- a/LongoMatch.Core/Handlers/Multimedia.cs
+++ b/LongoMatch.Core/Handlers/Multimedia.cs
@@ -27,6 +27,7 @@ namespace LongoMatch.Core.Handlers
public delegate void SegmentClosedHandler();
public delegate void SegmentDoneHandler();
public delegate void SeekEventHandler(Time pos, bool accurate);
+ public delegate void TogglePlayEventHandler(bool playing);
public delegate void VolumeChangedHandler(double level);
public delegate void NextButtonClickedHandler();
public delegate void PrevButtonClickedHandler();
diff --git a/LongoMatch.Drawing/CanvasObjects/NeedleObject.cs
b/LongoMatch.Drawing/CanvasObjects/NeedleObject.cs
new file mode 100644
index 0000000..5b9b022
--- /dev/null
+++ b/LongoMatch.Drawing/CanvasObjects/NeedleObject.cs
@@ -0,0 +1,104 @@
+//
+// Copyright (C) 2014 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using LongoMatch.Core.Interfaces.Drawing;
+using LongoMatch.Core.Common;
+using LongoMatch.Core.Store.Drawables;
+using System.IO;
+
+namespace LongoMatch.Drawing.CanvasObjects
+{
+ public class NeedleObject: CanvasObject, ICanvasSelectableObject
+ {
+ static ISurface needle;
+
+ public NeedleObject ()
+ {
+ if (needle == null) {
+ string path = Path.Combine (Config.IconsDir,
StyleConf.TimelineNeedleResource);
+ Image img = Image.LoadFromFile (path);
+ needle = Config.DrawingToolkit.CreateSurface (img.Width, img.Height, img,
false);
+ }
+ Size = needle.Width;
+ }
+
+ protected override void Dispose (bool disposing)
+ {
+ base.Dispose (disposing);
+ if (needle != null) {
+ needle.Dispose ();
+ needle = null;
+ }
+ }
+
+ public double X {
+ get;
+ set;
+ }
+
+ public double TimelineHeight {
+ get;
+ set;
+ }
+
+ public double Size {
+ get;
+ set;
+ }
+
+ Point TopLeft {
+ get {
+ return new Point (X - Size / 2, TimelineHeight - needle.Height);
+ }
+ }
+
+ Area Area {
+ get {
+ return new Area (TopLeft, Size, Size);
+ }
+ }
+
+ public override void Draw (IDrawingToolkit tk, LongoMatch.Core.Common.Area area)
+ {
+ if (!UpdateDrawArea (tk, area, Area)) {
+ return;
+ };
+
+ tk.Begin ();
+ tk.DrawSurface (needle, TopLeft);
+ tk.End ();
+ }
+
+ public Selection GetSelection (Point point, double precision, bool inMotion=false)
+ {
+ if ((Math.Abs (point.X - X) < Size / 2 + precision)) {
+ return new Selection (this, SelectionPosition.All, 0);
+ } else {
+ return null;
+ }
+ }
+
+ public void Move (Selection s, Point p, Point start)
+ {
+ if (s.Position == SelectionPosition.All) {
+ X = p.X;
+ }
+ }
+ }
+}
+
diff --git a/LongoMatch.Drawing/LongoMatch.Drawing.csproj b/LongoMatch.Drawing/LongoMatch.Drawing.csproj
index 53c9520..83658d0 100644
--- a/LongoMatch.Drawing/LongoMatch.Drawing.csproj
+++ b/LongoMatch.Drawing/LongoMatch.Drawing.csproj
@@ -67,6 +67,7 @@
<Compile Include="CanvasObjects\ButtonObject.cs" />
<Compile Include="CanvasObjects\LabelObject.cs" />
<Compile Include="Widgets\TimelineLabels.cs" />
+ <Compile Include="CanvasObjects\NeedleObject.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
diff --git a/LongoMatch.Drawing/Makefile.am b/LongoMatch.Drawing/Makefile.am
index d20b93f..21ca964 100644
--- a/LongoMatch.Drawing/Makefile.am
+++ b/LongoMatch.Drawing/Makefile.am
@@ -16,6 +16,7 @@ SOURCES = Canvas.cs \
CanvasObjects/FieldObject.cs \
CanvasObjects/LabelObject.cs \
CanvasObjects/LineObject.cs \
+ CanvasObjects/NeedleObject.cs \
CanvasObjects/PlayObject.cs \
CanvasObjects/PlayerObject.cs \
CanvasObjects/PlayersTaggerObject.cs \
diff --git a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
index 7fdba2f..f9daee5 100644
--- a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
@@ -39,6 +39,7 @@ namespace LongoMatch.Drawing.Widgets
double secondsPerPixel;
Time duration;
TimelineEvent loadedEvent;
+ bool movingTimeNode;
Dictionary<TimelineObject, object> timelineToFilter;
Dictionary<EventType, CategoryTimeline> eventsTimelines;
@@ -273,11 +274,19 @@ namespace LongoMatch.Drawing.Widgets
if (sel.Position != SelectionPosition.All) {
widget.SetCursor (CursorType.DoubleArrow);
}
+ if (sel.Drawable is TimeNodeObject) {
+ movingTimeNode = true;
+ Config.EventsBroker.EmitTogglePlayEvent (false);
+ }
}
protected override void StopMove (bool moved)
{
widget.SetCursor (CursorType.Arrow);
+ if (movingTimeNode) {
+ Config.EventsBroker.EmitTogglePlayEvent (true);
+ movingTimeNode = false;
+ }
}
protected override void ShowMenu (Point coords)
diff --git a/LongoMatch.Drawing/Widgets/Timerule.cs b/LongoMatch.Drawing/Widgets/Timerule.cs
index 59f0944..a6b891c 100644
--- a/LongoMatch.Drawing/Widgets/Timerule.cs
+++ b/LongoMatch.Drawing/Widgets/Timerule.cs
@@ -21,35 +21,39 @@ using LongoMatch.Core.Common;
using LongoMatch.Core.Interfaces.Drawing;
using LongoMatch.Core.Interfaces;
using System.IO;
+using LongoMatch.Drawing.CanvasObjects;
+using LongoMatch.Core.Store.Drawables;
namespace LongoMatch.Drawing.Widgets
{
- public class Timerule:Canvas
+ public class Timerule: SelectionCanvas
{
const int BIG_LINE_HEIGHT = 15;
const int SMALL_LINE_HEIGHT = 5;
const int TEXT_WIDTH = 20;
const int TIME_SPACING = 100;
- ISurface needle;
+ bool moving;
+ NeedleObject needle;
+ double scroll;
+ double secondsPerPixel;
+ Time currentTime;
public Timerule (IWidget widget):base (widget)
{
+ needle = new NeedleObject();
+ AddObject (needle);
SecondsPerPixel = 0.1;
CurrentTime = new Time (0);
}
- protected override void Dispose (bool disposing)
- {
- base.Dispose (disposing);
- if (needle != null) {
- needle.Dispose ();
- needle = null;
- }
- }
-
public double Scroll {
- set;
- protected get;
+ set {
+ scroll = value;
+ needle.ResetDrawArea ();
+ }
+ protected get {
+ return scroll;
+ }
}
public Time Duration {
@@ -58,13 +62,42 @@ namespace LongoMatch.Drawing.Widgets
}
public Time CurrentTime {
- get;
- set;
+ get {
+ return currentTime;
+ }
+ set {
+ currentTime = value;
+ needle.ResetDrawArea ();
+ }
}
public double SecondsPerPixel {
- set;
- get;
+ set {
+ secondsPerPixel = value;
+ needle.ResetDrawArea ();
+ }
+ get {
+ return secondsPerPixel;
+ }
+ }
+
+ protected override void StartMove (Selection sel)
+ {
+ moving = true;
+ Config.EventsBroker.EmitTogglePlayEvent (false);
+ }
+
+ protected override void StopMove (bool moved)
+ {
+ moving = false;
+ Config.EventsBroker.EmitTogglePlayEvent (true);
+ }
+
+ protected override void SelectionMoved (Selection sel)
+ {
+ Config.EventsBroker.EmitSeekEvent (Utils.PosToTime (new Point (needle.X, 0),
+ SecondsPerPixel), false);
+ Console.WriteLine ("Moved to " +
needle.X);
}
public override void Draw (IContext context, Area area)
@@ -76,12 +109,6 @@ namespace LongoMatch.Drawing.Widgets
return;
}
- if (needle == null) {
- string path = Path.Combine (Config.IconsDir,
StyleConf.TimelineNeedleResource);
- Image img = Image.LoadFromFile (path);
- needle = tk.CreateSurface (img.Width, img.Height, img);
- }
-
height = widget.Height;
width = widget.Width;
@@ -97,9 +124,9 @@ namespace LongoMatch.Drawing.Widgets
tk.DrawLine (new Point (area.Start.X, height),
new Point (area.Start.X + area.Width, height));
- startX = (int) (area.Start.X + Scroll);
+ startX = (int)(area.Start.X + Scroll);
start = (startX - (startX % TIME_SPACING)) + TIME_SPACING;
- stop = (int) (startX + area.Width);
+ stop = (int)(startX + area.Width);
/* Draw big lines each 10 * secondsPerPixel */
for (int i=start; i <= stop; i += TIME_SPACING) {
@@ -110,7 +137,7 @@ namespace LongoMatch.Drawing.Widgets
new Time { Seconds = (int) (i * SecondsPerPixel)
}.ToSecondsString ());
}
- start = (startX - (startX % (TIME_SPACING / 10))) + (TIME_SPACING/10);
+ start = (startX - (startX % (TIME_SPACING / 10))) + (TIME_SPACING / 10);
/* Draw small lines each 1 * secondsPerPixel */
for (int i=start; i<= stop; i+= TIME_SPACING / 10) {
double pos;
@@ -124,10 +151,13 @@ namespace LongoMatch.Drawing.Widgets
}
/* Draw position triangle */
- tpos = Utils.TimeToPos (CurrentTime, SecondsPerPixel);
- tpos -= Scroll;
- tpos -= needle.Width / 2;
- tk.DrawSurface (needle, new Point (tpos, widget.Height - needle.Height));
+ needle.TimelineHeight = height;
+ if (!moving) {
+ tpos = Utils.TimeToPos (CurrentTime, SecondsPerPixel);
+ tpos -= Scroll;
+ needle.X = tpos;
+ }
+ needle.Draw (tk, area);
tk.End ();
tk.Context = null;
}
diff --git a/LongoMatch.Services/Services/PlaylistManager.cs b/LongoMatch.Services/Services/PlaylistManager.cs
index 1547000..96ec498 100644
--- a/LongoMatch.Services/Services/PlaylistManager.cs
+++ b/LongoMatch.Services/Services/PlaylistManager.cs
@@ -58,6 +58,7 @@ namespace LongoMatch.Services
Config.EventsBroker.PlaybackRateChanged += HandlePlaybackRateChanged;
Config.EventsBroker.TimeNodeChanged += HandlePlayChanged;
Config.EventsBroker.SeekEvent += HandleSeekEvent;
+ Config.EventsBroker.TogglePlayEvent += HandleTogglePlayEvent;
}
void LoadPlay (TimelineEvent play, Time seekTime, bool playing)
@@ -210,5 +211,17 @@ namespace LongoMatch.Services
player.Seek (pos, accurate);
}
}
+
+ void HandleTogglePlayEvent (bool playing)
+ {
+ if (player != null) {
+ if (playing) {
+ player.Play ();
+ } else {
+ player.Pause ();
+ }
+ }
+ }
+
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]