Ejemplo n.º 1
0
        public Image Copy(ICanvas canvas, Area area)
        {
            Image  img;
            Pixmap pm;

            global::Cairo.Context ctx;

            var            w      = canvas.Widget;
            NoWindowWidget widget = new NoWindowWidget {
                Width = area.Width, Height = area.Height
            };

            canvas.SetWidget(widget);

            pm  = new Pixmap(null, (int)area.Width, (int)area.Height, 24);
            ctx = Gdk.CairoHelper.Create(pm);
            using (CairoContext c = new CairoContext(ctx)) {
                ctx.Translate(-area.Start.X, -area.Start.Y);
                canvas.Draw(c, null);
            }

            img = new Image(Pixbuf.FromDrawable(pm, Colormap.System, 0, 0, 0, 0,
                                                (int)area.Width, (int)area.Height));

            canvas.SetWidget(w);
            return(img);
        }
Ejemplo n.º 2
0
 public Surface(int width, int height, Image image, bool warnOnDispose = true, bool useDeviceScaleFactor = true)
 {
     DeviceScaleFactor  = 1;
     this.warnOnDispose = warnOnDispose;
     if (useDeviceScaleFactor)
     {
         if (image != null)
         {
             DeviceScaleFactor = image.DeviceScaleFactor;
         }
         else
         {
             DeviceScaleFactor = App.Current.GUIToolkit.DeviceScaleFactor;
         }
     }
     surface = new ImageSurface(Format.ARGB32, (int)(width * DeviceScaleFactor), (int)(height * DeviceScaleFactor));
     if (image != null)
     {
         using (CairoContext ccontext = new CairoContext(surface)) {
             var oldContext = App.Current.DrawingToolkit.Context;
             App.Current.DrawingToolkit.Context = ccontext;
             // The image must be drawn using it's real size, since the backend ImageSurface's size is also scalled
             App.Current.DrawingToolkit.DrawImage(new Core.Common.Point(0, 0), image.Width * DeviceScaleFactor,
                                                  image.Height * DeviceScaleFactor, image, ScaleMode.AspectFit);
             App.Current.DrawingToolkit.Context = oldContext;
         }
     }
 }
Ejemplo n.º 3
0
        protected void Draw(Area area)
        {
            if (DrawEvent != null)
            {
                using (CairoContext c = new CairoContext(widget.GdkWindow)) {
                    global::Cairo.Context cc = c.Value as global::Cairo.Context;
                    if (area == null)
                    {
                        Rectangle r = widget.GdkWindow.ClipRegion.Clipbox;
                        area = new Area(new Point(r.X, r.Y), r.Width, r.Height);
                    }

                    cc.Rectangle(area.Start.X, area.Start.Y, area.Width, area.Height);
                    cc.Clip();

                    if (widget.WidgetFlags.HasFlag(WidgetFlags.NoWindow))
                    {
                        Rectangle widgetArea = WidgetArea;
                        cc.Translate(widgetArea.X, widgetArea.Y);
                        area.Start.X -= widgetArea.X;
                        area.Start.Y -= widgetArea.Y;
                    }

                    DrawEvent(c, area);
                }
            }
        }