示例#1
0
        private unsafe static void RenderClouds(ImageSurface surface, Gdk.Rectangle rect, int scale, byte seed, double power, ColorBgra colorFrom, ColorBgra colorTo)
        {
            int w = surface.Width;
            int h = surface.Height;

            for (int y = rect.Top; y < rect.Bottom; ++y)
            {
                ColorBgra *ptr = surface.GetPointAddressUnchecked(rect.Left, y);
                int        dy  = 2 * y - h;

                for (int x = rect.Left; x < rect.Right; ++x)
                {
                    int    dx   = 2 * x - w;
                    double val  = 0;
                    double mult = 1;
                    int    div  = scale;

                    for (int i = 0; i < 12 && mult > 0.03 && div > 0; ++i)
                    {
                        double dxr = 65536 + (double)dx / (double)div;
                        double dyr = 65536 + (double)dy / (double)div;

                        int dxd = (int)dxr;
                        int dyd = (int)dyr;

                        dxr -= dxd;
                        dyr -= dyd;

                        double noise = Noise(
                            unchecked ((byte)dxd),
                            unchecked ((byte)dyd),
                            dxr, //(double)dxr / div,
                            dyr, //(double)dyr / div,
                            (byte)(seed ^ i));

                        val  += noise * mult;
                        div  /= 2;
                        mult *= power;
                    }

                    *ptr = ColorBgra.Lerp(colorFrom, colorTo, (val + 1) / 2);
                    ++ptr;
                }
            }
        }
示例#2
0
        protected override int measureRawSize(LayoutingType lt)
        {
            if (lines == null)
            {
                lines = getLines;
            }

            using (ImageSurface img = new ImageSurface(Format.Argb32, 10, 10)) {
                using (Context gr = new Context(img)) {
                    //Cairo.FontFace cf = gr.GetContextFontFace ();

                    gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight);
                    gr.SetFontSize(Font.Size);


                    fe = gr.FontExtents;
                    te = new TextExtents();

                    if (lt == LayoutingType.Height)
                    {
                        int lc = lines.Count;
                        //ensure minimal height = text line height
                        if (lc == 0)
                        {
                            lc = 1;
                        }

                        return((int)Math.Ceiling(fe.Height * lc) + Margin * 2);
                    }

                    foreach (string s in lines)
                    {
                        string l = s.Replace("\t", new String(' ', Interface.TabSize));

                        TextExtents tmp = gr.TextExtents(l);

                        if (tmp.XAdvance > te.XAdvance)
                        {
                            te = tmp;
                        }
                    }
                    return((int)Math.Ceiling(te.XAdvance) + Margin * 2);
                }
            }
        }
示例#3
0
        public void clip_image(Context cr, int width, int height)
        {
            Normalize(cr, width, height);
            cr.Arc(0.5, 0.5, 0.3, 0, 2 * Math.PI);
            cr.Clip();
            cr.NewPath();              // path not consumed by clip()

            ImageSurface image = new ImageSurface("data/romedalen.png");
            int          w     = image.Width;
            int          h     = image.Height;

            cr.Scale(1.0 / w, 1.0 / h);

            cr.SetSourceSurface(image, 0, 0);
            cr.Paint();

            image.Destroy();
        }
