Inheritance: IDisposable
Beispiel #1
0
        private void Form1_Shown(object sender, EventArgs e)
        {
            Debug.WriteLine("Form1_Shown");

            Win32Surface = new Win32Surface(this.CreateGraphics().GetHdc());
            FontContext = new Context(Win32Surface);

            //CRITICAL: Format of Win32Surface and ImageSurface must be identical!

            ImageSurface = new ImageSurface(Format.Rgb24, ClientSize.Width, ClientSize.Height);
            BackContext = new Context(ImageSurface);

            //Clear Surface2
            BackContext.SetSourceColor(new Color(1,1,1));
            BackContext.Operator = Operator.Source;
            BackContext.Paint();
            BackContext.Operator = Operator.Over;

            var textFormat = DWriteCairo.CreateTextFormat(
                "Arial",
                FontWeight.Normal,
                FontStyle.Normal,
                FontStretch.Normal,
                32f);
            
            Debug.Assert(Math.Abs(textFormat.FontSize - 32f) < 0.0001);
            
            const string s = "Hello World";
            textLayout = DWriteCairo.CreateTextLayout(s, textFormat, 300, 40);

        }
Beispiel #2
0
 public GtkGraphDrawer(Context g, Context gh, ImageSurface srfc)
 {
     this.g = g;
     this.gh = gh;
     this.srfc = srfc;
     gh.Antialias = Antialias.Subpixel;
 }
Beispiel #3
0
        static void Main()
        {
            // The using statement ensures that potentially heavy objects
            // are disposed immediately.
            using (ImageSurface draw = new ImageSurface(Format.Argb32, 70, 150))
            {
                using (Context gr = new Context(draw))
                {
                    gr.Antialias = Antialias.Subpixel;    // sets the anti-aliasing method
                    gr.LineWidth = 9;          // sets the line width
                    gr.SetSourceColor(new Color(0, 0, 0, 1));   // red, green, blue, alpha
                    gr.MoveTo(10, 10);          // sets the Context's start point.
                    gr.LineTo(40, 60);          // draws a "virtual" line from 5,5 to 20,30
                    gr.Stroke();          //stroke the line to the image surface

                    gr.Antialias = Antialias.Gray;
                    gr.LineWidth = 8;
                    gr.SetSourceColor(new Color(1, 0, 0, 1));
                    gr.LineCap = LineCap.Round;
                    gr.MoveTo(10, 50);
                    gr.LineTo(40, 100);
                    gr.Stroke();

                    gr.Antialias = Antialias.None;    //fastest method but low quality
                    gr.LineWidth = 7;
                    gr.MoveTo(10, 90);
                    gr.LineTo(40, 140);
                    gr.Stroke();

                    draw.WriteToPng("antialias.png");  //save the image as a png image.
                }
            }
        }
Beispiel #4
0
 protected override void OnPaint(PaintEventArgs e)
 {
     base.OnPaint(e);
     using (System.Drawing.Graphics graphics = e.Graphics)
     {
         using (Win32Surface surface = new Win32Surface(graphics.GetHdc()))
         {
             using (Context context = new Context(surface))
             {
                 context.LineWidth = 2.0;
                 context.SetSourceColor(this.bugColor);
                 context.MoveTo(7.0, 64.0);
                 context.CurveTo(1.0, 47.0, 2.0, 46.0, 9.0, 51.0);
                 context.MoveTo(25.0, 80.0);
                 context.CurveTo(10.0, 73.0, 11.0, 70.0, 14.0, 63.0);
                 context.MoveTo(10.0, 41.0);
                 context.CurveTo(2.0, 36.0, 1.0, 33.0, 1.0, 26.0);
                 context.LineWidth = 1.0;
                 context.MoveTo(1.0, 26.0);
                 context.CurveTo(5.0, 23.0, 7.0, 18.0, 12.0, 17.0);
                 context.LineTo(12.0, 14.0);
                 context.Stroke();
                 context.MoveTo(30.0, 74.0);
                 context.CurveTo(14.0, 64.0, 10.0, 48.0, 11.0, 46.0);
                 context.LineTo(10.0, 45.0);
                 context.LineTo(10.0, 40.0);
                 context.CurveTo(13.0, 37.0, 15.0, 35.0, 19.0, 34.0);
                 context.Stroke();
             }
         }
     }
 }
Beispiel #5
0
        protected override void DrawGraduations(Context gr, PointD pStart, PointD pEnd)
        {
            Rectangle r = ClientRectangle;
            Foreground.SetAsSource (gr);

            gr.LineWidth = 2;
            gr.MoveTo(pStart);
            gr.LineTo(pEnd);

            gr.Stroke();
            gr.LineWidth = 1;

            double sst = unity * SmallIncrement;
            double bst = unity * LargeIncrement;

            PointD vBar = new PointD(0, sst);
            for (double x = Minimum; x <= Maximum - Minimum; x += SmallIncrement)
            {
                double lineLength = r.Height / 3;
                if (x % LargeIncrement != 0)
                    lineLength /= 3;
                PointD p = new PointD(pStart.X + x * unity, pStart.Y);
                gr.MoveTo(p);
                gr.LineTo(new PointD(p.X, p.Y + lineLength));
            }
            gr.Stroke();
        }
