[longomatch] Optimize redraws for more objects
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Optimize redraws for more objects
- Date: Wed, 8 Oct 2014 00:13:13 +0000 (UTC)
commit c1bef66360a66bc872145ba1bdab8a8850319119
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Tue Oct 7 21:15:35 2014 +0200
Optimize redraws for more objects
LongoMatch.Drawing/CanvasObjects/PlayObject.cs | 15 ++++++--
LongoMatch.Drawing/CanvasObjects/PositionObject.cs | 35 +++++++++++++++++---
LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs | 11 +++++-
LongoMatch.Drawing/CanvasObjects/TimelineObject.cs | 15 ++++++++-
4 files changed, 64 insertions(+), 12 deletions(-)
---
diff --git a/LongoMatch.Drawing/CanvasObjects/PlayObject.cs b/LongoMatch.Drawing/CanvasObjects/PlayObject.cs
index f4e8474..8afd910 100644
--- a/LongoMatch.Drawing/CanvasObjects/PlayObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/PlayObject.cs
@@ -52,6 +52,14 @@ namespace LongoMatch.Drawing.CanvasObjects
}
}
+ Area Area {
+ get {
+ double ls = SelectionLeft.Width / 2;
+ return new Area (new Point (StartX - ls, OffsetY),
+ (StopX - StartX) + 2 * ls, Height);
+ }
+ }
+
void DrawLine (IDrawingToolkit tk, double start, double stop, int lineWidth)
{
double y;
@@ -78,8 +86,8 @@ namespace LongoMatch.Drawing.CanvasObjects
tk.StrokeColor = Config.Style.PaletteWidgets;
y1 = OffsetY + 6;
y2 = OffsetY + Height - 6;
- tk.DrawLine (new Point (start, y1), new Point (start, y2));
- tk.DrawLine (new Point (stop, y1), new Point (stop, y2));
+ tk.DrawLine (new Point (start, y1), new Point (start, y2));
+ tk.DrawLine (new Point (stop, y1), new Point (stop, y2));
}
public override void Draw (IDrawingToolkit tk, Area area)
@@ -87,8 +95,7 @@ namespace LongoMatch.Drawing.CanvasObjects
double start, stop;
int lineWidth = StyleConf.TimelineLineSize;
- if (!UpdateDrawArea (tk, area,
- new Area (new Point (StartX, OffsetY), StopX - StartX, Height)))
{
+ if (!UpdateDrawArea (tk, area, Area)) {
return;
};
diff --git a/LongoMatch.Drawing/CanvasObjects/PositionObject.cs
b/LongoMatch.Drawing/CanvasObjects/PositionObject.cs
index c3bf23b..4862e25 100644
--- a/LongoMatch.Drawing/CanvasObjects/PositionObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/PositionObject.cs
@@ -82,6 +82,24 @@ namespace LongoMatch.Drawing.CanvasObjects
}
}
+ Area GetArea (double relSize)
+ {
+ if (Points != null) {
+ if (Points.Count == 1) {
+ return new Area (new Point (Start.X - relSize * 2, Start.Y - relSize
* 2),
+ relSize * 4, relSize * 4);
+ } else {
+ Area a = new Line {Start = Start, Stop = Stop}.Area;
+ a.Start.X -= relSize * 3;
+ a.Start.Y -= relSize * 3;
+ a.Width += relSize * 6;
+ a.Height += relSize * 6;
+ return a;
+ }
+ }
+ return new Area (new Point (0, 0), 0, 0);
+ }
+
public Selection GetSelection (Point point, double precision, bool inMotion=false)
{
if (point.Distance (Start) < precision) {
@@ -110,24 +128,31 @@ namespace LongoMatch.Drawing.CanvasObjects
{
Color color, scolor;
double relSize;
+ Area objectArea;
+
relSize = Math.Max (1, (double)Width / 200);
+ if (!UpdateDrawArea (tk, area, GetArea (relSize))) {
+ return;
+ }
+
tk.Begin ();
if (Play != null) {
color = Play.Color;
} else {
color = Constants.TAGGER_POINT_COLOR;
}
- scolor = color;
if (Selected) {
- scolor = Constants.TAGGER_SELECTION_COLOR;
color = Constants.TAGGER_SELECTION_COLOR;
+ } else if (Highlighted) {
+ color = Config.Style.PaletteActive;
}
- tk.FillColor = color;
- tk.StrokeColor = scolor;
- tk.LineWidth = (int)relSize;
+
+ tk.FillColor = color;
+ tk.StrokeColor = color;
+ tk.LineWidth = 0;
tk.DrawCircle (Start, (int)relSize * 2);
if (Points.Count == 2) {
tk.LineWidth = (int)relSize * 2;
diff --git a/LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs
b/LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs
index 8d565ad..5687bed 100644
--- a/LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/TimeNodeObject.cs
@@ -95,6 +95,14 @@ namespace LongoMatch.Drawing.CanvasObjects
}
}
+ Area Area {
+ get {
+ double ls = StyleConf.TimelineLineSize;
+ return new Area (new Point (StartX - ls, OffsetY),
+ (StopX - StartX) + 2 * ls, Height);
+ }
+ }
+
public Selection GetSelection (Point point, double precision, bool inMotion=false)
{
double accuracy;
@@ -153,8 +161,7 @@ namespace LongoMatch.Drawing.CanvasObjects
{
double linepos;
- if (!UpdateDrawArea (tk, area,
- new Area (new Point (StartX, OffsetY), StopX - StartX, Height)))
{
+ if (!UpdateDrawArea (tk, area, Area)) {
return;
};
diff --git a/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
b/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
index 64f8b2d..bb05b29 100644
--- a/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/TimelineObject.cs
@@ -16,6 +16,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
using System;
+using System.Linq;
using System.Collections.Generic;
using LongoMatch.Core.Store;
using LongoMatch.Core.Common;
@@ -98,11 +99,18 @@ namespace LongoMatch.Drawing.CanvasObjects
public void AddNode (TimeNodeObject o)
{
nodes.Add (o);
+ o.RedrawEvent += HandleRedrawEvent;
}
public void RemoveNode (TimeNode node)
{
- nodes.RemoveAll (po => po.TimeNode == node);
+ TimeNodeObject to;
+
+ to = nodes.FirstOrDefault (n => n.TimeNode == node);
+ if (to != null) {
+ to.RedrawEvent -= HandleRedrawEvent;
+ nodes.Remove (to);
+ }
}
protected virtual bool TimeNodeObjectIsVisible (TimeNodeObject tn)
@@ -119,6 +127,11 @@ namespace LongoMatch.Drawing.CanvasObjects
tk.DrawRectangle (new Point (area.Start.X, OffsetY), area.Width, Height);
}
+ void HandleRedrawEvent (ICanvasObject co, Area area)
+ {
+ EmitRedrawEvent (co as CanvasObject, area);
+ }
+
public override void Draw (IDrawingToolkit tk, Area area)
{
double position;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]