示例#4
0
        public static void Image(this Context context, ImageSource source)
        {
            Surface imageSurface;
            bool    dispose = false;

            if (source is not CairoImageSource cairoImage)
            {
                byte[] bitmapData = source.GetBitmapData();

                imageSurface =
                    new ImageSurface(bitmapData,
                                     source.Format,
                                     source.Width,
                                     source.Height,
                                     source.Stride);

                dispose = true;
            }
        public override void RecomposeHandle()
        {
            Bounds.CalcWorldBounds();

            ImageSurface surface = new ImageSurface(Format.Argb32, (int)Bounds.InnerWidth - 1, (int)currentHandleHeight + 1);
            Context      ctx     = genContext(surface);

            RoundRectangle(ctx, 0, 0, Bounds.InnerWidth - 1, currentHandleHeight, 2);
            ctx.SetSourceRGBA(GuiStyle.DialogDefaultBgColor[0], GuiStyle.DialogDefaultBgColor[1], GuiStyle.DialogDefaultBgColor[2], GuiStyle.DialogDefaultBgColor[3]);
            ctx.Fill();

            EmbossRoundRectangleElement(ctx, 0, 0, Bounds.InnerWidth - 1, currentHandleHeight, false, 2, 2);

            generateTexture(surface, ref handleTexture);

            ctx.Dispose();
            surface.Dispose();
        }
示例#6
0
 protected void OnCustomWidgetChanged(Gtk.Widget widget)
 {
     OnCustomWidgetApply(widget);
     using (var surface = new ImageSurface(Format.ARGB32, 360, 254))
     {
         using (var gr = new Context(surface))
         {
             gr.SetSourceColor(new Color(1, 1, 1));
             gr.Rectangle(0, 0, 360, 254);
             gr.Fill();
             using (Gdk.Pixbuf pixbuf = Gdk.Pixbuf.LoadFromResource("flower.png"))
             {
                 DrawImage(gr, pixbuf, 0, 0, 360, 254);
             }
         }
         (widget as CustomPrintWidget).PreviewImage.Pixbuf = CreatePixbuf(surface);
     }
 }
示例#7
0
 public GraphicsController(int width, int height)
 {
     _idTimer        = 0;
     _mouseX         = 0; _mouseY = 0;
     _mousePressed   = false;
     _cursorPressed  = new Cursor(CursorType.Dot);
     _cursorReleased = new Cursor(CursorType.BlankCursor);
     _x      = 0;
     _y      = 0;
     _dx     = 3;
     _dy     = 3;
     _image  = new ImageSurface("camera-hands.png");
     _atlas  = new ImageSurface("Atlas2.png");
     _width  = width;
     _height = height;
     Load();
     FillCommonToBuffer();
 }
示例#8
0
        public void Draw(ImageSurface dst, PixelOp pixelOp)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("PlacedSurface");
            }

            Gdk.Rectangle dstRect = Bounds;
            Gdk.Rectangle dstClip = Gdk.Rectangle.Intersect(dstRect, dst.GetBounds());

            if (dstClip.Width > 0 && dstClip.Height > 0)
            {
                int dtX = dstClip.X - where.X;
                int dtY = dstClip.Y - where.Y;

                pixelOp.Apply(dst, dstClip.Location, what, new Gdk.Point(dtX, dtY), dstClip.Size);
            }
        }
示例#9
0
        private void Save(string filename, bool bSource, bool bDrawings)
        {
            Surface pngSurface = new ImageSurface(Format.ARGB32, sourceWidth, sourceHeight);

            using (Context c = new Context(pngSurface)) {
                if (bSource)
                {
                    c.SetSourceSurface(source, 0, 0);
                    c.Paint();
                }
                if (bDrawings)
                {
                    c.SetSourceSurface(drawings, 0, 0);
                    c.PaintWithAlpha(transparency);
                }
            }
            pngSurface.WriteToPng(filename);
        }
示例#10
0
        public override void ComposeElements(Context ctxStatic, ImageSurface surfaceStatic)
        {
            insideBounds = new ElementBounds().WithFixedPadding(unscaledCellSpacing).WithEmptyParent();
            insideBounds.CalcWorldBounds();
            CalcTotalHeight();
            Bounds.CalcWorldBounds();

            ImageSurface surface = new ImageSurface(Format.Argb32, (int)Bounds.InnerWidth, (int)GuiElement.scaled(unscaledCellHeight));
            Context      ctx     = new Context(surface);

            ctx.SetSourceRGBA(1, 1, 1, 0.5);
            ctx.Paint();

            generateTexture(surface, ref hoverOverlayTexture);

            ctx.Dispose();
            surface.Dispose();
        }