Beispiel #6
0
        public static ImageSurface Create (Gdk.Pixbuf pixbuf, bool disposePixbuf)
        {
            if (pixbuf == null || pixbuf.Handle == IntPtr.Zero) {
                return null;
            }

            if (!PlatformDetection.IsWindows) {
                try {
                    return new PixbufImageSurface (pixbuf, disposePixbuf);
                } catch {
                    return null;
                }
            } else {
                // FIXME:
                // Windows has some trouble running the PixbufImageSurface, so as a
                // workaround a slower but working version of this factory method is
                // implemented. One day we can come back and optimize this by finding
                // out what's causing the PixbufImageSurface to result in access
                // violations when the object is disposed.
                ImageSurface target = new ImageSurface (Format.ARGB32, pixbuf.Width, pixbuf.Height);
                Context context = new Context (target);
                try {
                    Gdk.CairoHelper.SetSourcePixbuf (context, pixbuf, 0, 0);
                    context.Paint ();
                } finally {
                    ((IDisposable)context).Dispose ();
                    if (disposePixbuf) {
                        ((IDisposable)pixbuf).Dispose ();
                    }
                }

                return target;
            }
        }
		private ImageInfo CreateBlur (ImageInfo source)
		{
			double scale = Math.Max (256 / (double) source.Bounds.Width,
						 256 / (double) source.Bounds.Height);

			Gdk.Rectangle small = new Gdk.Rectangle (0, 0,
								(int) Math.Ceiling (source.Bounds.Width * scale),
								(int) Math.Ceiling (source.Bounds.Height * scale));

			MemorySurface image = new MemorySurface (Format.Argb32,
								 small.Width,
								 small.Height);

			Context ctx = new Context (image);
			//Pattern solid = new SolidPattern (0, 0, 0, 0);
			//ctx.Source = solid;
			//ctx.Paint ();
			//solid.Destroy ();
			ctx.Matrix = source.Fit (small);
			ctx.Operator = Operator.Source;
			Pattern p = new SurfacePattern (source.Surface);
			ctx.Source = p;
			//Log.Debug (small);
			ctx.Paint ();
			p.Destroy ();
			((IDisposable)ctx).Dispose ();
			Gdk.Pixbuf normal = MemorySurface.CreatePixbuf (image);
			Gdk.Pixbuf blur = PixbufUtils.Blur (normal, 3);
			ImageInfo overlay = new ImageInfo (blur);
			blur.Dispose ();
			normal.Dispose ();
			image.Destroy ();
			return overlay;
		}
        public void Render(DrawingArea area, SettingsModel settings)
        {
            var width = area.Allocation.Width;
            var height = area.Allocation.Height;

            var kaleidoscope = _factory.Get (settings.Type);
            var rootNode = kaleidoscope.Generate (
                settings.GeometyWidth,
                settings.ImageUri,
                width, height);

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

            using (var context = new Context (surface)) {
                context.Translate(width / 2, height / 2);
                rootNode.Render (context);
            }
            rootNode.Geometry.Dispose ();

            using (Context context = Gdk.CairoHelper.Create (area.GdkWindow)) {
                context.Rectangle(0, 0, width, height);
                context.SetSource(surface);
                context.Fill();
                context.GetTarget ().Dispose ();
            }
            surface.Dispose ();
        }
 public override void Run()
 {
     ICollection<double> chapters = this.Theory.Chapters;
     StripCanvasSize scs = this.Manager.GenerateStripCanvasSize (chapters.Count);
     double dw = scs.CanvasSize.Width;
     double dh = scs.CanvasSize.Height;
     using (PdfSurface surface = new PdfSurface (this.Manager.OutputFile, scs.TotalWidth, scs.TotalHeight)) {
         using (Context ctx = new Context (surface)) {
             int index = 0x00;
             IPoint3 p;
             foreach (double chapter in chapters) {
                 p = scs.GetCanvasOffset (index);
                 ctx.Save ();
                 ctx.Translate (p.X, p.Y);
                 ctx.Rectangle (0.0d, 0.0d, dw, dh);
                 ctx.Stroke ();
                 this.Theory.Time = chapter;
                 CairoEngine engine = new CairoEngine (this.Theory);
                 engine.Context = ctx;
                 engine.Process ();
                 ctx.Restore ();
                 index++;
             }
         }
     }
 }
        public void DrawHist(TimeList<Complex[]> list, double t)
        {
            using (Context context = new Context(Surface)) {

                context.Rectangle(0, 0, Width, Height);
                context.Color = Background;
                context.Fill();

                int index = list.Index (t);
                int times = 30;

                double xl = (double)(Width - 60) / N;
                double yl = (double)Height / times;

                Complex[] points;
                Color c;
                int ii;
                for (int i = index; i >= Math.Max(0, index - times); i--) {
                    points = list.Get (i);
                    N = points.Length;
                    ii = index - i;
                    for (int j = 0; j < points.Length; j++) {
                        DrawHistArea (context, xl, yl, ii, j, _valueExtractor(points [j]));
                    }
                }
            }

            DrawExpose (null, null);
        }
