protected override bool OnExposeEvent(Gdk.EventExpose args) { //base.OnPaint(pe); Cairo.Context dc = Gdk.CairoHelper.Create(args.Window); // Draw white background //Graphics dc = pe.Graphics; dc.IdentityMatrix(); dc.SetSourceRGB(1.0, 1.0, 1.0); dc.Rectangle(0, 0, Allocation.Width, Allocation.Height); dc.Fill(); // Draw the raster Cairo.Matrix t = TheRasterModel.GetTikzToScreenTransform().ToCairoMatrix(); //t.Freeze(); dc.Save(); dc.LineWidth = 0.01; // todo: always 1 pixel dc.SetSourceRGB(0.7, 0.7, 0.7); // whitesmoke? { dc.Transform(t); TheRasterModel.DrawRaster( (p1, p2) => { dc.MoveTo(p1.X, p1.Y); dc.LineTo(p2.X, p2.Y); dc.Stroke(); }, (r1, r2) => { dc.DrawEllipse(0, 0, 2 * r1, 2 * r2); }); } dc.Restore(); // draw unavailable note if (TheDisplayModel.IsUnavailable) { dc.SetSourceRGB(0, 0, 0); dc.SelectFontFace("Arial", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); //StringFormat f = new StringFormat(); //f.Alignment = StringAlignment.Center; //f.LineAlignment = StringAlignment.Center; //dc.DrawString("<Unavailable>", new Font("Arial", 16), Brushes.Black, ClientRectangle, f); dc.MoveTo(Allocation.Width / 2, Allocation.Height / 2); //todo dc.ShowText("<Unavailable>"); } // draw the pdf image if (TheDisplayModel.IsImageVisible && TheDisplayModel.Bmp != null) { Point p = new Point((Allocation.Width - TheDisplayModel.Bmp.Width) / 2, (Allocation.Height - TheDisplayModel.Bmp.Height) / 2); //dc.DrawImageUnscaled(TheDisplayModel.Bmp, p); dc.SetSource(TheDisplayModel.Bmp, p.X, p.Y); //dc.Rectangle(p.X, p.Y, TheDisplayModel.Bmp.Width, TheDisplayModel.Bmp.Height); dc.Paint(); } // draw the overlay if (ShowOverlay) { dc.SetSourceRGB(0, 0, 0); // draw shapes from parsetree foreach (var osv in OSViews) { osv.Draw(dc); } // draw (visible) auxiliary shapes foreach (var ps in PreviewShapes.Where(o => o.Visible)) { ps.Draw(dc); } } // draw adorner(s) foreach (var scope in this.OSViews.OfType <OverlayScopeView>().Where(v => v.IsAdornerVisible)) { dc.SetSourceRGB(0.5, 0.5, 0.5); dc.LineWidth = 5; System.Windows.Rect ShowAt = scope.GetBB(Allocation.Height); ShowAt.Inflate(6, 6); dc.Rectangle(ShowAt.ToCairoRectangle()); //(PensAndBrushes.AdornerPen, ShowAt.ToRectangleF()); dc.Stroke(); } // draw the object marker if (MarkObject_ShowMarker && MarkObject_Marked != null) { System.Windows.Rect ShowAt = MarkObject_Marked.GetBB(Allocation.Height); ShowAt.Inflate(15, 15); //using (Pen p = new Pen(Brushes.Red, 6)) { dc.SetSourceRGB(1, 0, 0); dc.LineWidth = 6; dc.DrawEllipse(ShowAt);//p, } } ((IDisposable)dc.Target).Dispose(); ((IDisposable)dc).Dispose(); return(true); }