示例#11
0
        private void LoadImage(TrackInfo track)
        {
            ImageSurface image = artwork_manager.LookupScaleSurface(track.ArtworkId, ArtworkSizeRequest);

            if (image == null)
            {
                LoadMissingImage((track.MediaAttributes & TrackMediaAttributes.VideoStream) != 0);
            }
            else
            {
                incoming_image = image;
            }

            if (track == current_track)
            {
                current_image = incoming_image;
            }
        }
示例#12
0
        void ComposeActiveButton()
        {
            ImageSurface surface = new ImageSurface(Format.Argb32, (int)Bounds.InnerWidth + 6, (int)Bounds.InnerHeight + 6);
            Context      ctx     = genContext(surface);

            ctx.SetSourceRGBA(0, 0, 0, 0);
            ctx.Paint();

            ctx.SetSourceRGBA(1, 1, 1, 0.65);
            RoundRectangle(ctx, 3, 3, Bounds.InnerWidth + 3, Bounds.InnerHeight + 3, 1);
            ctx.LineWidth = 3;
            ctx.Stroke();

            generateTexture(surface, ref activeTexture);

            ctx.Dispose();
            surface.Dispose();
        }
示例#13
0
        protected override Gdk.Rectangle OnMouseMove(Context g, Color strokeColor, ImageSurface surface,
                                                     int x, int y, int lastX, int lastY)
        {
            int    dx = x - lastX;
            int    dy = y - lastY;
            double px = Math.Cos(theta) * dx - Math.Sin(theta) * dy;
            double py = Math.Sin(theta) * dx + Math.Cos(theta) * dy;

            g.MoveTo(lastX - px, lastY - py);
            g.LineTo(lastX + px, lastY + py);
            g.LineTo(x + px, y + py);
            g.LineTo(x - px, y - py);
            g.LineTo(lastX - px, lastY - py);

            g.StrokePreserve();

            return(g.FixedStrokeExtents().ToGdkRectangle());
        }
示例#14
0
        void ComposeList()
        {
            ImageSurface surface = new ImageSurface(Format.Argb32, (int)Bounds.OuterWidth, (int)Bounds.OuterHeight);
            Context      ctx     = genContext(surface);

            CalcTotalHeight();
            Bounds.CalcWorldBounds();

            foreach (GuiElement elem in Elements)
            {
                elem.ComposeElements(ctx, surface);
            }

            generateTexture(surface, ref listTexture);

            ctx.Dispose();
            surface.Dispose();
        }
示例#15
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (!is_drawing)
            {
                return;
            }

            double x = Utility.Clamp(point.X, 0, doc.ImageSize.Width - 1);
            double y = Utility.Clamp(point.Y, 0, doc.ImageSize.Height - 1);

            doc.ShowSelection = true;

            ImageSurface surf = doc.SelectionLayer.Surface;

            using (Context g = new Context(surf)) {
                g.Antialias = Antialias.Subpixel;

                if (path != null)
                {
                    g.AppendPath(path);
                    (path as IDisposable).Dispose();
                }
                else
                {
                    g.MoveTo(x, y);
                }

                g.LineTo(x, y);
                lassoPolygon.Add(new IntPoint((long)x, (long)y));

                path = g.CopyPath();

                g.FillRule = FillRule.EvenOdd;
                g.ClosePath();

                doc.Selection.DisposeSelectionPreserve();

                doc.Selection.SelectionPath = g.CopyPath();
            }

            doc.Workspace.Invalidate();
        }
