[longomatch] Use the stored frame drawing ROI



commit b16d93b708c013645bcf1670257cf9808226db3a
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Apr 23 13:40:12 2015 +0200

    Use the stored frame drawing ROI

 LongoMatch.Drawing/Utils.cs              |   13 ++++++++-----
 LongoMatch.Drawing/Widgets/Blackboard.cs |    8 +++++++-
 LongoMatch.GUI/Gui/Dialog/DrawingTool.cs |    5 ++---
 3 files changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/LongoMatch.Drawing/Utils.cs b/LongoMatch.Drawing/Utils.cs
index 37e11ca..4559683 100644
--- a/LongoMatch.Drawing/Utils.cs
+++ b/LongoMatch.Drawing/Utils.cs
@@ -79,14 +79,15 @@ namespace LongoMatch.Drawing
                        return d;
                }
 
-               protected static Image RenderFrameDrawing (IDrawingToolkit tk, int width, int height, 
FrameDrawing fd, Image image)
+               protected static Image RenderFrameDrawing (IDrawingToolkit tk, Area area, FrameDrawing fd, 
Image image)
                {
                        Image img;
                        ISurface surface;
                        
-                       surface = tk.CreateSurface (image.Width, image.Height, image);
+                       surface = tk.CreateSurface ((int)area.Width, (int)area.Height, image);
                        using (IContext c = surface.Context) {
                                tk.Context = c;
+                               tk.TranslateAndScale (new Point (-area.Start.X, -area.Start.Y), new Point (1, 
1));
                                foreach (Drawable d in fd.Drawables) {
                                        ICanvasSelectableObject obj = CanvasFromDrawableObject (d);
                                        obj.Draw (tk, null);
@@ -100,19 +101,21 @@ namespace LongoMatch.Drawing
 
                public static Image RenderFrameDrawing (IDrawingToolkit tk, int width, int height, 
FrameDrawing fd)
                {
-                       return RenderFrameDrawing (tk, width, height, fd, null);
+                       return RenderFrameDrawing (tk, new Area (0, 0, width, height), fd, null);
                }
 
                public static Image RenderFrameDrawingToImage (IDrawingToolkit tk, Image image, FrameDrawing 
fd)
                {
-                       return RenderFrameDrawing (tk, image.Width, image.Height, fd, image);
+                       Area area = fd.RegionOfInterest;
+                       if (area == null || area.Empty)
+                               area = new Area (0, 0, image.Width, image.Height);
+                       return RenderFrameDrawing (tk, area, fd, image);
                }
 
                public static Point ToUserCoords (Point p, Point offset, double scaleX, double scaleY)
                {
                        return new Point ((p.X - offset.X) / scaleX,
                                (p.Y - offset.Y) / scaleY);
-               
                }
        }
 }
diff --git a/LongoMatch.Drawing/Widgets/Blackboard.cs b/LongoMatch.Drawing/Widgets/Blackboard.cs
index 8adb021..68d0f35 100644
--- a/LongoMatch.Drawing/Widgets/Blackboard.cs
+++ b/LongoMatch.Drawing/Widgets/Blackboard.cs
@@ -225,9 +225,15 @@ namespace LongoMatch.Drawing.Widgets
                /// </summary>
                public Image Save ()
                {
+                       Area roi;
+
                        ClearSelection ();
                        drawing.Freehand = backbuffer.Copy ();
-                       return tk.Copy (this, Background.Width, Background.Height);
+                       roi = RegionOfInterest;
+                       if (roi == null || roi.Empty) {
+                               roi = new Area (0, 0, Background.Width, Background.Height);
+                       }
+                       return tk.Copy (this, roi);
                }
 
                /// <summary>
diff --git a/LongoMatch.GUI/Gui/Dialog/DrawingTool.cs b/LongoMatch.GUI/Gui/Dialog/DrawingTool.cs
index 0095c91..6da953e 100644
--- a/LongoMatch.GUI/Gui/Dialog/DrawingTool.cs
+++ b/LongoMatch.GUI/Gui/Dialog/DrawingTool.cs
@@ -158,6 +158,7 @@ namespace LongoMatch.Gui.Dialog
                        blackboard.Background = frame;
                        savetoprojectbutton.Visible = true;
                        blackboard.Drawing = drawing;
+                       blackboard.RegionOfInterest = drawing.RegionOfInterest;
                }
 
                public void LoadFrame (Image frame, Project project)
@@ -431,6 +432,7 @@ namespace LongoMatch.Gui.Dialog
 
                void OnSavetoprojectbuttonClicked (object sender, System.EventArgs e)
                {
+                       drawing.RegionOfInterest = blackboard.RegionOfInterest;
                        if (!play.Drawings.Contains (drawing)) {
                                play.Drawings.Add (drawing);
                        }
@@ -519,9 +521,6 @@ namespace LongoMatch.Gui.Dialog
 
                void HandleRegionOfInterestChanged (object sender, EventArgs e)
                {
-                       if (play != null) {
-                               //play.RegionOfInterest = blackboard.RegionOfInterest;
-                       }
                        if (blackboard.RegionOfInterest.Width == blackboard.Background.Width &&
                            blackboard.RegionOfInterest.Height == blackboard.Background.Height) {
                                hscrollbar.Visible = false;


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