Restore() public method

public Restore ( ) : void
return void
Ejemplo n.º 1
0
    //draw bar with specific (w)idth, (h)eight, grayscale (c)olor and fill level
    public void drawbar(Cairo.Context context, int w, int h, int c, double fill)
    {
        context.Save();
        context.LineWidth = 0.75;
        //Fill the area
        double gray_value = ColorChan(c);

        context.SetSourceRGB(gray_value, gray_value, gray_value);
        context.Rectangle(0, 0, w, h);
        context.Fill();
        //White color
        context.SetSourceRGB(1, 1, 1);
        //Updated coordinates with offset
        int h0 = 10, x0 = 10, w0 = w - x0, y0 = (h - 10) / 2, w1 = w0 - x0;

        context.Rectangle(x0, y0, w1, h0);
        context.Fill();
        //Fill the bar
        double r = ColorChan(255), g = ColorChan(186), b = ColorChan(0);

        context.SetSourceRGB(r, g, b);
        context.Rectangle(x0, y0, w1 * fill, h0);
        context.Fill();
        //Draw shadow of the bar
        gray_value = 0.2;
        for (int i = 0; i < 3; ++i)
        {
            context.SetSourceRGB(gray_value, gray_value, gray_value);
            drawshadow(context, x0 + i, y0 + i, w0 + i, h0 + i);
            context.LineWidth -= 0.2;
            gray_value        += 0.3;
        }
        context.Restore();
    }
Ejemplo n.º 2
0
        public void DrawObject(Context ctx, DrawingObject body)
        {
            if (body == null)
                return;
            ctx.Save ();
            ctx.Color = new Cairo.Color (0, 0, 0);

            ctx.LineWidth = 1;
            foreach (Tuple<PointDouble, PointDouble> line in body.lines) {
                ctx.MoveTo (line.Item1.toPointD());
                ctx.LineTo (line.Item2.toPointD());
            }

            if (body.points.Count > 1)
                ctx.Rectangle(body._centerOfMass.X - 5, body._centerOfMass.Y - 5, 10, 10);
            ctx.Stroke ();

            foreach (PointDouble point in body.points) {
                ctx.Rectangle (point.X - 5, point.Y - 5, 10, 10);
                ctx.Fill ();
            }
            foreach (Tuple<PointDouble, double, double> force in body._forces) {
                DrawForce (ctx, force);
            }

            foreach (Tuple<PointDouble, double> moment in body._moments) {
                DrawMoment (ctx, moment);
            }

            ctx.Restore ();
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
    void Draw(Context cr, int width, int height)
    {
        cr.LineWidth = 1.0;
        cr.Color = new Color(1.0, 1.0, 1.0);
        cr.Rectangle(0, 0, width, height);
        cr.Fill();

        cr.Save();
        cr.Scale(scale_factor, scale_factor);
        try
        {
            if(diagram != null)
            {
                DiagramRenderer dr = new DiagramRenderer(cr, width, height, diagram);
                cr.Color = new Color(0.0, 0.0, 0.0);
                dr.Render();
                dr.Draw();
            }
        }
        catch
        {
            error_counter++;
        }
        cr.Restore();
    }
        protected override void Draw(Context cr, Pixbuf prev, Pixbuf next, int width, int height, double progress)
        {
            cr.Color = new Color (0, 0, 0, progress);
            if (next != null) {
                double scale = Math.Min ((double)width/(double)next.Width, (double)height/(double)next.Height);
                cr.Save ();

                cr.Rectangle (0, 0, width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, height - .5 * (height - scale*next.Height), width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (width - .5 * (width - scale*next.Width), 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (0, 0, width, height);
                cr.Scale (scale, scale);
                CairoHelper.SetSourcePixbuf (cr, next, .5 * ((double)width/scale - next.Width), .5 * ((double)height/scale - next.Height));
                cr.PaintWithAlpha (progress);
                cr.Restore ();
            }
        }
Ejemplo n.º 6
0
 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++;
             }
         }
     }
 }
Ejemplo n.º 7
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);
  }