示例#16
0
        public ImageBrushImpl(
            ITileBrush brush,
            IBitmapImpl bitmap,
            Size targetSize)
        {
            var calc = new TileBrushCalculator(brush, new Size(bitmap.PixelWidth, bitmap.PixelHeight), targetSize);

            using (var intermediate = new ImageSurface(Format.ARGB32, (int)calc.IntermediateSize.Width, (int)calc.IntermediateSize.Height))
            {
                using (var context = new RenderTarget(intermediate).CreateDrawingContext(null))
                {
                    var rect = new Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight);

                    context.Clear(Colors.Transparent);
                    context.PushClip(calc.IntermediateClip);
                    context.Transform = calc.IntermediateTransform;
                    context.DrawImage(bitmap, 1, rect, rect);
                    context.PopClip();
                }

                var result = new SurfacePattern(intermediate);

                if ((brush.TileMode & TileMode.FlipXY) != 0)
                {
                    // TODO: Currently always FlipXY as that's all cairo supports natively.
                    // Support separate FlipX and FlipY by drawing flipped images to intermediate
                    // surface.
                    result.Extend = Extend.Reflect;
                }
                else
                {
                    result.Extend = Extend.Repeat;
                }

                if (brush.TileMode != TileMode.None)
                {
                    var matrix = result.Matrix;
                    matrix.InitTranslate(-calc.DestinationRect.X, -calc.DestinationRect.Y);
                    result.Matrix = matrix;
                }

                PlatformBrush = result;
            }
        }
示例#17
0
文件: Label.cs 项目: masums/Crow
        protected override int measureRawSize(LayoutingType lt)
        {
            if (lines == null)
            {
                lines = getLines;
            }
            if (!textMeasureIsUpToDate)
            {
                using (ImageSurface img = new ImageSurface(Format.Argb32, 10, 10)) {
                    using (Context gr = new Context(img)) {
                        //Cairo.FontFace cf = gr.GetContextFontFace ();

                        gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight);
                        gr.SetFontSize(Font.Size);
                        gr.FontOptions = Interface.FontRenderingOptions;
                        gr.Antialias   = Interface.Antialias;

                        fe = gr.FontExtents;
                        te = new TextExtents();

                        cachedTextSize.Height = (int)Math.Ceiling((fe.Ascent + fe.Descent) * Math.Max(1, lines.Count)) + Margin * 2;

                        try {
                            foreach (string s in lines)
                            {
                                string l = s.Replace("\t", new String(' ', Interface.TabSize));

                                TextExtents tmp = gr.TextExtents(l);

                                if (tmp.XAdvance > te.XAdvance)
                                {
                                    te = tmp;
                                }
                            }
                            cachedTextSize.Width  = (int)Math.Ceiling(te.XAdvance) + Margin * 2;
                            textMeasureIsUpToDate = true;
                        } catch {
                            return(-1);
                        }
                    }
                }
            }
            return(lt == LayoutingType.Height ? cachedTextSize.Height : cachedTextSize.Width);
        }
