// Constructor. public DrawingGraphics(IToolkit toolkit, Xsharp.Graphics graphics) : base(toolkit) { this.graphics = graphics; this.font = null; this.gaveHdc = false; }
// Handle a paint event from Xsharp. protected override void OnPaint(Xsharp.Graphics graphics) { if(sink != null) { System.Drawing.Region clip = DrawingWindow.RegionToDrawingRegion (graphics.ExposeRegion); DrawingGraphics g = new DrawingGraphics(toolkit, graphics); using(System.Drawing.Graphics gr = ToolkitManager.CreateGraphics(g, clip)) { sink.ToolkitExpose(gr); } } }
// Convert an Xsharp.Region to System.Drawing.Region internal static System.Drawing.Region RegionToDrawingRegion (Xsharp.Region region) { Xsharp.Rectangle[] rectangles = region.GetRectangles(); System.Drawing.Region newRegion = new System.Drawing.Region(); newRegion.MakeEmpty(); for(int i = 0; i < rectangles.Length; i++) { Xsharp.Rectangle rect = rectangles[i]; newRegion.Union(new System.Drawing.Rectangle (rect.x, rect.y, rect.width, rect.height)); } return newRegion; }