Beispiel #11
0
 public static void ExportToPdf(this Report report ,string path)
 {
     using (PdfSurface pdfSurface = new PdfSurface (
         path,report.WidthWithMargins,report.HeightWithMargins)) {
         Cairo.Context cr = new Cairo.Context (pdfSurface);
         cr.Translate(report.Margin.Left,report.Margin.Top);
         ReportRenderer renderer = new ReportRenderer (){ Context = cr};
         renderer.RegisterRenderer (typeof(TextBlock), new TextBlockRenderer ());
         renderer.RegisterRenderer (typeof(Line), new LineRenderer ());
         renderer.RegisterRenderer (typeof(Image), new ImageRenderer (){ PixbufRepository = new PixbufRepository(report.ResourceRepository)});
         SectionRenderer sr = new SectionRenderer();
         renderer.RegisterRenderer(typeof(ReportHeaderSection), sr);
         renderer.RegisterRenderer(typeof(ReportFooterSection), sr);
         renderer.RegisterRenderer(typeof(DetailSection), sr);
         renderer.RegisterRenderer(typeof(PageHeaderSection), sr);
         renderer.RegisterRenderer(typeof(PageFooterSection), sr);
         MonoReports.Model.Engine.ReportEngine engine = new MonoReports.Model.Engine.ReportEngine (report,renderer);
         engine.Process ();
         for (int i = 0; i < report.Pages.Count; ++i) {
             renderer.RenderPage (report.Pages [i]);
             cr.ShowPage ();
         }
         pdfSurface.Finish ();
         (cr as IDisposable).Dispose ();
     }
 }
Beispiel #12
0
 private void Image_Loaded(object sender, RoutedEventArgs e)
 {
     Image image = (Image)sender;
     using (ImageSurface surface = new ImageSurface(Format.Argb32, (int)image.Width, (int)image.Height))
     {
         using (Context context = new Context(surface))
         {
             PointD p = new PointD(10.0, 10.0);
             PointD p2 = new PointD(100.0, 10.0);
             PointD p3 = new PointD(100.0, 100.0);
             PointD p4 = new PointD(10.0, 100.0);
             context.MoveTo(p);
             context.LineTo(p2);
             context.LineTo(p3);
             context.LineTo(p4);
             context.LineTo(p);
             context.ClosePath();
             context.Fill();
             context.MoveTo(140.0, 110.0);
             context.SetFontSize(32.0);
             context.SetSourceColor(new Color(0.0, 0.0, 0.8, 1.0));
             context.ShowText("Hello Cairo!");
             surface.Flush();
             RgbaBitmapSource source = new RgbaBitmapSource(surface.Data, surface.Width);
             image.Source = source;
         }
     }
 }
Beispiel #13
0
 public static void Clear(this ImageSurface surface)
 {
     using (Context g = new Context (surface)) {
         g.Operator = Operator.Clear;
         g.Paint ();
     }
 }
 public CairoAdapter(System.Drawing.Graphics graphic)
 {
     Surface surface = new Win32Surface(graphic.GetHdc());
     this.context = new Context(surface);
     context.LineWidth = 2;
     context.Color = new Color(1, 0, 0);
 }
Beispiel #15
0
        public void clip(Context ctx)
        {
            foreach (Rectangle r in list)
                ctx.Rectangle(r);

            ctx.Clip();
        }
Beispiel #16
0
        public override void SetAsSource(Context ctx, Rectangle bounds = default(Rectangle))
        {
            float widthRatio = 1f;
            float heightRatio = 1f;

            if (Scaled){
                widthRatio = (float)bounds.Width / Dimensions.Width;
                heightRatio = (float)bounds.Height / Dimensions.Height;
            }

            if (KeepProportions) {
                if (widthRatio < heightRatio)
                    heightRatio = widthRatio;
                else
                    widthRatio = heightRatio;
            }

            using (ImageSurface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) {
                using (Cairo.Context gr = new Context (tmp)) {
                    gr.Translate (bounds.Left, bounds.Top);
                    gr.Scale (widthRatio, heightRatio);
                    gr.Translate ((bounds.Width/widthRatio - Dimensions.Width)/2, (bounds.Height/heightRatio - Dimensions.Height)/2);

                    hSVG.RenderCairo (gr);
                }
                ctx.SetSource (tmp);
            }
        }
Beispiel #17
0
        public override void DrawArrow(Context cr, Gdk.Rectangle alloc, SortType type)
        {
            cr.LineWidth = 1;
            cr.Translate (0.5, 0.5);
            double x1 = alloc.X;
            double x3 = alloc.X + alloc.Width / 2.0;
            double x2 = x3 + (x3 - x1);
            double y1 = alloc.Y;
            double y2 = alloc.Bottom;

            if (type == SortType.Ascending) {
                cr.MoveTo (x1, y1);
                cr.LineTo (x2, y1);
                cr.LineTo (x3, y2);
                cr.LineTo (x1, y1);
            } else {
                cr.MoveTo (x3, y1);
                cr.LineTo (x2, y2);
                cr.LineTo (x1, y2);
                cr.LineTo (x3, y1);
            }

            cr.SetSourceColor (Colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal));
            cr.FillPreserve ();
            cr.SetSourceColor (Colors.GetWidgetColor (GtkColorClass.Text, StateType.Normal));
            cr.Stroke ();
            cr.Translate (-0.5, -0.5);
        }
