コード例 #1
0
ファイル: ImageBuilderBackend.cs プロジェクト: m13253/xwt
		public override object CreateContext (object backend)
		{
			Cairo.Surface sf = (Cairo.Surface) backend;
			CairoContextBackend ctx = new CairoContextBackend (1);
			ctx.Context = new Cairo.Context (sf);
			return ctx;
		}
コード例 #2
0
        public override void DrawTextLayout(object backend, TextLayout layout, double x, double y)
        {
            var be = (GtkTextLayoutBackendHandler.PangoBackend)Toolkit.GetBackend(layout);
            var pl = be.Layout;
            CairoContextBackend ctx = (CairoContextBackend)backend;

            ctx.Context.MoveTo(x, y);
            if (layout.Height <= 0)
            {
                Pango.CairoHelper.ShowLayout(ctx.Context, pl);
            }
            else
            {
                var    lc       = pl.LineCount;
                var    scale    = Pango.Scale.PangoScale;
                double h        = 0;
                var    fe       = ctx.Context.FontExtents;
                var    baseline = fe.Ascent / (fe.Ascent + fe.Descent);
                for (int i = 0; i < lc; i++)
                {
                    var line = pl.Lines [i];
                    var ext  = new Pango.Rectangle();
                    var extl = new Pango.Rectangle();
                    line.GetExtents(ref ext, ref extl);
                    h += h == 0 ? (extl.Height / scale * baseline) : (extl.Height / scale);
                    if (h > layout.Height)
                    {
                        break;
                    }
                    ctx.Context.MoveTo(x, y + h);
                    Pango.CairoHelper.ShowLayoutLine(ctx.Context, line);
                }
            }
        }
コード例 #3
0
        public void DrawImage(object backend, object img, Rectangle srcRect, Rectangle destRect, double alpha)
        {
            CairoContextBackend ctx = (CairoContextBackend)backend;

            ctx.Context.Save();
            ctx.Context.NewPath();
            ctx.Context.Rectangle(destRect.X, destRect.Y, destRect.Width, destRect.Height);
            ctx.Context.Clip();
            ctx.Context.Translate(destRect.X - srcRect.X, destRect.Y - srcRect.Y);
            double sx = destRect.Width / srcRect.Width;
            double sy = destRect.Height / srcRect.Height;

            ctx.Context.Scale(sx, sy);
            SetSourceImage(ctx.Context, img, 0, 0);
            alpha = alpha * ctx.GlobalAlpha;
            if (alpha == 1)
            {
                ctx.Context.Paint();
            }
            else
            {
                ctx.Context.PaintWithAlpha(alpha);
            }
            ctx.Context.Restore();
        }
コード例 #4
0
        public override void ModifyCTM(object backend, Matrix m)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            Cairo.Matrix t = new Cairo.Matrix(m.M11, m.M12, m.M21, m.M22, m.OffsetX, m.OffsetY);
            gc.Context.Transform(t);
        }
コード例 #5
0
        public object Create(Context context)
        {
            CairoContextBackend c = (CairoContextBackend)WidgetRegistry.GetBackend(context);
            LayoutBackend       b = new LayoutBackend();

            b.Context = c;
            return(b);
        }
コード例 #6
0
        public object Create(ICanvasBackend canvas)
        {
            LayoutBackend       b  = new LayoutBackend();
            CairoContextBackend ba = new CairoContextBackend();

            ba.Context = SharedContext;
            b.Context  = ba;
            return(b);
        }
コード例 #7
0
        public override void DrawImage(object backend, ImageDescription img, double x, double y)
        {
            CairoContextBackend ctx = (CairoContextBackend)backend;

            img.Alpha *= ctx.GlobalAlpha;
            var pix = (Xwt.GtkBackend.GtkImage)img.Backend;

            pix.Draw(ApplicationContext, ctx.Context, ctx.ScaleFactor, x, y, img);
        }
コード例 #8
0
ファイル: CustomCellRenderer.cs プロジェクト: jfreax/xwt
 protected override void Render(Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags)
 {
     Parent.StartDrawing (new Rectangle (background_area.X, background_area.Y, background_area.Width, background_area.Height), new Rectangle (cell_area.X, cell_area.Y, cell_area.Width, cell_area.Height), flags);
     CellView.ApplicationContext.InvokeUserCode (delegate {
         CairoContextBackend ctx = new CairoContextBackend (Util.GetScaleFactor (widget));
         ctx.Context = Gdk.CairoHelper.Create (window);
         using (ctx) {
             CellView.Draw (ctx, new Rectangle (cell_area.X, cell_area.Y, cell_area.Width, cell_area.Height));
         }
     });
     Parent.EndDrawing ();
 }
