public override void Apply(object control, GraphicsHandler graphics) { graphics.Control.SetSourceColor((Cairo.Color)control); graphics.Control.Fill(); }
public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) { // copy to a surface using (var surface = new Cairo.ImageSurface(Cairo.Format.Rgb24, (int)source.Width, (int)source.Height)) { unsafe { var destrow = (byte *)surface.DataPtr; fixed(byte *srcdata = Control) { byte *srcrow = srcdata + ((int)source.Top * rowStride) + (int)source.Left; for (int y = (int)source.Top; y < (int)source.Bottom; y++) { var src = srcrow; var dest = (uint *)destrow; for (int x = (int)source.Left; x < (int)source.Right; x++) { * dest = colors[*src]; src++; dest++; } srcrow += rowStride; destrow += surface.Stride; } } } var context = graphics.Control; context.Save(); context.Rectangle(destination.ToCairo()); double scalex = 1; double scaley = 1; if (Math.Abs(source.Width - destination.Width) > 0.5f || Math.Abs(source.Height - destination.Height) > 0.5f) { scalex = (double)destination.Width / (double)source.Width; scaley = (double)destination.Height / (double)source.Height; context.Scale(scalex, scaley); } context.SetSourceSurface(surface, (int)destination.Left, (int)destination.Top); context.Fill(); context.Restore(); } /* * if (graphics == null || graphics.Control == null || graphics.GC == null) * throw new Exception("WHAA?"); * using (var drawable = new Gdk.Pixmap(graphics.Control, source.Right+1, source.Bottom+1)) * using (var gc = new Gdk.GC(drawable)) * { * if (drawable.Colormap == null) * drawable.Colormap = graphics.Control.Colormap; * drawable.DrawIndexedImage(gc, 0, 0, source.Right+1, source.Bottom+1, Gdk.RgbDither.None, Control, this.rowStride, GetPmap()); * if (source.Width != destination.Width || source.Height != destination.Height) * { * // scale da shit * Gdk.Pixbuf pb = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, source.Width, source.Height); * pb.GetFromDrawable(drawable, drawable.Colormap, source.X, source.Y, 0, 0, source.Width, source.Height); * * Gdk.Pixbuf pbDest = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, destination.Width, destination.Height); * pb.Scale(pbDest, 0, 0, destination.Width, destination.Height, 0, 0, (double)destination.Width / (double)source.Width, * (double)destination.Height / (double)source.Height, Gdk.InterpType.Bilinear); * pb.Dispose(); * * * graphics.Control.DrawPixbuf(graphics.GC, pbDest, 0, 0, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0); * pbDest.Dispose(); * } * else * { * // no scaling necessary! * graphics.Control.DrawDrawable(graphics.GC, drawable, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height); * } * * }*/ }
public abstract void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination);
public abstract void Apply(object control, GraphicsHandler graphics);
public virtual void DrawImage(GraphicsHandler graphics, float x, float y, float width, float height) { DrawImage(graphics, new RectangleF(new Point(0, 0), Size), new RectangleF(x, y, width, height)); }
public virtual void DrawImage(GraphicsHandler graphics, float x, float y) { DrawImage(graphics, x, y, Size.Width, Size.Height); }
public void Apply(Pen widget, GraphicsHandler graphics) { ((PenObject)widget.ControlObject).Apply(graphics); }
public override void Apply(object control, GraphicsHandler graphics) { ((TextureBrushObject)control).Apply(graphics); }
public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination) { var context = graphics.Control; context.Save(); context.Rectangle(destination.ToCairo()); double scalex = 1; double scaley = 1; if (Math.Abs(source.Width - destination.Width) > 0.5f || Math.Abs(source.Height - destination.Height) > 0.5f) { scalex = (double)destination.Width / (double)source.Width; scaley = (double)destination.Height / (double)source.Height; context.Scale(scalex, scaley); } Cairo.SurfacePattern pattern; if (Surface != null) { // we got a surface (by drawing on the bitmap using Graphics), so use that directly. pattern = new Cairo.SurfacePattern(Surface); var m = new Cairo.Matrix(); m.InitTranslate(source.Left - (destination.Left / scalex), source.Top - (destination.Top / scaley)); pattern.Matrix = m; context.SetSource(pattern); } else { Gdk.CairoHelper.SetSourcePixbuf(context, Control, (destination.Left / scalex) - source.Left, (destination.Top / scaley) - source.Top); pattern = (Cairo.SurfacePattern)context.GetSource(); } pattern.Filter = graphics.ImageInterpolation.ToCairo(); context.Fill(); context.Restore(); pattern.Dispose(); /* * Gdk.Pixbuf pb = Control; * * * if (source.Width != destination.Width || source.Height != destination.Height) { * Gdk.Pixbuf pbDest = new Gdk.Pixbuf (Gdk.Colorspace.Rgb, true, 8, destination.Width, destination.Height); * double scalex = (double)(destination.Width) / (double)(source.Width); * double scaley = (double)(destination.Height) / (double)(source.Height); * pb.Scale (pbDest, 0, 0, destination.Width, destination.Height, -(source.X * scalex), -(source.Y * scaley), * scalex, scaley, Gdk.InterpType.Bilinear); * source.Location = new Point (0, 0); * pb = pbDest; * } * /* * * pb.RenderToDrawable (graphics.Control, graphics.GC, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0); * /* * * Gdk.Pixmap pm, mask; * pb.RenderPixmapAndMask(out pm, out mask, 0); * graphics.Drawable.DrawDrawable(graphics.GC, pm, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height); * pm.Dispose(); * mask.Dispose(); * /* * * graphics.Drawable.DrawPixbuf(null, pb, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0); * /* */ /*if (pb != Control) * pb.Dispose ();*/ }