public Arc ( double xc, double yc, double radius, double angle1, double angle2 ) : void | ||
xc | double | |
yc | double | |
radius | double | |
angle1 | double | |
angle2 | double | |
리턴 | void |
static void draw (Context cr, int width, int height) { double xc = 0.5; double yc = 0.5; double radius = 0.4; double angle1 = 45.0 * (Math.PI / 180.0); // angles are specified double angle2 = 180.0 * (Math.PI / 180.0); // in radians cr.Scale (width, height); cr.LineWidth = 0.04; cr.Arc (xc, yc, radius, angle1, angle2); cr.Stroke (); // draw helping lines cr.Color = new Color(1, 0.2, 0.2, 0.6); cr.Arc (xc, yc, 0.05, 0, 2 * Math.PI); cr.Fill (); cr.LineWidth = 0.03; cr.Arc (xc, yc, radius, angle1, angle1); cr.LineTo (new PointD (xc, yc)); cr.Arc (xc, yc, radius, angle2, angle2); cr.LineTo (new PointD (xc, yc)); cr.Stroke (); }
//http://www.mono-project.com/docs/tools+libraries/libraries/Mono.Cairo/cookbook/ private static void drawRoundedRectangle(double x, double y, double width, double height, double radius, Cairo.Context g, Cairo.Color color) { g.Save(); //manage negative widths if (width < 0) { x += width; //it will shift to the left (width is negative) width *= -1; } if ((radius > height / 2) || (radius > width / 2)) { radius = min(height / 2, width / 2); } g.MoveTo(x, y + radius); g.Arc(x + radius, y + radius, radius, Math.PI, -Math.PI / 2); g.LineTo(x + width - radius, y); g.Arc(x + width - radius, y + radius, radius, -Math.PI / 2, 0); g.LineTo(x + width, y + height - radius); g.Arc(x + width - radius, y + height - radius, radius, 0, Math.PI / 2); g.LineTo(x + radius, y + height); g.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI); g.ClosePath(); g.Restore(); g.SetSourceRGB(color.R, color.G, color.B); g.FillPreserve(); g.SetSourceRGB(0, 0, 0); g.LineWidth = 2; g.Stroke(); }
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(); } }
protected void UpdateTexture () { text.SetSurfaceSize ((uint) (Width+MarginX),(uint) (Height+MarginY)); text.Clear (); Cairo.Context context = text.Create (); double lwidth = 1; double hlwidth = lwidth*0.5; double width = Width - lwidth; double height = Height - lwidth; double radius = Math.Min(marginX, marginY)*0.75; if ((radius > height / 2) || (radius > width / 2)) radius = Math.Min(height / 2, width / 2); context.MoveTo (hlwidth, hlwidth + radius); context.Arc (hlwidth + radius, hlwidth + radius, radius, Math.PI, -Math.PI / 2); context.LineTo (hlwidth + width - radius, hlwidth); context.Arc (hlwidth + width - radius, hlwidth + radius, radius, -Math.PI / 2, 0); context.LineTo (hlwidth + width, hlwidth + height - radius); context.Arc (hlwidth + width - radius, hlwidth + height - radius, radius, 0, Math.PI / 2); context.LineTo (hlwidth + radius, hlwidth + height); context.Arc (hlwidth + radius, hlwidth + height - radius, radius, Math.PI / 2, Math.PI); context.ClosePath (); context.LineWidth = lwidth; context.SetSourceRGB (1.0,1.0,1.0); context.Stroke (); ((IDisposable) context.Target).Dispose (); ((IDisposable) context).Dispose (); }
public static void DrawRoundedRectangle(Cairo.Context gr, double x, double y, double width, double height, double radius, Cairo.Color color, Cairo.Color borderColor) { gr.Save(); if ((radius > height / 2) || (radius > width / 2)) { radius = Math.Min(height / 2, width / 2); } gr.MoveTo(x, y + radius); gr.Arc(x + radius, y + radius, radius, Math.PI, -Math.PI / 2); gr.LineTo(x + width - radius, y); gr.Arc(x + width - radius, y + radius, radius, -Math.PI / 2, 0); gr.LineTo(x + width, y + height - radius); gr.Arc(x + width - radius, y + height - radius, radius, 0, Math.PI / 2); gr.LineTo(x + radius, y + height); gr.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI); gr.ClosePath(); gr.Restore(); gr.LineJoin = LineJoin.Round; gr.Color = borderColor; gr.StrokePreserve(); gr.Color = color; gr.Fill(); }
static void draw(Cairo.Context gr, int width, int height) { double xc = 0.5; double yc = 0.5; double radius = 0.4; double angle1 = 45.0 * (M_PI / 180.0); /* angles are specified */ double angle2 = 180.0 * (M_PI / 180.0); /* in radians */ gr.Scale(width, height); gr.LineWidth = 0.04; gr.Arc(xc, yc, radius, angle1, angle2); gr.Stroke(); /* draw helping lines */ gr.Color = new Color(1, 0.2, 0.2, 0.6); gr.Arc(xc, yc, 0.05, 0, 2 * M_PI); gr.Fill(); gr.LineWidth = 0.03; gr.Arc(xc, yc, radius, angle1, angle1); gr.LineTo(new PointD(xc, yc)); gr.Arc(xc, yc, radius, angle2, angle2); gr.LineTo(new PointD(xc, yc)); gr.Stroke(); }
static void draw(Cairo.Context gr, int width, int height) { int w, h; ImageSurface image; gr.Scale(width, height); gr.LineWidth = 0.04; gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI); gr.Clip(); gr.NewPath(); image = new ImageSurface("data/e.png"); w = image.Width; h = image.Height; gr.Scale(1.0 / w, 1.0 / h); image.Show(gr, 0, 0); image.Destroy(); gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI); gr.Clip(); gr.NewPath(); gr.Rectangle(new PointD(0, 0), 1, 1); gr.Fill(); gr.Color = new Color(0, 1, 0, 1); gr.MoveTo(new PointD(0, 0)); gr.LineTo(new PointD(1, 1)); gr.MoveTo(new PointD(1, 0)); gr.LineTo(new PointD(0, 1)); gr.Stroke(); }
//http://www.mono-project.com/docs/tools+libraries/libraries/Mono.Cairo/cookbook/ private static void drawRoundedRectangle(double x, double y, double width, double height, double radius, Cairo.Context g, Cairo.Color color) { g.Save(); if ((radius > height / 2) || (radius > width / 2)) { radius = min(height / 2, width / 2); } g.MoveTo(x, y + radius); g.Arc(x + radius, y + radius, radius, Math.PI, -Math.PI / 2); g.LineTo(x + width - radius, y); g.Arc(x + width - radius, y + radius, radius, -Math.PI / 2, 0); g.LineTo(x + width, y + height - radius); g.Arc(x + width - radius, y + height - radius, radius, 0, Math.PI / 2); g.LineTo(x + radius, y + height); g.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI); g.ClosePath(); g.Restore(); g.SetSourceRGB(color.R, color.G, color.B); g.FillPreserve(); g.SetSourceRGB(0, 0, 0); g.LineWidth = 2; g.Stroke(); }
void DrawDataPoint(Cairo.Context cr, int cellWidth, double height, int max, int day, int temp) { cr.Color = new Cairo.Color(0, 0, 0, 0.4); cr.Arc(BUTTON_SIZE + day * cellWidth * 2 + cellWidth / 2 + 2, 7 + height * (max - temp), 3, 0, 2 * Math.PI); cr.Fill(); cr.Color = colorTitle; cr.Arc(BUTTON_SIZE + day * cellWidth * 2 + cellWidth / 2, 5 + height * (max - temp), 3, 0, 2 * Math.PI); cr.Fill(); }
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(); }
public static void RoundedRectangle(Cairo.Context cr, double x, double y, double w, double h, double r, CairoCorners corners) { if (r < 0.0001 || corners == CairoCorners.None) { cr.Rectangle(x, y, w, h); return; } if ((corners & CairoCorners.TopLeft) != 0) { cr.MoveTo(x + r, y); } else { cr.MoveTo(x, y); } if ((corners & CairoCorners.TopRight) != 0) { cr.Arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2); } else { cr.LineTo(x + w, y); } if ((corners & CairoCorners.BottomRight) != 0) { cr.Arc(x + w - r, y + h - r, r, 0, Math.PI * 0.5); } else { cr.LineTo(x + w, y + h); } if ((corners & CairoCorners.BottomLeft) != 0) { cr.Arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI); } else { cr.LineTo(x, y + h); } if ((corners & CairoCorners.TopLeft) != 0) { cr.Arc(x + r, y + r, r, Math.PI, Math.PI * 1.5); } else { cr.LineTo(x, y); } }
public static void RoundedRectangle(this Context self, double x, double y, double width, double height, double radius) { // our radius can be no larger than half our height or width radius = Math.Min(radius, Math.Min(width / 2, height / 2)); self.MoveTo(x + radius, y); self.Arc(x + width - radius, y + radius, radius, Math.PI * 1.5, Math.PI * 2); self.Arc(x + width - radius, y + height - radius, radius, 0, Math.PI * .5); self.Arc(x + radius, y + height - radius, radius, Math.PI * .5, Math.PI); self.Arc(x + radius, y + radius, radius, Math.PI, Math.PI * 1.5); }
private void RoundedRect(Cairo.Context cr, Cairo.Rectangle rect, double r) { var rightAngle = Math.PI / 2.0; cr.NewPath(); cr.Arc(rect.X + rect.Width - r, rect.Y + r, r, -rightAngle, 0); cr.Arc(rect.X + rect.Width - r, rect.Y + rect.Height - r, r, 0, rightAngle); cr.Arc(rect.X + r, rect.Y + rect.Height - r, r, rightAngle, rightAngle * 2); cr.Arc(rect.X + r, rect.Y + r, r, rightAngle * 2, rightAngle * 3); cr.ClosePath(); }
private void SetTitlePath(Cairo.Context cr) { int radius = parent.WindowRadius; double x = .5; double y = .5; double width = parent.ThreePaneWidth - 1; cr.MoveTo(x + radius, y); cr.Arc(x + width - radius, y + radius, radius, Math.PI * 1.5, Math.PI * 2); cr.LineTo(x + width, Height); cr.LineTo(x, Height); cr.Arc(x + radius, y + radius, radius, Math.PI, Math.PI * 1.5); }
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); }
static void GetFrame(Cairo.Context cairo, double x, double y, double width, double height, double radius) { if (radius == 0) { cairo.MoveTo(x, y); cairo.Rectangle(x, y, width, height); } else { cairo.MoveTo(x + radius, y); cairo.Arc(x + width - radius, y + radius, radius, (Math.PI * 1.5), (Math.PI * 2)); cairo.Arc(x + width - radius, y + height - radius, radius, 0, (Math.PI * 0.5)); cairo.Arc(x + radius, y + height - radius, radius, (Math.PI * 0.5), Math.PI); cairo.Arc(x + radius, y + radius, radius, Math.PI, (Math.PI * 1.5)); } }
//private double last_invalidate_value = -1; /*private void Invalidate () * { * double current_value = (IsValueUpdatePending ? PendingValue : Value); * * // FIXME: Something is wrong with the updating below causing an * // invalid region when IsValueUpdatePending is true, so when * // that is the case for now, we trigger a full invalidation * if (last_invalidate_value < 0 || IsValueUpdatePending) { * last_invalidate_value = current_value; * InvalidateRender (); * return; * } * * double max = Math.Max (last_invalidate_value, current_value) * RenderSize.Width; * double min = Math.Min (last_invalidate_value, current_value) * RenderSize.Width; * * Rect region = new Rect ( * InvalidationRect.X + min, * InvalidationRect.Y, * (max - min) + 2 * ThrobberSize, * InvalidationRect.Height * ); * * last_invalidate_value = current_value; * InvalidateRender (region); * }*/ /*protected override Rect InvalidationRect { * get { return new Rect ( * -Margin.Left - ThrobberSize / 2, * -Margin.Top, * Allocation.Width + ThrobberSize, * Allocation.Height); * } * }*/ protected override void ClippedRender(Cairo.Context cr) { double throbber_r = ThrobberSize / 2.0; double throbber_x = Math.Round(RenderSize.Width * (IsValueUpdatePending ? PendingValue : Value)); double throbber_y = (Allocation.Height - ThrobberSize) / 2.0 - Margin.Top + throbber_r; double bar_w = RenderSize.Width * Value; Theme.Widget.StyleContext.Save(); Theme.Widget.StyleContext.AddClass("entry"); Theme.Widget.StyleContext.RenderBackground(cr, 0, 0, RenderSize.Width, RenderSize.Height); var color = CairoExtensions.GdkRGBAToCairoColor(Theme.Widget.StyleContext.GetColor(Gtk.StateFlags.Active)); Theme.Widget.StyleContext.Restore(); // TODO get Dark color Color fill_color = CairoExtensions.ColorShade(color, 0.4); Color light_fill_color = CairoExtensions.ColorShade(color, 0.3); fill_color.A = 1.0; light_fill_color.A = 1.0; using (var fill = new LinearGradient(0, 0, 0, RenderSize.Height)) { fill.AddColorStop(0, light_fill_color); fill.AddColorStop(0.5, fill_color); fill.AddColorStop(1, light_fill_color); cr.Rectangle(0, 0, bar_w, RenderSize.Height); cr.SetSource(fill); cr.Fill(); cr.SetSourceColor(fill_color); cr.Arc(throbber_x, throbber_y, throbber_r, 0, Math.PI * 2); cr.Fill(); } }
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(); }
static void draw(Cairo.Context gr, int width, int height) { gr.Scale(width, height); gr.LineWidth = 0.04; LinearGradient pat; pat = new LinearGradient(0.0, 0.0, 0.0, 1.0); pat.AddColorStop(1, new Color(0, 0, 0, 1)); pat.AddColorStop(0, new Color(1, 1, 1, 1)); gr.Rectangle(new PointD(0, 0), 1, 1 ); gr.Pattern = pat; gr.Fill(); pat.Destroy(); RadialGradient pat2 = new RadialGradient(0.45, 0.4, 0.1, 0.4, 0.4, 0.5); pat2.AddColorStop(0, new Color(1, 1, 1, 1)); pat2.AddColorStop(1, new Color(0, 0, 0, 1)); gr.Pattern = pat2; gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI); gr.Fill(); pat2.Destroy(); }
/// <summary>Paint on the graphics context</summary> /// <param name="context">The graphics context to draw on</param> public override void Paint(Cairo.Context context) { if (Selected) { context.SetSourceColor(OxyColors.Blue); } else { context.SetSourceColor(ForegroundColour); } // Draw circle context.LineWidth = 3; context.NewPath(); context.Arc(Location.X, Location.Y, Width / 2, 0, 2 * Math.PI); context.StrokePreserve(); context.SetSourceColor(Colour); context.Fill(); // Write text context.LineWidth = 1; context.SetSourceColor(OxyColors.Black); context.SetFontSize(13); DrawCentredText(context, Name, Location); }
//private double last_invalidate_value = -1; /*private void Invalidate () * { * double current_value = (IsValueUpdatePending ? PendingValue : Value); * * // FIXME: Something is wrong with the updating below causing an * // invalid region when IsValueUpdatePending is true, so when * // that is the case for now, we trigger a full invalidation * if (last_invalidate_value < 0 || IsValueUpdatePending) { * last_invalidate_value = current_value; * InvalidateRender (); * return; * } * * double max = Math.Max (last_invalidate_value, current_value) * RenderSize.Width; * double min = Math.Min (last_invalidate_value, current_value) * RenderSize.Width; * * Rect region = new Rect ( * InvalidationRect.X + min, * InvalidationRect.Y, * (max - min) + 2 * ThrobberSize, * InvalidationRect.Height * ); * * last_invalidate_value = current_value; * InvalidateRender (region); * }*/ /*protected override Rect InvalidationRect { * get { return new Rect ( * -Margin.Left - ThrobberSize / 2, * -Margin.Top, * Allocation.Width + ThrobberSize, * Allocation.Height); * } * }*/ protected override void ClippedRender(Cairo.Context cr) { double throbber_r = ThrobberSize / 2.0; double throbber_x = Math.Round(RenderSize.Width * (IsValueUpdatePending ? PendingValue : Value)); double throbber_y = (Allocation.Height - ThrobberSize) / 2.0 - Margin.Top + throbber_r; double bar_w = RenderSize.Width * Value; cr.SetSourceColor(Theme.Colors.GetWidgetColor(GtkColorClass.Base, Gtk.StateType.Normal)); cr.Rectangle(0, 0, RenderSize.Width, RenderSize.Height); cr.Fill(); Color color = Theme.Colors.GetWidgetColor(GtkColorClass.Dark, Gtk.StateType.Active); Color fill_color = CairoExtensions.ColorShade(color, 0.4); Color light_fill_color = CairoExtensions.ColorShade(color, 0.3); fill_color.A = 1.0; light_fill_color.A = 1.0; LinearGradient fill = new LinearGradient(0, 0, 0, RenderSize.Height); fill.AddColorStop(0, light_fill_color); fill.AddColorStop(0.5, fill_color); fill.AddColorStop(1, light_fill_color); cr.Rectangle(0, 0, bar_w, RenderSize.Height); cr.SetSource(fill); cr.Fill(); cr.SetSourceColor(fill_color); cr.Arc(throbber_x, throbber_y, throbber_r, 0, Math.PI * 2); cr.Fill(); }
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)); }
private static void DrawClock(object sender, DrawnArgs args) { Cairo.Context cr = args.Cr; int width = args.Width; int height = args.Height; DateTime now = DateTime.Now; double hours, minutes, seconds; Clutter.Color color; seconds = now.Second * Math.PI / 30; minutes = now.Minute * Math.PI / 30; hours = now.Hour * Math.PI / 6; cr.Save(); cr.Operator = Operator.Clear; cr.Paint(); cr.Restore(); cr.Operator = Operator.Over; cr.Scale(width, height); cr.LineCap = LineCap.Round; cr.LineWidth = 0.1; Global.CairoSetSourceColor(cr, Clutter.Color.New(0, 0, 0, 255)); cr.Translate(0.5, 0.5); cr.Arc(0, 0, 0.4, 0, Math.PI * 2); cr.Stroke(); color = Clutter.Color.New(255, 255, 255, 128); Global.CairoSetSourceColor(cr, color); cr.MoveTo(0, 0); cr.Arc(Math.Sin(seconds) * 0.4, -Math.Cos(seconds) * 0.4, 0.05, 0, Math.PI * 2); cr.Fill(); color = Clutter.Color.New(78, 154, 6, 196); Global.CairoSetSourceColor(cr, color); cr.MoveTo(0, 0); cr.LineTo(Math.Sin(minutes) * 0.4, -Math.Cos(minutes) * 0.4); cr.Stroke(); cr.MoveTo(0, 0); cr.LineTo(Math.Sin(hours) * 0.2, -Math.Cos(hours) * 0.2); cr.Stroke(); args.RetVal = true; }
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 void DrawPoints(List<PointD> points,Context cr) { foreach (PointD p in points){ cr.MoveTo(p); cr.SetSourceRGB (0.3, 0.3, 0.3); cr.Arc (p.X, p.Y, 2, 0, 2 * Math.PI); cr.Fill (); } }
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); }
protected void DrawRoundedRectangle(Cairo.Context gr, double x, double y, double width, double height, double radius) { gr.Save(); if ((radius > height / 2) || (radius > width / 2)) { radius = min(height / 2, width / 2); } gr.MoveTo(x, y + radius); gr.Arc(x + radius, y + radius, radius, Math.PI, -Math.PI / 2); gr.LineTo(x + width - radius, y); gr.Arc(x + width - radius, y + radius, radius, -Math.PI / 2, 0); gr.LineTo(x + width, y + height - radius); gr.Arc(x + width - radius, y + height - radius, radius, 0, Math.PI / 2); gr.LineTo(x + radius, y + height); gr.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI); gr.ClosePath(); gr.Restore(); }
public void DrawArc(Coordinate point, double radius, double startAngle, double sweepAngle) { var pt = ToCairoPoint(point); var r = transformer.ScaleOnX(radius); context.NewSubPath(); context.LineWidth = 1.0; context.SetSourceColor(currentLineColor); context.Arc(pt.X, pt.Y, r, startAngle, startAngle + sweepAngle); context.Stroke(); }
public override void RealRenderCairo(Cairo.Context context) { if (Camera.IsRendererOutOfScreen(this)) { return; } Vector2 screenPos = Camera.WorldToScreenPosition(gameObject.transform.position); float realRad = gameObject.transform.LocalToWorldLength(radius); double screenRad = (double)realRad * Camera.instance.zoom; context.Arc((double)screenPos.x, (double)screenPos.y, screenRad, 0, 2 * Math.PI); if (surf == null) { if (useShadow) { LinearGradient g = new LinearGradient(screenPos.x - screenRad, screenPos.y + screenRad, screenPos.x + screenRad, screenPos.y - screenRad); //g.AddColorStopRgb (0.75, new Cairo.Color (ColorR, ColorG, ColorB, ColorA)); g.AddColorStop(0, new Cairo.Color(ColorR * 0.5, ColorG * 0.5, ColorB * 0.5, ColorA * 0.5)); g.AddColorStop(1, new Cairo.Color(ColorR, ColorG, ColorB, ColorA)); context.SetSource(g); context.Fill(); g.Dispose(); } else { context.SetSourceRGBA(ColorR, ColorG, ColorB, ColorA); context.Fill(); } } else { context.SetSourceSurface(surf, (int)(screenPos.x - screenRad), (int)(screenPos.y - screenRad)); context.Fill(); context.GetSource().Dispose(); //surf.Dispose (); } /*context.SetSourceRGBA (1,1,1,1); * context.Arc ((double)screenPos.x, * (double)screenPos.y, * (double)realRad * Camera.instance.zoom, * MyMath.FixAngleRad(-Math.PI/4 - gameObject.transform.rotation), MyMath.FixAngleRad(Math.PI /4 - gameObject.transform.rotation)); * * context.Fill ();*/ }
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 void draw(Context cr) { Triangle t = model.tri; switch (model.alignment) { case ActiveTriangle.TriangleAlignment.ChaoticEvil: cr.SetSourceRGB (0.5, 0, 0); break; case ActiveTriangle.TriangleAlignment.TrueNeutral: cr.SetSourceRGB (0, 0.8, 0); break; default: cr.SetSourceRGB (1.0, 1.0, 0); break; } cr.LineWidth = 1.1; cr.MoveTo (t.a); cr.LineTo (t.b); cr.MoveTo (t.b); cr.LineTo (t.c); cr.MoveTo (t.c); cr.LineTo (t.a); cr.Stroke (); cr.Fill(); Tuple<PointD,PointD,PointD,PointD> points; points = model.getSharpestPointAndAssociatedMidpointAndDullestPoints (); PointD sharpest = points.Item1; PointD midPoint = points.Item2; cr.SetSourceRGB (1.0, 0.3, 0.3); cr.Arc (sharpest.X, sharpest.Y, 2, 0, 2 * Math.PI); cr.Fill (); cr.Arc (midPoint.X, midPoint.Y, 2, 0, 2 * Math.PI); cr.Fill (); }
public virtual void Update() { outline.Clear(); Cairo.Context context = outline.Create(); context.LineWidth = line_width; context.MoveTo(outline.Height * 0.5, 0.5); context.Arc(outline.Width - outline.Height * 0.5, outline.Height * 0.5, (outline.Height - line_width) * 0.5, 1.5 * Math.PI, 0.5 * Math.PI); context.Arc(outline.Height * 0.5, outline.Height * 0.5, (outline.Height - line_width) * 0.5, 0.5 * Math.PI, 1.5 * Math.PI); context.ClosePath(); context.SetSourceRGBA(1.0, 1.0, 1.0, 0.2); context.FillPreserve(); context.SetSourceRGB(1.0, 1.0, 1.0); context.Stroke(); ((IDisposable)context.Target).Dispose(); ((IDisposable)context).Dispose(); handle.Update(); handle.RaiseTop(); arrow_left.Update(); arrow_right.Update(); }
public static void RoundedCell(Cairo.Context gr, int i, int j, double radius, bool rotate) { double cellsize = radius * 2; double x = cellsize * i, y = cellsize * j; gr.Save(); if (rotate) { gr.MoveTo(x + radius, y); gr.Arc(x, y, radius, 0, Math.PI / 2); gr.MoveTo(x + cellsize, y + radius); gr.ArcNegative(x + cellsize, y + cellsize, radius, -Math.PI / 2, Math.PI); } else { gr.MoveTo(x, y + radius); gr.Arc(x, y + cellsize, radius, -Math.PI / 2, 0); gr.MoveTo(x + radius, y); gr.ArcNegative(x + cellsize, y, radius, Math.PI, Math.PI / 2); } gr.Restore(); }
public void arc(Context cr, int width, int height) { PointD c = new PointD (0.5, 0.5); double radius = 0.4; double angle1 = 45.0 * (Math.PI/180.0); /* angles are specified */ double angle2 = 180.0 * (Math.PI/180.0); /* in radians */ Normalize(cr, width, height); cr.Arc(c.X, c.Y, radius, angle1, angle2); cr.Stroke(); // draw helping lines cr.Color = new Color (1, 0.2, 0.2, 0.6); cr.Arc(c.X, c.Y, 0.05, 0, 2*Math.PI); cr.Fill(); cr.LineWidth = 0.03; cr.Arc(c.X, c.Y, radius, angle1, angle1); cr.LineTo(c); cr.Arc(c.X, c.Y, radius, angle2, angle2); cr.LineTo(c); cr.Stroke(); }
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 (); }
private static void plotArc(int centerx, int centery, int radius, double start, double end, Cairo.Context g, Cairo.Color color) { //pie chart g.MoveTo(centerx, centery); g.Arc(centerx, centery, radius, start * Math.PI, end * Math.PI); g.ClosePath(); g.SetSourceRGB(color.R, color.G, color.B); g.FillPreserve(); g.SetSourceRGB(0, 0, 0); g.LineWidth = 2; g.Stroke(); }
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 (); }
static void draw(Cairo.Context gr, int width, int height) { gr.Scale(width, height); gr.LineWidth = 0.04; gr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Bold); gr.SetFontSize(0.35); gr.MoveTo(new PointD(0.04, 0.53)); gr.ShowText("Hello"); gr.MoveTo(new PointD(0.27, 0.65)); gr.TextPath("void"); gr.ColorRgb = new Color(0.5, 0.5, 1, 0); gr.FillPreserve(); gr.ColorRgb = new Color(0, 0, 0, 0); gr.LineWidth = 0.01; gr.Stroke(); gr.Color = new Color(1, 0.2, 0.2, 0.6); gr.Arc(0.04, 0.53, 0.02, 0, 2 * M_PI); gr.Arc(0.27, 0.65, 0.02, 0, 2 * M_PI); gr.Fill(); }
public static void Draw (Context grw, ArcElement arc) { if (arc.Foregraund != null) { grw.SetSourceRGB ( arc.Foregraund.Red, arc.Foregraund.Green, arc.Foregraund.Blue); } grw.Arc ( arc.Center.GeometryX, arc.Center.GeometryY, arc.GeometryRadius, arc.ArcStart, arc.ArcStop); grw.Stroke (); }
public static void DrawVertexStructure(VertexStructure vs, Context cr) { VertexStructure head = vs; int i = 0; do { cr.MoveTo (vs.v); cr.SetSourceRGB (0, 0, 0.8); cr.Arc (vs.v.X, vs.v.Y, 2, 0, 2 * Math.PI); cr.Fill (); cr.LineWidth = 1; cr.MoveTo (vs.v); cr.LineTo(vs.next.v); cr.Stroke(); vs = vs.next; //Logger.Log("Meh..." + i); i++; } while(!ReferenceEquals(vs,head)); }
protected override Gdk.Rectangle OnMouseMove (Context g, Color strokeColor, ImageSurface surface, int x, int y, int lastX, int lastY) { int dx = x - lastX; int dy = y - lastY; double d = Math.Sqrt (dx * dx + dy * dy) * 2.0; double cx = Math.Floor (x / 100.0) * 100 + 50; double cy = Math.Floor (y / 100.0) * 100 + 50; int steps = Random.Next (1, 10); double step_delta = d / steps; for (int i = 0; i < steps; i++) { g.Arc (cx, cy, (steps - i) * step_delta, 0, Math.PI * 2); g.Stroke (); } return Gdk.Rectangle.Zero; }
public static void Draw(Context grw, Connector con) { var c = con.Selected ? AppController.Instance.Config.SelectedConnectorColor : !con.ConnectedTo.Any() ? con.Foregraund : AppController.Instance.Config.ConnectedColor; if ( c != null) { grw.SetSourceRGB ( c.Red, c.Green, c.Blue); } grw.Arc ( con.Center.GeometryX, con.Center.GeometryY, con.GeometryRadius, 0, 2 * Math.PI); grw.StrokePreserve (); grw.Fill (); }
static void DrawCloseButton (Context context, Gdk.Point center, bool hovered, double opacity, double animationProgress) { if (hovered) { const double radius = 6; context.Arc (center.X, center.Y, radius, 0, Math.PI * 2); context.SetSourceRGBA (.6, .6, .6, opacity); context.Fill (); context.SetSourceRGBA (0.95, 0.95, 0.95, opacity); context.LineWidth = 2; context.MoveTo (center.X - 3, center.Y - 3); context.LineTo (center.X + 3, center.Y + 3); context.MoveTo (center.X - 3, center.Y + 3); context.LineTo (center.X + 3, center.Y - 3); context.Stroke (); } else { double lineColor = .63 - .1 * animationProgress; const double fillColor = .74; double heightMod = Math.Max (0, 1.0 - animationProgress * 2); context.MoveTo (center.X - 3, center.Y - 3 * heightMod); context.LineTo (center.X + 3, center.Y + 3 * heightMod); context.MoveTo (center.X - 3, center.Y + 3 * heightMod); context.LineTo (center.X + 3, center.Y - 3 * heightMod); context.LineWidth = 2; context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity); context.Stroke (); if (animationProgress > 0.5) { double partialProg = (animationProgress - 0.5) * 2; context.MoveTo (center.X - 3, center.Y); context.LineTo (center.X + 3, center.Y); context.LineWidth = 2 - partialProg; context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity); context.Stroke (); double radius = partialProg * 3.5; // Background context.Arc (center.X, center.Y, radius, 0, Math.PI * 2); context.SetSourceRGBA (fillColor, fillColor, fillColor, opacity); context.Fill (); // Inset shadow using (var lg = new LinearGradient (0, center.Y - 5, 0, center.Y)) { context.Arc (center.X, center.Y + 1, radius, 0, Math.PI * 2); lg.AddColorStop (0, new Cairo.Color (0, 0, 0, 0.2 * opacity)); lg.AddColorStop (1, new Cairo.Color (0, 0, 0, 0)); context.SetSource (lg); context.Stroke (); } // Outline context.Arc (center.X, center.Y, radius, 0, Math.PI * 2); context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity); context.Stroke (); } } }
protected virtual void ShapeSurface(Context cr, Cairo.Color color) { cr.Operator = Operator.Source; Cairo.Pattern p = new Cairo.SolidPattern (new Cairo.Color (0, 0, 0, 0)); cr.Source = p; p.Destroy (); cr.Paint (); cr.Operator = Operator.Over; Cairo.Pattern r = new SolidPattern (color); cr.Source = r; r.Destroy (); cr.MoveTo (round, 0); if (x_align == 1.0) cr.LineTo (Allocation.Width, 0); else cr.Arc (Allocation.Width - round, round, round, - Math.PI * 0.5, 0); if (x_align == 1.0 || y_align == 1.0) cr.LineTo (Allocation.Width, Allocation.Height); else cr.Arc (Allocation.Width - round, Allocation.Height - round, round, 0, Math.PI * 0.5); if (y_align == 1.0) cr.LineTo (0, Allocation.Height); else cr.Arc (round, Allocation.Height - round, round, Math.PI * 0.5, Math.PI); cr.Arc (round, round, round, Math.PI, Math.PI * 1.5); cr.ClosePath (); cr.Fill (); }
private void DrawCircle(Context c, bool dashed, double x1, double y1, double x2, double y2) { double xc,yc,radius,angle1,angle2; xc=x1+(x2-x1)/2 - xOffset; yc=y1+(y2-y1)/2 - yOffset; radius = Math.Sqrt(Math.Pow((x2-x1),2)+ Math.Pow((y2-y1),2)); radius /=2; angle1 = 0.0 * (Math.PI/180); angle2 = 360.0 * (Math.PI/180); SetContextProperties(c, dashed); c.Arc(xc,yc,radius,angle1,angle2); c.Stroke(); c.Fill(); ResetDash(c); }
public static void Draw(Context grw, Arc3PointsElement arc) { const double eps = 0.000001; double arcStart; double arcEnd; if (arc.Foregraund != null) { grw.SetSourceRGB( arc.Foregraund.Red, arc.Foregraund.Green, arc.Foregraund.Blue); } var arcCenter = new PointD(0, 0); var yDeltaA = arc.Middle.GeometryY - arc.Start.GeometryY; var xDeltaA = arc.Middle.GeometryX - arc.Start.GeometryX; var yDeltaB = arc.End.GeometryY - arc.Middle.GeometryY; var xDeltaB = arc.End.GeometryX - arc.Middle.GeometryX; //common case - no perpendicular & collinear lines if ((Math.Abs(xDeltaA) > eps) && (Math.Abs(xDeltaB) > eps) && (Math.Abs(yDeltaA) > eps) && (Math.Abs(yDeltaB) > eps)) { var aSlope = yDeltaA / xDeltaA; var bSlope = yDeltaB / xDeltaB; if (Math.Abs(aSlope - bSlope) <= eps) { //throw new ArgumentException("3 points lie at one line"); return; } arcCenter.X = (aSlope * bSlope * (arc.Start.GeometryY - arc.End.GeometryY) + bSlope * (arc.Start.GeometryX + arc.Middle.GeometryX) - aSlope * (arc.Middle.GeometryX + arc.End.GeometryX)) / (2 * (bSlope - aSlope)); arcCenter.Y = -1 * (arcCenter.X - (arc.Start.GeometryX + arc.Middle.GeometryX) / 2) / aSlope + (arc.Start.GeometryY + arc.Middle.GeometryY) / 2; } else { //vertical or horizontal cases if (Math.Abs(xDeltaA) <= eps) { //1st is vertical if (Math.Abs(xDeltaB) <= eps) { //2nd is vertical too //throw new ArgumentException("Both lines are vertical"); return; } if (Math.Abs(yDeltaB) > eps) { // 2nd is not horizontal //throw new NotImplementedException("Only first vertical"); return; } //square angle arcCenter.X = 0.5 * (arc.Middle.GeometryX + arc.End.GeometryX); arcCenter.Y = 0.5 * (arc.Start.GeometryY + arc.Middle.GeometryY); } if (Math.Abs(yDeltaA) <= eps) { //1st is horizontal if (Math.Abs(yDeltaB) <= eps) { //2nd is horizontal too //throw new ArgumentException("Both line are horizontal"); return; } if (Math.Abs(xDeltaB) > eps) { //1st is not horizontal //throw new NotImplementedException("Only first horizontal"); return; } //square angle arcCenter.X = 0.5 * (arc.Start.GeometryX + arc.Middle.GeometryX); arcCenter.Y = 0.5 * (arc.Middle.GeometryY + arc.End.GeometryY); } } //radius var arcRadius = Math.Sqrt(Math.Pow(arc.Start.GeometryX - arcCenter.X, 2) + Math.Pow(arc.Start.GeometryY - arcCenter.Y, 2)); //arc angles var xStartDelta = arc.Start.GeometryX - arcCenter.X; var yStartDelta = arc.Start.GeometryY - arcCenter.Y; var xEndDelta = arc.End.GeometryX - arcCenter.X; var yEndDelta = arc.End.GeometryY - arcCenter.Y; //start of arc if (Math.Abs(xStartDelta) < eps) { if (yStartDelta < 0.0) { arcStart = -0.5 * Math.PI; } else { arcStart = 0.5 * Math.PI; } } else { arcStart = Math.Atan2(yStartDelta, xStartDelta); } //end of arc if (Math.Abs(xEndDelta) < eps) { if (yEndDelta < 0.0) { arcEnd = -0.5 * Math.PI; } else { arcEnd = 0.5 * Math.PI; } } else { arcEnd = Math.Atan2(yEndDelta, xEndDelta); } if (Math.Sign((arc.Middle.GeometryX - arc.Start.GeometryX) * (arc.Middle.GeometryY - arc.End.GeometryY) - (arc.Middle.GeometryY - arc.Start.GeometryY) * (arc.Middle.GeometryX - arc.End.GeometryX)) < 0) { grw.Arc( arcCenter.X, arcCenter.Y, arcRadius, arcStart, arcEnd); } else { grw.ArcNegative( arcCenter.X, arcCenter.Y, arcRadius, arcStart, arcEnd); } grw.Stroke(); }
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 (); } }
private void DrawPoint(Context context, int j, double val) { double xl = 0.5 * (double)(Width - 60) / N; int x = (int)((Width - 60) * ((double)j / N) + 50 + xl); int y = ValueToY (val); context.MoveTo (x, y); context.Arc(x, y, 2, 0, 2 * Math.PI); context.StrokePreserve(); context.Fill(); }
public void clip_image(Context cr, int width, int height) { Normalize (cr, width, height); cr.Arc (0.5, 0.5, 0.3, 0, 2*Math.PI); cr.Clip (); cr.NewPath (); // path not consumed by clip() ImageSurface image = new ImageSurface ("data/romedalen.png"); int w = image.Width; int h = image.Height; cr.Scale (1.0/w, 1.0/h); cr.SetSourceSurface (image, 0, 0); cr.Paint (); image.Destroy (); }
public void gradient(Context cr, int width, int height) { Normalize (cr, width, height); LinearGradient lg = new LinearGradient(0.0, 0.0, 0.0, 1.0); lg.AddColorStop(1, new Color(0, 0, 0, 1)); lg.AddColorStop(0, new Color(1, 1, 1, 1)); cr.Rectangle(0,0,1,1); cr.Source = lg; cr.Fill(); RadialGradient rg = new RadialGradient(0.45, 0.4, 0.1, 0.4, 0.4, 0.5); rg.AddColorStop(0, new Color (1, 1, 1, 1)); rg.AddColorStop(1, new Color (0, 0, 0, 1)); cr.Source = rg; cr.Arc(0.5, 0.5, 0.3, 0, 2 * Math.PI); cr.Fill(); }
protected override bool OnExposed(Context cr, Rectangle area) { cr.Color = Color; if(rL > 0.0 && rR > 0.0 && rT > 0.0 && rB > 0.0) { double width = Allocation.Width; double height = Allocation.Height; double radL = rL * width; double radR = rR * width; double radT = rT * height; double radB = rB * height; Matrix m = cr.Matrix; cr.Translate(radL, radT); cr.Scale(radL, radT); cr.Arc(0.0, 0.0, 1.0, 1.0 * Math.PI, 1.5 * Math.PI); cr.Matrix = m; cr.Translate(width - radR, radT); cr.Scale(radR, radT); cr.Arc(0.0, 0.0, 1.0, 1.5 * Math.PI, 2.0 * Math.PI); cr.Matrix = m; cr.Translate(width - radR, height - radB); cr.Scale(radR, radB); cr.Arc(0.0, 0.0, 1.0, 0.0 * Math.PI, 0.5 * Math.PI); cr.Matrix = m; cr.Translate(radL, height - radB); cr.Scale(radL, radB); cr.Arc(0.0, 0.0, 1.0, 0.5 * Math.PI, 1.0 * Math.PI); cr.ClosePath(); } else cr.Rectangle(area); cr.Fill(); return true; }
public void text(Context cr, int width, int height) { Normalize (cr, width, height); cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Bold); cr.SetFontSize(0.35); cr.MoveTo(0.04, 0.53); cr.ShowText("Hello"); cr.MoveTo(0.27, 0.65); cr.TextPath("void"); cr.Save(); cr.Color = new Color (0.5,0.5,1); cr.Fill(); cr.Restore(); cr.LineWidth = 0.01; cr.Stroke(); // draw helping lines cr.Color = new Color (1.0, 0.2, 0.2, 0.6); cr.Arc(0.04, 0.53, 0.02, 0, 2*Math.PI); cr.Arc(0.27, 0.65, 0.02, 0, 2*Math.PI); cr.Fill(); }
public override void Draw(Context cr, Gdk.Rectangle clip) { base.Draw(cr, clip); double X = clip.X; double Y = clip.Y; double Width = clip.Width; double Height = clip.Height; // Blue Rulings if(horizontalRule) { cr.Color = blue; for(double i = Y - (Y % ruleDistance) + ruleDistance; i <= Y + Height; i += ruleDistance) { cr.MoveTo(X, i); cr.LineTo(X + Width, i); cr.Stroke(); } } if(verticalRule) { cr.Color = blue; for(double i = X - (X % ruleDistance) + ruleDistance; i <= X + Width; i += ruleDistance) { cr.MoveTo(i, Y); cr.LineTo(i, Y + Height); cr.Stroke(); } } // Red Margin Line if(leftMargin) { cr.Color = red; cr.MoveTo(marginSize, Y); cr.LineTo(marginSize, Y + Height); cr.Stroke(); } // Holes if(holes) { cr.Color = black; cr.Arc(ruleDistance/2, 150, 17, 0, 2 * Math.PI); cr.Arc(ruleDistance/2, 650, 17, 0, 2 * Math.PI); cr.Arc(ruleDistance/2, 1150,17, 0, 2 * Math.PI); cr.Fill(); } }
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(); } } } } } }
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 (); }
public void text_align_center(Context cr, int width, int height) { Normalize (cr, width, height); cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal); cr.SetFontSize(0.2); TextExtents extents = cr.TextExtents("cairo"); double x = 0.5 -((extents.Width/2.0) + extents.XBearing); double y = 0.5 -((extents.Height/2.0) + extents.YBearing); cr.MoveTo(x, y); cr.ShowText("cairo"); // draw helping lines cr.Color = new Color (1, 0.2, 0.2, 0.6); cr.Arc(x, y, 0.05, 0, 2*Math.PI); cr.Fill(); cr.MoveTo(0.5, 0); cr.RelLineTo(0, 1); cr.MoveTo(0, 0.5); cr.RelLineTo(1, 0); cr.Stroke(); }
public void clip(Context cr, int width, int height) { Normalize (cr, width, height); cr.Arc(0.5, 0.5, 0.3, 0, 2 * Math.PI); cr.Clip(); cr.NewPath(); // current path is not consumed by cairo_clip() cr.Rectangle(0, 0, 1, 1); cr.Fill(); cr.Color = new Color (0, 1, 0); cr.MoveTo(0, 0); cr.LineTo(1, 1); cr.MoveTo(1, 0); cr.LineTo(0, 1); cr.Stroke(); }
void RoundRectangle (Context ctx, Rectangle rect, double radius) { double degrees = Math.PI / 180; var x = rect.X; var y = rect.Y; var height = rect.Height; var width = rect.Width; ctx.NewSubPath (); ctx.Arc (x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees); ctx.Arc (x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees); ctx.Arc (x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees); ctx.Arc (x + radius, y + radius, radius, 180 * degrees, 270 * degrees); ctx.ClosePath (); }
public void text_extents(Context cr, int width, int height) { double x=0.1; double y=0.6; string utf8 = "cairo"; Normalize (cr, width, height); cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal); cr.SetFontSize(0.4); TextExtents extents = cr.TextExtents(utf8); cr.MoveTo(x,y); cr.ShowText(utf8); // draw helping lines cr.Color = new Color (1, 0.2, 0.2, 0.6); cr.Arc(x, y, 0.05, 0, 2*Math.PI); cr.Fill(); cr.MoveTo(x,y); cr.RelLineTo(0, -extents.Height); cr.RelLineTo(extents.Width, 0); cr.RelLineTo(extents.XBearing, -extents.YBearing); cr.Stroke(); }