///<summary>Benchmark the rendering</summary> public void Benchmark() { System.DateTime t1; System.DateTime t2; int sum = 0; Gdk.Window win = drawingArea.GdkWindow; Gdk.Rectangle alloc = drawingArea.Allocation; Gdk.Rectangle rect1 = new Gdk.Rectangle(0, 0, alloc.Width, alloc.Height); for (int i = 0; i < 100; i++) { t1 = System.DateTime.Now; win.BeginPaintRect(rect1); layout.AreaGroup.Render(true); win.EndPaint(); t2 = System.DateTime.Now; sum += (t2 - t1).Milliseconds; } Gdk.Rectangle rect = drawingArea.Allocation; Console.WriteLine("100 render screen ({0},{1}): {2} ms", rect.Width, rect.Height, sum / 100); }
public void Render(Player player, List <Ball> balls, List <Monster> monsters) { Gdk.Window canvas = area.GdkWindow; if (canvas != null) { using (Cairo.Context context = Gdk.CairoHelper.Create(canvas)) { canvas.BeginPaintRegion(new Gdk.Region()); context.SetSourceSurface(background, 0, 0); context.Paint(); foreach (Field field in player.Trail) { paintTrail(context, field.X * fieldSize, field.Y * fieldSize); } foreach (Ball ball in balls) { context.SetSourceRGB(1, 0, 0); paintCircle(context, ball.X, ball.Y); } foreach (Monster monster in monsters) { paintMonster(context, monster); } context.SetSourceRGB(0, 0, 1); paintPlayer(context, player); canvas.EndPaint(); } } }
/// <summary> /// Expose event handler, calls PaintBackground and then PaintCells /// </summary> /// <param name="evnt"> /// Arguments <see cref="Gdk.EventExpose"/> /// </param> /// <returns> /// true if successful, false if not <see cref="System.Boolean"/> /// </returns> protected override bool OnExposeEvent(Gdk.EventExpose evnt) { base.OnExposeEvent(evnt); int x, y, w, h, d = 0; GdkWindow.GetGeometry(out x, out y, out w, out h, out d); CellRectangle r = new CellRectangle(0, 0, w, h); System.Console.WriteLine("Using cellrendererwindow=" + (IsCellRenderer == true)); Gdk.Window masterDrawable = (IsCellRenderer == true) ? cellRendererWindow : evnt.Window; Gdk.Drawable buffer = null; Cairo.Context context = null; if (IsDoubleBuffered == true) { System.Console.WriteLine("DoubleBuffered"); buffer = new Gdk.Pixmap(masterDrawable, Allocation.Width, Allocation.Height, 24); context = Gdk.CairoHelper.Create(buffer); } else { masterDrawable.BeginPaintRect(evnt.Area); context = Gdk.CairoHelper.Create(masterDrawable); } Gdk.Color clr = Style.Backgrounds[(int)StateType.Normal]; // context.Color = new Cairo.Color (0, 0, 1); context.Color = clr.GetCairoColor(); r.DrawPath(context); context.Fill(); // if ((BackgroundPainted == true) && (Sensitive == true)) // PaintBackground (evnt, g, rect); // Cairo.Rectangle r = rect.CopyAndShrink (Padding); r.Shrink(Padding); CalculateCellAreas(r); if (IsDoubleBuffered == true) { PaintCells(evnt, buffer, context, r); evnt.Window.DrawDrawable(Style.BlackGC, buffer, evnt.Area.X, evnt.Area.Y, evnt.Area.X, evnt.Area.Y, evnt.Area.Width, evnt.Area.Height); buffer.Dispose(); } else { PaintCells(evnt, masterDrawable, context, r); masterDrawable.EndPaint(); } ((IDisposable)context.Target).Dispose(); ((IDisposable)context).Dispose(); context = null; return(true); }