[longomatch] Add support for scaled canvas
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add support for scaled canvas
- Date: Mon, 7 Jul 2014 11:28:48 +0000 (UTC)
commit cd31ca09bafc681e602485629793cecd0cca3393
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Tue Jun 17 18:48:56 2014 +0200
Add support for scaled canvas
LongoMatch.Drawing/Canvas.cs | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/LongoMatch.Drawing/Canvas.cs b/LongoMatch.Drawing/Canvas.cs
index 35bb27a..8806822 100644
--- a/LongoMatch.Drawing/Canvas.cs
+++ b/LongoMatch.Drawing/Canvas.cs
@@ -30,6 +30,8 @@ namespace LongoMatch.Drawing
{
protected IDrawingToolkit tk;
protected IWidget widget;
+ protected double scaleX, scaleY;
+ protected Point translation;
public Canvas (IWidget widget)
{
@@ -37,6 +39,9 @@ namespace LongoMatch.Drawing
tk = Config.DrawingToolkit;
Objects = new List<ICanvasObject>();
widget.DrawEvent += HandleDraw;
+ scaleX = 1;
+ scaleY = 1;
+ translation = new Point (0, 0);
}
public List<ICanvasObject> Objects {
@@ -44,14 +49,23 @@ namespace LongoMatch.Drawing
set;
}
+ protected Point ToUserCoords (Point p) {
+ return new Point ((p.X - translation.X) / scaleX,
+ (p.Y - translation.Y) / scaleY);
+
+ }
+
protected virtual void HandleDraw (object context, Area area) {
tk.Context = context;
+ tk.TranslateAndScale (translation, new Point (scaleX, scaleY));
+ tk.Begin ();
for (int i=Objects.Count - 1; i >= 0; i--) {
ICanvasObject o = Objects[i];
if (o.Visible) {
o.Draw (tk, area);
}
}
+ tk.End ();
tk.Context = null;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]