示例#18
0
        protected override void onDraw(Cairo.Context gr)
        {
            base.onDraw(gr);

            if (string.IsNullOrEmpty(cardName))
            {
                return;
            }

            Crow.Rectangle r = ClientRectangle;
            //int zoom = 50;
            string imgPath = cardName + ".full.jpg";

            string[] imgsPath = Directory.GetFiles(Magic.cardImgsBasePath, imgPath, SearchOption.AllDirectories);

            if (imgsPath.Length == 0)
            {
                return;
            }

            System.Drawing.Bitmap bmp = null;
            using (Stream s = new FileStream(imgsPath[0], FileMode.Open)) {
                bmp = new System.Drawing.Bitmap(s);
            }

            if (bmp == null)
            {
                return;
            }

            System.Drawing.Imaging.BitmapData data = bmp.LockBits
                                                         (new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
                                                         System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            int stride = data.Stride;


            using (ImageSurface imgSurf = new ImageSurface(data.Scan0, Format.Argb32,
                                                           bmp.Width, bmp.Height, 4 * bmp.Width)) {
                gr.SetSourceSurface(imgSurf, r.Width / 2 - bmp.Width / 2, r.Height / 2 - bmp.Height / 2);
                gr.Paint();
            }
            bmp.UnlockBits(data);
        }
示例#19
0
        private void fullnessMeterDraw(Context ctx, ImageSurface surface, ElementBounds currentBounds)
        {
            ItemSlot liquidSlot = Inventory[1];

            if (liquidSlot.Empty)
            {
                return;
            }

            BlockEntityBarrel bebarrel      = capi.World.BlockAccessor.GetBlockEntity(BlockEntityPosition) as BlockEntityBarrel;
            float             itemsPerLitre = 1f;
            int capacity = bebarrel.CapacityLitres;

            WaterTightContainableProps props = BlockLiquidContainerBase.GetInContainerProps(liquidSlot.Itemstack);

            if (props != null)
            {
                itemsPerLitre = props.ItemsPerLitre;
                capacity      = Math.Max(capacity, props.MaxStackSize);
            }

            float fullnessRelative = liquidSlot.StackSize / itemsPerLitre / capacity;

            double offY = (1 - fullnessRelative) * currentBounds.InnerHeight;

            ctx.Rectangle(0, offY, currentBounds.InnerWidth, currentBounds.InnerHeight - offY);
            //ctx.SetSourceRGBA(ravg/255.0, gavg / 255.0, bavg / 255.0, aavg / 255.0);
            //ctx.Fill();

            CompositeTexture tex = liquidSlot.Itemstack.Collectible.Attributes?["waterTightContainerProps"]?["texture"]?.AsObject <CompositeTexture>(null, liquidSlot.Itemstack.Collectible.Code.Domain);

            if (tex != null)
            {
                ctx.Save();
                Matrix m = ctx.Matrix;
                m.Scale(GuiElement.scaled(3), GuiElement.scaled(3));
                ctx.Matrix = m;

                AssetLocation loc = tex.Base.Clone().WithPathAppendixOnce(".png");
                GuiElement.fillWithPattern(capi, ctx, loc.Path, true, false);

                ctx.Restore();
            }
        }
示例#20
0
        /// <summary>
        /// Takes a texture and applies some text to it.
        /// </summary>
        /// <param name="text">The text to texture.</param>
        /// <param name="font">The font of the text.</param>
        /// <param name="width">The width of the text.</param>
        /// <param name="height">The height of the text.</param>
        /// <param name="loadedTexture">The texture to be loaded on to.</param>
        /// <param name="background">The background of the text. (default: none/null)</param>
        /// <param name="orientation">The orientation of the text. (default: left)</param>
        public void GenOrUpdateTextTexture(string text, CairoFont font, int width, int height, ref LoadedTexture loadedTexture, TextBackground background = null, EnumTextOrientation orientation = EnumTextOrientation.Left, bool demulAlpha = false)
        {
            if (background == null)
            {
                background = defaultBackground;
            }

            ElementBounds bounds = new ElementBounds().WithFixedSize(width, height);

            ImageSurface surface = new ImageSurface(Format.Argb32, width, height);
            Context      ctx     = new Context(surface);

            GuiElementTextBase elTeBa = new GuiElementTextBase(capi, text, font, bounds);

            ctx.SetSourceRGBA(background.FillColor);
            GuiElement.RoundRectangle(ctx, 0, 0, width, height, background.Radius);

            if (background.BorderWidth > 0)
            {
                ctx.FillPreserve();

                ctx.Operator  = Operator.Atop;
                ctx.LineWidth = background.BorderWidth;
                ctx.SetSourceRGBA(background.BorderColor);
                ctx.Stroke();
                ctx.Operator = Operator.Over;
            }
            else
            {
                ctx.Fill();
            }

            elTeBa.textUtil.AutobreakAndDrawMultilineTextAt(ctx, font, text, background.Padding, background.Padding, width, orientation);

            if (demulAlpha)
            {
                surface.DemulAlpha();
            }

            capi.Gui.LoadOrUpdateCairoTexture(surface, true, ref loadedTexture);

            surface.Dispose();
            ctx.Dispose();
        }
示例#21
0
        /// <summary>
        /// Gets the number of lines of text.
        /// </summary>
        /// <param name="font">The font of the text.</param>
        /// <param name="text">The text itself.</param>
        /// <param name="flowPath">The path for the text.</param>
        /// <param name="lineY">The height of the line</param>
        /// <returns>The number of lines.</returns>
        public int GetQuantityTextLines(CairoFont font, string text, TextFlowPath[] flowPath, double lineY = 0)
        {
            if (text == null || text.Length == 0)
            {
                return(0);
            }

            ImageSurface surface = new ImageSurface(Format.Argb32, 1, 1);
            Context      ctx     = new Context(surface);

            font.SetupContext(ctx);

            int quantityLines = Lineize(ctx, text, flowPath, 0, lineY, font.LineHeightMultiplier).Length;

            ctx.Dispose();
            surface.Dispose();

            return(quantityLines);
        }
示例#22
0
        /// <summary>
        /// Turns the supplied text into line of text constrained by supplied flow path and starting at supplied start coordinates
        /// </summary>
        /// <param name="font">The font of the text.</param>
        /// <param name="fulltext">The text of the lines.</param>
        /// <param name="flowPath">The flow direction of text.</param>
        /// <param name="startOffsetX">The offset start position for X</param>
        /// <param name="startY">The offset start position for Y</param>
        /// <returns>The text broken up into lines.</returns>
        public TextLine[] Lineize(CairoFont font, string fulltext, TextFlowPath[] flowPath, double startOffsetX = 0, double startY = 0)
        {
            if (fulltext == null || fulltext.Length == 0)
            {
                return(new TextLine[0]);
            }

            ImageSurface surface = new ImageSurface(Format.Argb32, 1, 1);
            Context      ctx     = new Context(surface);

            font.SetupContext(ctx);

            TextLine[] textlines = Lineize(ctx, fulltext, flowPath, startOffsetX, startY, font.LineHeightMultiplier);

            ctx.Dispose();
            surface.Dispose();

            return(textlines);
        }
示例#23
0
        private ColorBgra ComputeCellColor(int x, int y, ImageSurface src, int cellSize, Gdk.Rectangle srcBounds)
        {
            Gdk.Rectangle cell = GetCellBox(x, y, cellSize);
            cell.Intersect(srcBounds);

            int left   = cell.Left;
            int right  = cell.GetRight();
            int bottom = cell.GetBottom();
            int top    = cell.Top;

            ColorBgra colorTopLeft     = src.GetColorBgraUnchecked(left, top).ToStraightAlpha();
            ColorBgra colorTopRight    = src.GetColorBgraUnchecked(right, top).ToStraightAlpha();
            ColorBgra colorBottomLeft  = src.GetColorBgraUnchecked(left, bottom).ToStraightAlpha();
            ColorBgra colorBottomRight = src.GetColorBgraUnchecked(right, bottom).ToStraightAlpha();

            ColorBgra c = ColorBgra.BlendColors4W16IP(colorTopLeft, 16384, colorTopRight, 16384, colorBottomLeft, 16384, colorBottomRight, 16384);

            return(c.ToPremultipliedAlpha());
        }
示例#24
0
        internal void ComposeWaterTexture()
        {
            double sliderWidth    = Bounds.InnerWidth - 2 * padding - handleWidth / 2;
            double handlePosition = sliderWidth * (1.0 * currentValue - minValue) / (maxValue - minValue);
            double insetHeight    = Bounds.InnerHeight - 2 * padding;

            ImageSurface surface = new ImageSurface(Format.Argb32, (int)(handlePosition + 5), (int)insetHeight);
            Context      ctx     = genContext(surface);

            SurfacePattern pattern = getPattern(api, waterTextureName);

            RoundRectangle(ctx, 0, 0, surface.Width, surface.Height, 1);
            ctx.SetSource(pattern);
            ctx.Fill();

            generateTexture(surface, ref waterTexture);
            ctx.Dispose();
            surface.Dispose();
        }
示例#25
0
 public SurfaceWrapper(Cairo.Context similar, int width, int height)
 {
     if (Platform.IsMac)
     {
         Surface = new QuartzSurface(Cairo.Format.ARGB32, width, height);
     }
     else if (Platform.IsWindows)
     {
         using (var target = similar.GetTarget()) {
             Surface = target.CreateSimilar(Cairo.Content.ColorAlpha, width, height);
         }
     }
     else
     {
         Surface = new ImageSurface(Cairo.Format.ARGB32, width, height);
     }
     Width  = width;
     Height = height;
 }
示例#26
0
        public override void ProcessResize(Rectangle bounds)
        {
            if (bounds == clientRectangle)
            {
                return;
            }
            lock (UpdateMutex) {
                clientRectangle = bounds;
                surf.Dispose();
                surf = new ImageSurface(Format.Argb32, clientRectangle.Width, clientRectangle.Height);

                foreach (Widget g in GraphicTree)
                {
                    g.RegisterForLayouting(LayoutingType.All);
                }

                RegisterClip(clientRectangle);
            }
        }
示例#27
0
        public override void Redo()
        {
            Matrix swap_transfrom = new Matrix();

            swap_transfrom.InitMatrix(PintaCore.Layers.SelectionLayer.Transform);
            ImageSurface swap_surf = PintaCore.Layers.CurrentLayer.Surface.Clone();
            ImageSurface swap_sel  = PintaCore.Layers.SelectionLayer.Surface;

            PintaCore.Layers.CurrentLayer.Surface   = old_surface;
            PintaCore.Layers.SelectionLayer.Surface = old_selection_layer;
            PintaCore.Layers.SelectionLayer.Transform.InitMatrix(old_transform);

            old_surface         = swap_surf;
            old_selection_layer = swap_sel;
            old_transform.InitMatrix(swap_transfrom);

            PintaCore.Layers.DestroySelectionLayer();
            PintaCore.Workspace.Invalidate();
        }
示例#28
0
        /// <summary>
        /// Gets the final pixel color for the given point, taking layers, opacity, and blend modes into account.
        /// </summary>
        public ColorBgra GetComputedPixel(int x, int y)
        {
            using (var dst = new ImageSurface(Format.Argb32, 1, 1)) {
                using (var g = new Context(dst)) {
                    foreach (var layer in GetLayersToPaint())
                    {
                        var color = layer.Surface.GetColorBgraUnchecked(x, y).ToCairoColor();

                        g.SetBlendMode(layer.BlendMode);
                        g.SetSourceColor(color);

                        g.Rectangle(dst.GetBounds().ToCairoRectangle());
                        g.PaintWithAlpha(layer.Opacity);
                    }
                }

                return(dst.GetPixel(0, 0).ToColorBgra());
            }
        }
示例#29
0
        //---------------------------------------------------------------------
        private static void Gradient()
        {
            Action <Surface> draw = surface =>
            {
                using (var c = new Context(surface))
                {
                    Gradient pat = new LinearGradient(0.0, 0.0, 0.0, 256.0);
                    pat.AddColorStopRgba(1, 0, 0, 0, 1);
                    pat.AddColorStopRgba(0, 1, 1, 1, 1);
                    c.Rectangle(0, 0, 256, 256);
                    c.SetSource(pat);
                    c.Fill();
                    pat.Dispose();

                    pat = new RadialGradient(115.2, 102.4, 25.6,
                                             102.4, 102.4, 128.0);
                    pat.AddColorStopRgba(0, 1, 1, 1, 1);
                    pat.AddColorStopRgba(1, 0, 0, 0, 1);
                    c.SetSource(pat);
                    c.Arc(128.0, 128.0, 76.8, 0, 2 * Math.PI);
                    c.Fill();
                    pat.Dispose();
                }
            };

            using (Surface surface = new ImageSurface(Format.Argb32, 500, 500))
            {
                draw(surface);
                surface.WriteToPng("gradient.png");
            }

            using (Surface surface = new PdfSurface("gradient.pdf", 500, 500))
            {
                draw(surface);
                surface.WriteToPng("gradient1.png");
            }

            using (Surface surface = new SvgSurface("gradient.svg", 500, 500))
            {
                draw(surface);
                surface.WriteToPng("gradient2.png");
            }
        }
示例#30
0
 public override void ApplyBrushToContext(GraphicsContext g)
 {
     using (ImageSurface surface = ((ImageSurface)g.GetTarget()))
     {
         double actualWidth  = surface.Width;
         double actualHeight = surface.Height;
         using (LinearGradient lg = new LinearGradient(X0 * actualWidth, Y0 * actualHeight, X1 * actualWidth, Y1 * actualHeight))
         {
             if (GradientStops != null)
             {
                 foreach (GradientStop gs in GradientStops)
                 {
                     lg.AddColorStop(gs.Offset, gs.Color);
                 }
             }
             g.SetSource(lg);
         }
     }
 }
示例#31
0
 public RenderTarget(ImageSurface surface)
 {
     _surface = surface;
 }
示例#32
0
        private void InitializeView(WebView view)
        {
            if (view == null)
                return;

            // Create an image surface to render the
            // WebView's pixel buffer.
            surface = new ImageSurface();
            surface.Updated += OnSurfaceUpdated;

            webView = view;

            // Assign our surface.
            webView.Surface = surface;

            // Handle some important events.
            webView.CursorChanged += OnCursorChanged;
            //webView.TitleChanged += OnTitleChanged;

            bindingSource = new BindingSource() { DataSource = webView };
            this.DataBindings.Add(new Binding("Text", bindingSource, "Title", true));

            //webView.AddressChanged += OnAddressChanged;
            //webView.ShowCreatedWebView += OnShowNewView;
            //webView.Crashed += OnCrashed;

            // Load a URL, if this is not a child view.
            if (webView.ParentView == null)
                // Tip: /ncr = No Country Redirect ;-)
                webView.Source = new Uri("http://www.forgeofempires.com/");

            // Give focus to the view.
            webView.FocusView();
        }
        private void RenderPage(ref Gtk.Image img)
        {
            Poppler.Page page = this.pdf.GetPage(this.pageIndex);
            double width=0D;
            double height=0D;
            page.GetSize(out width, out height);
            pageHeight = (int)height;

            // It is important to set the image to have the correct size
            img.Pixbuf = new  Gdk.Pixbuf (Gdk.Colorspace.Rgb, true, 8, (int)width, (int)height);

            using (var sur = new ImageSurface (img.Pixbuf.Pixels, Format.Argb32, (int)width, (int)height, img.Pixbuf.Rowstride))
                using (var con = new Context (sur)) {
                    page.Render (con);
                }

            vboxImages.Add (img);
        }
示例#34
0
 protected virtual void InitializeUserInterface()
 {
     this._surface = new ImageSurface();
     base.Controls.Add(this._surface);
 }
示例#35
0
        private void InitializeView( WebView view, bool isChild = false, Uri targetURL = null )
        {
            if ( view == null )
                return;

            // Create an image surface to render the
            // WebView's pixel buffer.
            surface = new ImageSurface();
            surface.Updated += OnSurfaceUpdated;

            webView = view;

            // Assign our surface.
            webView.Surface = surface;

            if ( !isChild )
                webView.Source = targetURL ?? new Uri( "http://www.google.com/ncr" );

            // Give focus to the view.
            webView.FocusView();
        }
示例#36
0
 public Renderer(ImageSurface surface)
 {
     _surface = surface;
 }
示例#37
0
 public IBitmapImpl LoadBitmap(string fileName)
 {
     ImageSurface result = new ImageSurface(fileName);
     return new BitmapImpl(result);
 }
示例#38
0
        private void InitializeView( WebView view )
        {
            if ( view == null )
                return;

            // Create an image surface to render the
            // WebView's pixel buffer.
            surface = new ImageSurface();
            surface.Updated += OnSurfaceUpdated;

            webView = view;
            // Assign our surface.
            webView.Surface = surface;

            // Handle some important events.
            webView.CursorChanged += OnCursorChanged;
            webView.TitleChanged += OnTitleChanged;
            webView.DocumentReady += OnDocumentReady;
            webView.ShowCreatedWebView += OnShowNewView;
            webView.Crashed += OnCrashed;

            // Load a URL, if this is not a child view.
            if ( webView.Parent == null )
                webView.LoadHTML( "<h1>Opening a popup window...</h1>" );

            // Give focus to the view.
            webView.FocusView();
        }
示例#39
0
 public Renderer(ImageSurface surface)
 {
     this.surface = surface;
 }