/*override (Gdk.EventButton evnt) * { * var res = base.OnButtonPressEvent(evnt); * if ((evnt.Button & (uint)Gdk.ModifierType.Button1Mask) != 0) * { * if ((evnt.Button & (uint)Gdk.ModifierType.ShiftMask) != 0) * { * // if is left click + shift * EnableMode = EnableMode.ActiveWithLimit; * } * else * { * // if is left click * EnableMode = EnableMode.Active; * } * }else if ((evnt.Button & (uint)Gdk.ModifierType.Button3Mask) != 0) * { * //right clicked * EnableMode = EnableMode.Disabled; * } * * QueueDraw(); * * return res; * }*/ void SetBgColor(EnableMode enableMode, Gdk.EventExpose evnt) { //this.ModifyBg(StateType.Normal, Colors[(int)EnableMode]); Cairo.Context cr = Gdk.CairoHelper.Create(this.GdkWindow); cr.Rectangle(0, 0, Allocation.Width, Allocation.Height); Color c = new Color(0, 0, 0); cr.SetSourceColor(c); cr.Stroke(); cr.Rectangle(1, 1, Allocation.Width - 1, Allocation.Height - 1); if (enableMode == EnableMode.Active) { c = Colors[1]; } else if (enableMode == EnableMode.ActiveWithLimit) { c = Colors[2]; } else if (enableMode == EnableMode.Disabled) { c = Colors[0]; } cr.SetSourceColor(c); cr.Fill(); cr.Target.Dispose(); cr.Dispose(); // set tooltip HasTooltip = true; TooltipText = enableMode.ToString(); }
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(); }
public override void Dispose() { base.Dispose(); if (grw != null) { grw.Dispose(); } }
//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(); } }
void RedrawBoard() { boardContext = Gdk.CairoHelper.Create(BoardArea.GdkWindow); double transx = Math.Abs((BoardArea.Allocation.Width - (boardBackground.Width * 0.75))) / 2; boardContext.Translate(transx, 0); boardContext.Scale(0.75, 0.75); boardBackground.Show(boardContext, 0, 0); PieceDisplay.DrawPieces(boardContext); boardContext.Dispose(); }
void DrawPath() { Cairo.Context cr = Gdk.CairoHelper.Create(daCanvas.GdkWindow); if (tracer != null) { tracer.DrawLine(cr, Allocation); } cr.GetTarget().Dispose(); cr.Dispose(); }
public override void Dispose() { base.Dispose(); if (grw != null) { grw.Dispose(); } if (taskGc != null) { taskGc.Dispose(); } }
// Thanks to: Chris Thomson // https://stackoverflow.com/questions/25106063/how-do-i-draw-pixbufs-onto-a-surface-with-cairo-sharp private static ImageSurface pixbufToCairoImageSurface(Pixbuf pixbuf) { ImageSurface imgSurface = new ImageSurface(Format.ARGB32, pixbuf.Width, pixbuf.Height); using (Cairo.Context cr = new Cairo.Context(imgSurface)) { Gdk.CairoHelper.SetSourcePixbuf(cr, pixbuf, 0, 0); cr.Paint(); cr.Dispose(); } return(imgSurface); }
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; }
public void Draw() { if (ActiveInstance == null) { return; } Cairo.Context context = Gdk.CairoHelper.Create(this.GdkWindow); DrawBackground(context); DrawGrid(context); DrawGarden(context); DrawSelection(context); DrawCropRotation(context); context.Dispose(); }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { base.OnExposeEvent(ev); Cairo.Context cr = Gdk.CairoHelper.Create(GdkWindow); foreach (NodeVisualization source in nodes) { foreach (NodeVisualization destination in source.successors.Keys) { DrawEdge(cr, source, destination); } } cr.Dispose(); return(true); }
void DrawOverlay(System.Object o, Gtk.DrawnArgs args) { var imageViewWidget = this.drawingArea as ImageViewWidget; if (imageViewWidget == null || imageViewWidget.Image == null || !this.IsActive || !this.UpdateFade(imageViewWidget)) { return; } this.canvasSize = new Cairo.PointD(this.drawingArea.Allocation.Width, this.drawingArea.Allocation.Height); var image = imageViewWidget.Image; bool redrawOverlay = this.canvasSize.X != this.lastCanvasSize.X || this.canvasSize.Y != this.lastCanvasSize.Y || image != this.lastImage || image.NeedsOverlayRedrawn; if (redrawOverlay) { var overlaySurface = new Cairo.ImageSurface(Cairo.Format.ARGB32, (int)this.canvasSize.X, (int)this.canvasSize.Y); var overlayCr = new Cairo.Context(overlaySurface); this.RedrawOverlay(overlayCr, image); overlayCr.Dispose(); if (this.overlaySurface != null) { this.overlaySurface.Dispose(); } this.overlaySurface = overlaySurface; image.NeedsOverlayRedrawn = false; } args.Cr.SetSourceSurface(this.overlaySurface, 0, 0); args.Cr.PaintWithAlpha(this.currentFadeOpacity); this.lastCanvasSize = this.canvasSize; this.lastImage = image; }
public void ShowResult([System.Runtime.CompilerServices.CallerMemberName] string memberName = null) { var surface = CairoEx.BuildSurface((int)rect.Width, (int)rect.Height, CairoEx.ColorMetal, Format.Rgb24); var context = new Cairo.Context(surface); Draw(context, needClip: true); string outputPath = "D:\\LayoutTest"; if (!System.IO.Directory.Exists(outputPath)) { System.IO.Directory.CreateDirectory(outputPath); } string filePath = outputPath + "\\" + DateTime.UtcNow.ToString("yyyy-MM-dd_HH-mm-ss-fff_") + surface.GetHashCode() + memberName + ".png"; surface.WriteToPng(filePath); surface.Dispose(); context.Dispose(); Process.Start("rundll32.exe", @"""C:\Program Files\Windows Photo Viewer\PhotoViewer.dll"",ImageView_Fullscreen " + filePath); }
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(); } } }
protected override void UpdateCache(Context ctx) { Rectangle rb = Slot + Parent.ClientRectangle.Position; using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) { Context gr = new Context (cache); if (Clipping.count > 0) { Clipping.clearAndClip (gr); base.onDraw (gr); //clip to client zone CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); gr.Clip (); foreach (GraphicObject c in Children) { if (!c.Visible) continue; if (Clipping.intersect(c.Slot + ClientRectangle.Position)) c.Paint (ref gr); } #if DEBUG_CLIP_RECTANGLE Clipping.stroke (gr, Color.Amaranth.AdjustAlpha (0.8)); #endif } gr.Dispose (); ctx.SetSourceSurface (cache, rb.X, rb.Y); ctx.Paint (); } Clipping.Reset(); }
ImageInfo CreateBlur(ImageInfo source) { double scale = Math.Max (256 / (double)source.Bounds.Width, 256 / (double)source.Bounds.Height); var small = new Gdk.Rectangle (0, 0, (int)Math.Ceiling (source.Bounds.Width * scale), (int)Math.Ceiling (source.Bounds.Height * scale)); var image = new ImageSurface (Format.Argb32, small.Width, small.Height); var ctx = new Context (image); ctx.Matrix = source.Fit (small); ctx.Operator = Operator.Source; Pattern p = new SurfacePattern (source.Surface); ctx.SetSource (p); ctx.Paint (); p.Dispose (); ctx.Dispose (); ImageInfo overlay = null; using (var normal = image.ToPixbuf ()) { using (var pixbufBlur = PixbufUtils.Blur (normal, 3, null)) { overlay = new ImageInfo (pixbufBlur); } } image.Dispose (); return overlay; }
private ImageSurface GenerateStub() { ImageSurface stub = new ImageSurface (Format.ARGB32, 600, 300); Context cairo = new Context(stub); cairo.IdentityMatrix (); cairo.Scale (600,300); cairo.Rectangle (0, 0, 1, 1); cairo.SetSourceRGB (1,1,1); cairo.Fill (); cairo.MoveTo (0.14, 0.5); cairo.SetFontSize (0.08); cairo.SetSourceRGB (0, 0, 0); cairo.ShowText ("Загрузите подложку"); cairo.Dispose (); return stub; }
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(); }
protected void OnPieceClick(object o, ButtonPressEventArgs args) { double transx = Math.Abs((BoardArea.Allocation.Width - (boardBackground.Width * 0.75))) / 2; PointD clickLocation = new PointD(args.Event.X - transx, args.Event.Y - transx); if (clickLocation.X < 30 || clickLocation.Y < 30 || clickLocation.X > 522 || clickLocation.Y > 522) { return; } PointD pieceLocation = PieceDisplay.pieceCoordinates [0]; int pieceIndex = 0; for (int i = 0; i < PieceDisplay.pieceCoordinates.Length; i++) { PointD p = PieceDisplay.pieceCoordinates[i]; double x1 = p.X * 0.75; double y1 = p.Y * 0.75; double x2 = x1 + 61.5; double y2 = y1 + 61.5; if (x1 <= clickLocation.X && clickLocation.X <= x2) { if (y1 <= clickLocation.Y && clickLocation.Y <= y2) { pieceLocation = p; pieceIndex = MainClass.BoardOrientation == PieceColour.White ? i : Math.Abs(i - 63); break; } } } if (currentSelectionState == PieceSelectionState.None) { if (MainClass.CurrentBoard.Squares [pieceIndex].Piece == null) { return; } selectedPiece = (byte)pieceIndex; boardContext = Gdk.CairoHelper.Create(BoardArea.GdkWindow); boardContext.Translate(transx, 0); boardContext.Scale(0.75, 0.75); selectionBorder.Show(boardContext, pieceLocation.X + 1, pieceLocation.Y + 1); boardContext.Dispose(); currentSelectionState = PieceSelectionState.Selected; } else { if (!MainClass.CurrentBoard.IsMoveValid(selectedPiece, (byte)pieceIndex)) { currentSelectionState = PieceSelectionState.None; Gtk.Application.Invoke(delegate { RedrawBoard(); }); return; } if (MainClass.CurrentGameStatus != GameStatus.Active && MainClass.CurrentGameStatus != GameStatus.Inactive) { Console.Error.WriteLine("(EE) Attempted move during finished game."); MessageDialog errorDialog = new MessageDialog( this, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, "The game is over!"); errorDialog.Run(); errorDialog.Destroy(); return; } // Handle pawn promotion PieceType?promoteTo = null; if (MainClass.CurrentBoard.Squares [selectedPiece].Piece.Type == PieceType.Pawn && MainClass.CurrentBoard.IsMoveValid(selectedPiece, (byte)pieceIndex) && Array.IndexOf(MainClass.CurrentBoard.pawnPromotionDestinations, (byte)pieceIndex) != -1) { PawnPromotionDialog dialog = new PawnPromotionDialog(); if (dialog.Run() == (int)Gtk.ResponseType.Ok) { promoteTo = dialog.PromoteTo; } else { dialog.Destroy(); return; } dialog.Destroy(); } try { SpecifierType specifierRequired = GameHistory.checkDisabiguationNeeded(MainClass.CurrentBoard, selectedPiece, (byte)pieceIndex); MoveResult result = MainClass.CurrentBoard.MakeMove(selectedPiece, (byte)pieceIndex, promoteTo); Piece movingPiece = null; if (promoteTo == null) { movingPiece = MainClass.CurrentBoard.Squares[(byte)pieceIndex].Piece; } else { movingPiece = new Piece(MainClass.CurrentBoard.Squares [(byte)pieceIndex].Piece.Colour, PieceType.Pawn); } if (result == MoveResult.Capture && movingPiece.Type == PieceType.Pawn) { specifierRequired = SpecifierType.File; } int checkOrCheckmate = 0; GameStatus mateState = MainClass.CurrentBoard.CheckForMate(); if (mateState == GameStatus.WhiteCheckmate || mateState == GameStatus.BlackCheckmate) { checkOrCheckmate = 2; } else if (MainClass.CurrentBoard.WhiteCheck || MainClass.CurrentBoard.BlackCheck) { checkOrCheckmate = 1; } string fenPosition = MainClass.CurrentBoard.ToFEN().Split(' ')[0]; MainClass.CurrentGameHistory.AddMove(new Move(selectedPiece, (byte)pieceIndex, MainClass.CurrentBoard.Squares [(byte)pieceIndex].Piece.Colour, movingPiece, result, MainClass.CurrentBoard.ToFEN(), checkOrCheckmate, specifierRequired, promoteTo), fenPosition); UpdateGameHistoryView(); if (MainClass.CurrentGameHistory.UpdateFiftyMoveCount(result) == GameStatus.DrawFifty) { MainClass.CurrentGameStatus = GameStatus.DrawFifty; } else if (MainClass.CurrentGameHistory.CheckThreefoldRepetition() == GameStatus.DrawRepetition) { MainClass.CurrentGameStatus = GameStatus.DrawRepetition; } } catch (InvalidOperationException) { } Gtk.Application.Invoke(delegate { RedrawBoard(); }); GameStatus isMate = MainClass.CurrentBoard.CheckForMate(); if (isMate != GameStatus.Active) { MainClass.CurrentGameStatus = isMate; } if (MainClass.CurrentGameStatus != GameStatus.Active && MainClass.CurrentGameStatus != GameStatus.Inactive) { ShowGameOverDialog(MainClass.CurrentGameStatus); } if (MainClass.CurrentGameStatus == GameStatus.Inactive) { MainClass.CurrentGameStatus = GameStatus.Active; } Gtk.Application.Invoke(delegate { MainClass.UpdateClock(); UpdatePlayerToMove(); }); currentSelectionState = PieceSelectionState.None; } }
public ImageInfo(ImageInfo info, Gdk.Rectangle allocation) { Surface = info.Surface.CreateSimilar (Content.Color, allocation.Width, allocation.Height); var ctx = new Context (Surface); Bounds = allocation; ctx.Matrix = info.Fill (allocation); Pattern p = new SurfacePattern (info.Surface); ctx.SetSource (p); ctx.Paint (); ctx.Dispose (); p.Dispose (); }
public ImageInfo(ImageInfo info, Widget w, Gdk.Rectangle bounds) { using (var similar = CairoUtils.CreateSurface (w.GdkWindow)) { Bounds = bounds; Surface = similar.CreateSimilar (Content.ColorAlpha, Bounds.Width, Bounds.Height); var ctx = new Context (Surface); ctx.Matrix = info.Fill (Bounds); Pattern p = new SurfacePattern (info.Surface); ctx.SetSource (p); ctx.Paint (); ctx.Dispose (); p.Dispose (); } }
public static void Do(List <JumpsProfileIndex> l_jpi, DrawingArea area, string title, string date) { //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) { if (jpi.Result >= 0) { sum += jpi.Result; } } //4 prepare font g.SelectFontFace("Helvetica", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); int textHeight = 12; g.SetFontSize(textHeight); if (sum == 0) { g.SetSourceRGB(0, 0, 0); g.SetFontSize(16); printText(100, 100, 24, textHeight, Constants.JumpsProfileNeededJumps, g, false); g.GetTarget().Dispose(); g.Dispose(); return; } //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 if (percent > 0) { plotArc(200, 200, 150, acc - .5, acc + percent - .5, g, jpi.Color); //-.5 to start at top of the pie acc += percent; } } //fix last radius line, because ClosePath has been disabled g.MoveTo(200, 50); g.LineTo(200, 200); g.LineWidth = 2; g.Stroke(); } //6 draw legend at right int legendX = findLegendTextXPos(l_jpi, sum, 400); int y = 40; //R seq(from=50,to=(350-24),length.out=5) //[1] 50 119 188 257 326 #difference is 69 //g.SelectFontFace("Helvetica", Cairo.FontSlant.Normal, Cairo.FontWeight.Bold); foreach (JumpsProfileIndex jpi in l_jpi) { double percent = 100 * Util.DivideSafe(jpi.Result, sum); printText(legendX, y, 24, textHeight, Util.TrimDecimals(percent, 1) + jpi.Text, g, false); if (percent != 0) { drawRoundedRectangle(legendX, y + 30, Convert.ToInt32(2 * percent), 20, 4, g, jpi.Color); } y += 69; } //print title and date g.SetFontSize(18); printText(200, y, 0, textHeight, title, g, true); g.SetFontSize(textHeight); printText(200, y + 20, 0, textHeight, "Chronojump profile (" + date + ")", g, true); //g.SelectFontFace("Helvetica", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); //7 print errors (if any) g.SetSourceRGB(0.5, 0, 0); y = 70; foreach (JumpsProfileIndex jpi in l_jpi) { if (jpi.ErrorMessage != "") { printText(legendX + 12, y, 24, textHeight, jpi.ErrorMessage, g, false); } y += 69; } //8 dispose g.GetTarget().Dispose(); g.Dispose(); }
public static void DisposeContext(Cairo.Context cr) { cr.Dispose(); }
protected override void UpdateCache(Context ctx) { Rectangle rb = Slot + Parent.ClientRectangle.Position; using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) { Context gr = new Context (cache); if (Clipping.count > 0) { Clipping.clearAndClip (gr); onDraw (gr); } gr.Dispose (); ctx.SetSourceSurface (cache, rb.X, rb.Y); ctx.Paint (); } Clipping.Reset(); }
public void dibujarVista(DrawingArea area) { using (Cairo.Context g = Gdk.CairoHelper.Create(area.GdkWindow)) { //draw white square g.Antialias = Antialias.None; int area_w = area.Allocation.Width; int area_h = area.Allocation.Height; dibujarCuadrado(g, 0, 0, area_w, area_h, new Color(0.3, 0.3, 0.3), new Color(0, 0, 0), 2); if (preview) { //draw A4 Sheet g.Color = new Color(0, 1, 1); g.SetFontSize(15 * zoom); String txt_sheet = "Hoja " + sheetW + "x" + sheetH + "mm."; TextExtents te = g.TextExtents(txt_sheet); g.MoveTo(area_w - sheetW / 2 * zoom - te.Width / 2 - te.XBearing, area_h - sheetH * zoom - 10 * zoom - te.Height / 2 - te.YBearing); g.ShowText(txt_sheet); int a4_w = (int)(this.sheetW * this.zoom); int a4_h = (int)(this.sheetH * this.zoom); dibujarCuadrado(g, area_w, area_h, area_w - a4_w, area_h - a4_h, new Color(1, 1, 1), new Color(0, 0, 0), 1); g.Antialias = Antialias.Default; //Dibujar formas g.Color = new Color(1, 0, 0); if (this.isOpen) { count = 0; //formas dibujadas this.rows = (int)(this.cant / this.columns) + 1; for (int i = 0; i < rows; i++) //filas { for (int j = 0; j < columns; j++) //columnas { if (count == cant) { break; } //dibuja el archivo foreach (var forma in formas) { PointD p0 = new PointD(area_w - sheetMargin * zoom - spaceX / 40 * j * zoom - (forma[0].Y + (height) * j) * zoom * scaleY / 40, area_h - sheetMargin * zoom - spaceY / 40 * i * zoom - (forma[0].X + (width) * i) * zoom * scaleX / 40); //PointD p0 = new PointD (area_w-forma[0].X*zoom*scaleX/40-sheetMargin*zoom-(width*scaleX*zoom-spaceX*zoom)*i,area_h-forma[0].Y*zoom*scaleY/40-sheetMargin*zoom-(height*scaleY*zoom-spaceY*zoom)*j); g.MoveTo(p0); foreach (var punto in forma) { PointD pn = new PointD(area_w - sheetMargin * zoom - spaceX / 40 * j * zoom - (punto.Y + (height) * j) * zoom * scaleY / 40, area_h - sheetMargin * zoom - spaceY / 40 * i * zoom - (punto.X + (width) * i) * zoom * scaleX / 40); g.LineTo(pn); } g.Color = new Color(0, 0, 0, 0.1); //g.ClosePath (); g.FillPreserve(); g.Color = new Color(0, 0, 1); g.Stroke(); } //suma 1 count++; } } } g.Antialias = Antialias.None; } //draw black border dibujarCuadrado(g, 0, 0, area_w, area_h, new Color(0, 0, 0, 0), new Color(0, 0, 0), 2); g.GetTarget().Dispose(); g.Dispose(); } }