Beispiel #18
0
  protected override FlowReturn OnTransformIp (Gst.Buffer buf) {
    if (!buf.IsWritable)
      return FlowReturn.Error;

    Cairo.ImageSurface img = new Cairo.ImageSurface (buf.Data, Cairo.Format.Rgb24, width, height, width*4);

    using (Cairo.Context context = new Cairo.Context (img)) {
      double dx = (double) ( (buf.Timestamp / Clock.MSecond) % 2180) / 5;
      context.Save ();
      context.Scale (width / 640.0, height / 480.0);
      context.MoveTo (300, 10 + dx);
      context.LineTo (500 - dx, 400);
      context.LineWidth = 4.0;
      context.Color = new Color (0, 0, 1.0);
      context.Stroke();
      context.Restore ();

      if (lastX != -1 && lastY != -1) {
        context.Color = new Color (1.0, 0, 0);
        context.Translate (lastX, lastY);
        context.Scale (Math.Min (width / 640.0, height / 480.0), Math.Min (width / 640.0, height / 480.0));
        context.Arc (0, 0, 10.0, 0.0, 2 * Math.PI);
        context.Fill();
      }
    }

    img.Destroy ();
    return base.OnTransformIp (buf);
  }
Beispiel #19
0
 public SketchPad(IPuzzleQueryResolver resolver)
 {
     ImageSurface imsu = new ImageSurface(Format.Argb32,0x01,0x01);
     this.subcontext = new Context(imsu);
     this.AddEvents((int) (Gdk.EventMask.PointerMotionMask|Gdk.EventMask.ButtonPressMask|Gdk.EventMask.ButtonReleaseMask));
     this.resolver = resolver;
 }
Beispiel #20
0
		protected void UpdateRectangle (PointD point)
		{
			if (!is_drawing)
				return;

			Document doc = PintaCore.Workspace.ActiveDocument;

			Rectangle r = PointsToRectangle (shape_origin, point);
			Rectangle dirty;

			doc.ToolLayer.Clear ();
			doc.ToolLayer.Hidden = false;

			using (Context g = new Context (doc.ToolLayer.Surface)) {
				g.Antialias = Antialias.Subpixel;

				dirty = g.FillStrokedRectangle (r, new Color (0, 0.4, 0.8, 0.1), new Color (0, 0, 0.9), 1);
				dirty = dirty.Clamp ();

				doc.Workspace.Invalidate (last_dirty.ToGdkRectangle ());
				doc.Workspace.Invalidate (dirty.ToGdkRectangle ());
				
				last_dirty = dirty;
			}
		}
Beispiel #21
0
		protected override Gdk.Rectangle OnMouseMove (Context g, Color strokeColor, ImageSurface surface,
		                                              int x, int y, int lastX, int lastY)
		{
			// Cairo does not support a single-pixel-long single-pixel-wide line
			if (x == lastX && y == lastY && g.LineWidth == 1 &&
			    PintaCore.Workspace.ActiveWorkspace.PointInCanvas (new PointD(x,y))) {
				surface.Flush ();

				ColorBgra source = surface.GetColorBgraUnchecked (x, y);
				source = UserBlendOps.NormalBlendOp.ApplyStatic (source, strokeColor.ToColorBgra ());
				surface.SetColorBgra (source, x, y);
				surface.MarkDirty ();

				return new Gdk.Rectangle (x - 1, y - 1, 3, 3);
			}

			g.MoveTo (lastX + 0.5, lastY + 0.5);
			g.LineTo (x + 0.5, y + 0.5);
			g.StrokePreserve ();

			Gdk.Rectangle dirty = g.FixedStrokeExtents ().ToGdkRectangle ();

			// For some reason (?!) we need to inflate the dirty
			// rectangle for small brush widths in zoomed images
			dirty.Inflate (1, 1);

			return dirty;
		}
Beispiel #22
0
 public virtual void Draw(Context cr, Gdk.Rectangle clip)
 {
     cr.Rectangle(clip.X, clip.Y, clip.Width, clip.Height);
     cr.Color = BackgroundColor;
     cr.Fill();
     cr.Stroke();
 }
Beispiel #23
0
        protected unsafe override void OnFillRegionComputed(Point[][] polygonSet)
        {
            SimpleHistoryItem hist = new SimpleHistoryItem (Icon, Name);
            hist.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayer);

            PintaCore.Layers.ToolLayer.Clear ();
            ImageSurface surface = PintaCore.Layers.ToolLayer.Surface;

            ColorBgra* surf_data_ptr = (ColorBgra*)surface.DataPtr;
            int surf_width = surface.Width;

            for (int x = 0; x < stencil.Width; x++)
                for (int y = 0; y < stencil.Height; y++)
                    if (stencil.GetUnchecked (x, y))
                        surface.SetPixel (surf_data_ptr, surf_width, x, y, fill_color);

            using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = Antialias.Subpixel;

                g.SetSource (surface);
                g.Paint ();
            }

            PintaCore.History.PushNewItem (hist);
            PintaCore.Workspace.Invalidate ();
        }
        public override void Apply (CanvasItem item, Context cr)
        {
            int steps = ShadowSize;
            double opacity_step = ShadowOpacity / ShadowSize;
            Color color = new Color (0, 0, 0);

            double width = Math.Round (item.Allocation.Width);
            double height = Math.Round (item.Allocation.Height);

            if (Fill != null) {
                cr.Rectangle (shadow_size, shadow_size, width - ShadowSize * 2, height - ShadowSize * 2);
                Fill.Apply (cr);
                cr.Fill ();
            }

            cr.LineWidth = 1.0;

            for (int i = 0; i < steps; i++) {
                CairoExtensions.RoundedRectangle (cr,
                    i + 0.5,
                    i + 0.5,
                    (width - 2 * i) - 1,
                    (height - 2 * i) - 1,
                    steps - i);

                color.A = opacity_step * (i + 1);
                cr.Color = color;
                cr.Stroke ();
            }
        }
