void OnDrawAreaRedraw(object sender, RedrawEventArgs e) { if (redraw_backbuffer) { if (!RedrawBackbuffer(e.Painter)) { return; //no active drawing } screen_dirty = new Rectangle2i(0, 0, backbuffer.Width - 1, backbuffer.Height - 1); //entire screen is now dirty } RedrawOverlay(); }
void RedrawOverlay() { Drawing drw = CurrentDrawing; if (drw == null || backbuffer == null) { return; //no overlay if no drawing } //Point2i dcs = cursorpixel; Point2d cursor_wcs = CursorWorldPos; //make sure overlay area is as big as backbuffer if (overlay == null || overlay.Width < backbuffer.Width || overlay.Height < backbuffer.Height) { if (overlay != null) { overlay.Dispose(); } overlay = Guppy.CreatePicture(backbuffer.Width, backbuffer.Height, PictureMode.Software); } using (PainterExtentsRecorder exrec = new PainterExtentsRecorder()) //to remember area drawn to { using (Painter overlaypainter = overlay.CreatePainter()) { if (overlay_needs_background) { overlaypainter.Blit(backbuffer, 0, 0, backbuffer.Width, backbuffer.Height, 0, 0, backbuffer.Width, backbuffer.Height); overlay_needs_background = false; } using (PainterAggregate painter = new PainterAggregate(overlaypainter, exrec)) { //let the current sink do its job painter.Transform = CurrentDrawing.ViewTransform; CurrentSink.OnTracking(cursorpixel, cursor_wcs, painter); } Rectangle2i fliprect = Rectangle2i.Empty; //the part of screen to flip Rectangle2i newdirtyrect = fliprect; //the new dirty screen rectangle //compute slightly grown extents of area to show var er = exrec.RecordedExtents; if (!er.Empty) { newdirtyrect = new Rectangle2i((int)(er.XMin - 5), (int)(er.YMin - 5), (int)(er.XMax + 5), (int)(er.YMax + 5)); fliprect = newdirtyrect; } //include old dirty area in flipping rectangle if (!screen_dirty.IsEmpty) { fliprect = fliprect.Append(screen_dirty.XMin, screen_dirty.YMin); fliprect = fliprect.Append(screen_dirty.XMax, screen_dirty.YMax); } //flip if fliprect not empty. if (!fliprect.IsEmpty) { using (Painter frontpainter = drawarea.CreatePainter()) { int x = fliprect.XMin, y = fliprect.YMin, w = fliprect.Width, h = fliprect.Height; frontpainter.Blit(overlay, x, y, w, h, x, y, w, h); overlaypainter.Blit(backbuffer, x, y, w, h, x, y, w, h); } } //remove the temp graphics from the overlay buffer if (!screen_dirty.IsEmpty) { int x = screen_dirty.XMin, y = screen_dirty.YMin, w = screen_dirty.Width, h = screen_dirty.Height; overlaypainter.Color = RGB.Green; } screen_dirty = newdirtyrect; } } }