private void DrawShape(Cairo.Context g, int width, int height) { int inner_x = radius + border + inner; int cx = Center.X; int cy = Center.Y; g.Operator = Operator.Source; g.Source = new SolidPattern(new Cairo.Color(0, 0, 0, 0)); g.Rectangle(0, 0, width, height); g.Paint(); g.NewPath(); g.Translate(cx, cy); g.Rotate(angle); g.Source = new SolidPattern(new Cairo.Color(0.2, 0.2, 0.2, .6)); g.Operator = Operator.Over; g.Rectangle(0, -(border + inner), inner_x, 2 * (border + inner)); g.Arc(inner_x, 0, inner + border, 0, 2 * Math.PI); g.Arc(0, 0, radius + border, 0, 2 * Math.PI); g.Fill(); g.Source = new SolidPattern(new Cairo.Color(0, 0, 0, 1.0)); g.Operator = Operator.DestOut; g.Arc(inner_x, 0, inner, 0, 2 * Math.PI); #if true g.Fill(); #else g.FillPreserve(); g.Operator = Operator.Over; RadialGradient rg = new RadialGradient(inner_x - (inner * 0.3), inner * 0.3, inner * 0.1, inner_x, 0, inner); rg.AddColorStop(0, new Cairo.Color(0.0, 0.2, .8, 0.5)); rg.AddColorStop(0.7, new Cairo.Color(0.0, 0.2, .8, 0.1)); rg.AddColorStop(1.0, new Cairo.Color(0.0, 0.0, 0.0, 0.0)); g.Source = rg; g.Fill(); rg.Destroy(); #endif g.Operator = Operator.Over; g.Matrix = new Matrix(); g.Translate(cx, cy); if (source != null) { SetSourcePixbuf(g, source, -source.Width / 2, -source.Height / 2); } g.Arc(0, 0, radius, 0, 2 * Math.PI); g.Fill(); if (overlay != null) { SetSourcePixbuf(g, overlay, -overlay.Width / 2, -overlay.Height / 2); g.Arc(0, 0, radius, angle, angle + Math.PI); g.ClosePath(); g.FillPreserve(); g.Source = new SolidPattern(new Cairo.Color(1.0, 1.0, 1.0, 1.0)); g.Stroke(); } }
/// <summary> /// Draw the robot taking into account the center x and y position of the map which /// will be different from the true center x and y positions on the drawing context. /// This method will result in a red wheeled robot with black tyres being drawn at /// the robots location on the map. /// /// The scale value is currently unused but it could be useful if the map was scaled /// in some way for example a mini-map may be 10 times smaller than the original /// results in 1:10 scale robot. /// </summary> /// <param name="cairoContext">Cairo context to draw to (assuming a map).</param> /// <param name="centerX">Center x position of map to draw onto.</param> /// <param name="centerY">Center y position of map to draw onto.</param> /// <param name="scale">Scale currently unused.</param> public void Draw(Cairo.Context cairoContext, int centerX, int centerY, double scale) { // Scale up to centimeters. int width = (int)(robot.Width * 100); int height = (int)(robot.Height * 100); int x = (int)(robot.X * 100); int y = (int)(robot.Y * 100); // Set a red colour. cairoContext.SetSourceRGB(255, 0, 0); cairoContext.LineWidth = 1.0; cairoContext.LineCap = LineCap.Butt; cairoContext.Translate(centerX + x, centerY - y); cairoContext.Rotate(relativeRotation); // Rotate the robot based on its orientation in radians. // Draw the robot as a triangle. cairoContext.MoveTo(0, -height / 2); cairoContext.LineTo(-width / 2, height / 2); cairoContext.LineTo(width / 2, height / 2); cairoContext.LineTo(0, -height / 2); cairoContext.Stroke(); // Reset the drawing context. cairoContext.Rotate(-relativeRotation); cairoContext.Translate(-(centerX + x), -(centerY - y)); }
protected void DrawSmallCovers(Cairo.Context context, float width, float height, double lwidth) { context.Save(); double hlwidth = lwidth * 0.5; context.MoveTo(hlwidth, height - hlwidth); context.LineTo(hlwidth, 0.3 * (height - lwidth)); context.LineTo((width - lwidth) * 0.65, hlwidth); context.LineTo((width - lwidth) * 0.65, 0.7 * (height - lwidth)); context.ClosePath(); context.LineWidth = lwidth; context.SetSourceRGBA(0.1, 0.1, 0.1, 1.0); context.FillPreserve(); context.SetSourceRGBA(1.0, 1.0, 1.0, 0.7); context.Stroke(); context.Translate((4 + hlwidth), 0); context.MoveTo(hlwidth, height - hlwidth); context.LineTo(hlwidth, 0.3 * (height - lwidth)); context.LineTo((width - lwidth) * 0.65, hlwidth); context.LineTo((width - lwidth) * 0.65, 0.7 * (height - lwidth)); context.ClosePath(); context.SetSourceRGBA(0.1, 0.1, 0.1, 1.0); context.FillPreserve(); context.SetSourceRGBA(1.0, 1.0, 1.0, 0.7); context.Stroke(); context.Translate(-(4 + hlwidth), 0); context.Restore(); }
protected void DrawBackground(Cairo.Context cr) { var totalRect = GetTotalBounds(); cr.SetSourceColor(BackgroundColor); cr.Rectangle(totalRect.X, totalRect.Y, totalRect.Width, totalRect.Height); cr.Fill(); cr.Save(); cr.Translate(XOffset, YOffset); cr.Scale(Scale, Scale); if (Surface != null) { cr.SetSource(Surface, 0, 0); using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) { pattern.Filter = Filter.Nearest; } cr.Paint(); } else if (Image != null) { using (Surface source = new BitmapSurface(Image)) { cr.SetSource(source, 0, 0); using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) { pattern.Filter = Filter.Nearest; } cr.Paint(); } } else { Cairo.Rectangle extents = cr.ClipExtents(); for (int i = 0; i < Width * Height; i++) { int tileX = i % Width; int tileY = i / Width; Cairo.Rectangle rect = GetTileRectWithPadding(tileX, tileY, scale: false, offset: false); if (!CairoHelper.RectsOverlap(extents, rect)) { continue; } cr.Save(); cr.Translate(rect.X + TilePaddingX, rect.Y + TilePaddingY); cr.Rectangle(0, 0, TileWidth, TileHeight); cr.Clip(); TileDrawer(i, cr); cr.Restore(); } } cr.Restore(); // Undo scale, offset }
protected override void OnDrawContent(Gdk.EventExpose evnt, Cairo.Context g) { Theme.BorderColor = marker.TooltipColor.Color; g.Rectangle(0, 0, Allocation.Width, Allocation.Height); g.SetSourceColor(marker.TooltipColor.Color); g.Fill(); using (var drawingLayout = new Pango.Layout(this.PangoContext)) { drawingLayout.FontDescription = cache.tooltipFontDescription; double y = verticalTextBorder; var showBulletedList = marker.Errors.Count > 1; foreach (var msg in marker.Errors) { var icon = msg.IsError ? cache.errorPixbuf : cache.warningPixbuf; if (!showBulletedList) { drawingLayout.Width = maxTextWidth; } drawingLayout.SetText(GetFirstLine(msg)); int w; int h; drawingLayout.GetPixelSize(out w, out h); if (showBulletedList) { g.Save(); g.Translate( textBorder, y + verticalTextSpace / 2 + 1 + Math.Max(0, (h - icon.Height) / 2) ); Gdk.CairoHelper.SetSourcePixbuf(g, icon, 0, 0); g.Paint(); g.Restore(); } g.Save(); g.Translate(showBulletedList ? textBorder + iconTextSpacing + icon.Width: textBorder, y + verticalTextSpace / 2 + 1); g.SetSourceColor(ShadowColor); g.ShowLayout(drawingLayout); g.Translate(0, -1); g.SetSourceColor(marker.TagColor.SecondColor); g.ShowLayout(drawingLayout); g.Restore(); y += h + verticalTextSpace; } } }
private void Render(Clutter.CairoTexture texture, int with_state, bool outwards) { texture.Clear(); Cairo.Context context = texture.Create(); double lwidth = 1; double hlwidth = lwidth * 0.5; //Draw outline rectangles: context.Rectangle(hlwidth, hlwidth, texture.Width - lwidth, texture.Height - lwidth); context.SetSourceRGB(1.0, 1.0, 1.0); context.LineWidth = lwidth; context.StrokePreserve(); double sat = (with_state == 0 ? 0.4 : (with_state == 1 ? 0.6 : 0.8)); context.SetSourceRGB(sat, sat, sat); context.Fill(); double dim = 4; context.MoveTo(-dim, 0); context.LineTo(outwards ? 0 : -dim, outwards ? 0 : dim); context.LineTo(0, dim); context.MoveTo(-dim, dim); context.LineTo(0, 0); context.ClosePath(); Cairo.Path arrow = context.CopyPath(); context.NewPath(); double margin = 2 + hlwidth; PointD center = new PointD(texture.Width * 0.5, texture.Height * 0.5); PointD transl = new PointD(center.X - margin, -(center.Y - margin)); context.LineWidth = lwidth; sat = (with_state == 1 ? 0.0 : 1.0); context.SetSourceRGB(sat, sat, sat); context.Translate(center.X, center.Y); for (int i = 0; i < 4; i++) { context.Rotate(Math.PI * 0.5 * i); context.Translate(transl.X, transl.Y); context.AppendPath(arrow); context.Stroke(); context.Translate(-transl.X, -transl.Y); } ((IDisposable)arrow).Dispose(); ((IDisposable)context.Target).Dispose(); ((IDisposable)context).Dispose(); }
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 (); } }
void DrawPixbuf(Cairo.Context ctx, Gdk.Pixbuf img, double x, double y, Size idesc) { ctx.Save(); ctx.Translate(x, y); ctx.Scale(idesc.Width / (double)img.Width, idesc.Height / (double)img.Height); Gdk.CairoHelper.SetSourcePixbuf(ctx, img, 0, 0); #pragma warning disable 618 using (var p = ctx.Source) { if (p is SurfacePattern pattern) { if (idesc.Width > img.Width || idesc.Height > img.Height) { // Fixes blur issue when rendering on an image surface pattern.Filter = Cairo.Filter.Fast; } else { pattern.Filter = Cairo.Filter.Good; } } } #pragma warning restore 618 ctx.Paint(); ctx.Restore(); }
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(); } }
protected void DrawHoverAndSelection(Cairo.Context cr) { cr.Save(); cr.Translate(XOffset, YOffset); cr.Scale(Scale, Scale); if (Hoverable && hoveringIndex != -1) { Cairo.Rectangle rect = GetTileRectSansPadding(HoveringX, HoveringY, scale: false, offset: false); cr.NewPath(); cr.SetSourceColor(HoverColor); cr.Rectangle(new Cairo.Rectangle(rect.X + 0.5, rect.Y + 0.5, rect.Width - 1, rect.Height - 1)); cr.LineWidth = 1; cr.LineJoin = LineJoin.Bevel; cr.Stroke(); } if (Selectable) { var rect = GetTileRectSansPadding(SelectedX, SelectedY, scale: false, offset: false); if (IsInBounds((int)rect.X, (int)rect.Y, scale: false, offset: false)) { cr.NewPath(); cr.SetSourceColor(SelectionColor); cr.Rectangle(rect.X + 0.5, rect.Y + 0.5, rect.Width - 1, rect.Height - 1); cr.LineWidth = 1; cr.Stroke(); } } cr.Restore(); }
public void Draw(Cairo.Context g, double scale, bool fillSelection) { g.Save(); g.Translate(0.5, 0.5); g.Scale(scale, scale); g.AppendPath(selection_path); if (fillSelection) { g.Color = new Cairo.Color(0.7, 0.8, 0.9, 0.2); g.FillRule = Cairo.FillRule.EvenOdd; g.FillPreserve(); } g.LineWidth = 1 / scale; // Draw a white line first so it shows up on dark backgrounds g.Color = new Cairo.Color(1, 1, 1); g.StrokePreserve(); // Draw a black dashed line over the white line g.SetDash(new double[] { 2 / scale, 4 / scale }, 0); g.Color = new Cairo.Color(0, 0, 0); g.Stroke(); g.Restore(); }
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 (); }
protected override bool OnExposeEvent(EventExpose ev) { using (Cairo.Context context = CairoHelper.Create(ev.Window)) { context.Save(); PointD translation = DrawingToView(0.0, 0.0); context.Translate(translation.X, translation.Y); context.Scale(Scale, Scale); foreach (IFigure figure in Drawing.FiguresEnumerator) { // check region for update bool shouldDraw = true; if (shouldDraw) { figure.Draw(context); } } foreach (IFigure figure in SelectionEnumerator) { figure.DrawSelected(context); } context.Restore(); foreach (IHandle handle in SelectionHandles) { handle.Draw(context, this); } } DebugUpdateFrame(); return(base.OnExposeEvent(ev)); }
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)); }
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 (); } }
void RenderBackground(Cairo.Context context, Gdk.Rectangle region) { region.Inflate(-Padding, -Padding); context.RenderOuterShadow(new Gdk.Rectangle(region.X + 10, region.Y + 15, region.Width - 20, region.Height - 15), Padding, 3, .25); context.RoundedRectangle(region.X + 0.5, region.Y + 0.5, region.Width - 1, region.Height - 1, 5); using (var lg = new LinearGradient(0, region.Y, 0, region.Bottom)) { lg.AddColorStop(0, new Cairo.Color(.36, .53, .73)); lg.AddColorStop(1, new Cairo.Color(.21, .37, .54)); context.SetSource(lg); context.FillPreserve(); } context.Save(); context.Translate(IconPosition.X, IconPosition.Y); context.Scale(0.75, 0.75); Gdk.CairoHelper.SetSourcePixbuf(context, starburst, -starburst.Width / 2, -starburst.Height / 2); context.FillPreserve(); context.Restore(); context.LineWidth = 1; context.SetSourceRGB(.29, .47, .67); context.Stroke(); }
protected void OnDrawingarea1ExposeEvent(object o, ExposeEventArgs args) { Console.WriteLine("Exposed"); DrawingArea area = (DrawingArea)o; Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow); int width = area.Allocation.Width; int height = area.Allocation.Height; int radius = (width < height ? width : height); cr.SetSourceRGB(0.0, 0.0, 0.0); cr.Rectangle(0, 0, width, height); cr.Fill(); cr.Translate(this.offsetX, this.offsetY); // move "pointer" cr.Scale(this.scale, this.scale); cr.SetSourceSurface(this.surface, 0, 0); // offset surface cr.Rectangle(0, 0, this.surface.Width, // offset cutout this.surface.Height); cr.Fill(); // apply cr.SetSourceRGB(1.0, 0.0, 0.0); cr.Arc(this.pointX, this.pointY, 2, 0, 2 * Math.PI); cr.Fill(); ((IDisposable)cr.GetTarget()).Dispose(); ((IDisposable)cr).Dispose(); }
void OnExpose(object sender, EventArgs args) { Cairo.Context cr = Gdk.CairoHelper.Create(this.Window); cr.LineWidth = 3; cr.LineCap = LineCap.Round; int width, height; width = Allocation.Width; height = Allocation.Height; cr.Translate(width / 2, height / 2); for (int i = 0; i < 8; i++) { cr.SetSourceRGBA(0, 0, 0, trs[count % 8, i]); cr.MoveTo(0.0, -10.0); cr.LineTo(0.0, -40.0); cr.Rotate(Math.PI / 4); cr.Stroke(); } cr.GetTarget().Dispose(); cr.Dispose(); }
void DrawButtonTabs(Cairo.Context cr, Cairo.Rectangle rectangle) { if (IsSeparator) { cr.NewPath(); double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5; cr.MoveTo(x, rectangle.Y + 0.5 + 2); cr.RelLineTo(0, rectangle.Height - 1 - 4); cr.ClosePath(); cr.Color = (HslColor)parent.Style.Dark(StateType.Normal); cr.LineWidth = 1; cr.Stroke(); return; } int topPadding = 2; if (Active || HoverPosition.X >= 0) { cr.NewPath(); cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5 + topPadding, rectangle.Width - 1, rectangle.Height - topPadding); cr.ClosePath(); if (Active) { cr.Color = (HslColor)parent.Style.Background(StateType.Prelight); } else if (HoverPosition.X >= 0) { double rx = rectangle.X + HoverPosition.X; double ry = rectangle.Y + HoverPosition.Y; Cairo.RadialGradient gradient = new Cairo.RadialGradient(rx, ry, rectangle.Height * 1.5, rx, ry, 2); var color = (HslColor)parent.Style.Dark(StateType.Normal); color.L *= 1.1; gradient.AddColorStop(0, color); color.L *= 1.1; gradient.AddColorStop(1, color); cr.Pattern = gradient; } if (!Active) { cr.Fill(); } else { cr.FillPreserve(); cr.Color = (HslColor)parent.Style.Dark(StateType.Normal); cr.LineWidth = 1; cr.Stroke(); } } cr.Save(); cr.Translate(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2 + topPadding); cr.Color = (HslColor)parent.Style.Text(StateType.Normal); cr.ShowLayout(layout); cr.Restore(); }
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++; } } } }
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); }
protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point) { if (!is_dragging) { return; } Document doc = PintaCore.Workspace.ActiveDocument; PointD new_offset = new PointD(point.X, point.Y); double dx = origin_offset.X - new_offset.X; double dy = origin_offset.Y - new_offset.Y; Path path = doc.SelectionPath; using (Cairo.Context g = new Cairo.Context(doc.CurrentLayer.Surface)) { g.AppendPath(path); g.Translate(dx, dy); doc.SelectionPath = g.CopyPath(); } (path as IDisposable).Dispose(); doc.SelectionLayer.Offset = new PointD(doc.SelectionLayer.Offset.X - dx, doc.SelectionLayer.Offset.Y - dy); origin_offset = new_offset; (o as Gtk.DrawingArea).GdkWindow.Invalidate(); }
protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point) { if (!is_dragging) { return; } Document doc = PintaCore.Workspace.ActiveDocument; PointD new_offset = point; double dx = origin_offset.X - new_offset.X; double dy = origin_offset.Y - new_offset.Y; using (Cairo.Context g = new Cairo.Context(doc.CurrentLayer.Surface)) { Path old = doc.SelectionPath; g.FillRule = FillRule.EvenOdd; g.AppendPath(doc.SelectionPath); g.Translate(dx, dy); doc.SelectionPath = g.CopyPath(); (old as IDisposable).Dispose(); } origin_offset = new_offset; doc.ShowSelection = true; (o as Gtk.DrawingArea).GdkWindow.Invalidate(); }
public override void Render(Cairo.Context c) { InvalidateBound(); c.Save(); c.FillRectangle(AbsoluteBound, section.BackgroundColor.ToCairoColor()); Rectangle r = new Rectangle(AbsoluteBound.X, AbsoluteBound.Y, parentReport.Width, SectionheaderHeight); Cairo.Gradient pat = new Cairo.LinearGradient(0, AbsoluteBound.Y, 0, AbsoluteBound.Y + SectionheaderHeight); pat.AddColorStop(0, sectionHeaderColor); pat.AddColorStop(1, sectionHeaderColor1); c.FillRectangle(r, pat); c.DrawText(new Cairo.PointD(r.X + 3, r.Y + 3), "Tahoma", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal, 11, blackColor, 600, Section.Name); c.FillRectangle(GripperAbsoluteBound, SectionGripperColor); c.Translate(AbsoluteDrawingStartPoint.X, AbsoluteDrawingStartPoint.Y); for (int j = 0; j < Controls.Count; j++) { var ctrl = Controls [j]; ctrl.Render(c); } c.Restore(); }
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); }
void RenderPreview(Cairo.Context context, Gdk.Point position, double opacity) { if (brandedIcon != null) { /* if (previewSurface == null) { * previewSurface = new SurfaceWrapper (context, brandedIcon); * } * double scale = PreviewSize / previewSurface.Width; * * context.Save (); * context.Translate (position.X, position.Y); * context.Scale (scale * IconScale, scale * IconScale); * context.SetSourceSurface (previewSurface.Surface, -previewSurface.Width / 2, -previewSurface.Height / 2); * context.PaintWithAlpha (opacity); * context.Restore (); */ double scale = PreviewSize / brandedIcon.Width; context.Save(); context.Translate(position.X, position.Y); context.Scale(scale * IconScale, scale * IconScale); context.DrawImage(this, brandedIcon.WithAlpha(opacity), -brandedIcon.Width / 2, -brandedIcon.Height / 2); context.Restore(); } }
/// <summary> /// Rotates layer by the specified angle (in degrees). /// </summary> /// <param name='angle'> /// Angle (in degrees). /// </param> public void Rotate(double angle) { int w = PintaCore.Workspace.ImageSize.Width; int h = PintaCore.Workspace.ImageSize.Height; double radians = (angle / 180d) * Math.PI; double cos = Math.Cos(radians); double sin = Math.Sin(radians); var newSize = RotateDimensions(PintaCore.Workspace.ImageSize, angle); Layer dest = PintaCore.Layers.CreateLayer(string.Empty, newSize.Width, newSize.Height); using (Cairo.Context g = new Cairo.Context(dest.Surface)) { g.Matrix = new Matrix(cos, sin, -sin, cos, newSize.Width / 2.0, newSize.Height / 2.0); g.Translate(-w / 2.0, -h / 2.0); g.SetSource(Surface); g.Paint(); } Surface old = Surface; Surface = dest.Surface; (old as IDisposable).Dispose(); }
protected override bool OnExposeEvent(EventExpose evnt) { if (!IsRealized) { return(false); } using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) { if (background_buffer == null) { if (Orientation == DockPosition.Bottom || Orientation == DockPosition.Top) { background_buffer = new DockySurface(allocation.Width, allocation.Height, cr.Target); } else { // switch width and height so we can rotate it later background_buffer = new DockySurface(allocation.Height, allocation.Width, cr.Target); } DrawBackground(background_buffer); } switch (Orientation) { case DockPosition.Top: cr.Scale(1, -1); cr.Translate(0, -background_buffer.Height); break; case DockPosition.Left: cr.Rotate(Math.PI * .5); cr.Translate(0, -background_buffer.Height); break; case DockPosition.Right: cr.Rotate(Math.PI * -0.5); cr.Translate(-background_buffer.Width, 0); break; } cr.Operator = Operator.Source; background_buffer.Internal.Show(cr, 0, 0); (cr.Target as IDisposable).Dispose(); } return(base.OnExposeEvent(evnt)); }
static void oval_path(Cairo.Context gr, double xc, double yc, double xr, double yr) { gr.Translate(xc, yc); gr.Scale(1.0, yr / xr); gr.MoveTo(new PointD(xr, 0.0)); gr.Arc(0, 0, xr, 0, 2 * M_PI); gr.ClosePath(); }
public static Cairo.Context CreateDrawable(Gdk.Drawable drawable) { IntPtr x_drawable = IntPtr.Zero; int x_off = 0, y_off = 0; int x, y, w, h, d; ((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d); bool is_gdk_window = drawable is Gdk.Window; if (is_gdk_window) { ((Gdk.Window)drawable).GetInternalPaintInfo(out drawable, out x_off, out y_off); } Cairo.Surface surface; PlatformID os = Environment.OSVersion.Platform; if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT || os == PlatformID.Win32S || os == PlatformID.WinCE) { Gdk.GC gcc = new Gdk.GC(drawable); IntPtr windc = gdk_win32_hdc_get(drawable.Handle, gcc.Handle, 0); surface = new Win32Surface(windc); gdk_win32_hdc_release(drawable.Handle, gcc.Handle, 0); } else { x_drawable = drawable.Handle; IntPtr visual = gdk_drawable_get_visual(x_drawable); IntPtr Xdisplay = gdk_x11_drawable_get_xdisplay(x_drawable); IntPtr Xvisual = gdk_x11_visual_get_xvisual(visual); IntPtr Xdrawable = gdk_x11_drawable_get_xid(x_drawable); surface = new Cairo.XlibSurface(Xdisplay, Xdrawable, Xvisual, w, h); } Cairo.Context g = new Cairo.Context(surface); // this can be safely removed now, just keep it for a bit more //Cairo.Context g = new Cairo.Context ( // gdk_cairo_create (x_drawable )); if (is_gdk_window) { g.Translate(-(double)x_off, -(double)y_off); } return(g); }
void DrawCurveTabs(Cairo.Context cr, Cairo.Rectangle rectangle) { if (IsSeparator) { return; } cr.MoveTo(rectangle.X, rectangle.Y); double bottom = rectangle.Y + rectangle.Height - 1; cr.CurveTo( rectangle.X + SpacerWidth / 2, rectangle.Y, rectangle.X + SpacerWidth / 2, bottom, rectangle.X + SpacerWidth, bottom); cr.LineTo(rectangle.X + rectangle.Width - SpacerWidth, bottom); cr.CurveTo( rectangle.X + rectangle.Width - SpacerWidth / 2, bottom, rectangle.X + rectangle.Width - SpacerWidth / 2, rectangle.Y, rectangle.X + rectangle.Width, rectangle.Y); cr.Color = (HslColor)parent.Style.Dark(StateType.Normal); cr.StrokePreserve(); cr.ClosePath(); if (Active) { cr.Color = (HslColor)parent.Style.Background(StateType.Prelight); } else if (HoverPosition.X >= 0) { double rx = rectangle.X + HoverPosition.X; double ry = rectangle.Y + HoverPosition.Y; Cairo.RadialGradient gradient = new Cairo.RadialGradient(rx, ry, rectangle.Height * 1.5, rx, ry, 2); var color = (HslColor)parent.Style.Mid(StateType.Normal); color.L *= 1.05; gradient.AddColorStop(0, color); color.L *= 1.07; gradient.AddColorStop(1, color); cr.Pattern = gradient; } else { cr.Color = (HslColor)parent.Style.Mid(StateType.Normal); } cr.Fill(); cr.Save(); cr.Translate(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2); cr.Color = (HslColor)parent.Style.Text(StateType.Normal); cr.ShowLayout(layout); cr.Restore(); }
void DrawBuildEffect(Cairo.Context context, Gdk.Rectangle area, double progress, double opacity) { context.Save(); LayoutRoundedRectangle(context, area); context.Clip(); Gdk.Point center = new Gdk.Point(area.Left + 19, (area.Top + area.Bottom) / 2); context.Translate(center.X, center.Y); var circles = new [] { new { Radius = 200, Thickness = 12, Speed = 1, ArcLength = Math.PI * 1.50 }, new { Radius = 195, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.50 }, new { Radius = 160, Thickness = 17, Speed = 3, ArcLength = Math.PI * 0.75 }, new { Radius = 200, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.25 }, new { Radius = 240, Thickness = 12, Speed = 3, ArcLength = Math.PI * 1.50 }, new { Radius = 160, Thickness = 17, Speed = 3, ArcLength = Math.PI * 0.75 }, new { Radius = 200, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.25 }, new { Radius = 215, Thickness = 20, Speed = 2, ArcLength = Math.PI * 1.25 } }; double zmod = 1.0d; double zporg = progress; foreach (var arc in circles) { double zoom = 1.0d; zoom = (double)Math.Sin(zporg * Math.PI * 2 + zmod); zoom = ((zoom + 1) / 6.0d) + .05d; context.Rotate(Math.PI * 2 * progress * arc.Speed); context.MoveTo(arc.Radius * zoom, 0); context.Arc(0, 0, arc.Radius * zoom, 0, arc.ArcLength); context.LineWidth = arc.Thickness * zoom; context.SetSourceColor(CairoExtensions.ParseColor("B1DDED", 0.35 * opacity)); context.Stroke(); context.Rotate(Math.PI * 2 * -progress * arc.Speed); progress = -progress; context.Rotate(Math.PI * 2 * progress * arc.Speed); context.MoveTo(arc.Radius * zoom, 0); context.Arc(0, 0, arc.Radius * zoom, 0, arc.ArcLength); context.LineWidth = arc.Thickness * zoom; context.Stroke(); context.Rotate(Math.PI * 2 * -progress * arc.Speed); progress = -progress; zmod += (float)Math.PI / circles.Length; } context.LineWidth = 1; context.ResetClip(); context.Restore(); }
static void draw(Cairo.Context gr, int width, int height) { int w, h; ImageSurface image; gr.Scale(width, height); gr.LineWidth = 0.04; image = new ImageSurface("data/e.png"); w = image.Width; h = image.Height; gr.Translate(0.5, 0.5); gr.Rotate(45 * M_PI / 180); gr.Scale(1.0 / w, 1.0 / h); gr.Translate(-0.5 * w, -0.5 * h); image.Show(gr, 0, 0); image.Destroy(); }
protected override bool OnDrawn(Cairo.Context ctx) { // color the screen black ctx.SetSourceRGB(0, 0, 0); ctx.Paint(); // Normally (0,0) is in the corner, but we want it in the middle, so we must translate: ctx.Translate(AllocatedWidth / 2, AllocatedHeight / 2); var bounds = bounds_multiplier * max * new Vector3(1, 1, 1); // we care about the limiting factor, since most orbits will be bounded roughly by a square // but screens are rectangular var scale = Math.Min((AllocatedWidth / 2) * bounds.x, (AllocatedHeight / 2) / bounds.y); ctx.Scale(scale, scale); if (paths == null) { this.ClearPaths(); } order = order.OrderByDescending(x => Vector3.Magnitude(sys[x].position - camera.position)).ToArray(); for (int i = 0; i < sys.Count; i++) { var body = sys[order[i]]; var cl = body.color; ctx.SetSourceRGB(cl.x, cl.y, cl.z); var T = camera.Transform(body.position - sys.origin); //camera.position);// - camera.Transform(sys.origin); var r = radius_multiplier * camera.TransformProjectionRadius(T, body.radius); //body.radius; var pos = camera.TransformProjection(T); ctx.Arc(pos.x, pos.y, r, 0, 2 * Math.PI); ctx.Fill(); Vector3 lastPath; try { lastPath = camera.TransformProjection(camera.Transform(paths[order[i]][0])); } catch (ArgumentOutOfRangeException) { lastPath = Vector3.zero; } ctx.LineWidth = Math.Min(LINE_MULTIPLIER * radius_multiplier * body.radius, LINE_MULTIPLIER * r); foreach (Vector3 p in paths[order[i]]) { pos = camera.TransformProjection(camera.Transform(p)); ctx.MoveTo(lastPath.x, lastPath.y); ctx.LineTo(pos.x, pos.y); ctx.Stroke(); lastPath = pos; } paths[order[i]].Add(body.position - sys.origin); if (paths[order[i]].Count > line_max) { paths[order[i]] = paths[order[i]].TakeLast(line_max).ToList(); } } return(true); }
void RedrawBoard() { boardContext = Gdk.CairoHelper.Create(BoardArea.GdkWindow); double transx = Math.Abs((BoardArea.Allocation.Width - (boardBackground.Width * 0.75))) / 2; boardContext.Translate(transx, 0); boardContext.Scale(0.75, 0.75); boardBackground.Show(boardContext, 0, 0); PieceDisplay.DrawPieces(boardContext); boardContext.Dispose(); }
public static void RotatePng(ParsedPath pngPath, ImageRotation rotation) { if (rotation == ImageRotation.None) { return; } using (ImageSurface originalImage = new ImageSurface(pngPath)) { int w; int h; if (rotation == ImageRotation.Left || rotation == ImageRotation.Right) { w = originalImage.Height; h = originalImage.Width; } else { w = originalImage.Width; h = originalImage.Height; } double[] rotationRadians = { 0, -Math.PI / 2, Math.PI / 2, Math.PI }; using (ImageSurface rotatedImage = new ImageSurface(Format.Argb32, w, h)) { using (Cairo.Context g = new Cairo.Context(rotatedImage)) { g.Translate(rotatedImage.Width / 2.0, rotatedImage.Height / 2.0); g.Rotate(rotationRadians[(int)rotation]); g.Translate(-originalImage.Width / 2.0, -originalImage.Height / 2.0); g.SetSourceSurface(originalImage, 0, 0); g.Paint(); } rotatedImage.WriteToPng(pngPath); } } }
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; }
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 (); }
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 (); }
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 (); }
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 (); }
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); }
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 (); }
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 (); }
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 (); }
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 (); } } }
public override void Render(Context cr) { if (!CanResize) { return; } var selected_color = CairoExtensions.GdkColorToCairoColor (Window.Style.Dark (StateType.Active)); var grad = new LinearGradient (0, 0, 0, Allocation.Height); selected_color.A = 0.4; grad.AddColorStop (0, selected_color); selected_color.A = 1.0; grad.AddColorStop (1, selected_color); cr.Pattern = grad; cr.LineWidth = 1.0; cr.Rectangle (0.5, 0.5, Allocation.Width - 1, Allocation.Height - 1); cr.Stroke (); selected_color.A = 0.5; cr.Color = selected_color; double handle_size = 8; double ty = 0.5 + Allocation.Height - handle_size - 3; double tx = 0.5 + (Window.Direction == TextDirection.Ltr ? Allocation.Width - handle_size - 3 : 3); cr.Translate (tx, ty); for (double i = 0; i < 3; i++) { if (Window.Direction == TextDirection.Ltr) { cr.MoveTo (i * 3, handle_size); cr.LineTo (handle_size, i * 3); } else { cr.MoveTo (0, i * 3); cr.LineTo (handle_size - i * 3, handle_size); } } cr.Stroke (); cr.Translate (-tx, -ty); }
public static Cairo.Context CreateDrawable (Gdk.Drawable drawable, bool double_buffered) { int x, y, w, h, d; Cairo.Surface surface; bool needs_xlate; ((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d); PlatformID os = Environment.OSVersion.Platform; needs_xlate = drawable is Gdk.Window && double_buffered; if (needs_xlate) ((Gdk.Window)drawable).GetInternalPaintInfo (out drawable, out x, out y); if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT || os == PlatformID.Win32S || os == PlatformID.WinCE) { Gdk.GC gcc = new Gdk.GC (drawable); IntPtr windc = gdk_win32_hdc_get (drawable.Handle, gcc.Handle, 0); surface = new Win32Surface (windc); if (double_buffered) gdk_win32_hdc_release (drawable.Handle, gcc.Handle, 0); } else { IntPtr display = gdk_x11_drawable_get_xdisplay (drawable.Handle); IntPtr visual = gdk_drawable_get_visual (drawable.Handle); IntPtr xvisual = gdk_x11_visual_get_xvisual (visual); IntPtr xdrawable = gdk_x11_drawable_get_xid (drawable.Handle); surface = new XlibSurface (display, xdrawable, xvisual, w, h); } Cairo.Context ctx = new Cairo.Context (surface); if (needs_xlate) ctx.Translate (-(double) x, -(double) y); return ctx; }
public void Crop(Gdk.Rectangle rect, Path path) { ImageSurface dest = new ImageSurface (Format.Argb32, rect.Width, rect.Height); using (Context g = new Context (dest)) { // Move the selected content to the upper left g.Translate (-rect.X, -rect.Y); g.Antialias = Antialias.None; // Respect the selected path g.AppendPath (path); g.FillRule = Cairo.FillRule.EvenOdd; g.Clip (); g.SetSource (Surface); g.Paint (); } (Surface as IDisposable).Dispose (); Surface = dest; }
public void draw(Context cr) { PointD p = model.position; cr.Save(); cr.Translate (p.X-image.Width/2, p.Y-image.Height/2); cr.SetSource(image); cr.Paint(); cr.Restore(); cr.MoveTo(p); cr.SetSourceRGB (0.3, 1.0, 0.3); cr.Arc (p.X, p.Y, 5, 0, 2 * Math.PI); cr.Fill (); }
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 (); }
protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point) { if (!is_dragging) return; Document doc = PintaCore.Workspace.ActiveDocument; PointD new_offset = point; double dx = origin_offset.X - new_offset.X; double dy = origin_offset.Y - new_offset.Y; using (Cairo.Context g = new Cairo.Context (doc.CurrentLayer.Surface)) { Path old = doc.SelectionPath; g.FillRule = FillRule.EvenOdd; g.AppendPath (doc.SelectionPath); g.Translate (dx, dy); doc.SelectionPath = g.CopyPath (); (old as IDisposable).Dispose (); } origin_offset = new_offset; doc.ShowSelection = true; (o as Gtk.DrawingArea).GdkWindow.Invalidate (); }
public override void DrawArrow (Context cr, Gdk.Rectangle alloc, double rotation) { rotation -= Math.PI / 2.0; double x1 = alloc.X; double x2 = alloc.Right; double x3 = alloc.X + alloc.Width / 2.0; double y1 = alloc.Y; double y2 = alloc.Bottom; double cx = x3; double cy = alloc.Y + alloc.Height / 2.0; if (rotation != 0) { // Rotate about the center of the arrow cr.Translate (cx, cy); cr.Rotate (rotation); cr.Translate (-cx, -cy); } cr.LineWidth = 1.0; bool hz = (rotation % (Math.PI / 2.0)) == 0; double dx = hz ? 0 : 0.5; double dy = hz ? 0.5 : 0.5; cr.Translate (dx, dy); cr.MoveTo (x1, y1); cr.LineTo (x2, y1); cr.LineTo (x3, y2); cr.LineTo (x1, y1); cr.Color = Colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal); cr.FillPreserve (); cr.Color = Colors.GetWidgetColor (GtkColorClass.Text, StateType.Normal); cr.Stroke (); cr.Translate (-dx, -dy); if (rotation != 0) { cr.Translate (cx, cy); cr.Rotate (-rotation); cr.Translate (-cx, -cy); } }
public override void DrawSelected(Context context) { context.Save (); context.Translate (DisplayBox.X, DisplayBox.Y); context.Scale (DisplayBox.Width, DisplayBox.Height); context.Rectangle (0.0, 0.0, 1, 1); context.Restore (); context.Save (); context.LineWidth = 3; context.Color = new Cairo.Color (1, 0.0784314, 0.576471, 1); context.Stroke (); context.Restore (); context.Save (); BasicDrawSelected (context); foreach (IFigure fig in FiguresEnumerator) { fig.Draw (context); } context.Restore (); }
public void Rotate90CW() { int w = PintaCore.Workspace.ImageSize.X; int h = PintaCore.Workspace.ImageSize.Y; Layer dest = PintaCore.Layers.CreateLayer (string.Empty, h, w); using (Cairo.Context g = new Cairo.Context (dest.Surface)) { g.Translate (h / 2d, w / 2d); g.Rotate (Math.PI / 2); g.Translate (-w / 2d, -h / 2d); g.SetSource (Surface); g.Paint (); } Surface old = Surface; Surface = dest.Surface; (old as IDisposable).Dispose (); }
public static void RotatePng(ParsedPath pngPath, ImageRotation rotation) { if (rotation == ImageRotation.None) return; using (ImageSurface originalImage = new ImageSurface(pngPath)) { int w; int h; if (rotation == ImageRotation.Left || rotation == ImageRotation.Right) { w = originalImage.Height; h = originalImage.Width; } else { w = originalImage.Width; h = originalImage.Height; } double[] rotationRadians = {0, -Math.PI / 2, Math.PI / 2, Math.PI }; using (ImageSurface rotatedImage = new ImageSurface(Format.Argb32, w, h)) { using (Cairo.Context g = new Cairo.Context(rotatedImage)) { g.Translate(rotatedImage.Width / 2.0, rotatedImage.Height / 2.0); g.Rotate(rotationRadians[(int)rotation]); g.Translate(-originalImage.Width / 2.0, -originalImage.Height / 2.0); g.SetSourceSurface(originalImage, 0, 0); g.Paint(); } rotatedImage.WriteToPng(pngPath); } } }
/// <summary> /// Rotates layer by the specified angle (in degrees). /// </summary> /// <param name='angle'> /// Angle (in degrees). /// </param> public void Rotate(double angle) { int w = PintaCore.Workspace.ImageSize.Width; int h = PintaCore.Workspace.ImageSize.Height; double radians = (angle / 180d) * Math.PI; double cos = Math.Cos (radians); double sin = Math.Sin (radians); var newSize = RotateDimensions (PintaCore.Workspace.ImageSize, angle); Layer dest = PintaCore.Layers.CreateLayer (string.Empty, newSize.Width, newSize.Height); using (Cairo.Context g = new Cairo.Context (dest.Surface)) { g.Matrix = new Matrix (cos, sin, -sin, cos, newSize.Width / 2.0, newSize.Height / 2.0); g.Translate (-w / 2.0, -h / 2.0); g.SetSource (Surface); g.Paint (); } Surface old = Surface; Surface = dest.Surface; (old as IDisposable).Dispose (); }
protected override void onDraw(Context gr) { Rectangle rBack = new Rectangle (Slot.Size); Background.SetAsSource (gr, rBack); CairoHelpers.CairoRectangle(gr,rBack, CornerRadius); gr.Fill (); gr.Save (); if (ClipToClientRect) { //clip to scrolled client zone CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); gr.Clip (); } gr.Translate (-ScrollX, -ScrollY); if (child != null) child.Paint (ref gr); gr.Restore (); }
protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point) { if (mouse_button == 1) { StrokeColor = PintaCore.Palette.PrimaryColor; FillColor = PintaCore.Palette.SecondaryColor; } else if (mouse_button == 3) { StrokeColor = PintaCore.Palette.SecondaryColor; FillColor = PintaCore.Palette.PrimaryColor; } else { LastPoint = point_empty; return; } // TODO: also multiply by pressure StrokeColor = new Color (StrokeColor.R, StrokeColor.G, StrokeColor.B, StrokeColor.A * active_brush.StrokeAlphaMultiplier); int x = (int)point.X; int y = (int)point.Y; if (LastPoint.Equals (point_empty)) LastPoint = new Point (x, y); if (PintaCore.Workspace.PointInCanvas (point)) surface_modified = true; var surf = PintaCore.Layers.CurrentLayer.Surface; var invalidate_rect = Gdk.Rectangle.Zero; var brush_width = BrushWidth; using (Drawable = new Context (surf)) { Drawable.AppendPath (PintaCore.Workspace.ActiveDocument.SelectionPath); Drawable.FillRule = FillRule.EvenOdd; Drawable.Clip (); Drawable.Antialias = Antialias.Subpixel; Drawable.LineWidth = brush_width; Drawable.LineJoin = LineJoin.Round; Drawable.LineCap = BrushWidth == 1 ? LineCap.Butt : LineCap.Round; Drawable.Color = StrokeColor; Drawable.Translate (brush_width / 2.0, brush_width / 2.0); active_brush.Tool = this; invalidate_rect = active_brush.DoMouseMove (x, y, LastPoint.X, LastPoint.Y); active_brush.Tool = null; } Drawable = null; if (invalidate_rect.IsEmpty) { PintaCore.Workspace.Invalidate (); } else { PintaCore.Workspace.Invalidate (invalidate_rect); } LastPoint = new Point (x, y); }
void DrawShape(Context g, int width, int height) { int inner_x = radius + border + inner; int cx = Center.X; int cy = Center.Y; g.Operator = Operator.Source; g.SetSource (new SolidPattern (new Cairo.Color (0,0,0,0))); g.Rectangle (0, 0, width, height); g.Paint (); g.NewPath (); g.Translate (cx, cy); g.Rotate (angle); g.SetSource (new SolidPattern (new Cairo.Color (0.2, 0.2, 0.2, .6))); g.Operator = Operator.Over; g.Rectangle (0, - (border + inner), inner_x, 2 * (border + inner)); g.Arc (inner_x, 0, inner + border, 0, 2 * Math.PI); g.Arc (0, 0, radius + border, 0, 2 * Math.PI); g.Fill (); g.SetSource (new SolidPattern (new Cairo.Color (0, 0, 0, 1.0))); g.Operator = Operator.DestOut; g.Arc (inner_x, 0, inner, 0, 2 * Math.PI); #if true g.Fill (); #else g.FillPreserve (); g.Operator = Operator.Over; RadialGradient rg = new RadialGradient (inner_x - (inner * 0.3), inner * 0.3 , inner * 0.1, inner_x, 0, inner); rg.AddColorStop (0, new Cairo.Color (0.0, 0.2, .8, 0.5)); rg.AddColorStop (0.7, new Cairo.Color (0.0, 0.2, .8, 0.1)); rg.AddColorStop (1.0, new Cairo.Color (0.0, 0.0, 0.0, 0.0)); g.Source = rg; g.Fill (); rg.Destroy (); #endif g.Operator = Operator.Over; g.Matrix = new Matrix (); g.Translate (cx, cy); if (source != null) CairoHelper.SetSourcePixbuf (g, source, -source.Width / 2, -source.Height / 2); g.Arc (0, 0, radius, 0, 2 * Math.PI); g.Fill (); if (overlay != null) { CairoHelper.SetSourcePixbuf (g, overlay, -overlay.Width / 2, -overlay.Height / 2); g.Arc (0, 0, radius, angle, angle + Math.PI); g.ClosePath (); g.FillPreserve (); g.SetSource (new SolidPattern (new Cairo.Color (1.0, 1.0, 1.0, 1.0))); g.Stroke (); } }