コード例 #9
0
        public void DrawImage(object backend, object img, double x, double y, double alpha)
        {
            CairoContextBackend ctx = (CairoContextBackend)backend;

            SetSourceImage(ctx.Context, img, x, y);
            alpha = alpha * ctx.GlobalAlpha;
            if (alpha == 1)
            {
                ctx.Context.Paint();
            }
            else
            {
                ctx.Context.PaintWithAlpha(alpha);
            }
        }
コード例 #10
0
        public override void DrawImage(object backend, ImageDescription img, Rectangle srcRect, Rectangle destRect)
        {
            CairoContextBackend ctx = (CairoContextBackend)backend;

            ctx.Context.Save();
            ctx.Context.NewPath();
            ctx.Context.Rectangle(destRect.X, destRect.Y, destRect.Width, destRect.Height);
            ctx.Context.Clip();
            double sx = destRect.Width / srcRect.Width;
            double sy = destRect.Height / srcRect.Height;

            ctx.Context.Translate(destRect.X - srcRect.X * sx, destRect.Y - srcRect.Y * sy);
            ctx.Context.Scale(sx, sy);
            img.Alpha *= ctx.GlobalAlpha;

            var pix = (Xwt.GtkBackend.GtkImage)img.Backend;

            pix.Draw(ApplicationContext, ctx.Context, ctx.ScaleFactor, 0, 0, img);
            ctx.Context.Restore();
        }
コード例 #11
0
        public void DrawImage(object backend, object img, double x, double y, double width, double height, double alpha)
        {
            CairoContextBackend ctx = (CairoContextBackend)backend;

            ctx.Context.Save();
            var    s  = GetImageSize(img);
            double sx = ((double)width) / s.Width;
            double sy = ((double)height) / s.Height;

            ctx.Context.Translate(x, y);
            ctx.Context.Scale(sx, sy);
            SetSourceImage(ctx.Context, img, 0, 0);
            alpha = alpha * ctx.GlobalAlpha;
            if (alpha == 1)
            {
                ctx.Context.Paint();
            }
            else
            {
                ctx.Context.PaintWithAlpha(alpha);
            }
            ctx.Context.Restore();
        }
コード例 #12
0
        public override void ArcNegative(object backend, double xc, double yc, double radius, double angle1, double angle2)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Context.ArcNegative(xc, yc, radius, angle1 * degrees, angle2 * degrees);
        }
コード例 #13
0
        public override void SetGlobalAlpha(object backend, double alpha)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.GlobalAlpha = alpha;
        }
コード例 #14
0
        public override void Translate(object backend, double tx, double ty)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Context.Translate(tx, ty);
        }
コード例 #15
0
        public override void Rotate(object backend, double angle)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Context.Rotate((angle * System.Math.PI) / 180);
        }
コード例 #16
0
ファイル: CanvasBackend.cs プロジェクト: StEvUgnIn/xwt
		protected void OnDraw (Rectangle dirtyRect, CairoContextBackend context)
		{
			Backend.ApplicationContext.InvokeUserCode (delegate {
				using (context) {
					var r = new Rectangle (dirtyRect.X - context.Origin.X, dirtyRect.Y - context.Origin.Y, dirtyRect.Width, dirtyRect.Height);
					EventSink.OnDraw (context, r);
				}
			});
		}
コード例 #17
0
        public override void Rectangle(object backend, double x, double y, double width, double height)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Context.Rectangle(x, y, width, height);
        }
コード例 #18
0
ファイル: ImageHandler.cs プロジェクト: StEvUgnIn/xwt
		public void Draw (ApplicationContext actx, Cairo.Context ctx, double scaleFactor, double x, double y, ImageDescription idesc)
		{
			if (stockId != null) {
				ImageFrame frame = null;
				if (frames != null)
					frame = frames.FirstOrDefault (f => f.Width == (int) idesc.Size.Width && f.Height == (int) idesc.Size.Height && f.Scale == scaleFactor);
				if (frame == null) {
					frame = new ImageFrame (ImageHandler.CreateBitmap (stockId, idesc.Size.Width, idesc.Size.Height, scaleFactor), (int)idesc.Size.Width, (int)idesc.Size.Height, false);
					frame.Scale = scaleFactor;
					AddFrame (frame);
				}
				DrawPixbuf (ctx, frame.Pixbuf, x, y, idesc);
			}
			else if (drawCallback != null) {
				CairoContextBackend c = new CairoContextBackend (scaleFactor) {
					Context = ctx
				};
				if (actx != null) {
					actx.InvokeUserCode (delegate {
						drawCallback (c, new Rectangle (x, y, idesc.Size.Width, idesc.Size.Height));
					});
				} else
					drawCallback (c, new Rectangle (x, y, idesc.Size.Width, idesc.Size.Height));
			}
			else {
				DrawPixbuf (ctx, GetBestFrame (actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false), x, y, idesc);
			}
		}
