当前位置: 首页>>代码示例>>C#>>正文


C# Context.Translate方法代码示例

本文整理汇总了C#中Cairo.Context.Translate方法的典型用法代码示例。如果您正苦于以下问题:C# Context.Translate方法的具体用法?C# Context.Translate怎么用?C# Context.Translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cairo.Context的用法示例。


在下文中一共展示了Context.Translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Draw

        protected override void Draw(Context cr, Pixbuf prev, Pixbuf next, int width, int height, double progress)
        {
            cr.Color = 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 ();
            }
        }
开发者ID:iainlane,项目名称:f-spot,代码行数:50,代码来源:PushTransition.cs

示例2: Run

 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++;
             }
         }
     }
 }
开发者ID:KULeuven-KRR,项目名称:IdpGie,代码行数:26,代码来源:OutputPdfStripDevice.cs

示例3: ExportToPdf

 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 ();
     }
 }
开发者ID:modesto,项目名称:monoreports,代码行数:26,代码来源:ReportExtensions.cs

示例4: OnTransformIp

  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);
  }
开发者ID:jwzl,项目名称:ossbuild,代码行数:29,代码来源:TransformSample.cs

示例5: Render

        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 ();
        }
开发者ID:imagineblueeyes,项目名称:KaleidoscopeGenerator,代码行数:27,代码来源:CairoRenderer.cs

示例6: DrawArrow

        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);
        }
开发者ID:Kalnor,项目名称:monodevelop,代码行数:28,代码来源:GtkTheme.cs

示例7: Render

        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.Color = fill ? fill_color : hover_fill_color;
                    } else {
                        cr.Color = hover_fill ? fill_color : hover_fill_color;
                    }
                    cr.Fill ();
                } else {
                    cr.Color = stroke_color;
                    cr.Stroke ();
                }
            }
            cr.Restore ();
        }
开发者ID:fatman2021,项目名称:gnome-apps,代码行数:53,代码来源:RatingRenderer.cs

示例8: OvalPath

	void OvalPath (Context cr, double xc, double yc, double xr, double yr)
	{
		Matrix m = cr.Matrix;

		cr.Translate (xc, yc);
		cr.Scale (1.0, yr / xr);
		cr.MoveTo (xr, 0.0);
		cr.Arc (0, 0, xr, 0, 2 * Math.PI);
		cr.ClosePath ();

		cr.Matrix = m;
	}
开发者ID:ystk,项目名称:debian-gtk-sharp2,代码行数:12,代码来源:CairoSample.cs

示例9: Render

        public static void Render (Context cr, Rectangle box,
            double xalign, double yalign, Color innerColor, Color outerColor)
        {
            // virtual size of the figure we will draw below on the 1:1 scale
            double original_width = 8;
            double original_height = 12;

            // figure out the scale dimensions of the bounding box and the glyph
            double box_size = Math.Min (box.Width, box.Height);
            double original_size = Math.Max (original_width, original_height);

            // create a scale for the box (ratio between virtual glyph size and the box),
            // then re-scale to account for the extra size that will be added via stroke.
            // glyph_scale is the stroke width and the actual transformation size
            double box_scale = box_size / original_size;
            double glyph_scale = Math.Floor ((box_size - box_scale) / original_size);

            // compute the alignment to the pixel grid for the stroke/scale
            double pixel_align = Math.Floor (glyph_scale + 0.5) / 2.0;

            // figure out the actual size in pixels of the glyph
            double actual_width = glyph_scale * original_width + 2 * Math.Floor (pixel_align);
            double actual_height = glyph_scale * original_height + 2 * Math.Floor (pixel_align);

            // compute the offset accounting for box, grid alignment, and figure alignment
            double tx = box.X + pixel_align + Math.Round ((box.Width - actual_width) * xalign);
            double ty = box.Y + pixel_align + Math.Round ((box.Height - actual_height) * yalign);

            // save the context, and transform the current/new context
            cr.Save ();
            cr.Translate (tx, ty);
            cr.Scale (glyph_scale, glyph_scale);

            // define how the strokes look
            cr.LineWidth = 1;
            cr.LineCap = LineCap.Round;
            cr.LineJoin = LineJoin.Round;

            // inner 'b' note
            cr.Color = innerColor;
            cr.MoveTo (0, 2);
            cr.LineTo (2, 0);
            cr.Arc (4, 8, 2, Math.PI, Math.PI * 3);
            cr.Stroke ();

            // outer 'cut' circle
            cr.Color = outerColor;
            cr.Arc (4, 8, 4, Math.PI * 1.5, Math.PI * 1.12);
            cr.Stroke ();

            cr.Restore ();
        }
开发者ID:haugjan,项目名称:banshee-hacks,代码行数:52,代码来源:BansheeLineLogo.cs

示例10: onDraw

        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 ();
        }
开发者ID:jpbruyere,项目名称:Crow,代码行数:22,代码来源:AnalogMeter.cs

示例11: DrawBasis

        public void DrawBasis(Context cr, int CubePxSize)
        {
            if (OriginalFile == null)
                return;
            if (DrawingSvg == null)
                ModifyDrawingImage();

            FrameScale = DrawingSvg.Dimensions.Width / SvgWidht;

            double ratio = CubePxSize / (BaseWidht * FrameScale);
            cr.Scale(ratio, ratio);
            cr.Translate(0.0 - ((BaseX - AddX) * FrameScale), 0.0 - ((BaseY - AddY) * FrameScale));
            DrawingSvg.RenderCairo(cr);
        }
开发者ID:QualitySolution,项目名称:CupboardDesigner,代码行数:14,代码来源:SVGHelper.cs

示例12: Draw

        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 ();
        }
开发者ID:mono,项目名称:monohotdraw,代码行数:14,代码来源:LabelHandle.cs

示例13: DrawBackground

		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 ();
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:50,代码来源:StatusAreaBuildTheme.cs

示例14: BasicDraw

		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 ();
		}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:15,代码来源:EllipseFigure.cs

示例15: Draw

		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 ();
		}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:15,代码来源:PolyLineHandle.cs


注:本文中的Cairo.Context.Translate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。