Beispiel #25
0
        public override void Draw(Context context)
        {
            SetupLayout(context);

            RectangleD displayBox = DisplayBox;
            displayBox.OffsetDot5();
            double side = 10.0;

            context.LineWidth = LineWidth;
            context.Save ();
            //Box
            context.MoveTo (displayBox.X, displayBox.Y);
            context.LineTo (displayBox.X, displayBox.Y + displayBox.Height);
            context.LineTo (displayBox.X + displayBox.Width, displayBox.Y + displayBox.Height);
            context.LineTo (displayBox.X + displayBox.Width, displayBox.Y + side);
            context.LineTo (displayBox.X + displayBox.Width - side, displayBox.Y);
            context.LineTo (displayBox.X, displayBox.Y);
            context.Save ();
            //Triangle
            context.MoveTo (displayBox.X + displayBox.Width - side, displayBox.Y);
            context.LineTo (displayBox.X + displayBox.Width - side, displayBox.Y + side);
            context.LineTo (displayBox.X + displayBox.Width, displayBox.Y + side);
            context.LineTo (displayBox.X + displayBox.Width - side, displayBox.Y);
            context.Restore ();

            context.Color = FillColor;
            context.FillPreserve ();
            context.Color = LineColor;
            context.Stroke ();

            DrawText (context);
        }
Beispiel #26
0
        public static SurfacePattern CreateImageBrush(ImageBrush brush, Size targetSize)
        {
            if (brush.Source == null)
            {
                return null;
            }

            // TODO: This is directly ported from Direct2D and could probably be made more
            // efficient on cairo by taking advantage of the fact that cairo has Extend.None.
            var image = ((BitmapImpl)brush.Source.PlatformImpl).Surface;
            var imageSize = new Size(brush.Source.PixelWidth, brush.Source.PixelHeight);
            var tileMode = brush.TileMode;
            var sourceRect = brush.SourceRect.ToPixels(imageSize);
            var destinationRect = brush.DestinationRect.ToPixels(targetSize);
            var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size);
            var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale);
            var intermediateSize = CalculateIntermediateSize(tileMode, targetSize, destinationRect.Size);

			var intermediate = new ImageSurface (Format.ARGB32, (int)intermediateSize.Width, (int)intermediateSize.Height);
            using (var context = new Context(intermediate))
            {
                Rect drawRect;
                var transform = CalculateIntermediateTransform(
                    tileMode,
                    sourceRect,
                    destinationRect,
                    scale,
                    translate,
                    out drawRect);
                context.Rectangle(drawRect.ToCairo());
                context.Clip();
                context.Transform(transform.ToCairo());
                Gdk.CairoHelper.SetSourcePixbuf(context, image, 0, 0);
                context.Rectangle(0, 0, imageSize.Width, imageSize.Height);
                context.Fill();

                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(-destinationRect.X, -destinationRect.Y);
                    result.Matrix = matrix;
                }

                return result;
            }
        }
Beispiel #27
0
 public void clear(Context ctx)
 {
     foreach (Rectangle r in list)
         ctx.Rectangle(r);
     ctx.Operator = Operator.Clear;
     ctx.Fill();
     ctx.Operator = Operator.Over;
 }
Beispiel #28
0
        public override void Render(Node node, Context context)
        {
            PolygonNode poly = node as PolygonNode;

            LayoutOutline (poly, context);
            context.Color = poly.Color.MultiplyAlpha (poly.Opacity).ToCairo ();
            context.Fill ();
        }
Beispiel #29
0
		public static Cairo.Context Create (Gdk.Drawable drawable)
		{
			Cairo.Context ctx = new Cairo.Context (gdk_cairo_create (drawable.Handle));
			if (ctx == null) 
				throw new Exception ("Couldn't create Cairo Graphics!");
			
			return ctx;
		}
Beispiel #30
0
        public override void Render(Node node, Context context)
        {
            BoxNode box = node as BoxNode;

            LayoutOutline (node, context);
            context.Color = box.Color.MultiplyAlpha (node.Opacity).ToCairo ();
            context.Fill ();
        }
Beispiel #31
0
 public void DrawFrameBackground(Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Pattern pattern)
 {
     DrawFrameBackground(cr, alloc, black, pattern);
 }
Beispiel #32
0
 /// <summary>
 /// Dibuja una linea desde un punto a otro definidos por 2 ints cada uno
 /// </summary>
 /// <param name="canvas">Canvas en donde dibujar.</param>
 /// <param name="x1">Coordenada x punto base</param>
 /// <param name="y1">Coordenada y punto base</param>
 /// <param name="x2">Coordenada x punto destino</param>
 /// <param name="y2">Coordenada y punto destino</param>
 private void DrawLine(Cairo.Context canvas, double x1, double y1, double x2, double y2)
 {
     canvas.MoveTo(x1, y1);
     canvas.LineTo(x2, y2);
 }