コード例 #19
0
        public void Restore(object backend)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Context.Restore();
        }
コード例 #20
0
        public void Save(object backend)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Context.Save();
        }
コード例 #21
0
        public void ResetTransform(object backend)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Context.IdentityMatrix();
        }
コード例 #22
0
ファイル: CanvasBackend.cs プロジェクト: nirenyang/xwt
 public CairoContextBackend CreateContext()
 {
     CairoContextBackend ctx = new CairoContextBackend (Util.GetScaleFactor (this));
     if (!IsRealized) {
         Cairo.Surface sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1);
         Cairo.Context c = new Cairo.Context (sf);
         ctx.Context = c;
         ctx.TempSurface = sf;
     } else {
         ctx.Context = Gdk.CairoHelper.Create (GdkWindow);
     }
     if (!VisibleWindow) {
         ctx.Context.Translate (Allocation.X, Allocation.Y);
         // Set ContextBackend Origin
         ctx.Origin.X = Allocation.X;
         ctx.Origin.Y = Allocation.Y;
     }
     return ctx;
 }
コード例 #23
0
        public override void CurveTo(object backend, double x1, double y1, double x2, double y2, double x3, double y3)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Context.CurveTo(x1, y1, x2, y2, x3, y3);
        }
コード例 #24
0
        public override void MoveTo(object backend, double x, double y)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Context.MoveTo(x, y);
        }
コード例 #25
0
        public override void SetStyles(object backend, StyleSet styles)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Styles = styles;
        }
コード例 #26
0
ファイル: ImageHandler.cs プロジェクト: jbeaurain/xwt
 public void Draw(ApplicationContext actx, Cairo.Context ctx, double scaleFactor, double x, double y, ImageDescription idesc)
 {
     if (stockId != null) {
         Gdk.Pixbuf img = null;
         if (frames != null)
             img = frames.FirstOrDefault (p => p.Width == (int) idesc.Size.Width && p.Height == (int) idesc.Size.Height);
         if (img == null) {
             img = ImageHandler.CreateBitmap (stockId, idesc.Size.Width, idesc.Size.Height);
             AddFrame (img);
         }
         DrawPixbuf (ctx, img, x, y, idesc);
     }
     else if (drawCallback != null) {
         CairoContextBackend c = new CairoContextBackend (scaleFactor) {
             Context = ctx
         };
         actx.InvokeUserCode (delegate {
             drawCallback (c, new Rectangle (x, y, idesc.Size.Width, idesc.Size.Height));
         });
     }
     else {
         DrawPixbuf (ctx, GetBestFrame (actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false), x, y, idesc);
     }
 }
コード例 #27
0
 public override object Create(ICanvasBackend canvas)
 {
     LayoutBackend b = new LayoutBackend ();
     CairoContextBackend ba = new CairoContextBackend ();
     ba.Context = SharedContext;
     b.Context = ba;
     return b;
 }
コード例 #28
0
        public override double GetScaleFactor(object backend)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            return(gc.ScaleFactor);
        }
コード例 #29
0
        public override void Save(object backend)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Save();
        }
コード例 #30
0
        public override void Scale(object backend, double scaleX, double scaleY)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Context.Scale(scaleX, scaleY);
        }
コード例 #31
0
        public override void Restore(object backend)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Restore();
        }
コード例 #32
0
ファイル: CanvasBackend.cs プロジェクト: dellis1972/xwt
 public CairoContextBackend CreateContext()
 {
     CairoContextBackend ctx = new CairoContextBackend ();
     if (!IsRealized) {
         Cairo.Surface sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1);
         Cairo.Context c = new Cairo.Context (sf);
         ctx.Context = c;
         ctx.TempSurface = sf;
     } else {
         ctx.Context = Gdk.CairoHelper.Create (GdkWindow);
     }
     return ctx;
 }
コード例 #33
0
        public void LineTo(object backend, double x, double y)
        {
            CairoContextBackend gc = (CairoContextBackend)backend;

            gc.Context.LineTo(x, y);
        }