protected unsafe override void OnFillRegionComputed(IBitVector2D stencil) { Document doc = PintaCore.Workspace.ActiveDocument; ImageSurface surf = doc.ToolLayer.Surface; using (var g = new Context(surf)) { g.Operator = Operator.Source; g.SetSource(doc.CurrentUserLayer.Surface); g.Paint(); } SimpleHistoryItem hist = new SimpleHistoryItem(Icon, Name); hist.TakeSnapshotOfLayer(doc.CurrentUserLayer); ColorBgra color = fill_color.ToColorBgra().ToPremultipliedAlpha(); ColorBgra *dstPtr = (ColorBgra *)surf.DataPtr; int width = surf.Width; surf.Flush(); // Color in any pixel that the stencil says we need to fill Parallel.For(0, stencil.Height, y => { int stencil_width = stencil.Width; for (int x = 0; x < stencil_width; ++x) { if (stencil.GetUnchecked(x, y)) { surf.SetColorBgraUnchecked(dstPtr, width, color, x, y); } } }); surf.MarkDirty(); // Transfer the temp layer to the real one, // respecting any selection area using (var g = doc.CreateClippedContext()) { g.Operator = Operator.Source; g.SetSource(surf); g.Paint(); } doc.ToolLayer.Clear(); doc.History.PushNewItem(hist); doc.Workspace.Invalidate(); }
private void StopEditing() { // If we don't have an open document, some of this stuff will crash if (!PintaCore.Workspace.HasOpenDocuments) { return; } if (!is_editing) { return; } try { Document doc = PintaCore.Workspace.ActiveDocument; doc.ToolLayer.Clear(); doc.ToolLayer.Hidden = true; if (engine.EditMode == EditingMode.Editing) { SimpleHistoryItem hist = new SimpleHistoryItem(Icon, Name); hist.TakeSnapshotOfLayer(doc.CurrentLayerIndex); // Redraw the text without the cursor, // and on to the real layer RedrawText(false, false); doc.History.PushNewItem(hist); } engine.Clear(); doc.Workspace.Invalidate(old_bounds); old_bounds = Rectangle.Zero; is_editing = false; } catch (Exception) { // Just ignore the error } }