[longomatch] Add support for tooltips in canvas
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add support for tooltips in canvas
- Date: Mon, 7 Jul 2014 11:30:44 +0000 (UTC)
commit fb4612037c25ace5de4577c915f5831b54c2c33e
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Thu Jun 19 22:07:25 2014 +0200
Add support for tooltips in canvas
LongoMatch.Core/Handlers/Drawing.cs | 1 +
.../Interfaces/Drawing/ICanvasObject.cs | 1 +
LongoMatch.Core/Interfaces/Drawing/IWidget.cs | 2 +
LongoMatch.Drawing.Cairo/WidgetWrapper.cs | 39 ++++++++++++++++----
LongoMatch.Drawing/Canvas.cs | 33 +++++++++++++----
.../CanvasObject/BaseCanvasObject.cs | 5 +++
LongoMatch.Drawing/CanvasObject/PlayObject.cs | 6 +++
LongoMatch.Drawing/CanvasObject/PositionObject.cs | 9 +++++
LongoMatch.Drawing/Widgets/PlaysTimeline.cs | 6 +++
9 files changed, 87 insertions(+), 15 deletions(-)
---
diff --git a/LongoMatch.Core/Handlers/Drawing.cs b/LongoMatch.Core/Handlers/Drawing.cs
index 338b589..9cdca40 100644
--- a/LongoMatch.Core/Handlers/Drawing.cs
+++ b/LongoMatch.Core/Handlers/Drawing.cs
@@ -24,6 +24,7 @@ namespace LongoMatch.Handlers.Drawing
public delegate void ButtonPressedHandler (Point coords, uint time, ButtonType type, ButtonModifier
modifier);
public delegate void ButtonReleasedHandler (Point coords, ButtonType type, ButtonModifier modifier);
public delegate void MotionHandler (Point coords);
+ public delegate void ShowTooltipHandler (Point coords);
public delegate void SizeChangedHandler ();
}
diff --git a/LongoMatch.Core/Interfaces/Drawing/ICanvasObject.cs
b/LongoMatch.Core/Interfaces/Drawing/ICanvasObject.cs
index f107c91..e13b55a 100644
--- a/LongoMatch.Core/Interfaces/Drawing/ICanvasObject.cs
+++ b/LongoMatch.Core/Interfaces/Drawing/ICanvasObject.cs
@@ -27,6 +27,7 @@ namespace LongoMatch.Interfaces.Drawing
{
void Draw (IDrawingToolkit tk, Area area);
bool Visible {set; get;}
+ string Description {set; get;}
}
public interface ICanvasSelectableObject: ICanvasObject, IDrawable
diff --git a/LongoMatch.Core/Interfaces/Drawing/IWidget.cs b/LongoMatch.Core/Interfaces/Drawing/IWidget.cs
index 8cd3666..374edb3 100644
--- a/LongoMatch.Core/Interfaces/Drawing/IWidget.cs
+++ b/LongoMatch.Core/Interfaces/Drawing/IWidget.cs
@@ -28,12 +28,14 @@ namespace LongoMatch.Interfaces.Drawing
event ButtonReleasedHandler ButtonReleasedEvent;
event MotionHandler MotionEvent;
event SizeChangedHandler SizeChangedEvent;
+ event ShowTooltipHandler ShowTooltipEvent;
double Width {get;set;}
double Height {get;set;}
void ReDraw (Area area = null);
void ReDraw (IDrawable drawable);
void SetCursor (CursorType type);
+ void ShowTooltip (string text);
}
}
diff --git a/LongoMatch.Drawing.Cairo/WidgetWrapper.cs b/LongoMatch.Drawing.Cairo/WidgetWrapper.cs
index 190a36c..5156e6d 100644
--- a/LongoMatch.Drawing.Cairo/WidgetWrapper.cs
+++ b/LongoMatch.Drawing.Cairo/WidgetWrapper.cs
@@ -36,12 +36,14 @@ namespace LongoMatch.Drawing.Cairo
public event ButtonPressedHandler ButtonPressEvent;
public event ButtonReleasedHandler ButtonReleasedEvent;
public event MotionHandler MotionEvent;
+ public event ShowTooltipHandler ShowTooltipEvent;
public event LongoMatch.Handlers.Drawing.SizeChangedHandler SizeChangedEvent;
DrawingArea widget;
int currentWidth, currentHeight;
+ double lastX, lastY;
bool canMove;
- uint timerID;
+ uint moveTimerID, hoverTimerID;
public WidgetWrapper (DrawingArea widget)
{
@@ -94,6 +96,11 @@ namespace LongoMatch.Drawing.Cairo
ReDraw ();
}
+ public void ShowTooltip (string text) {
+ widget.HasTooltip = true;
+ widget.TooltipText = text;
+ }
+
public void SetCursor (CursorType type) {
GCursorType gtype;
@@ -167,22 +174,40 @@ namespace LongoMatch.Drawing.Cairo
bool ReadyToMove () {
canMove = true;
+ moveTimerID = 0;
+ return false;
+ }
+
+ bool EmitShowTooltip () {
+ if (ShowTooltipEvent != null) {
+ ShowTooltipEvent (new Point (lastX, lastY));
+ }
+ hoverTimerID = 0;
return false;
- timerID = 0;
}
void HandleMotionNotifyEvent (object o, MotionNotifyEventArgs args)
{
+ if (hoverTimerID != 0){
+ GLib.Source.Remove (hoverTimerID);
+ hoverTimerID = 0;
+ }
+ hoverTimerID = GLib.Timeout.Add (100, EmitShowTooltip);
+ widget.HasTooltip = false;
+
+ lastX = args.Event.X;
+ lastY = args.Event.Y;
+
if (MotionEvent != null && canMove) {
- MotionEvent (new Point (args.Event.X, args.Event.Y));
+ MotionEvent (new Point (lastX, lastY));
}
}
void HandleButtonReleaseEvent (object o, ButtonReleaseEventArgs args)
{
- if (timerID != 0) {
- GLib.Source.Remove (timerID);
- timerID = 0;
+ if (moveTimerID != 0) {
+ GLib.Source.Remove (moveTimerID);
+ moveTimerID = 0;
}
if (ButtonReleasedEvent != null) {
@@ -201,7 +226,7 @@ namespace LongoMatch.Drawing.Cairo
* should be ignored. Start moving only when the button has been
* pressed for more than 200ms */
canMove = false;
- timerID = GLib.Timeout.Add (200, ReadyToMove);
+ moveTimerID = GLib.Timeout.Add (200, ReadyToMove);
if (ButtonPressEvent != null) {
ButtonType bt;
ButtonModifier bm;
diff --git a/LongoMatch.Drawing/Canvas.cs b/LongoMatch.Drawing/Canvas.cs
index d14c235..349f984 100644
--- a/LongoMatch.Drawing/Canvas.cs
+++ b/LongoMatch.Drawing/Canvas.cs
@@ -84,6 +84,7 @@ namespace LongoMatch.Drawing
widget.ButtonPressEvent += HandleButtonPressEvent;
widget.ButtonReleasedEvent += HandleButtonReleasedEvent;
widget.MotionEvent += HandleMotionEvent;
+ widget.ShowTooltipEvent += HandleShowTooltipEvent;
}
public double Accuracy {
@@ -145,24 +146,40 @@ namespace LongoMatch.Drawing
}
widget.ReDraw (so);
}
-
- void HandleLeftButton (Point coords, ButtonModifier modif) {
+
+ Selection GetSelection (Point coords)
+ {
Selection sel = null;
- /* Try with the selected item first */
- if (Selections.Count > 0) {
- sel = Selections.LastOrDefault().Drawable.GetSelection (coords, Accuracy);
+ /* Try with the selected item first */if (Selections.Count > 0) {
+ sel = Selections.LastOrDefault ().Drawable.GetSelection (coords, Accuracy);
}
-
if (sel == null) {
- foreach (object o in Objects) {
- ICanvasSelectableObject co = o as ICanvasSelectableObject;
+ foreach (ICanvasSelectableObject co in Objects) {
sel = co.GetSelection (coords, Accuracy);
if (sel != null) {
break;
}
}
}
+ return sel;
+ }
+
+ void HandleShowTooltipEvent (Point coords)
+ {
+ Selection sel = GetSelection (ToUserCoords (coords));
+ if (sel != null) {
+ ICanvasObject co = sel.Drawable as ICanvasObject;
+ if (co.Description != null) {
+ widget.ShowTooltip (co.Description);
+ }
+ }
+ }
+
+ void HandleLeftButton (Point coords, ButtonModifier modif) {
+ Selection sel;
+
+ sel = GetSelection (coords);
if ((SelectionMode == MultiSelectionMode.Multiple) ||
(SelectionMode == MultiSelectionMode.MultipleWithModifier &&
diff --git a/LongoMatch.Drawing/CanvasObject/BaseCanvasObject.cs
b/LongoMatch.Drawing/CanvasObject/BaseCanvasObject.cs
index cb7bfe0..16890fb 100644
--- a/LongoMatch.Drawing/CanvasObject/BaseCanvasObject.cs
+++ b/LongoMatch.Drawing/CanvasObject/BaseCanvasObject.cs
@@ -30,6 +30,11 @@ namespace LongoMatch.Drawing.CanvasObject
Visible = true;
}
+ public virtual string Description {
+ get;
+ set;
+ }
+
public bool Visible {
get;
set;
diff --git a/LongoMatch.Drawing/CanvasObject/PlayObject.cs b/LongoMatch.Drawing/CanvasObject/PlayObject.cs
index c57154c..64ce320 100644
--- a/LongoMatch.Drawing/CanvasObject/PlayObject.cs
+++ b/LongoMatch.Drawing/CanvasObject/PlayObject.cs
@@ -30,6 +30,12 @@ namespace LongoMatch.Drawing.CanvasObject
{
}
+ public override string Description {
+ get {
+ return Play.Name;
+ }
+ }
+
public Play Play {
get {
return TimeNode as Play;
diff --git a/LongoMatch.Drawing/CanvasObject/PositionObject.cs
b/LongoMatch.Drawing/CanvasObject/PositionObject.cs
index a5dfdc7..b16feae 100644
--- a/LongoMatch.Drawing/CanvasObject/PositionObject.cs
+++ b/LongoMatch.Drawing/CanvasObject/PositionObject.cs
@@ -36,6 +36,15 @@ namespace LongoMatch.Drawing.CanvasObject
Height = height;
}
+ public override string Description {
+ get {
+ if (Play != null) {
+ return Play.Name;
+ }
+ return null;
+ }
+ }
+
public int Width {
get;
set;
diff --git a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
index c403501..4fba821 100644
--- a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
@@ -45,6 +45,7 @@ namespace LongoMatch.Drawing.Widgets
secondsPerPixel = 0.1;
Accuracy = Common.TIMELINE_ACCURACY;
SelectionMode = MultiSelectionMode.MultipleWithModifier;
+ widget.ShowTooltipEvent += HandleShowTooltipEvent;
}
public void LoadProject (Project project, PlaysFilter filter) {
@@ -139,6 +140,11 @@ namespace LongoMatch.Drawing.Widgets
widget.ReDraw (categories[po.Play.Category]);
}
+ void HandleShowTooltipEvent (Point coords)
+ {
+
+ }
+
protected override void SelectionChanged (List<Selection> selections) {
if (selections.Count > 0) {
PlayObject po = selections.Last().Drawable as PlayObject;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]