Beispiel #33
0
 /// <summary>
 /// Escribe el string <paramref name="text"/> en un punto definido por dos ints
 /// </summary>
 /// <param name="canvas">Canvas.</param>
 /// <param name="x">Coordenada x punto</param>
 /// <param name="y">Coordenada y punto</param>
 /// <param name="text">Texto.</param>
 private void DrawString(Cairo.Context canvas, double x, double y, string text)
 {
     canvas.MoveTo(x, y);
     canvas.ShowText(text);
 }
Beispiel #34
0
 public void DrawArrow(Cairo.Context cr, Gdk.Rectangle alloc, Hyena.Data.SortType type)
 {
     DrawArrow(cr, alloc, Math.PI / 2.0 * (type == Hyena.Data.SortType.Ascending ? 1 : -1));
 }
Beispiel #35
0
 public void DrawFrame(Cairo.Context cr, Gdk.Rectangle alloc, bool baseColor)
 {
     DrawFrameBackground(cr, alloc, baseColor);
     DrawFrameBorder(cr, alloc);
 }
Beispiel #36
0
 public abstract void DrawListBackground(Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color);
Beispiel #37
0
 public void DrawColumnHighlight(Cairo.Context cr, Gdk.Rectangle alloc)
 {
     Cairo.Color color = CairoExtensions.GdkRGBAToCairoColor(Widget.StyleContext.GetBackgroundColor(StateFlags.Selected));
     DrawColumnHighlight(cr, alloc, color);
 }
Beispiel #38
0
 public abstract void DrawColumnHeaderFocus(Cairo.Context cr, Gdk.Rectangle alloc);
Beispiel #39
0
 public abstract void DrawHeaderSeparator(Cairo.Context cr, Gdk.Rectangle alloc, int x);
Beispiel #40
0
 protected void LayoutRoundedRectangle(Cairo.Context context, Gdk.Rectangle region, int inflateX = 0, int inflateY = 0, float rounding = 3)
 {
     region.Inflate(inflateX, inflateY);
     CairoExtensions.RoundedRectangle(context, region.X + .5, region.Y + .5, region.Width - 1, region.Height - 1, rounding);
 }
Beispiel #41
0
 void ClipProgressBar(Cairo.Context context, Gdk.Rectangle bounding)
 {
     LayoutRoundedRectangle(context, bounding);
     context.Clip();
 }
Beispiel #42
0
        public void Render(Cairo.Context context, StatusArea.RenderArg arg)
        {
            context.CachedDraw(surface: ref backgroundSurface,
                               region: arg.Allocation,
                               draw: (c, o) => DrawBackground(c, new Gdk.Rectangle(0, 0, arg.Allocation.Width, arg.Allocation.Height)));

            if (arg.BuildAnimationOpacity > 0.001f)
            {
                DrawBuildEffect(context, arg.Allocation, arg.BuildAnimationProgress, arg.BuildAnimationOpacity);
            }

            if (arg.ErrorAnimationProgress > 0.001 && arg.ErrorAnimationProgress < .999)
            {
                DrawErrorAnimation(context, arg);
            }

            DrawBorder(context, arg.Allocation);

            if (arg.HoverProgress > 0.001f)
            {
                context.Clip();
                int x1 = arg.Allocation.X + arg.MousePosition.X - 200;
                int x2 = x1 + 400;
                using (Cairo.LinearGradient gradient = new LinearGradient(x1, 0, x2, 0))
                {
                    Cairo.Color targetColor      = Styles.StatusBarFill1Color;
                    Cairo.Color transparentColor = targetColor;
                    targetColor.A      = .7;
                    transparentColor.A = 0;

                    targetColor.A = .7 * arg.HoverProgress;

                    gradient.AddColorStop(0.0, transparentColor);
                    gradient.AddColorStop(0.5, targetColor);
                    gradient.AddColorStop(1.0, transparentColor);

                    context.SetSource(gradient);

                    context.Rectangle(x1, arg.Allocation.Y, x2 - x1, arg.Allocation.Height);
                    context.Fill();
                }
                context.ResetClip();
            }
            else
            {
                context.NewPath();
            }

            int progress_bar_x     = arg.ChildAllocation.X;
            int progress_bar_width = arg.ChildAllocation.Width;

            if (arg.CurrentPixbuf != null)
            {
                int y = arg.Allocation.Y + (arg.Allocation.Height - arg.CurrentPixbuf.Height) / 2;
                Gdk.CairoHelper.SetSourcePixbuf(context, arg.CurrentPixbuf, arg.ChildAllocation.X, y);
                context.Paint();
                progress_bar_x     += arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding;
                progress_bar_width -= arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding;
            }

            int center = arg.Allocation.Y + arg.Allocation.Height / 2;

            Gdk.Rectangle progressArea = new Gdk.Rectangle(progress_bar_x, center - Styles.ProgressBarHeight / 2, progress_bar_width, Styles.ProgressBarHeight);
            if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0)
            {
                DrawProgressBar(context, arg.ProgressBarFraction, progressArea, arg);
                ClipProgressBar(context, progressArea);
            }

            int text_x     = progress_bar_x + Styles.ProgressBarInnerPadding;
            int text_width = progress_bar_width - (Styles.ProgressBarInnerPadding * 2);

            double textTweenValue = arg.TextAnimationProgress;

            if (arg.LastText != null)
            {
                double opacity = Math.Max(0.0f, 1.0f - textTweenValue);
                DrawString(arg.LastText, arg.LastTextIsMarkup, context, text_x,
                           center - (int)(textTweenValue * arg.Allocation.Height * 0.3), text_width, opacity, arg.Pango, arg);
            }

            if (arg.CurrentText != null)
            {
                DrawString(arg.CurrentText, arg.CurrentTextIsMarkup, context, text_x,
                           center + (int)((1.0f - textTweenValue) * arg.Allocation.Height * 0.3), text_width, Math.Min(textTweenValue, 1.0), arg.Pango, arg);
            }

            if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0)
            {
                context.ResetClip();
            }
        }
