[longomatch] Add a new parameter to scale images



commit 421d8823bdf4c7e3da27c58d7a813f517d2db701
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed May 28 16:49:50 2014 +0200

    Add a new parameter to scale images

 .../Interfaces/Drawing/IDrawingToolkit.cs          |    2 +-
 LongoMatch.Drawing.Cairo/CairoBackend.cs           |   20 +++++++++++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/LongoMatch.Core/Interfaces/Drawing/IDrawingToolkit.cs 
b/LongoMatch.Core/Interfaces/Drawing/IDrawingToolkit.cs
index 8e096c8..bb5124f 100644
--- a/LongoMatch.Core/Interfaces/Drawing/IDrawingToolkit.cs
+++ b/LongoMatch.Core/Interfaces/Drawing/IDrawingToolkit.cs
@@ -45,7 +45,7 @@ namespace LongoMatch.Interfaces
                void DrawCircle (Point center, double radius);
                void DrawEllipse (Point center, double axisX, double axisY);
                void DrawText (Point point, double width, double height, string text);
-               void DrawImage (Point start, double width, double height, Image image); 
+               void DrawImage (Point start, double width, double height, Image image, bool scale); 
        }
 }
 
diff --git a/LongoMatch.Drawing.Cairo/CairoBackend.cs b/LongoMatch.Drawing.Cairo/CairoBackend.cs
index a7f174c..e981bd3 100644
--- a/LongoMatch.Drawing.Cairo/CairoBackend.cs
+++ b/LongoMatch.Drawing.Cairo/CairoBackend.cs
@@ -27,6 +27,8 @@ using LFontSlant = LongoMatch.Common.FontSlant;
 using LFontWeight = LongoMatch.Common.FontWeight;
 using FontSlant = Cairo.FontSlant;
 using FontWeight = Cairo.FontWeight;
+using Image = LongoMatch.Common.Image;
+using Gdk;
 
 namespace LongoMatch.Drawing.Cairo
 {
@@ -239,7 +241,23 @@ namespace LongoMatch.Drawing.Cairo
                        context.ShowText (text);
                }
                
-               public void DrawImage (Point start, double width, double height, Image image) {
+               public void DrawImage (Point start, double width, double height, Image image, bool scale) {
+                       double scaleX, scaleY;
+                       Point offset;
+                       
+                       if (scale) {
+                               image.ScaleFactor ((int) width, (int) height, out scaleX, out scaleY, out 
offset);
+                       } else {
+                               offset = new Point (0, 0);
+                               scaleX = width / image.Width;
+                               scaleY = height / image.Height;
+                       }
+                       context.Save ();
+                       context.Translate (start.X + offset.X, start.Y + offset.Y);
+                       context.Scale (scaleX, scaleY);
+                       CairoHelper.SetSourcePixbuf (context, image.Value, 0, 0);
+                       context.Paint ();
+                       context.Restore ();
                }
 
                public void DrawEllipse (Point center, double axisX, double axisY) {


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