public static Surface CreateSurfaceForPixbuf(Cairo.Context cr, Gdk.Pixbuf pixbuf) { Surface surface = cr.GetTarget().CreateSimilar(cr.GetTarget().Content, pixbuf.Width, pixbuf.Height); Cairo.Context surface_cr = new Context(surface); Gdk.CairoHelper.SetSourcePixbuf(surface_cr, pixbuf, 0, 0); surface_cr.Paint(); ((IDisposable)surface_cr).Dispose(); return(surface); }
/// <summary> /// Helper to create a surface similar to the current target of a context /// </summary> /// <returns>A <see cref="Cairo.Surface"/>. Caller owns this surface, and must dispose it.</returns> /// <param name="cr">Context</param> /// <param name="width">Width for new surface</param> /// <param name="height">Height for new surface</param> public static Surface CreateSimilarToTarget(this Cairo.Context cr, int width, int height) { #if USING_OLD_CAIRO return(cr.GetTarget().CreateSimilar(cr.GetTarget().Content, width, height)); #else using (var targetSurface = cr.GetTarget()) { return(targetSurface.CreateSimilar(targetSurface.Content, width, height)); } #endif }
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(); }
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 (); }
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(); }
private void Resize(Cairo.Context cr) //tested work fine { Coordinate map_position = GetCurrentMapLocation(); for (int i = 0; i < GetPath().Count; ++i) //it resize only on pathpoint (you can't add waypoint beyond the map and see it before it flies there) { var list = GetPath(); Coordinate temp = list [i]; if (temp.Latitude < startPoint.Latitude || temp.Longitude < startPoint.Longitude || temp.Latitude > stopPoint.Latitude || temp.Longitude > stopPoint.Longitude) //have to resize sufrace and change start and stop coordinates. { const double resize_value = 0.5; Coordinate test = new Coordinate(resize_value * (stopPoint.Latitude - startPoint.Latitude), resize_value * (stopPoint.Longitude - startPoint.Longitude)); offset = CoordinateToPixel(test).X; using (var target = cr.GetTarget()) { waypoints = target.CreateSimilar(Content.ColorAlpha, (int)(this.mapImage.Pixbuf.Width + 2 * CoordinateToPixel(test).X), (int)(this.mapImage.Pixbuf.Height + 2 * CoordinateToPixel(test).Y)); // there is *2 because we have to add this much to // to both side of map } startPoint.Latitude -= test.Latitude; startPoint.Longitude -= test.Longitude; stopPoint.Latitude += test.Latitude; stopPoint.Longitude += test.Longitude; } } JumpTo(map_position); }
public SurfaceWrapper(Cairo.Context similar, Gdk.Pixbuf source) { Cairo.Surface surface; // There is a bug in Cairo for OSX right now that prevents creating additional accellerated surfaces. if (Platform.IsMac) { surface = new QuartzSurface(Format.ARGB32, source.Width, source.Height); } else if (Platform.IsWindows) { using (var t = similar.GetTarget()) { surface = t.CreateSimilar(Content.ColorAlpha, source.Width, source.Height); } } else { surface = new ImageSurface(Format.ARGB32, source.Width, source.Height); } using (Context context = new Context(surface)) { Gdk.CairoHelper.SetSourcePixbuf(context, source, 0, 0); context.Paint(); } Surface = surface; Width = source.Width; Height = source.Height; }
/// <summary>The drawing canvas is being exposed to user.</summary> private void OnDrawingAreaExpose(object sender, ExposeEventArgs args) { try { DrawingArea area = (DrawingArea)sender; #if NETFRAMEWORK Cairo.Context context = Gdk.CairoHelper.Create(area.GdkWindow); #else Cairo.Context context = args.Cr; #endif foreach (DGArc tmpArc in arcs) { tmpArc.Paint(context); } foreach (DGNode tmpNode in nodes) { tmpNode.Paint(context); } ((IDisposable)context.GetTarget()).Dispose(); ((IDisposable)context).Dispose(); } catch (Exception err) { ShowError(err); } }
//2 handlers, drawing corresponding custom controls protected void OnSoundbarExposeEvent(object o, ExposeEventArgs args) { using (Cairo.Context context = Gdk.CairoHelper.Create(((Widget)o).GdkWindow)) { drawbar(context, args.Event.Area.Width, args.Event.Area.Height, 77, soundratio); context.GetTarget().Dispose(); context.Dispose(); } }
private void DrawWaypoints(Cairo.Context cr) { using (var target = cr.GetTarget()) { if (waypoints == null) { waypoints = target.CreateSimilar(Content.ColorAlpha, this.mapImage.Pixbuf.Width, this.mapImage.Pixbuf.Height); } } using (Context cr_overlay = new Context(waypoints)) { int i = 0; cr.SetSourceSurface(waypoints, (int)(drag_position_x), (int)(drag_position_y)); cr_overlay.SelectFontFace("Courier", FontSlant.Normal, FontWeight.Bold); cr_overlay.SetFontSize(16); if (GetWaypointList().Count > 1) { cr_overlay.LineWidth = 2; for (int j = 0; j < GetWaypointList().Count - 1; ++j) { cr_overlay.SetSourceRGB(0.5, 0.5, 0.5); Coordinate way1 = GetWaypoint(j); Coordinate way2 = GetWaypoint(j + 1); cr_overlay.MoveTo(CoordinateToPixel(way1)); cr_overlay.LineTo(CoordinateToPixel(way2)); cr_overlay.Stroke(); } } foreach (Coordinate c in GetWaypointList()) { PointD cords = CoordinateToPixel(c); cr_overlay.SetSourceRGB(0.5, 0.5, 0.5); cr_overlay.Arc(cords.X, cords.Y, 12, 0, 2 * Math.PI); cr_overlay.Fill(); cords.X -= 5; //to draw in center of circle cords.Y += 4; if (i >= 10) { cords.X -= 4; //if number is 2-digit diffrent center } cr_overlay.MoveTo(cords); cr_overlay.SetSourceRGB(1.0, 1.0, 1.0); cr_overlay.TextPath(Convert.ToString(i)); cr_overlay.Fill(); ++i; } } cr.Paint(); }
private void FillCell(CellNumber cell, Cairo.Color color) { using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow)) { g.SetSourceRGBA(color.R, color.G, color.B, color.A); g.MoveTo(GetCellCoordinates(cell.Y, cell.X)); g.Rectangle(GetCellCoordinates(cell.Y, cell.X), cellWidth, cellHeight); g.Fill(); g.GetTarget().Dispose(); } }
private void FillCell(PointD coord, Cairo.Color color) { using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow)) { g.SetSourceRGBA(color.R, color.G, color.B, color.A); g.MoveTo(coord); g.Rectangle(coord, cellWidth, cellHeight); g.Fill(); g.GetTarget().Dispose(); } }
public static Surface CreateSurfaceForPixbuf(Cairo.Context cr, Gdk.Pixbuf pixbuf) { var target = cr.GetTarget(); Surface surface = target.CreateSimilar(target.Content, pixbuf.Width, pixbuf.Height); using (var surface_cr = new Context(surface)) { Gdk.CairoHelper.SetSourcePixbuf(surface_cr, pixbuf, 0.0, 0.0); surface_cr.Paint(); } return(surface); }
void DrawPath() { Cairo.Context cr = Gdk.CairoHelper.Create(daCanvas.GdkWindow); if (tracer != null) { tracer.DrawLine(cr, Allocation); } cr.GetTarget().Dispose(); cr.Dispose(); }
/// <summary> /// Raises the expose event and draws the map. /// </summary> /// <param name="sender">Sender.</param> /// <param name="args">Arguments.</param> private void OnExpose(object sender, ExposeEventArgs args) { DrawingArea area = (DrawingArea)sender; Cairo.Context cairoContext = Gdk.CairoHelper.Create(area.GdkWindow); // Draw the background. cairoContext.Rectangle(0, 0, viewWidth, viewHeight); cairoContext.SetSourceRGB(255, 255, 255); cairoContext.StrokePreserve(); cairoContext.Fill(); // Draw the grid. cairoContext.LineWidth = 1.0; cairoContext.LineCap = LineCap.Butt; cairoContext.SetSourceRGB(0, 0, 0); // Columns. int position = cellWidth; for (; position <= viewWidth - cellWidth; position += cellWidth) { // We have to add 0.5 to the x position otherwise Cairo will // smear it across 2 pixels. cairoContext.MoveTo(position + 0.5, 0.0); cairoContext.LineTo(position + 0.5, viewHeight); cairoContext.Stroke(); } // Rows. position = cellHeight; for (; position <= viewHeight - cellHeight; position += cellHeight) { // We have to add 0.5 to the y position otherwise Cairo will // smear it across 2 pixels. cairoContext.MoveTo(0.0, position + 0.5); cairoContext.LineTo(viewWidth, position + 0.5); cairoContext.Stroke(); } if (robotView.Robot.PathPointList.Count > 1) { pathView.Draw(cairoContext, centerX, centerY, 1.0); } robotView.Draw(cairoContext, centerX, centerY, 1.0); landmarkView.Draw(cairoContext, centerX, centerY, 1.0); ((IDisposable)cairoContext.GetTarget()).Dispose(); ((IDisposable)cairoContext).Dispose(); }
public static Surface CreateSurfaceForPixbuf (Context cr, Pixbuf pixbuf) { Surface surface; using (var t = cr.GetTarget ()) { surface = t.CreateSimilar (t.Content, pixbuf.Width, pixbuf.Height); } using (Context surface_cr = new Context (surface)) { CairoHelper.SetSourcePixbuf (surface_cr, pixbuf, 0, 0); surface_cr.Paint (); surface_cr.Dispose (); } return surface; }
private void DrawText(string text, int top, int left) { using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow)) { g.SetSourceRGB(0, 0, 0); g.SetFontSize(cellHeight / 1.5); FontExtents fe = g.FontExtents; TextExtents te = g.TextExtents(text); g.MoveTo(left * cellWidth + (cellWidth - te.Width) / 2, top * cellHeight + (cellHeight + te.YBearing + fe.Height) / 2); g.ShowText(text); g.GetTarget().Dispose(); } }
void OnExpose(object o, ExposeEventArgs args) { picGameBoard.GdkWindow.Clear(); Cairo.Context ct = Gdk.CairoHelper.Create(picGameBoard.GdkWindow); for (int i = 1; i < 12; i++) { //top ct.SetSourceSurface(images[6], i * 35, 0); ct.Paint(); //bottom ct.SetSourceSurface(images[6], i * 35, 11 * 35); ct.Paint(); } for (int i = 0; i < 12; i++) { //left ct.SetSourceSurface(images[6], 0, i * 35); ct.Paint(); //right ct.SetSourceSurface(images[6], 11 * 35, i * 35); ct.Paint(); } //snake head ct.SetSourceSurface(images[5], snakeXY[0].x * 35, snakeXY[0].y * 35); ct.Paint(); //snake body ct.SetSourceSurface(images[4], snakeXY[1].x * 35, snakeXY[1].y * 35); ct.Paint(); ct.SetSourceSurface(images[4], snakeXY[2].x * 35, snakeXY[2].y * 35); ct.Paint(); for (int i = 0; i < 4; i++) { Bonus(); bonusCount++; } /* * if (bonusCount == 0) * { * for (int i = 0; i < 4; i++) * { * Bonus(); * bonusCount++; * } * }*/ ct.GetTarget().Dispose(); }
private void FillHalf(PointD coord, Cairo.Color color, Half half) { if (half == Half.Bottom) { coord.Y += cellHeight / 2; } using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow)) { g.SetSourceRGBA(color.R, color.G, color.B, color.A); g.MoveTo(coord); g.Rectangle(coord, cellWidth, cellHeight / 2); g.Fill(); g.GetTarget().Dispose(); } }
/// <summary>The drawing canvas is being exposed to user.</summary> private void OnDrawingAreaExpose(object sender, ExposeEventArgs args) { DrawingArea area = (DrawingArea)sender; Cairo.Context context = Gdk.CairoHelper.Create(area.GdkWindow); foreach (DGArc tmpArc in Arcs) { tmpArc.Paint(context); } foreach (DGNode tmpNode in Nodes) { tmpNode.Paint(context); } ((IDisposable)context.GetTarget()).Dispose(); ((IDisposable)context).Dispose(); }
private void FillHalf(HalfCell cell, Cairo.Color color) { PointD coord = GetCellCoordinates(cell.CellNumber.Y, cell.CellNumber.X); if (cell.half == Half.Bottom) { coord.Y += cellHeight / 2; } using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow)) { g.SetSourceRGBA(color.R, color.G, color.B, color.A); g.MoveTo(coord); g.Rectangle(coord, cellWidth, cellHeight / 2); g.Fill(); g.GetTarget().Dispose(); } }
public SurfaceWrapper(Cairo.Context similar, int width, int height) { if (Platform.IsMac) { Surface = new QuartzSurface(Cairo.Format.ARGB32, width, height); } else if (Platform.IsWindows) { using (var target = similar.GetTarget()) { Surface = target.CreateSimilar(Cairo.Content.ColorAlpha, width, height); } } else { Surface = new ImageSurface(Cairo.Format.ARGB32, width, height); } Width = width; Height = height; }
protected override bool OnExposeEvent(Gdk.EventExpose args) { Cairo.Context cr = Gdk.CairoHelper.Create(this.GdkWindow); cr.LineWidth = 9; //cr.SetSourceRGB(0.7, 0.2, 0.0); int grow = 0; for (int i = 0; i < ColorList.Length; i++) { grow = 0; if (SelectedIndex == i) { grow = 3; } DrawRoundedRectangle(cr, TileSpacing + (TileSize + TileSpacing) * i - grow, TileSpacing - grow, TileSize + grow * 2, TileSize + grow * 2, 3); cr.SetSourceRGB(CachedColors[i].Red / (float)0x10000, CachedColors[i].Green / (float)0x10000, CachedColors[i].Blue / (float)0x10000); cr.FillPreserve(); /* * c = c.ContrastColor(); * cr.SetSourceRGB(c.Red / (float)0x10000, c.Green / (float)0x10000, c.Blue / (float)0x10000); */ cr.SetSourceRGB(0, 0, 0); cr.LineWidth = 1.2; cr.Stroke(); } allOffCoords = drawButton(cr, TileSpacing + (TileSize + TileSpacing) * ColorList.Length, TileSpacing, "All Off", allOffSelected); //coords = drawButton(cr, coords.X, TileSpacing, "Custom", false); ((IDisposable)cr.GetTarget()).Dispose(); ((IDisposable)cr).Dispose(); return(true); }
/// <summary>The drawing canvas is being exposed to user.</summary> private void OnDrawingAreaExpose(object sender, DrawnArgs args) { try { DrawingArea area = (DrawingArea)sender; Cairo.Context context = args.Cr; CairoContext drawingContext = new CairoContext(context, MainWidget); DirectedGraphRenderer.Draw(drawingContext, arcs, nodes); ((IDisposable)context.GetTarget()).Dispose(); ((IDisposable)context).Dispose(); } catch (Exception err) { ShowError(err); } }
static 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(); gr.GetTarget().Dispose(); }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { base.OnExposeEvent(ev); CalculateSize(); weekends = CalculateWeekends(month, year); using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow)) { FillWhite(g); FillWeekends(); FillHeaders(); FillBackLight(); FillNow(); FillActiveCells(); DrawHeaders(g); DrawGrid(g); g.GetTarget().Dispose(); } return(true); }
private Surface CreateScene(Cairo.Context window_cr, ImageSurface image, int reflect) { var target = window_cr.GetTarget(); Surface surface = target.CreateSimilar(target.Content, image.Width, image.Height + reflect); using (var cr = new Context(surface)) { cr.Save(); cr.SetSource(image); cr.Paint(); cr.Rectangle(0, image.Height, image.Width, reflect); cr.Clip(); Matrix matrix = new Matrix(); matrix.InitScale(1, -1); matrix.Translate(0, -(2 * image.Height) + 1); cr.Transform(matrix); cr.SetSource(image); cr.Paint(); cr.Restore(); Color bg_transparent = BackgroundColor; bg_transparent.A = 0.65; using (var mask = new LinearGradient(0, image.Height, 0, image.Height + reflect)) { mask.AddColorStop(0, bg_transparent); mask.AddColorStop(1, BackgroundColor); cr.Rectangle(0, image.Height, image.Width, reflect); cr.SetSource(mask); cr.Fill(); } } target.Dispose(); return(surface); }
void Draw() { using (Cairo.Context g = Gdk.CairoHelper.Create(area.GdkWindow)) { g.SetSourceColor(new Color(0, 0, 0)); g.Rectangle(0, 0, 500, 300); g.Fill(); g.SetSourceColor(new Color(1, 1, 1)); for (int x = 0; x < data.Length; x++) { g.Rectangle(x * (500 / data.Length) + 1, 0, (500 / data.Length) - 1, data[x]); } g.Fill(); g.GetTarget().Dispose(); } }
void OnDrawnEvent(object obj, DrawnArgs args) { if (Disposed) { return; } try { if (args.Cr == null) { return; } Context cr = args.Cr; if (obj is Widget w) { Paint(cr, w.AllocatedWidth, w.AllocatedHeight); } args.RetVal = true; } catch { } finally { if (args.Cr != null) { Context cr = args.Cr; Surface cs = cr.GetTarget(); cs?.Dispose(); cr.Dispose(); } } }
private void Form1_Shown(object sender, EventArgs e) { Debug.WriteLine("Form1_Shown"); surface = new Win32Surface(this.CreateGraphics().GetHdc()); context = new Context(surface); textFormat = DWriteCairo.CreateTextFormat( "Consolas", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 12); textFormat.TextAlignment = TextAlignment.Center; float left, top, width, height; // get actual size of the text var measureLayout = DWriteCairo.CreateTextLayout(s, textFormat, 4096, 4096); measureLayout.GetRect(out left, out top, out width, out height); measureLayout.Dispose(); // build text context against the size and format textLayout = DWriteCairo.CreateTextLayout(s, textFormat, (int)Math.Ceiling(width), (int)Math.Ceiling(height)); Debug.WriteLine("showing layout"); Path path = DWriteCairo.RenderLayoutToCairoPath(context, textLayout); context.AppendPath(path); context.Fill(); textLayout.GetRect(out left, out top, out width, out height); textRect = new System.Drawing.RectangleF(left, top, width, height); context.Rectangle(left, top, width, height); context.Stroke(); context.GetTarget().Flush(); }
/// <summary>The drawing canvas is being exposed to user.</summary> private void OnDrawingAreaExpose(object sender, DrawnArgs args) { try { DrawingArea area = (DrawingArea)sender; Cairo.Context context = args.Cr; DGObject.DefaultOutlineColour = area.StyleContext.GetColor(StateFlags.Normal).ToColour(); #pragma warning disable 0612 DGObject.DefaultBackgroundColour = area.StyleContext.GetBackgroundColor(StateFlags.Normal).ToColour(); #pragma warning restore 0612 CairoContext drawingContext = new CairoContext(context, MainWidget); DirectedGraphRenderer.Draw(drawingContext, arcs, nodes); ((IDisposable)context.GetTarget()).Dispose(); ((IDisposable)context).Dispose(); } catch (Exception err) { ShowError(err); } }
void FillChecks (Context cr, int x, int y, int width, int height) { int CHECK_SIZE = 32; cr.Save (); Surface check; using (var target = cr.GetTarget ()) { check = target.CreateSimilar (Content.Color, 2 * CHECK_SIZE, 2 * CHECK_SIZE); } // draw the check using (Context cr2 = new Context (check)) { cr2.Operator = Operator.Source; cr2.SetSourceRGB (0.4, 0.4, 0.4); cr2.Rectangle (0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE); cr2.Fill (); cr2.SetSourceRGB (0.7, 0.7, 0.7); cr2.Rectangle (x, y, CHECK_SIZE, CHECK_SIZE); cr2.Fill (); cr2.Rectangle (x + CHECK_SIZE, y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE); cr2.Fill (); } // Fill the whole surface with the check SurfacePattern check_pattern = new SurfacePattern (check); check_pattern.Extend = Extend.Repeat; cr.SetSource (check_pattern); cr.Rectangle (0, 0, width, height); cr.Fill (); check_pattern.Dispose (); check.Dispose (); cr.Restore (); }
public static void Do(List <JumpsProfileIndex> l_jpi, DrawingArea area) { //1 create context Cairo.Context g = Gdk.CairoHelper.Create(area.GdkWindow); //2 clear DrawingArea (white) g.SetSourceRGB(1, 1, 1); g.Paint(); //3 calculate sum double sum = 0; foreach (JumpsProfileIndex jpi in l_jpi) { sum += jpi.Result; } //4 prepare font g.SelectFontFace("Helvetica", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); int textHeight = 12; g.SetFontSize(textHeight); //5 plot arcs if (sum > 0) { double acc = 0; //accumulated foreach (JumpsProfileIndex jpi in l_jpi) { double percent = 2 * jpi.Result / sum; //*2 to be in range 0*pi - 2*pi plotArc(200, 200, 150, acc - .5, acc + percent - .5, g, jpi.Color); //-.5 to start at top of the pie acc += percent; } } //6 draw legend at right int y = 50; //R seq(from=50,to=(350-24),length.out=5) //[1] 50 119 188 257 326 #difference is 69 foreach (JumpsProfileIndex jpi in l_jpi) { drawRoundedRectangle(400, y, 40, 24, 6, g, jpi.Color); double percent = 0; if (sum > 0) { percent = 100 * jpi.Result / sum; } printText(460, y, 24, textHeight, Util.TrimDecimals(percent, 1) + jpi.Text, g); y += 69; } //7 print errors (if any) g.SetSourceRGB(0.5, 0, 0); y = 70; foreach (JumpsProfileIndex jpi in l_jpi) { printText(460, y, 24, textHeight, jpi.ErrorMessage, g); y += 69; } //8 dispose g.GetTarget().Dispose(); g.Dispose(); }
void OnExpose(object sender, ExposeEventArgs args) { DrawingArea area = (DrawingArea)sender; // area.AddEvents ((int) Gdk.EventMask.ButtonPressMask); // area.ButtonPressEvent += delegate(object o, ButtonPressEventArgs arg) { // int i,j; // area.GetPointer(out i,out j); // System.Console.WriteLine(i+" , "+j); // // }; if (Constantes.simulacion || Constantes.escenario) { area.SetSizeRequest((int)(Constantes.limites.Width * Constantes.sx), (int)(Constantes.limites.Height * Constantes.sy)); Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow); cr.Scale(Constantes.sx, Constantes.sy); if (ventana.calor.Active && !ventana.trayectoria.Active) { dibujar_grilla_estadistica(area, cr); } if (ventana.trayectoria.Active && !ventana.calor.Active) { dibujar_trayectorias(area, cr); } if (ventana.trayectoria.Active && ventana.calor.Active) { dibujar_trayectorias(area, cr); } if (ventana.grilla.Active && !ventana.calor.Active && !ventana.trayectoria.Active) { dibujar_grilla(area, cr); } if (Constantes.escenarioCargado) { escenarioCargado(cr); } if (Constantes.simulacion && !ventana.calor.Active && !ventana.trayectoria.Active) { Constantes.sincronizar = true; if (Constantes.simulacionContinua) { play_simulacion_continua2(area, cr); //para simulacion continua poner play_simulacion_grilla (area, cr); y cambiar en BoidAutonomo el metodo update_obejtivo() } else { play_simulacion_finita2(area, cr); } Constantes.sincronizar = false; } if (Constantes.escenario) { scene_design(area, cr); } cr.GetTarget().Dispose(); ((IDisposable)cr).Dispose(); } }
private void draw() { if (viewSurface != null) { viewSurface.Dispose(); } viewSurface = new ImageSurface(Format.ARGB32, winWidth, winHeight); //Context cr = Gdk.CairoHelper.Create(drawArea.GdkWindow); Context cr = new Context(viewSurface); clearDrawArea (cr); Drawer.DrawPoints (points,cr); foreach (VertexStructure vs in vertexStructs) { Drawer.DrawVertexStructure (vs,cr); } foreach (IGameObject go in gos) { if (go.needsDrawing ()) { go.draw (cr); } } ((IDisposable) cr.GetTarget()).Dispose(); ((IDisposable) cr).Dispose(); using (Context cr2 = Gdk.CairoHelper.Create(drawArea.GdkWindow)) { cr2.SetSourceSurface(viewSurface, 0, 0); cr2.Paint(); } drawArea.QueueDraw (); }
//Getting end of the would-be line, kept for possible re-use of lines void OnMouseRelease(object source, ButtonReleaseEventArgs args) { End.X = args.Event.X; End.Y = args.Event.Y; isDrawing = false; using (Context ctx = new Context(surface)) { Painter(ctx, Start, End); ((IDisposable) ctx.GetTarget()).Dispose (); ((IDisposable)ctx).Dispose (); } dArea.QueueDraw(); }
//Updates every time the mouse is moved while button is pressed void OnMouseMotion(object source, MotionNotifyEventArgs args) { if (isDrawing) { End.X = args.Event.X; End.Y = args.Event.Y; using (Context ctx = new Context (surface)) { //Reset of end's points so there are no accidental if (isDot) { Start.X = args.Event.X; Start.Y = args.Event.Y; } Painter (ctx, Start, End); ((IDisposable) ctx.GetTarget()).Dispose (); ((IDisposable)ctx).Dispose (); } dArea.QueueDraw(); } }
void Draw (Context cr, int width, int height) { double radius = 0.5 * Math.Min (width, height) - 10; int xc = width / 2; int yc = height / 2; Surface overlay, punch, circles; using (var target = cr.GetTarget ()) { overlay = target.CreateSimilar (Content.ColorAlpha, width, height); punch = target.CreateSimilar (Content.Alpha, width, height); circles = target.CreateSimilar (Content.ColorAlpha, width, height); } FillChecks (cr, 0, 0, width, height); cr.Save (); // Draw a black circle on the overlay using (Context cr_overlay = new Context (overlay)) { cr_overlay.SetSourceRGB (0.0, 0.0, 0.0); OvalPath (cr_overlay, xc, yc, radius, radius); cr_overlay.Fill (); // Draw 3 circles to the punch surface, then cut // that out of the main circle in the overlay using (Context cr_tmp = new Context (punch)) Draw3Circles (cr_tmp, xc, yc, radius, 1.0); cr_overlay.Operator = Operator.DestOut; cr_overlay.SetSourceSurface (punch, 0, 0); cr_overlay.Paint (); // Now draw the 3 circles in a subgroup again // at half intensity, and use OperatorAdd to join up // without seams. using (Context cr_circles = new Context (circles)) { cr_circles.Operator = Operator.Over; Draw3Circles (cr_circles, xc, yc, radius, 0.5); } cr_overlay.Operator = Operator.Add; cr_overlay.SetSourceSurface (circles, 0, 0); cr_overlay.Paint (); } cr.SetSourceSurface (overlay, 0, 0); cr.Paint (); overlay.Dispose (); punch.Dispose (); circles.Dispose (); }