Ejemplo n.º 8
0
	void FillChecks (Context cr, int x, int y, int width, int height)
	{
		int CHECK_SIZE = 32;
		
		cr.Save ();
		Surface check = cr.Target.CreateSimilar (Content.Color, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
		
		// draw the check
		using (Context cr2 = new Context (check)) {
			cr2.Operator = Operator.Source;
			cr2.Color = new Color (0.4, 0.4, 0.4);
			cr2.Rectangle (0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
			cr2.Fill ();

			cr2.Color = new Color (0.7, 0.7, 0.7);
			cr2.Rectangle (x, y, CHECK_SIZE, CHECK_SIZE);
			cr2.Fill ();

			cr2.Rectangle (x + CHECK_SIZE, y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE);
			cr2.Fill ();
		}

		// Fill the whole surface with the check
		SurfacePattern check_pattern = new SurfacePattern (check);
		check_pattern.Extend = Extend.Repeat;
		cr.Source = check_pattern;
		cr.Rectangle (0, 0, width, height);
		cr.Fill ();

		check_pattern.Destroy ();
		check.Destroy ();
		cr.Restore ();
	}
Ejemplo n.º 9
0
 protected void OnRender(Context cr, int width, int height)
 {
     cr.Save();
     cr.SetSourceRGBA(1, 0, 0, mTick*0.1);
     cr.Rectangle(0, 0, width, height);
     cr.Fill();
     cr.Restore();
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Erase the handle that was drawn in a previous call to Render ().
        /// </summary>
        public void Clear (Context g)
        {
            g.Save ();

            var rect = GetHandleRect ().Inflate (2, 2);
            using (var path = g.CreateRectanglePath (rect))
                g.AppendPath (path);
            g.Operator = Operator.Clear;
            g.Fill ();

            g.Restore ();
        }
		public override void BasicDraw (Context context) {
			RectangleD displayBox = DisplayBox;

			context.LineWidth = LineWidth;
			context.Save ();
			displayBox.OffsetDot5 ();
			context.Rectangle (GdkCairoHelper.CairoRectangle(displayBox));
			context.Restore ();
			context.Color = FillColor;
			context.FillPreserve ();
			context.Color = LineColor;
			context.Stroke ();
		}
Ejemplo n.º 12
0
        protected override void Draw(Context cr, Pixbuf prev, Pixbuf next, int width, int height, double progress)
        {
            cr.SetSourceColor (new Color (0, 0, 0));
            if (prev != null) {
                double scale = Math.Min ((double)width/(double)prev.Width, (double)height/(double)prev.Height);
                cr.Save ();
                cr.Translate (-progress * width, 0);

                cr.Rectangle (0, 0, width, .5 * (height - scale*prev.Height));
                cr.Fill ();

                cr.Rectangle (0, height - .5 * (height - scale*prev.Height), width, .5 * (height - scale*prev.Height));
                cr.Fill ();

                cr.Rectangle (0, 0, .5 * (width - scale*prev.Width), height);
                cr.Fill ();

                cr.Rectangle (width - .5 * (width - scale*prev.Width), 0, .5 * (width - scale*prev.Width), height);
                cr.Fill ();

                cr.Rectangle (0, 0, width, height);
                cr.Scale (scale, scale);
                CairoHelper.SetSourcePixbuf (cr, prev, .5 * ((double)width/scale - prev.Width), .5 * ((double)height/scale - prev.Height));
                cr.Fill ();
                cr.Restore ();
            }
            if (next != null) {
                double scale = Math.Min ((double)width/(double)next.Width, (double)height/(double)next.Height);
                cr.Save ();
                cr.Translate (width * (1.0 - progress), 0);

                cr.Rectangle (0, 0, width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, height - .5 * (height - scale*next.Height), width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (width - .5 * (width - scale*next.Width), 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (0, 0, width, height);
                cr.Scale (scale, scale);
                CairoHelper.SetSourcePixbuf (cr, next, .5 * ((double)width/scale - next.Width), .5 * ((double)height/scale - next.Height));
                cr.Fill ();
                cr.Restore ();
            }
        }
Ejemplo n.º 13
0
        public override void Draw(Context context)
        {
            double middle = DisplayBox.Width / 2.0;

            context.LineWidth = LineWidth;
            context.Save ();
            context.Translate (DisplayBox.X + middle, DisplayBox.Y + middle);
            context.Arc (0.0, 0.0, middle, 0.0, 2.0 * Math.PI);
            context.Restore ();
            context.Color = new Cairo.Color (1.0, 1.0, 0.2, 0.2);
            context.FillPreserve ();
            context.Color = new Cairo.Color (0.0, 0.0, 0.0, 1.0);
            context.Stroke ();
        }
		protected override void DrawBackground (Context context, Gdk.Rectangle region)
		{
			LayoutRoundedRectangle (context, region);
			context.Clip ();

			context.SetSourceColor (CairoExtensions.ParseColor ("D3E6FF"));
			context.Paint ();

			context.Save ();
			context.Translate (region.X + region.Width / 2.0, region.Y + region.Height);

			using (var rg = new RadialGradient (0, 0, 0, 0, 0, region.Height * 1.2)) {
				var color = CairoExtensions.ParseColor ("E5F0FF");
				rg.AddColorStop (0, color);
				color.A = 0;
				rg.AddColorStop (1, color);

				context.Scale (region.Width / (double)region.Height, 1.0);
				context.SetSource (rg);
				context.Paint ();
			}

			context.Restore ();

			LayoutRoundedRectangle (context, region, -3, -3, 2);
			context.SetSourceRGBA (1, 1, 1, 0.4);
			context.LineWidth = 1;
			context.StrokePreserve ();

			context.Clip ();

			int boxSize = 11;
			int x = region.Left + (region.Width % boxSize) / 2;
			for (; x < region.Right; x += boxSize) {
				context.MoveTo (x + 0.5, region.Top);
				context.LineTo (x + 0.5, region.Bottom);
			}

			int y = region.Top + (region.Height % boxSize) / 2;
			y += boxSize / 2;
			for (; y < region.Bottom; y += boxSize) {
				context.MoveTo (region.Left, y + 0.5);
				context.LineTo (region.Right, y + 0.5);
			}

			context.SetSourceRGBA (1, 1, 1, 0.2);
			context.Stroke ();

			context.ResetClip ();
		}
Ejemplo n.º 15
0
		public static void Main(string[] args)
		{
			// call the snippets
			Snippets snip = new Snippets();
			Surface surface = new PSSurface("snippets.ps", IMAGE_WIDTH, IMAGE_WIDTH);
			Context cr = new Context(surface);
			foreach (string snippet in Snippets.snippets)
			{
				cr.Save();
				Snippets.InvokeSnippet(snip, snippet, cr, IMAGE_WIDTH, IMAGE_HEIGHT);
				cr.ShowPage();
				cr.Restore();
			}
			surface.Finish ();
		}
Ejemplo n.º 16
0
		public override void Draw (Context context, IDrawingView view) {
			RectangleD rect = ViewDisplayBox(view);
			
			double middle = rect.Width / 2.0;

			context.LineWidth = LineWidth;
			context.Save ();
			context.Translate (rect.X + middle, rect.Y + middle);
			context.Arc (0.0, 0.0, middle, 0.0, 2.0 * Math.PI);
			context.Restore ();
			context.Color = new Cairo.Color (0.2, 0.2, 1.0, 0.5);
			context.FillPreserve ();
			context.Color = new Cairo.Color (0.0, 0.0, 0.0, 1.0);
			context.Stroke ();
		}
Ejemplo n.º 17
0
		public override void BasicDraw (Context context) {
			double midwidth  = DisplayBox.Width / 2.0;
			double midheight = DisplayBox.Height / 2.0;

			context.LineWidth = LineWidth;
			context.Save ();
			context.Translate (DisplayBox.X + midwidth, DisplayBox.Y + midheight);
			context.Scale (midwidth - 1.0, midheight - 1.0);
			context.Arc (0.0, 0.0, 1.0, 0.0, 2.0 * Math.PI);
			context.Restore ();
			context.Color = FillColor;
			context.FillPreserve ();
			context.Color = LineColor;
			context.Stroke ();
		}
Ejemplo n.º 18
0
		public static void Main(string[] args)
		{
			// call the snippets
			Snippets snip = new Snippets();
			foreach (string snippet in Snippets.snippets)
			{
				string filename = "./" + snippet + ".png";
				Surface surface = new ImageSurface(Format.ARGB32, IMAGE_WIDTH, IMAGE_WIDTH);
				Context cr = new Context(surface);
			
				cr.Save();
				Snippets.InvokeSnippet(snip, snippet, cr, IMAGE_WIDTH, IMAGE_HEIGHT);
				surface.WriteToPng(filename);
				cr.Restore();
			}
		}
Ejemplo n.º 19
0
 public override void Run()
 {
     StripCanvasSize scs = this.Manager.GenerateStripCanvasSize (0x01);
     using (PdfSurface surface = new PdfSurface (this.Manager.OutputFile, scs.TotalWidth, scs.TotalHeight)) {
         using (Context ctx = new Context (surface)) {
             IPoint3 p = scs.GetCanvasOffset (0x00);
             ctx.Save ();
             ctx.Translate (p.X, p.Y);
             this.Theory.Time = this.Manager.Time;
             CairoEngine engine = new CairoEngine (this.Theory);
             engine.Context = ctx;
             engine.Process ();
             ctx.Restore ();
         }
     }
 }
Ejemplo n.º 20
0
		public static void Main(string[] args)
		{
			// call the snippets
			Snippets snip = new Snippets();
			foreach (string snippet in Snippets.snippets)
			{
				string filename = "./" + snippet + ".svg";
				Surface surface = new SvgSurface(filename, IMAGE_WIDTH, IMAGE_WIDTH);
				Context cr = new Context(surface);
			
				cr.Save();
				Snippets.InvokeSnippet(snip, snippet, cr, IMAGE_WIDTH, IMAGE_HEIGHT);
				cr.ShowPage();
				cr.Restore();
				surface.Finish ();
			}
		}
Ejemplo n.º 21
0
        protected override void RenderExpander(Context context, Gdk.Rectangle pix_rect)
        {
            Gdk.Pixbuf expander;

            if (IsExpanded)
                expander = new Gdk.Pixbuf(ExpandedIcon);
            else
                expander = new Gdk.Pixbuf(CollapsedIcon);

            context.Save();

            Gdk.CairoHelper.SetSourcePixbuf(context, expander, pix_rect.Left, pix_rect.Y);

            m_TextXOffset = expander.Width;

            context.Paint();
            context.Restore();
        }
Ejemplo n.º 22
0
		protected override Gdk.Rectangle OnMouseMove (Context g, Color strokeColor, ImageSurface surface,
		                                              int x, int y, int lastX, int lastY)
		{
			int line_width = (int)g.LineWidth;
			int size;

			// we want a minimum size of 2 for the splatter (except for when the brush width is 1), since a splatter of size 1 is very small
			if (line_width == 1)
			{
				size = 1;
			}
			else
			{
				size = Random.Next (2, line_width);
			}

			Rectangle r = new Rectangle (x - Random.Next (-15, 15), y - Random.Next (-15, 15), size, size);

			double rx = r.Width / 2;
			double ry = r.Height / 2;
			double cx = r.X + rx;
			double cy = r.Y + ry;
			double c1 = 0.552285;

			g.Save ();

			g.MoveTo (cx + rx, cy);

			g.CurveTo (cx + rx, cy - c1 * ry, cx + c1 * rx, cy - ry, cx, cy - ry);
			g.CurveTo (cx - c1 * rx, cy - ry, cx - rx, cy - c1 * ry, cx - rx, cy);
			g.CurveTo (cx - rx, cy + c1 * ry, cx - c1 * rx, cy + ry, cx, cy + ry);
			g.CurveTo (cx + c1 * rx, cy + ry, cx + rx, cy + c1 * ry, cx + rx, cy);

			g.ClosePath ();

			Rectangle dirty = g.FixedStrokeExtents ();

			g.Fill ();
			g.Restore ();

			return dirty.ToGdkRectangle ();
		}
Ejemplo n.º 23
0
        protected override void onDraw(Context gr)
        {
            base.onDraw (gr);

            Rectangle r = ClientRectangle;
            Point m = r.Center;

            gr.Save ();

            double aUnit = Math.PI*2.0 / (Maximum - Minimum);
            gr.Translate (m.X, r.Height *1.1);
            gr.Rotate (Value/4.0 * aUnit - Math.PI/4.0);
            gr.Translate (-m.X, -m.Y);

            gr.LineWidth = 2;
            Foreground.SetAsSource (gr);
            gr.MoveTo (m.X,0.0);
            gr.LineTo (m.X, -m.Y*0.5);
            gr.Stroke ();

            gr.Restore ();
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Exports the specified <see cref="PlotModel" /> to a png file.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="fileName">Name of the output file.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="background">The background color.</param>
        public static void Export(IPlotModel model, string fileName, int width, int height, Pattern background = null)
        {
            using (var bm = new ImageSurface(Format.ARGB32, width, height))
            {
                using (var g = new Context(bm))
                {
                    if (background != null)
                    {
                        g.Save();
                        g.SetSource(background);
                        g.Rectangle(0, 0, width, height);
                        g.Fill();
                        g.Restore();
                    }

                    var rc = new GraphicsRenderContext { RendersToScreen = false };
                    rc.SetGraphicsTarget(g);
                    model.Update(true);
                    model.Render(rc, width, height);
                    bm.WriteToPng(fileName);
                }
            }
        }
Ejemplo n.º 25
0
 private void ClearGraph(Context ctx)
 {
     ctx.Save();
     ctx.Operator = Operator.Clear;
     ctx.Paint();
     ctx.Restore();
 }
Ejemplo n.º 26
0
    private void DrawGraphCurve()
    {
        if (MainNotebook.CurrentPage == 1 && CurveSelectBox.Active != -1)
        {
            GCurves.GCurve SelCurve;
            AllCurves.Curves.TryGetValue(CurveSelectBox.ActiveText, out SelCurve);

            using (Context CurveGraphCtx = new Context(CurveGraph))
            {
                CurveGraphCtx.Antialias = Antialias.Subpixel;
                CurveGraphCtx.LineWidth = 1;

                ClearGraph(CurveGraphCtx);
                List<PointF> MovePoints = new List<PointF>();

                //drawing the Brightness Input
                if (AllCurves.BrInCurve != null && CurveSelectBox.ActiveText == GCurves.CurveName.Exposure_Compensation.ToString())
                {
                    CurveGraphCtx.Color = new Cairo.Color(0, 0, 1);
                    CurveGraphCtx.LineWidth = 0.8;
                    for (int i = 0; i < AllCurves.BrInCurve.Points.Count; i++)
                    {
                        MovePoints.Add(GetGraphXY(AllCurves.BrInCurve.Points[i].Value));
                    }
                    CurveGraphCtx.MoveTo(MovePoints[0].X, MovePoints[0].Y);
                    for (int i = 1; i < MovePoints.Count; i++)
                    {
                        CurveGraphCtx.LineTo(MovePoints[i].X, MovePoints[i].Y);
                    }
                    CurveGraphCtx.Stroke();
                }

                if (SelCurve.Points.Count >= 2)
                {
                    //Drawing the output curve
                    CurveGraphCtx.Color = new Cairo.Color(0, 1, 0);
                    PointF[] DrawPoints = new PointF[200];
                    GetGraphXY(SelCurve.GetSmoothCurve(200)).CopyTo(DrawPoints);
                    List<PointF> Cpoints = new List<PointF>();
                    for (int i = 0; i < SelCurve.Points.Count; i++)
                    {
                        Cpoints.Add(GetGraphXY(SelCurve.Points[i].Value));
                    }

                    CurveGraphCtx.MoveTo(DrawPoints[0].X, DrawPoints[0].Y);

                    for (int i = 0; i < DrawPoints.Length; i++)
                    {
                        CurveGraphCtx.LineTo(DrawPoints[i].X, DrawPoints[i].Y);
                    }
                    CurveGraphCtx.Stroke();

                    
                    //Draw the activated point
                    CurveGraphCtx.Color = new Cairo.Color(0.8, 0.8, 0);
                    CurveGraphCtx.Arc(Cpoints[SelCurve.SelectedPoint].X, Cpoints[SelCurve.SelectedPoint].Y, 3, 0, 2 * Math.PI);
                    CurveGraphCtx.Fill();

                    //Draw the control points
                    CurveGraphCtx.Color = new Cairo.Color(0, 0, 0);
                    for (int i = 0; i < SelCurve.Points.Count; i++)
                    {
                        if (i != SelCurve.SelectedPoint && !SelCurve.Points[i].Key ) { CurveGraphCtx.Arc(Cpoints[i].X, Cpoints[i].Y, 3, 0, 2 * Math.PI); CurveGraphCtx.Fill(); }
                        else if (SelCurve.Points[i].Key)
                        {
                            CurveGraphCtx.Save();
                            CurveGraphCtx.Color = new Cairo.Color(0.8, 0, 0);
                            CurveGraphCtx.Arc(Cpoints[i].X, Cpoints[i].Y, 3, 0, 2 * Math.PI);
                            CurveGraphCtx.Fill();
                            CurveGraphCtx.Restore();
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 27
0
        public virtual void Render(Context cr, Gdk.Rectangle area, Color color, bool showEmptyStars, bool isHovering,
            int hoverValue, double fillOpacity, double hoverFillOpacity, double strokeOpacity)
        {
            if (Value == MinRating && !isHovering && !showEmptyStars) {
                return;
            }

            cr.Save ();

            Cairo.Color fill_color = color;
            fill_color.A = fillOpacity;
            Cairo.Color stroke_color = fill_color;
            stroke_color.A = strokeOpacity;
            Cairo.Color hover_fill_color = fill_color;
            hover_fill_color.A = hoverFillOpacity;

            double x, y;
            ComputePosition (area, out x, out y);

            cr.LineWidth = 1.0;
            cr.Translate (0.5, 0.5);

            for (int i = MinRating + 1, s = isHovering || showEmptyStars ? MaxRating : Value; i <= s; i++, x += Size) {
                bool fill = i <= Value && Value > MinRating;
                bool hover_fill = i <= hoverValue && hoverValue > MinRating;
                double scale = fill || hover_fill ? Size : Size - 2;
                double ofs = fill || hover_fill ? 0 : 1;

                for (int p = 0, n = star_plot.GetLength (0); p < n; p++) {
                    double px = x + ofs + star_plot[p, 0] * scale;
                    double py = y + ofs + star_plot[p, 1] * scale;
                    if (p == 0) {
                        cr.MoveTo (px, py);
                    } else {
                        cr.LineTo (px, py);
                    }
                }
                cr.ClosePath ();

                if (fill || hover_fill) {
                    if (!isHovering || hoverValue >= Value) {
                        cr.SetSourceColor (fill ? fill_color : hover_fill_color);
                    } else {
                        cr.SetSourceColor (hover_fill ? fill_color : hover_fill_color);
                    }
                    cr.Fill ();
                } else {
                    cr.SetSourceColor (stroke_color);
                    cr.Stroke ();
                }
            }
            cr.Restore ();
        }
Ejemplo n.º 28
0
        private void DrawImage(Context cr, Gdk.Pixbuf pixbuf, double x, double y, double w, double h)
        {
            double scalex, scaley;
            switch (fit) {
            case CustomPrintWidget.FitMode.Zoom:
                scalex = scaley = Math.Max (w/pixbuf.Width, h/pixbuf.Height);
                break;
            case CustomPrintWidget.FitMode.Fill:
                scalex = w/pixbuf.Width;
                scaley = h/pixbuf.Height;
                break;
            default:
            case CustomPrintWidget.FitMode.Scaled:
                scalex = scaley = Math.Min (w/pixbuf.Width, h/pixbuf.Height);
                break;
            }

            double rectw = w / scalex;
            double recth = h / scaley;

            cr.Save ();
            if (white_borders)
                cr.Translate (w * .025, h * .025);

            cr.Translate (x, y);
            if (white_borders)
                cr.Scale (.95, .95);
            cr.Scale (scalex, scaley);
            cr.Rectangle (0, 0, rectw, recth);
            Gdk.CairoHelper.SetSourcePixbuf (cr, pixbuf, (rectw - pixbuf.Width) / 2.0, (recth - pixbuf.Height) / 2.0);
            cr.Fill ();

            if (white_borders) {
                cr.Rectangle (0, 0 ,rectw, recth);
                cr.Color = new Color (0, 0, 0);
                cr.LineWidth = 1 / scalex;
                cr.Stroke ();
            }
            cr.Restore ();
        }
Ejemplo n.º 29
0
 private void DrawCropMarks(Context cr, double x, double y, double length)
 {
     cr.Save ();
     cr.Color = new Color (0, 0, 0);
     cr.MoveTo (x - length/2, y);
     cr.LineTo (x + length/2, y);
     cr.MoveTo (x, y - length/2);
     cr.LineTo (x, y + length/2);
     cr.LineWidth = .2;
     cr.SetDash (new double[] {length*.4, length*.2}, 0);
     cr.Stroke ();
     cr.Restore ();
 }
Ejemplo n.º 30
0
 public override void Render( Context c)
 {
     c.Save();
     if(true){
         Cairo.PointD p1 = new Cairo.PointD(line.Location.X ,line.Location.Y);
         Cairo.PointD p2 = new Cairo.PointD(line.End.X, line.End.Y);
      		c.DrawLine(p1,p2,line.BackgroundColor.ToCairoColor(), line.LineWidth,line.LineType,true);
     }
     c.Restore();
 }
Ejemplo n.º 31
0
		public static void CachedDraw (this Cairo.Context self, ref SurfaceWrapper surface, Gdk.Rectangle region, 
		                               object parameters = null, float opacity = 1.0f, Action<Cairo.Context, float> draw = null, double? forceScale = null)
		{
			double displayScale = forceScale.HasValue ? forceScale.Value : QuartzSurface.GetRetinaScale (self);
			int targetWidth = (int) (region.Width * displayScale);
			int targetHeight = (int) (region.Height * displayScale);

			bool redraw = false;
			if (surface == null || surface.Width != targetWidth || surface.Height != targetHeight) {
				if (surface != null)
					surface.Dispose ();
				surface = new SurfaceWrapper (self, targetWidth, targetHeight);
				redraw = true;
			} else if ((surface.Data == null && parameters != null) || (surface.Data != null && !surface.Data.Equals (parameters))) {
				redraw = true;
			}


			if (redraw) {
				surface.Data = parameters;
				using (var context = new Cairo.Context (surface.Surface)) {
					context.Operator = Operator.Clear;
					context.Paint();
					context.Operator = Operator.Over;
					context.Save ();
					context.Scale (displayScale, displayScale);
					draw(context, 1.0f);
					context.Restore ();
				}
			}

			self.Save ();
			self.Translate (region.X, region.Y);
			self.Scale (1 / displayScale, 1 / displayScale);
			self.SetSourceSurface (surface.Surface, 0, 0);
			self.PaintWithAlpha (opacity);
			self.Restore ();
		}
Ejemplo n.º 32
0
        protected override void onDraw(Cairo.Context gr)
        {
            base.onDraw(gr);

            Rectangle cb = new Rectangle(0, 0, designWidth, designHeight);             // ClientRectangle;

            gr.Save();

            double z = zoom / 100.0;

            gr.Scale(z, z);

            if (drawGrid)
            {
                double gridLineWidth = 0.2 / z;
                double glhw          = gridLineWidth / 2.0;
                int    nbLines       = cb.Width / gridSpacing;
                double d             = cb.Left + gridSpacing;
                for (int i = 0; i < nbLines; i++)
                {
                    gr.MoveTo(d - glhw, cb.Y);
                    gr.LineTo(d - glhw, cb.Bottom);
                    d += gridSpacing;
                }
                nbLines = cb.Height / gridSpacing;
                d       = cb.Top + gridSpacing;
                for (int i = 0; i < nbLines; i++)
                {
                    gr.MoveTo(cb.X, d - glhw);
                    gr.LineTo(cb.Right, d - glhw);
                    d += gridSpacing;
                }
                gr.LineWidth = gridLineWidth;
                Foreground.SetAsSource(gr, cb);
                gr.Stroke();
            }

            lock (imlVE.RenderMutex) {
                using (Cairo.Surface surf = new Cairo.ImageSurface(imlVE.bmp, Cairo.Format.Argb32,
                                                                   imlVE.ClientRectangle.Width, imlVE.ClientRectangle.Height, imlVE.ClientRectangle.Width * 4)) {
                    gr.SetSourceSurface(surf, cb.Left, cb.Top);
                    gr.Paint();
                }
                imlVE.IsDirty = false;
            }
            if (Error == null)
            {
                gr.SetSourceColor(Color.Black);
                gr.Rectangle(cb, 1.0 / z);
            }
            else
            {
                gr.SetSourceColor(Color.LavenderBlush);
                gr.Rectangle(cb, 2.0 / z);
                string[] lerrs = Error.ToString().Split('\n');
                Point    p     = cb.Center;
                p.Y -= lerrs.Length * 20;
                foreach (string le in lerrs)
                {
                    drawCenteredTextLine(gr, p, le);
                    p.Y += 20;
                }
            }
            gr.Stroke();

            Rectangle hr;

            if (SelectedItem?.Parent != null)
            {
                gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight);
                gr.SetFontSize(Font.Size);
                gr.FontOptions = Interface.FontRenderingOptions;
                gr.Antialias   = Interface.Antialias;

                GraphicObject g = SelectedItem;
                hr = g.ScreenCoordinates(g.getSlot());

//				Rectangle rIcons = new Rectangle (iconSize);
//				rIcons.Width *= 4;
//				rIcons.Top = hr.Bottom;
//				rIcons.Left = hr.Right - rIcons.Width + iconSize.Width;
                Rectangle rIcoMove = new Rectangle(hr.BottomRight, iconSize);
//				Rectangle rIcoStyle = rIcoMove;
//				rIcoStyle.Left += iconSize.Width + 4;

                using (Surface mask = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) {
                    using (Context ctx = new Context(mask)) {
                        ctx.Save();
                        ctx.SetSourceRGBA(1.0, 1.0, 1.0, 0.4);
                        ctx.Paint();
                        ctx.Rectangle(hr);
                        ctx.Operator = Operator.Clear;
                        ctx.Fill();
                    }

                    gr.SetSourceSurface(mask, 0, 0);
                    gr.Paint();

                    using (Surface ol = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) {
                        using (Context ctx = new Context(ol)) {
                            ctx.SetSourceColor(Color.Black);
                            drawDesignOverlay(ctx, g, cb, hr, 0.4 / z, 6.5);
                        }

                        gr.SetSourceSurface(ol, 0, 0);
                        gr.Paint();
                    }

                    drawIcon(gr, icoMove, rIcoMove);
                    //drawIcon (gr, icoStyle, rIcoStyle);
                }
            }
            if (HoverWidget != null)
            {
                hr = HoverWidget.ScreenCoordinates(HoverWidget.getSlot());
                gr.SetSourceColor(Color.SkyBlue);
                //gr.SetDash (new double[]{ 5.0, 3.0 }, 0.0);
                gr.Rectangle(hr, 0.4 / z);
            }
            gr.Restore();
        }
Ejemplo n.º 33
0
        void Draw(Cairo.Context ctx, List <TableRow> rowList, int dividerX, int x, ref int y)
        {
            if (!heightMeasured)
            {
                return;
            }

            Pango.Layout layout       = new Pango.Layout(PangoContext);
            TableRow     lastCategory = null;

            Pango.FontDescription defaultFont = new Pango.FontDescription();
            Pango.FontDescription changedFont = defaultFont.Copy();
            defaultFont.Weight = Pango.Weight.Bold;

            foreach (var r in rowList)
            {
                int w, h;
                layout.SetText(r.Label);
                if (r.IsDefaultValue && (r.Expanded || HasDefaultValue(r.ChildRows)))
                {
                    layout.FontDescription = changedFont;
                }
                else
                {
                    layout.FontDescription = defaultFont;
                }
                layout.GetPixelSize(out w, out h);
                int indent = 0;

                if (r.IsCategory)
                {
                    var rh = h + CategoryTopBottomPadding * 2;
                    ctx.Rectangle(0, y, Allocation.Width, rh);
                    using (var gr = new LinearGradient(0, y, 0, rh)) {
                        gr.AddColorStop(0, new Cairo.Color(248d / 255d, 248d / 255d, 248d / 255d));
                        gr.AddColorStop(1, new Cairo.Color(240d / 255d, 240d / 255d, 240d / 255d));
                        ctx.SetSource(gr);
                        ctx.Fill();
                    }

                    if (lastCategory == null || lastCategory.Expanded || lastCategory.AnimatingExpand)
                    {
                        ctx.MoveTo(0, y + 0.5);
                        ctx.LineTo(Allocation.Width, y + 0.5);
                    }
                    ctx.MoveTo(0, y + rh - 0.5);
                    ctx.LineTo(Allocation.Width, y + rh - 0.5);
                    ctx.SetSourceColor(DividerColor);
                    ctx.Stroke();

                    ctx.MoveTo(x, y + CategoryTopBottomPadding);
                    ctx.SetSourceColor(CategoryLabelColor);
                    Pango.CairoHelper.ShowLayout(ctx, layout);

                    var img  = r.Expanded ? discloseUp : discloseDown;
                    var area = GetCategoryArrowArea(r);

                    CairoHelper.SetSourcePixbuf(ctx, img, area.X + (area.Width - img.Width) / 2, area.Y + (area.Height - img.Height) / 2);
                    ctx.Paint();

                    y           += rh;
                    lastCategory = r;
                }
                else
                {
                    var cell = GetCell(r);
                    r.Enabled = !r.Property.IsReadOnly || cell.EditsReadOnlyObject;
                    var state = r.Enabled ? State : Gtk.StateType.Insensitive;
                    ctx.Save();

                    if (r == lastEditorRow)
                    {
                        ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2);
                        ctx.SetSourceColor(new Cairo.Color(0.8, 0.9, 1.0, 1));
                        ctx.Fill();


                        //int dividerX = (int)((double)Allocation.Width * dividerPosition);
                        //var cell = GetCell(r);
                        //cell.GetSize(Allocation.Width - dividerX, out w, out eh);
                        //eh = Math.Max(h + PropertyTopBottomPadding * 2, eh);
                        //r.EditorBounds = new Gdk.Rectangle(dividerX + PropertyContentLeftPadding, y, Allocation.Width - dividerX - PropertyContentLeftPadding, eh);

                        //var bounds = new Gdk.Rectangle(dividerX + 1, r.EditorBounds.Y, Allocation.Width - dividerX - 1, r.EditorBounds.Height);

                        //ctx.MoveTo(bounds.Right, bounds.Y+1);
                        //ctx.LineTo(bounds.X, bounds.Y+1);
                        //ctx.MoveTo(bounds.Right, bounds.Bottom);
                        //ctx.LineTo(bounds.X, bounds.Bottom);

                        //ctx.Stroke();

                        //ctx.Rectangle(dividerX + 1, r.EditorBounds.Y, Allocation.Width - dividerX - 1, r.EditorBounds.Height);
                        //ctx.SetSourceColor(new Cairo.Color(0.8, 0.9, 1.0, 1));
                        //ctx.Fill();
                    }

                    if (r.ChildRows != null && r.ChildRows.Count > 0)
                    {
                        var img = r.Expanded ? arrowLeft : arrowRight;
                        CairoHelper.SetSourcePixbuf(ctx, img, 2, y + (h + PropertyTopBottomPadding * 2) / 2 - img.Height / 2);
                        ctx.Paint();
                    }

                    ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2);
                    ctx.Clip();
                    ctx.MoveTo(x, y + PropertyTopBottomPadding);
                    ctx.SetSourceColor(Style.Text(state).ToCairoColor());
                    Pango.CairoHelper.ShowLayout(ctx, layout);
                    ctx.Restore();

                    if (r != currentEditorRow)
                    {
                        cell.Render(GdkWindow, ctx, r.EditorBounds, state);
                    }

                    y     += r.EditorBounds.Height;
                    indent = PropertyIndent;
                }

                if (r.ChildRows != null && r.ChildRows.Count > 0 && (r.Expanded || r.AnimatingExpand))
                {
                    int py = y;

                    ctx.Save();
                    if (r.AnimatingExpand)
                    {
                        ctx.Rectangle(0, y, Allocation.Width, r.AnimationHeight);
                    }
                    else
                    {
                        ctx.Rectangle(0, 0, Allocation.Width, Allocation.Height);
                    }

                    ctx.Clip();
                    Draw(ctx, r.ChildRows, dividerX, x + indent, ref y);
                    ctx.Restore();

                    if (r.AnimatingExpand)
                    {
                        y = py + r.AnimationHeight;
                        // Repaing the background because the cairo clip doesn't work for gdk primitives
                        int dx = (int)((double)Allocation.Width * dividerPosition);
                        ctx.Rectangle(0, y, dx, Allocation.Height - y);
                        ctx.SetSourceColor(LabelBackgroundColor);
                        ctx.Fill();
                        ctx.Rectangle(dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y);
                        ctx.SetSourceRGB(1, 1, 1);
                        ctx.Fill();
                    }
                }
            }
        }
Ejemplo n.º 34
0
        void Draw(Cairo.Context ctx, List <TableRow> rowList, int dividerX, int x, ref int y)
        {
            if (!heightMeasured)
            {
                return;
            }

            Pango.Layout layout       = new Pango.Layout(PangoContext);
            TableRow     lastCategory = null;

            foreach (var r in rowList)
            {
                int w, h;
                layout.SetText(r.Label);
                layout.GetPixelSize(out w, out h);
                int indent = 0;

                if (r.IsCategory)
                {
                    var rh = h + CategoryTopBottomPadding * 2;
                    ctx.Rectangle(0, y, Allocation.Width, rh);
                    Cairo.LinearGradient gr = new LinearGradient(0, y, 0, rh);
                    gr.AddColorStop(0, new Cairo.Color(248d / 255d, 248d / 255d, 248d / 255d));
                    gr.AddColorStop(1, new Cairo.Color(240d / 255d, 240d / 255d, 240d / 255d));
                    ctx.SetSource(gr);
                    ctx.Fill();

                    if (lastCategory == null || lastCategory.Expanded || lastCategory.AnimatingExpand)
                    {
                        ctx.MoveTo(0, y + 0.5);
                        ctx.LineTo(Allocation.Width, y + 0.5);
                    }
                    ctx.MoveTo(0, y + rh - 0.5);
                    ctx.LineTo(Allocation.Width, y + rh - 0.5);
                    ctx.SetSourceRGBA(DividerColor.R, DividerColor.G, DividerColor.B, DividerColor.A);

                    ctx.Stroke();

                    ctx.MoveTo(x, y + CategoryTopBottomPadding);
                    ctx.SetSourceRGBA(CategoryLabelColor.R, CategoryLabelColor.G, CategoryLabelColor.B,
                                      CategoryLabelColor.A);
                    Pango.CairoHelper.ShowLayout(ctx, layout);

                    //var img = r.Expanded ? discloseUp : discloseDown;
                    //CairoHelper.SetSourcePixbuf(ctx, img, Allocation.Width - img.Width - CategoryTopBottomPadding, y +(rh - img.Height) / 2);
                    //ctx.Paint();

                    y           += rh;
                    lastCategory = r;
                }
                else
                {
                    var cell = GetCell(r);
                    r.Enabled = !r.Inspector.IsReadOnly || cell.EditsReadOnlyObject;
                    var state = r.Enabled ? State : Gtk.StateType.Insensitive;
                    ctx.Save();
                    ctx.Rectangle(0, y, dividerX, h + InspectorTopBottomPadding * 2);
                    ctx.Clip();
                    ctx.MoveTo(x, y + InspectorTopBottomPadding);
                    Gdk.Color color = Style.Text(state);
                    ctx.SetSourceRGB(color.Red, color.Green, color.Blue);
                    Pango.CairoHelper.ShowLayout(ctx, layout);
                    ctx.Restore();

                    if (r != currentEditorRow)
                    {
                        cell.Render(GdkWindow, r.EditorBounds, state);
                    }

                    y     += r.EditorBounds.Height;
                    indent = InspectorIndent;
                }

                if (r.ChildRows != null && r.ChildRows.Count > 0 && (r.Expanded || r.AnimatingExpand))
                {
                    int py = y;
                    if (r.AnimatingExpand)
                    {
                        ctx.Save();
                        ctx.Rectangle(0, y, Allocation.Width, r.AnimationHeight);
                        ctx.Clip();
                    }

                    Draw(ctx, r.ChildRows, dividerX, x + indent, ref y);

                    if (r.AnimatingExpand)
                    {
                        ctx.Restore();
                        y = py + r.AnimationHeight;
                        // Repaing the background because the cairo clip doesn't work for gdk primitives
                        int dx = (int)((double)Allocation.Width * dividerPosition);
                        ctx.Rectangle(0, y, dx, Allocation.Height - y);
                        ctx.SetSourceRGBA(LabelBackgroundColor.R, LabelBackgroundColor.G,
                                          LabelBackgroundColor.B, LabelBackgroundColor.A);
                        ctx.Fill();
                        ctx.Rectangle(dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y);
                        ctx.SetSourceRGB(1, 1, 1);
                        ctx.Fill();
                    }
                }
            }
        }
    static void draw(Cairo.Context gr, int width, int height)
    {
        Surface overlay, punch, circles;

        /* Fill the background */
        double radius = 0.5 * (width < height ? width : height) - 10;
        double xc     = width / 2;
        double yc     = height / 2;

        Surface target = gr.Target;

        overlay = target.CreateSimilar(Content.ColorAlpha, width, height);
        punch   = target.CreateSimilar(Content.Alpha, width, height);
        circles = target.CreateSimilar(Content.ColorAlpha, width, height);

        gr.Save();
        gr.Target = overlay;

        /* Draw a black circle on the overlay
         */

        gr.Color = new Color(0, 0, 0, 1);

        oval_path(gr, xc, yc, radius, radius);
        gr.Fill();
        gr.Save();
        gr.Target = punch;


        /* Draw 3 circles to the punch surface, then cut
         * that out of the main circle in the overlay
         */
        draw_3circles(gr, xc, yc, radius);

        gr.Restore();

        gr.Operator = Operator.DestOut;
        punch.Show(gr, width, height);


        /* Now draw the 3 circles in a subgroup again
         * at half intensity, and use OperatorAdd to join up
         * without seams.
         */
        gr.Save();
        gr.Target = circles;

        //gr.Alpha = 0.5;
        gr.Operator = Operator.Over;
        draw_3circles(gr, xc, yc, radius);

        gr.Restore();

        gr.Operator = Operator.Add;
        circles.Show(gr, width, height);


        gr.Restore();

        overlay.Show(gr, width, height);
    }