Beispiel #43
0
 public abstract void DrawRowSelection(Cairo.Context cr, int x, int y, int width, int height,
                                       bool filled, bool stroked, Cairo.Color color, CairoCorners corners);
Beispiel #44
0
 public abstract void DrawColumnHighlight(Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color);
Beispiel #45
0
 public abstract void DrawRowRule(Cairo.Context cr, int x, int y, int width, int height);
Beispiel #46
0
 public void DrawRowSelection(Cairo.Context cr, int x, int y, int width, int height)
 {
     DrawRowSelection(cr, x, y, width, height, true);
 }
Beispiel #47
0
 public abstract void DrawArrow(Cairo.Context cr, Gdk.Rectangle alloc, double rotation);
Beispiel #48
0
 public void DrawRowSelection(Cairo.Context cr, int x, int y, int width, int height, bool filled)
 {
     Cairo.Color color = CairoExtensions.GdkRGBAToCairoColor(Widget.StyleContext.GetBackgroundColor(StateFlags.Selected));
     DrawRowSelection(cr, x, y, width, height, filled, true, color, CairoCorners.All);
 }
Beispiel #49
0
 /// <summary>
 /// Dibuja una linea desde un punto a otro definidos por <see cref="Gdk.Point"/>
 /// </summary>
 /// <param name="canvas">Canvas en donde dibujar.</param>
 /// <param name="p1">Punto base</param>
 /// <param name="p2">Punto destino</param>
 private void DrawLine(Cairo.Context canvas, Gdk.Point p1, Gdk.Point p2)
 {
     this.DrawLine(canvas, p1.X, p1.Y, p2.X, p2.Y);
 }
Beispiel #50
0
 public void DrawRowSelection(Cairo.Context cr, int x, int y, int width, int height,
                              bool filled, bool stroked, Cairo.Color color)
 {
     DrawRowSelection(cr, x, y, width, height, filled, stroked, color, CairoCorners.All);
 }
Beispiel #51
0
        /// <summary>
        /// Dibuja los nombres de los meses si es un gráfico por meses o los años si es por años
        /// También dibuja el rango de valores izquierdo
        /// </summary>
        /// <param name="canvas">Canvas.</param>
        private void DrawLegend(Cairo.Context canvas)
        {
            canvas.SetFontSize(this.LegendsFontSize);             //Hay que retocar esto
            canvas.SetSourceRGB(0, 0, 0);

            double maxHeight = Margin.Height;
            double maxWidth  = Margin.Width;
            double yGap      = (maxHeight - Margin.Y) / (NumLineas - 1);
            double xGap      = (maxWidth - Margin.X) / (NumLineas - 1);
            double x         = Margin.X;
            double y         = Margin.Y;


            canvas.LineWidth = 0.25;
            canvas.SetSourceRGB(0, 0, 0);

            int max = 0;
            int i   = 0;

            this.lista.ForEach((obj) => max = System.Math.Max(max, obj));
            // Draw horizontal lines
            while (y < maxHeight + 1)
            {
                //Arreglar este %
                if (i % 4 == 0)
                {
                    this.DrawString(canvas, Width * 0.05, y, Convert.ToString(max - (i++ *max / NumLineas)));
                }

                y += yGap;
                if (y >= maxHeight + 1)
                {
                    this.DrawString(canvas, Width * 0.05, y, "0");
                }
            }

            if (!this.PorMeses)
            {
                i = 2018 - this.lista.Count + 1;
            }
            else
            {
                i = 0;
            }
            // Draw vertical lines
            while (x < maxWidth + 1)
            {
                if (this.PorMeses)
                {
                    this.DrawString(canvas, x - this.LegendsFontSize, Height * 0.95, getMesString(i++));
                }
                else
                {
                    this.DrawString(canvas, x - this.LegendsFontSize, Height * 0.95, Convert.ToString(i++));
                }

                x += xGap;
            }
            this.DrawString(canvas, Margin.X - this.LegendsFontSize * 1.5, Margin.Y - this.LegendsFontSize, "Cantidad");
            this.DrawString(canvas, Margin.Width / 2 - this.LegendsFontSize, Margin.Height + 5 * this.LegendsFontSize, this.Titulo);

            canvas.Stroke();
        }
