2007-01-05 Alp Toker <alp@atoker.com>
[mono.git] / mcs / class / Mono.Cairo / Mono.Cairo / Surface.cs
index 4fb2db8a60af9e2e143acbade689799a0737a1dc..527ffe621414ebc3ada331cf46ee694656f082c5 100644 (file)
@@ -1,5 +1,5 @@
 //
-// Mono.Cairo.CairoSurfaceObject.cs
+// Mono.Cairo.Surface.cs
 //
 // Authors:
 //    Duncan Mak
 //
 
 using System;
-using System.Drawing;
-using System.Runtime.InteropServices;
 using System.Collections;
-using Cairo;
 
 namespace Cairo {
 
        public class Surface : IDisposable 
-        {
-               static Hashtable surfaces = new Hashtable ();
+        {                                              
+               protected static Hashtable surfaces = new Hashtable ();
                 internal IntPtr surface = IntPtr.Zero;
 
-                private Surface (IntPtr ptr, bool owns)
+               protected Surface()
+               {
+               }
+               
+                protected Surface (IntPtr ptr, bool owns)
                 {
                         surface = ptr;
                        lock (surfaces.SyncRoot){
@@ -64,17 +65,48 @@ namespace Cairo {
                                }
                                return (Surface) o;
                        }
+               }               
+
+               static internal Surface LookupSurface (IntPtr surface)
+               {
+                               SurfaceType st = CairoAPI.cairo_surface_get_type (surface);
+                               switch (st) {
+                                       case SurfaceType.Image:
+                                               return new ImageSurface (surface, true);
+                                       case SurfaceType.XLib:
+                                               return new XlibSurface (surface, true);
+                                       case SurfaceType.Xcb:
+                                               return new XcbSurface (surface, true);
+                                       case SurfaceType.Glitz:
+                                               return new GlitzSurface (surface, true);
+                                       case SurfaceType.Win32:
+                                               return new Win32Surface (surface, true);
+#if CAIRO_1_2
+                                       case SurfaceType.Pdf:
+                                               return new PdfSurface (surface, true);
+                                       case SurfaceType.PS:
+                                               return new PSSurface (surface, true);
+                                       case SurfaceType.DirectFB:
+                                               return new DirectFBSurface (surface, true);
+                                       case SurfaceType.Svg:
+                                               return new SvgSurface (surface, true);
+#endif
+                                       default:
+                                               return Surface.LookupExternalSurface (surface);
+                               }
                }
 
+               [Obsolete ("Use an ImageSurface constructor instead.")]
                 public static Cairo.Surface CreateForImage (
-                        string data, Cairo.Format format, int width, int height, int stride)
+                        ref byte[] data, Cairo.Format format, int width, int height, int stride)
                 {
-                        IntPtr p = CairoAPI.cairo_surface_create_for_image (
+                        IntPtr p = CairoAPI.cairo_image_surface_create_for_data (
                                 data, format, width, height, stride);
                         
                         return new Cairo.Surface (p, true);
                 }
 
+               [Obsolete ("Use an ImageSurface constructor instead.")]
                 public static Cairo.Surface CreateForImage (
                         Cairo.Format format, int width, int height)
                 {
@@ -85,21 +117,11 @@ namespace Cairo {
                 }
 
 
-                public static Cairo.Surface CreateSimilar (
-                        Cairo.Surface surface, Cairo.Format format, int width, int height)
+                public Cairo.Surface CreateSimilar (
+                        Cairo.Content content, int width, int height)
                 {
                         IntPtr p = CairoAPI.cairo_surface_create_similar (
-                                surface.Handle, format, width, height);
-
-                        return new Cairo.Surface (p, true);
-                }
-
-                public static Cairo.Surface CreateSimilarSolid (
-                        Cairo.Surface surface, Cairo.Format format,
-                        int width, int height, double red, double green, double blue, double alpha)
-                {
-                        IntPtr p = CairoAPI.cairo_surface_create_similar_solid (
-                                surface.Handle, format, width, height, red, green, blue, alpha);
+                                this.Handle, content, width, height);
 
                         return new Cairo.Surface (p, true);
                 }
@@ -109,9 +131,10 @@ namespace Cairo {
                        Dispose (false);
                }
 
-               public void Show (Graphics gr, int width, int height
+               public void Show (Context gr, double x, double y
                {
-                       CairoAPI.cairo_show_surface (gr.Handle, surface, width,  height);
+                       CairoAPI.cairo_set_source_surface (gr.Handle, surface, x, y);
+                       CairoAPI.cairo_paint (gr.Handle);
                }
 
                void IDisposable.Dispose ()
@@ -124,46 +147,90 @@ namespace Cairo {
                {
                        if (surface == (IntPtr) 0)
                                return;
-                       lock (surfaces.SyncRoot){
+                       
+                       lock (surfaces.SyncRoot)
                                surfaces.Remove (surface);
-                       }
+
                        CairoAPI.cairo_surface_destroy (surface);
                        surface = (IntPtr) 0;
                }
                
+               public Status Finish ()
+               {
+                       CairoAPI.cairo_surface_finish (surface);
+                       return Status;
+               }
+               
+               public void Flush ()
+               {
+                       CairoAPI.cairo_surface_flush (surface);
+               }
+               
+               public void MarkDirty ()
+               {
+                       CairoAPI.cairo_surface_mark_dirty (Handle);
+               }
+               
+               public void MarkDirty (Rectangle rectangle)
+               {
+                       CairoAPI.cairo_surface_mark_dirty_rectangle (Handle, (int)rectangle.X, (int)rectangle.Y, (int)rectangle.Width, (int)rectangle.Height);
+               }
+               
                 public IntPtr Handle {
-                        get { return surface; }
-                }
-
-                public int Repeat {
-                        set {
-                                CairoAPI.cairo_surface_set_repeat (surface, value);
-                        } 
-                }
-
-                public Cairo.Matrix Matrix {
-                        set {
-                                CairoAPI.cairo_surface_set_matrix (surface, value.Pointer);
-                        }
-
                         get {
-                                IntPtr p = IntPtr.Zero;
-                                CairoAPI.cairo_surface_get_matrix (surface, out p);
-                                return new Cairo.Matrix (p);
-                        }
+                               return surface;
+                       }
                 }
 
-                public Cairo.Filter Filter {
-                        set {
-                                CairoAPI.cairo_surface_set_filter (surface, value);
-                        }
-                }
+               public PointD DeviceOffset {
+#if CAIRO_1_2
+                       get {
+                               double x, y;
+                               CairoAPI.cairo_surface_get_device_offset (surface, out x, out y);
+                               return new PointD (x, y);
+                       }
+#endif
+                       set {
+                               CairoAPI.cairo_surface_set_device_offset (surface, value.X, value.Y);
+                       }
+               }
+               
+               public void Destroy()
+               {
+                       Dispose (true);
+               }
 
+#if CAIRO_1_2
+               public void SetFallbackResolution (double x, double y)
+               {
+                       CairoAPI.cairo_surface_set_fallback_resolution (surface, x, y);
+               }
+#endif
+
+               public void WriteToPng (string filename)
+               {
+                       CairoAPI.cairo_surface_write_to_png (surface, filename);
+               }
+               
+               [Obsolete ("Use Handle instead.")]
                 public IntPtr Pointer {
-                        get { return surface; }
+                        get {
+                               return surface;
+                       }
                 }
+               
+               public Status Status {
+                       get { return CairoAPI.cairo_surface_status (surface); }
+               }
 
+#if CAIRO_1_2
+               public Content Content {
+                       get { return CairoAPI.cairo_surface_get_content (surface); }
+               }
 
-
+               public SurfaceType SurfaceType {
+                       get { return CairoAPI.cairo_surface_get_type (surface); }
+               }
+#endif
         }
 }