/// <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)); }
public void draw(Cairo.Context cr) { cr.MoveTo (position); cr.SetSourceRGB (0, 1.0, 0); cr.Arc (position.X, position.Y, 5, 0, 2 * Math.PI); cr.Fill (); }
/// <summary> /// Draw the specified cairoContext, centerX, centerY and scale. /// </summary> /// <param name="cairoContext">Cairo context.</param> /// <param name="centerX">Center x.</param> /// <param name="centerY">Center y.</param> /// <param name="scale">Scale.</param> public void Draw(Cairo.Context cairoContext, int centerX, int centerY, double scale) { cairoContext.SetSourceRGB (0, 0, 200); cairoContext.LineWidth = 1.0; cairoContext.LineCap = LineCap.Butt; //cairoContext.MoveTo (OriginalX, -OriginalY); //int x = centerX; //Console.WriteLine ("point: " + (robot.PathPointList [robot.PathPointList.Count-1] [1]*100)); //if (30 <= (robot.PathPointList [robot.PathPointList.Count - 1] [1] * 100)) //{ //robot.Halt (); //Console.WriteLine ("\n\n Has Gone 30cm \n\n"); //} for (int i = 1; i < robot.PathPointList.Count; i++) { cairoContext.MoveTo (centerX + (robot.PathPointList [i - 1] [0] * 100), centerY - (robot.PathPointList [i - 1] [1] * 100)); cairoContext.LineTo (centerX + (robot.PathPointList [i] [0] * 100), centerY - (robot.PathPointList [i] [1] * 100)); // Console.WriteLine (path[0]*100+" , "+ path[1]*100); cairoContext.Stroke (); } foreach (double[] path in robot.PathPointList) { //cairoContext.MoveTo (centerX - (path[0] * 100), centerY - (path[1] * 100)); } }
private void Draw(Cairo.Context cr, int width, int heigth) { foreach (var path in pathPosition.Keys) { var pPosition = pathPosition[path]; var begin = pPosition.Item1; var end = pPosition.Item2; cr.SetSourceRGB(1, 1, 1); cr.MoveTo(begin.X, begin.Y); cr.LineTo(end.X, end.Y); cr.Stroke(); cr.SetSourceRGB(0, 0, 0); } foreach (var path in pathPosition.Keys) { var pPosition = pathPosition[path]; var begin = pPosition.Item1; var end = pPosition.Item2; if (path is BlockingPath) { var blockingPath = path as BlockingPath; if (blockingPath.IsBlocked) { cr.SetSourceRGB(1, 0, 0); } else { cr.SetSourceRGB(0, 1, 0); } cr.Rectangle(new Cairo.Rectangle(end.X - 6, end.Y - 6, 12, 12)); cr.Fill(); cr.SetSourceRGB(0, 0, 0); } else if (path is SourcePath) { var sourcePath = path as SourcePath; cr.MoveTo(begin.X, begin.Y); cr.TextPath(sourcePath.Queue.ToString()); cr.Fill(); } foreach (var vehicle in path.VehiclePosition.Keys) { var position = path.VehiclePosition[vehicle]; var r = position / path.Length; var x = begin.X + (end.X - begin.X) * r; var y = begin.Y + (end.Y - begin.Y) * r; cr.Arc(x, y, 5, 0, 2 * Math.PI); cr.Fill(); } } cr.Stroke(); }
public void draw(Cairo.Context cr) { if (!canSeePlayer) { return; } cr.MoveTo (position); cr.SetSourceRGB (1.0, 0.0, 0); cr.Arc (position.X, position.Y, 5, 0, 2 * Math.PI); cr.Fill (); }
public void draw(Cairo.Context cr) { cr.LineWidth = 3; cr.SetSourceRGB(0, 0.9, 0.0); //cr.Translate (l1.P1.X, l1.P1.Y); cr.MoveTo(position); cr.LineTo (position.X + width, position.Y); cr.LineTo (position.X + width, position.Y + height); cr.LineTo (position.X, position.Y + height); cr.LineTo (position.X, position.Y); cr.Stroke (); }
public override void DrawBackground (MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset) { int markerStart = Offset; int markerEnd = EndOffset; double @from; double to; var startXPos = metrics.TextRenderStartPosition; var endXPos = metrics.TextRenderEndPosition; var y = metrics.LineYRenderStartPosition; if (markerStart < startOffset && endOffset < markerEnd) { @from = startXPos; to = endXPos; } else { int start = startOffset < markerStart ? markerStart : startOffset; int end = endOffset < markerEnd ? endOffset : markerEnd; uint curIndex = 0, byteIndex = 0; TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex); int x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X; @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale); TextViewMargin.TranslateToUTF8Index (metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex); x_pos = metrics.Layout.Layout.IndexToPos ((int)byteIndex).X; to = startXPos + (int)(x_pos / Pango.Scale.PangoScale); } @from = Math.Max (@from, editor.TextViewMargin.XOffset); to = Math.Max (to, editor.TextViewMargin.XOffset); if (@from <= to) { if (metrics.TextEndOffset < markerEnd) to = metrics.WholeLineWidth + metrics.TextRenderStartPosition; var c1 = editor.Options.GetColorStyle ().PlainText.Background; var c2 = editor.Options.GetColorStyle ().SelectedText.Background; cr.SetSourceRGB ((c1.R + c2.R) / 2, (c1.G + c2.G) / 2, (c1.B + c2.B) / 2); cr.Rectangle (@from, y, to - @from, metrics.LineHeight); cr.Fill (); } }
/// <summary> /// Draw every landmark contained within this class. /// </summary> /// <param name="cairoContext">Cairo context.</param> /// <param name="centerX">Center x.</param> /// <param name="centerY">Center y.</param> /// <param name="scale">Scale currently unused.</param> public void Draw(Cairo.Context cairoContext, int centerX, int centerY, double scale/*, Landmark[] a*/) { cairoContext.SetSourceRGB (0, 255, 0); cairoContext.LineWidth = 1.0; cairoContext.LineCap = LineCap.Butt; /*for (int i = 0; i < a.Length; i++) { // Draw the slope. cairoContext.MoveTo (centerX + ((a[i].a / -a[i].b) * 100), centerY); cairoContext.LineTo (centerX, centerY - (a[i].b * 100)); // Draw the line. //cairoContext.MoveTo (centerX - (landmark.x1y1[0] * 100), centerY - (landmark.x1y1[1] * 100)); //cairoContext.LineTo (centerX - (landmark.x2y2[0] * 100), centerY - (landmark.x2y2[1] * 100)); cairoContext.Stroke (); }*/ foreach (Landmark landmark in landmarks) { // Draw the slope. //cairoContext.MoveTo (centerX + (slope * 100), centerY); //cairoContext.LineTo (centerX, centerY - (landmark.b * 100)); // Draw the real line. double x1 = (((-centerY) / 100) - landmark.b) / landmark.a; double x2 = (((centerY) / 100) - landmark.b) / landmark.a; cairoContext.MoveTo (centerX + (-x1 * 100), centerY * 2); cairoContext.LineTo (centerX - (x2 * 100), 0); // Draw the length of the line. //cairoContext.MoveTo (centerX - (landmark.x1y1[0] * 100), centerY - (landmark.x1y1[1] * 100)); //cairoContext.LineTo (centerX - (landmark.x2y2[0] * 100), centerY - (landmark.x2y2[1] * 100)); cairoContext.Stroke (); } }
void DrawRoundedRectangle (Cairo.Context c, Cairo.Rectangle rect) { double x = rect.X; double y = rect.Y; double width = rect.Width; double height = rect.Height; double radius = 5; c.MoveTo (x, y + radius); c.Arc (x + radius, y + radius, radius, Math.PI, -Math.PI / 2); c.LineTo (x + width - radius, y); c.Arc (x + width - radius, y + radius, radius, -Math.PI / 2, 0); c.LineTo (x + width, y + height - radius); c.Arc (x + width - radius, y + height - radius, radius, 0, Math.PI / 2); c.LineTo (x + radius, y + height); c.Arc (x + radius, y + height - radius, radius, Math.PI / 2, Math.PI); c.ClosePath (); c.SetSourceRGB (161 / 255.0, 40 / 255.0, 48 / 255.0); c.Fill (); }
void DrawVersionNumber (Cairo.Context c, ref Cairo.PointD bottomRight, string text) { c.SelectFontFace (SplashFontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); c.SetFontSize (SplashFontSize); var extents = c.TextExtents (text); c.MoveTo (bottomRight.X - extents.Width - 1, bottomRight.Y - extents.Height); c.SetSourceRGB (1, 1, 1); c.ShowText (text); }
void DrawRectangle (Cairo.Context c, Cairo.Rectangle rect) { double x = rect.X; double y = rect.Y; double width = rect.Width; double height = rect.Height; c.Rectangle (x, y, width, height); c.SetSourceRGB (0, 0, 0); c.Fill (); }
void Draw(Cairo.Context ctx, List<TableRow> rowList, int dividerX, int x, ref int y) { if (!heightMeasured) return; Pango.Layout layout = new Pango.Layout (PangoContext); TableRow lastCategory = null; foreach (var r in rowList) { int w,h; layout.SetText (r.Label); layout.GetPixelSize (out w, out h); int indent = 0; if (r.IsCategory) { var rh = h + CategoryTopBottomPadding*2; ctx.Rectangle (0, y, Allocation.Width, rh); using (var gr = new LinearGradient (0, y, 0, rh)) { gr.AddColorStop (0, new Cairo.Color (248d/255d, 248d/255d, 248d/255d)); gr.AddColorStop (1, new Cairo.Color (240d/255d, 240d/255d, 240d/255d)); ctx.SetSource (gr); ctx.Fill (); } if (lastCategory == null || lastCategory.Expanded || lastCategory.AnimatingExpand) { ctx.MoveTo (0, y + 0.5); ctx.LineTo (Allocation.Width, y + 0.5); } ctx.MoveTo (0, y + rh - 0.5); ctx.LineTo (Allocation.Width, y + rh - 0.5); ctx.SetSourceColor (DividerColor); ctx.Stroke (); ctx.MoveTo (x, y + CategoryTopBottomPadding); ctx.SetSourceColor (CategoryLabelColor); Pango.CairoHelper.ShowLayout (ctx, layout); var img = r.Expanded ? discloseUp : discloseDown; ctx.DrawImage (this, img, Allocation.Width - img.Width - CategoryTopBottomPadding, y + Math.Round ((rh - img.Height) / 2)); y += rh; lastCategory = r; } else { var cell = GetCell (r); r.Enabled = !r.Property.IsReadOnly || cell.EditsReadOnlyObject; var state = r.Enabled ? State : Gtk.StateType.Insensitive; ctx.Save (); ctx.Rectangle (0, y, dividerX, h + PropertyTopBottomPadding*2); ctx.Clip (); ctx.MoveTo (x, y + PropertyTopBottomPadding); ctx.SetSourceColor (Style.Text (state).ToCairoColor ()); Pango.CairoHelper.ShowLayout (ctx, layout); ctx.Restore (); if (r != currentEditorRow) cell.Render (GdkWindow, ctx, r.EditorBounds, state); y += r.EditorBounds.Height; indent = PropertyIndent; } if (r.ChildRows != null && r.ChildRows.Count > 0 && (r.Expanded || r.AnimatingExpand)) { int py = y; ctx.Save (); if (r.AnimatingExpand) ctx.Rectangle (0, y, Allocation.Width, r.AnimationHeight); else ctx.Rectangle (0, 0, Allocation.Width, Allocation.Height); ctx.Clip (); Draw (ctx, r.ChildRows, dividerX, x + indent, ref y); ctx.Restore (); if (r.AnimatingExpand) { y = py + r.AnimationHeight; // Repaing the background because the cairo clip doesn't work for gdk primitives int dx = (int)((double)Allocation.Width * dividerPosition); ctx.Rectangle (0, y, dx, Allocation.Height - y); ctx.SetSourceColor (LabelBackgroundColor); ctx.Fill (); ctx.Rectangle (dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y); ctx.SetSourceRGB (1, 1, 1); ctx.Fill (); } } } }
protected override bool OnDrawn(Cairo.Context cr) { cr.Save (); cr.SetSourceRGB (0.0, 0.0, 0.0); cr.Rectangle (0, 0, Allocation.Width, Allocation.Height); cr.Fill (); cr.Restore (); return base.OnDrawn (cr); }
/// <summary> /// Draws the label. /// </summary> /// <param name="context">Context.</param> /// <param name="bordertype">Bordertype.</param> /// <param name="pin">Pin.</param> /// <param name="xpos">Xpos.</param> /// <param name="ypos">Ypos.</param> private static void DrawLabel(Cairo.Context context, BorderType bordertype, IPin pin, int xpos = 0, int ypos = 0) { const int widht = 100; const int height = BoldHeight; const int fontsize = 12; //Rect context.Rectangle (xpos, ypos, widht, 26); context.SetSourceRGBA (BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, BackgroundColor.A); context.Fill (); string displaytext = pin.Name; if (displaytext.Length > 12) { displaytext = displaytext.Substring (0, 12); displaytext += "..."; } if (bordertype == BorderType.Line) { //Border context.SetSourceRGB (0, 0, 0); context.LineWidth = .5; context.Rectangle (xpos, ypos, widht, height); context.Stroke (); } //ColorFlag context.Rectangle (xpos, ypos, 5, height); context.SetSourceRGB (pin.PlotColor.Red, pin.PlotColor.Green, pin.PlotColor.Blue); context.Fill (); //Number context.SetSourceRGB (0, 0, 0); context.SelectFontFace ("Sans", FontSlant.Normal, FontWeight.Bold); context.SetFontSize (fontsize); context.MoveTo (xpos + 5, ypos + fontsize); context.ShowText (pin.DisplayNumberShort); context.MoveTo (xpos + 5, ypos + fontsize * 2); context.ShowText (displaytext); }
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.LineWidth = 1; context.SetSourceRGB (.29, .47, .67); context.Stroke (); }
protected void paintMonster(Cairo.Context context, Monster monster) { switch (monster.Type) { case "Wanderer": context.SetSourceRGB (0, 1, 0); paintWanderer (context, monster); break; case "Sniffer": context.SetSourceRGB (1, 0, 1); paintSniffer (context, monster); break; case "Circulator": context.SetSourceRGB (0, 0, 0); paintCirculator (context, monster); break; default: context.SetSourceRGB (1, 1, 0); paintCircle (context, monster.X, monster.Y); break; } }
protected void paintPlayer(Cairo.Context context, Player player) { context.SetSourceRGB (0, 0, 1); paintArrow (context, player.Direction, player.X, player.Y); }
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.SetSourceRGBA(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.SetSourceRGB (1, 1, 1); g.StrokePreserve (); // Draw a black dashed line over the white line g.SetDash (new double[] { 2 / scale, 4 / scale }, 0); g.SetSourceRGB (0, 0, 0); g.Stroke (); g.Restore (); }
protected void paintTrail(Cairo.Context context, int x, int y) { context.Save (); context.SetSourceRGB (0, 1, 0); context.Translate (x, y); context.Rectangle (new Cairo.Rectangle (0, 0, fieldSize, fieldSize)); context.SetSourceRGBA (0, 1, 0, 0.3); context.FillPreserve (); context.NewPath (); context.Restore (); }
protected void paintSquare(Cairo.Context context, int x, int y, bool fill) { context.Save (); context.SetSourceRGB (0, 0, 1); context.Translate (x, y); context.Rectangle (new Cairo.Rectangle (0, 0, fieldSize, fieldSize)); context.SetSourceRGBA (0, 0, 0, fill ? 0.5 : 0.3); context.FillPreserve (); context.NewPath (); context.Restore (); }
/// <summary> /// Draws the label flat. /// </summary> /// <param name="context">Context.</param> /// <param name="bordertype">Bordertype.</param> /// <param name="labelposition">Labelposition.</param> /// <param name="pin">Pin.</param> /// <param name="xpos">Xpos.</param> /// <param name="ypos">Ypos.</param> private static void DrawLabelFlat(Cairo.Context context, BorderType bordertype, LabelPosition labelposition, IPin pin, int xpos = 0, int ypos = 0) { string displaytext = ""; var color = GdkToCairo (pin.PlotColor); displaytext = pin.DisplayNumberShort + " " + pin.Name; if (displaytext.Length > 12) { displaytext = displaytext.Substring (0, 12); displaytext += "..."; } if (bordertype == BorderType.Line) { DrawRoundedRectangle (context, xpos, ypos, LabelWidth - LabelBorderWeight, FlatHeight, 5); context.SetSourceRGBA (color.R, color.G, color.B, color.A); context.LineWidth = LabelBorderWeight; context.Stroke (); } //PinToLabelLine int xposlabelline = 0; int yposlabelline = 0; switch (labelposition) { case LabelPosition.Left: xposlabelline = xpos + LabelWidth; yposlabelline = ypos + (FlatHeight / 2); break; case LabelPosition.Right: xposlabelline = xpos; yposlabelline = ypos + (FlatHeight / 2); break; case LabelPosition.Bottom: xpos = xpos + LabelWidth / 2; yposlabelline = ypos; break; default: break; } if (PinLocations.ContainsKey ((int)pin.RealNumber)) { DrawLines ( context, xposlabelline, yposlabelline, (int)(MCUImageXZero + PinLocations [(int)pin.RealNumber].x), (int)(MCUImageYZero + PinLocations [(int)pin.RealNumber].y), color ); } //Number context.SetSourceRGB (0, 0, 0); context.SelectFontFace ("Sans", FontSlant.Normal, FontWeight.Bold); context.SetFontSize (LabelFontSize); context.MoveTo (xpos + 5, ypos + LabelFontSize + LabelBorderWeight); context.ShowText (displaytext); }
void DrawCodeSegmentBorder (Gdk.GC gc, Cairo.Context ctx, double x, int width, BlockInfo firstBlock, BlockInfo lastBlock, string[] lines, Gtk.Widget widget, Gdk.Drawable window) { int shadowSize = 2; int spacing = 4; int bottomSpacing = (lineHeight - spacing) / 2; ctx.Rectangle (x + shadowSize + 0.5, firstBlock.YStart + bottomSpacing + spacing - shadowSize + 0.5, width - shadowSize*2, shadowSize); ctx.SetSourceRGB (0.9, 0.9, 0.9); ctx.LineWidth = 1; ctx.Fill (); ctx.Rectangle (x + shadowSize + 0.5, lastBlock.YEnd + bottomSpacing + 0.5, width - shadowSize*2, shadowSize); ctx.SetSourceRGB (0.9, 0.9, 0.9); ctx.Fill (); ctx.Rectangle (x + 0.5, firstBlock.YStart + bottomSpacing + spacing + 0.5, width, lastBlock.YEnd - firstBlock.YStart - spacing); ctx.SetSourceRGB (0.7,0.7,0.7); ctx.Stroke (); string text = lines[firstBlock.FirstLine].Replace ("@","").Replace ("-",""); text = "<span size='x-small'>" + text.Replace ("+","</span><span size='small'>➜</span><span size='x-small'> ") + "</span>"; layout.SetText (""); layout.SetMarkup (text); int tw,th; layout.GetPixelSize (out tw, out th); th--; int dy = (lineHeight - th) / 2; ctx.Rectangle (x + 2 + LeftPaddingBlock - 1 + 0.5, firstBlock.YStart + dy - 1 + 0.5, tw + 2, th + 2); ctx.LineWidth = 1; ctx.SetSourceColor (widget.Style.Base (StateType.Normal).ToCairoColor ()); ctx.FillPreserve (); ctx.SetSourceRGB (0.7, 0.7, 0.7); ctx.Stroke (); window.DrawLayout (gc, (int)(x + 2 + LeftPaddingBlock), firstBlock.YStart + dy, layout); }
public override void DrawForeground (TextEditor editor, Cairo.Context cr, MarginDrawMetrics metrics) { cr.Arc (metrics.X + metrics.Width / 2 + 2, metrics.Y + metrics.Height / 2, 7 * editor.Options.Zoom, 0, Math.PI * 2); isFailed = false; var test = NUnitService.Instance.SearchTestById (unitTest.UnitTestIdentifier); bool searchCases = false; if (unitTest.IsIgnored) { cr.SetSourceRGB (0.9, 0.9, 0); } else { if (test != null) { var result = test.GetLastResult (); if (result == null) { cr.SetSourceRGB (0.5, 0.5, 0.5); searchCases = true; } else if (result.IsNotRun) { cr.SetSourceRGBA (0.9, 0.9, 0, test.IsHistoricResult ? 0.5 : 1.0); } else if (result.IsSuccess) { cr.SetSourceRGBA (0, 1, 0, test.IsHistoricResult ? 0.2 : 1.0); } else if (result.IsFailure) { cr.SetSourceRGBA (1, 0, 0, test.IsHistoricResult ? 0.2 : 1.0); failMessage = result.Message; isFailed = true; } else if (result.IsInconclusive) { cr.SetSourceRGBA (0, 1, 1, test.IsHistoricResult ? 0.2 : 1.0); } else { cr.SetSourceRGB (0.5, 0.5, 0.5); } } else { cr.SetSourceRGB (0.5, 0.5, 0.5); searchCases = true; } if (searchCases) { foreach (var caseId in unitTest.TestCases) { test = NUnitService.Instance.SearchTestById (unitTest.UnitTestIdentifier + caseId); if (test != null) { var result = test.GetLastResult (); if (result == null || result.IsNotRun || test.IsHistoricResult) { } else if (result.IsNotRun) { cr.SetSourceRGB (0.9, 0.9, 0); } else if (result.IsSuccess) { cr.SetSourceRGB (0, 1, 0); } else if (result.IsFailure) { cr.SetSourceRGB (1, 0, 0); failMessage = result.Message; isFailed = true; break; } else if (result.IsInconclusive) { cr.SetSourceRGB (0, 1, 1); } } } } } cr.FillPreserve (); if (unitTest.IsIgnored) { cr.SetSourceRGB (0.4, 0.4, 0); cr.Stroke (); } else { if (test != null) { var result = test.GetLastResult (); if (result == null) { cr.SetSourceRGB (0.2, 0.2, 0.2); cr.Stroke (); } else if (result.IsNotRun && !test.IsHistoricResult) { cr.SetSourceRGB (0.4, 0.4, 0); cr.Stroke (); } else if (result.IsSuccess && !test.IsHistoricResult) { cr.SetSourceRGB (0, 0.5, 0); cr.Stroke (); } else if (result.IsFailure && !test.IsHistoricResult) { cr.SetSourceRGB (0.5, 0, 0); cr.Stroke (); } else if (result.IsInconclusive && !test.IsHistoricResult) { cr.SetSourceRGB (0, 0.7, 0.7); cr.Stroke (); } } } cr.NewPath (); }
void DrawLineBox (Gdk.GC gc, Cairo.Context ctx, int right, int top, int line, Gtk.Widget widget, Gdk.Drawable window) { layout.SetText (""); layout.SetMarkup ("<small>" + line.ToString () + "</small>"); int tw,th; layout.GetPixelSize (out tw, out th); th--; int dy = (lineHeight - th) / 2; ctx.Rectangle (right - tw - 2 + 0.5, top + dy - 1 + 0.5, tw + 2, th + 2); ctx.LineWidth = 1; ctx.SetSourceColor (widget.Style.Base (Gtk.StateType.Normal).ToCairoColor ()); ctx.FillPreserve (); ctx.SetSourceRGB (0.7, 0.7, 0.7); ctx.Stroke (); window.DrawLayout (gc, right - tw - 1, top + dy, layout); }
/* public override void SetSelColor() { Stroke = new SolidColorBrush(Properties.Settings.Default.Overlay_CoordSelColor); } public override void SetStdColor() { Stroke = new SolidColorBrush(Properties.Settings.Default.Overlay_CoordColor); } */ /// <summary> /// Draw an X /// </summary> /// <param name="dc"></param> public override void Draw(Cairo.Context dc) { Pen p = IsSelected ? SelPen : StdPen; Rect lBB = GetBB(Parent.Height); dc.SetSourceRGB(1, 0, 0); // todo dc.DrawLine(lBB.TopLeft, lBB.BottomRight); dc.DrawLine(lBB.BottomLeft, lBB.TopRight); }
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 (); }
protected override void OnDrawContent (Gdk.EventExpose evnt, Cairo.Context context) { context.LineWidth = 1; var alloc = ChildAllocation; var adjustedMarginSize = alloc.X - Allocation.X + headerMarginSize; var r = results.Where (res => res.Item2.ItemCount > 0).ToArray (); if (r.Any ()) { context.SetSourceColor (lightSearchBackground); context.Rectangle (Allocation.X, Allocation.Y, adjustedMarginSize, Allocation.Height); context.Fill (); context.SetSourceColor (darkSearchBackground); context.Rectangle (Allocation.X + adjustedMarginSize, Allocation.Y, Allocation.Width - adjustedMarginSize, Allocation.Height); context.Fill (); context.MoveTo (0.5 + Allocation.X + adjustedMarginSize, 0); context.LineTo (0.5 + Allocation.X + adjustedMarginSize, Allocation.Height); context.SetSourceColor (separatorLine); context.Stroke (); } else { context.SetSourceRGB (1, 1, 1); context.Rectangle (Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height); context.Fill (); } double y = alloc.Y + yMargin; int w, h; if (topItem != null) { headerLayout.SetText (GettextCatalog.GetString ("Top Result")); headerLayout.GetPixelSize (out w, out h); context.MoveTo (alloc.Left + headerMarginSize - w - xMargin, y); context.SetSourceColor (headerColor); Pango.CairoHelper.ShowLayout (context, headerLayout); var category = topItem.Category; var dataSrc = topItem.DataSource; var i = topItem.Item; double x = alloc.X + xMargin + headerMarginSize; context.SetSourceRGB (0, 0, 0); layout.SetMarkup (GetRowMarkup (dataSrc, i)); layout.GetPixelSize (out w, out h); if (selectedItem != null && selectedItem.Category == category && selectedItem.Item == i) { context.SetSourceColor (selectionBackgroundColor); context.Rectangle (alloc.X + headerMarginSize, y, Allocation.Width - adjustedMarginSize, h); context.Fill (); context.SetSourceRGB (1, 1, 1); } var px = dataSrc.GetIcon (i); if (px != null) { context.DrawImage (this, px, (int)x + marginIconSpacing, (int)y + (h - px.Height) / 2); x += px.Width + iconTextSpacing + marginIconSpacing; } context.MoveTo (x, y); context.SetSourceRGB (0, 0, 0); Pango.CairoHelper.ShowLayout (context, layout); y += h + itemSeparatorHeight; } foreach (var result in r) { var category = result.Item1; var dataSrc = result.Item2; if (dataSrc.ItemCount == 0) continue; if (dataSrc.ItemCount == 1 && topItem != null && topItem.DataSource == dataSrc) continue; headerLayout.SetText (category.Name); headerLayout.GetPixelSize (out w, out h); if (y + h > Allocation.Height) break; context.MoveTo (alloc.X + headerMarginSize - w - xMargin, y); context.SetSourceColor (headerColor); Pango.CairoHelper.ShowLayout (context, headerLayout); layout.Width = Pango.Units.FromPixels (Allocation.Width - adjustedMarginSize - 35); for (int i = 0; i < maxItems && i < dataSrc.ItemCount; i++) { if (topItem != null && topItem.Category == category && topItem.Item == i) continue; double x = alloc.X + xMargin + headerMarginSize; context.SetSourceRGB (0, 0, 0); layout.SetMarkup (GetRowMarkup (dataSrc, i)); layout.GetPixelSize (out w, out h); if (y + h + itemSeparatorHeight > Allocation.Height) break; if (selectedItem != null && selectedItem.Category == category && selectedItem.Item == i) { context.SetSourceColor (selectionBackgroundColor); context.Rectangle (alloc.X + headerMarginSize, y, Allocation.Width - adjustedMarginSize, h); context.Fill (); context.SetSourceRGB (1, 1, 1); } var px = dataSrc.GetIcon (i); if (px != null) { context.DrawImage (this, px, (int)x + marginIconSpacing, (int)y + (h - px.Height) / 2); x += px.Width + iconTextSpacing + marginIconSpacing; } context.MoveTo (x, y); context.SetSourceRGB (0, 0, 0); Pango.CairoHelper.ShowLayout (context, layout); y += h + itemSeparatorHeight; } if (result != r.Last ()) { y += categorySeparatorHeight; } } if (y == alloc.Y + yMargin) { context.SetSourceRGB (0, 0, 0); layout.SetMarkup (isInSearch ? GettextCatalog.GetString ("Searching...") : GettextCatalog.GetString ("No matches")); context.MoveTo (alloc.X + xMargin, y); Pango.CairoHelper.ShowLayout (context, layout); } }
//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 DrawArrow (Cairo.Context g, double x, double y) { var editor = mode.editor; double phi = 1.618; double arrowLength = editor.LineHeight * phi; double arrowHeight = editor.LineHeight / phi; g.MoveTo (x - arrowLength, y - arrowHeight); g.LineTo (x, y); g.LineTo (x - arrowLength, y + arrowHeight); g.LineTo (x - arrowLength / phi, y); g.ClosePath (); g.SetSourceRGB (1.0, 0, 0); g.StrokePreserve (); g.SetSourceRGBA (1.0, 0, 0, 0.1); g.Fill (); }
void DrawAlphaBetaMarker (Cairo.Context c, ref Cairo.PointD bottomRight, string text) { c.SelectFontFace (SplashFontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Bold); c.SetFontSize (SplashFontSize); // Create a rectangle larger than the text so we can have a nice border // And round the value so we don't have a blurry rectangle. var extents = c.TextExtents (text); var x = Math.Round (bottomRight.X - extents.Width * 1.3); var y = Math.Round (bottomRight.Y - extents.Height * 2.8); var rectangle = new Cairo.Rectangle (x, y, bottomRight.X - x, bottomRight.Y - y); // Draw the background color the text will be overlaid on DrawRectangle (c, rectangle); // Calculate the offset the text will need to be at to be centralised // in the border x = x + extents.XBearing + (rectangle.Width - extents.Width) / 2; y = y - extents.YBearing + (rectangle.Height - extents.Height) / 2; c.MoveTo (x, y); // Draw the text c.SetSourceRGB (1, 1, 1); c.ShowText (text); bottomRight.Y -= rectangle.Height - 2; }