Beispiel #52
0
 public void DrawRowCursor(Cairo.Context cr, int x, int y, int width, int height)
 {
     Cairo.Color color = CairoExtensions.GdkRGBAToCairoColor(Widget.StyleContext.GetBackgroundColor(StateFlags.Selected));
     DrawRowCursor(cr, x, y, width, height, color);
 }
Beispiel #53
0
 /// <summary>
 /// Escribe el string <paramref name="text"/> en un punto definido por Gdk.Point
 /// </summary>
 /// <param name="canvas">Canvas.</param>
 /// <param name="pos">Punto.</param>
 /// <param name="text">Texto.</param>
 private void DrawString(Cairo.Context canvas, Gdk.Point pos, string text)
 {
     this.DrawString(canvas, pos.X, pos.Y, text);
 }
Beispiel #54
0
 public void DrawRowCursor(Cairo.Context cr, int x, int y, int width, int height, Cairo.Color color)
 {
     DrawRowCursor(cr, x, y, width, height, color, CairoCorners.All);
 }
        /// <summary>
        /// Draws a layout with a given style to the render context.
        /// </summary>
        /// <param name="displayContext">The display context.</param>
        /// <param name="renderContext">The render context.</param>
        /// <param name="region">The region for the various elements.</param>
        /// <param name="style">The style used for borders and padding.</param>
        public static void DrawLayout(
            IDisplayContext displayContext,
            IRenderContext renderContext,
            Rectangle region,
            BlockStyle style)
        {
            // If we don't have a style, then don't do anything.
            if (style == null)
            {
                return;
            }

            // Get the style for the line number.
            Spacing margins = style.GetMargins();
            Borders borders = style.GetBorders();

            double marginLeftX  = margins.Left + borders.Left.LineWidth;
            double marginRightX = margins.Right + borders.Right.LineWidth;

            // Get the context and save settings because we use anti-aliasing
            // to get a sharper line.
            Context   cairoContext = renderContext.CairoContext;
            Antialias oldAntialias = cairoContext.Antialias;

            try
            {
                // Draw the background color.
                Color?backgroundColor = style.GetBackgroundColor();

                if (backgroundColor.HasValue)
                {
                    var cairoArea = new Rectangle(
                        region.X + marginLeftX,
                        region.Y,
                        region.Width - marginLeftX - marginRightX,
                        region.Height);

                    cairoContext.Color = backgroundColor.Value;
                    cairoContext.Rectangle(cairoArea);
                    cairoContext.Fill();
                }

                // Figure out the width for rendering the horizontal borders so
                // they line up a little bit nicer. We adjust for half the border
                // width because Cairo draws in the middle and we have to shift by
                // half that to get the side to line up with the end of the
                // horizontal.
                double topMarginY    = region.Y + margins.Top;
                double bottomMarginY = region.Y + region.Height - margins.Bottom;

                double leftMarginX  = region.X + margins.Left + (borders.Left.LineWidth / 2);
                double rightMarginX = leftMarginX + region.Width - margins.Width;

                // Draw the border lines.
                cairoContext.Antialias = Antialias.None;

                if (borders.Top.LineWidth > 0)
                {
                    // Set up the line width and colors.
                    cairoContext.LineWidth = borders.Top.LineWidth;
                    cairoContext.Color     = borders.Top.Color;

                    cairoContext.MoveTo(leftMarginX, topMarginY);
                    cairoContext.LineTo(rightMarginX, topMarginY);
                    cairoContext.Stroke();
                }

                if (borders.Bottom.LineWidth > 0)
                {
                    cairoContext.LineWidth = borders.Bottom.LineWidth;
                    cairoContext.Color     = borders.Bottom.Color;

                    cairoContext.MoveTo(leftMarginX, bottomMarginY);
                    cairoContext.LineTo(rightMarginX, bottomMarginY);
                    cairoContext.Stroke();
                }

                if (borders.Left.LineWidth > 0)
                {
                    cairoContext.LineWidth = borders.Left.LineWidth;
                    cairoContext.Color     = borders.Left.Color;

                    cairoContext.MoveTo(region.X + marginLeftX, topMarginY);
                    cairoContext.LineTo(region.X + marginLeftX, bottomMarginY);
                    cairoContext.Stroke();
                }

                if (borders.Right.LineWidth > 0)
                {
                    cairoContext.LineWidth = borders.Right.LineWidth;
                    cairoContext.Color     = borders.Right.Color;

                    cairoContext.MoveTo(region.X + region.Width - margins.Right, topMarginY);
                    cairoContext.LineTo(region.X + region.Width - margins.Right, bottomMarginY);
                    cairoContext.Stroke();
                }
            }
            finally
            {
                // Restore the context.
                cairoContext.Antialias = oldAntialias;
            }
        }
Beispiel #56
0
 public abstract void DrawRowCursor(Cairo.Context cr, int x, int y, int width, int height, Cairo.Color color, CairoCorners corners);
Beispiel #57
0
 public abstract void DrawFrameBorder(Cairo.Context cr, Gdk.Rectangle alloc);
Beispiel #58
0
 public void DrawFrameBackground(Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color)
 {
     DrawFrameBackground(cr, alloc, color, null);
 }
Beispiel #59
0
 public abstract void DrawFrameBackground(Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color, Cairo.Pattern pattern);
Beispiel #60
0
 public abstract void DrawHeaderBackground(Cairo.Context cr, Gdk.Rectangle alloc);