protected override void OnActivate() { base.OnActivate(); this.pencilToolCursor = new Cursor(PdnResources.GetResourceStream("Cursors.PencilToolCursor.cur")); this.Cursor = this.pencilToolCursor; this.savedRects = new List <Rectangle>(); if (ActiveLayer != null) { bitmapLayer = (BitmapLayer)ActiveLayer; renderArgs = new RenderArgs(bitmapLayer.Surface); tracePoints = new List <Point>(); } else { bitmapLayer = null; if (renderArgs != null) { renderArgs.Dispose(); renderArgs = null; } } }
protected override void OnDeactivate() { base.OnDeactivate(); if (cursorMouseUp != null) { cursorMouseUp.Dispose(); cursorMouseUp = null; } if (cursorMouseDown != null) { cursorMouseDown.Dispose(); cursorMouseDown = null; } if (mouseDown) { OnMouseUp(new MouseEventArgs(mouseButton, 0, lastMouseXY.X, lastMouseXY.Y, 0)); } this.RendererList.Remove(this.previewRenderer); this.previewRenderer.Dispose(); this.previewRenderer = null; this.savedRects.Clear(); if (renderArgs != null) { renderArgs.Dispose(); renderArgs = null; } bitmapLayer = null; }
public void RemoveDocumentWorkspace(DocumentWorkspace removeMe) { this.VerifyThreadAccess(); removeMe.CompositionUpdated -= new EventHandler(this.OnWorkspaceCompositionUpdated); if (this.selectedDocument == removeMe) { this.selectedDocument = null; } removeMe.DocumentChanging -= new ValueEventHandler <Document>(this.OnWorkspaceDocumentChanging); removeMe.DocumentChanged -= new EventHandler(this.OnWorkspaceDocumentChanged); if (removeMe.Document != null) { removeMe.Document.DirtyChanged -= new EventHandler(this.OnDocumentDirtyChanged); } this.documents.Remove(removeMe); this.thumbnailManager.RemoveFromQueue(removeMe); ImageStrip.Item item = this.dw2button[removeMe]; base.RemoveItem(item); this.dw2button.Remove(removeMe); this.documentButtons.Remove(item); if (this.thumbs.ContainsKey(removeMe)) { RenderArgs args = this.thumbs[removeMe]; ISurface <ColorBgra> iSurface = args.ISurface; args.Dispose(); this.thumbs.Remove(removeMe); iSurface.Dispose(); } this.OnDocumentListChanged(); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if ((this.layerIndex < 1) || (this.layerIndex >= historyWorkspace.Document.Layers.Count)) { object[] objArray1 = new object[] { "layerIndex must be greater than or equal to 1, and a valid layer index. layerIndex=", this.layerIndex, ", allowableRange=[0,", historyWorkspace.Document.Layers.Count, ")" }; throw new ArgumentException(string.Concat(objArray1)); } int layerIndex = this.layerIndex - 1; RectInt32 rect = historyWorkspace.Document.Bounds(); GeometryList list = new GeometryList(); list.AddRect(rect); RectInt32[] changedRegion = list.EnumerateInteriorScans().ToArrayEx <RectInt32>(); BitmapHistoryMemento memento = new BitmapHistoryMemento(null, null, historyWorkspace, layerIndex, changedRegion); BitmapLayer layer = (BitmapLayer)historyWorkspace.Document.Layers[this.layerIndex]; BitmapLayer layer2 = (BitmapLayer)historyWorkspace.Document.Layers[layerIndex]; RenderArgs args = new RenderArgs(layer2.Surface); base.EnterCriticalRegion(); foreach (RectInt32 num4 in changedRegion) { layer.Render(args, num4.ToGdipRectangle()); } layer2.Invalidate(); args.Dispose(); args = null; list = null; HistoryMemento memento2 = new DeleteLayerFunction(this.layerIndex).Execute(historyWorkspace); return(new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { memento, memento2 })); }
private void OnThumbnailRendered(object sender, ValueEventArgs <Tuple <IThumbnailProvider, ISurface <ColorBgra> > > e) { this.VerifyThreadAccess(); RenderArgs args = null; DocumentWorkspace item = (DocumentWorkspace)e.Value.Item1; ISurface <ColorBgra> renderer = e.Value.Item2; if (this.documents.Contains(item)) { SizeInt32 num = renderer.Size <ColorBgra>(); if (this.thumbs.ContainsKey(item)) { args = this.thumbs[item]; if (args.Size.ToSizeInt32() != num) { args.ISurface.Dispose(); args.Dispose(); args = null; this.thumbs.Remove(item); } } if (args == null) { args = new RenderArgs(e.Value.Item2.ToSurface()); this.thumbs.Add(item, args); } e.Value.Item2.Render <ColorBgra>(args.ISurface); e.Value.Item2.Dispose(); this.OnThumbnailUpdated(item); } }
private static DialogResult ShowExpandCanvasTaskDialog(IWin32Window owner, Surface thumbnail) { DialogResult result; Icon formIcon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.MenuEditPasteIcon.png").Reference); string formTitle = PdnResources.GetString("ExpandCanvasQuestion.Title"); RenderArgs taskImageRA = new RenderArgs(thumbnail); Image taskImage = taskImageRA.Bitmap; string introText = PdnResources.GetString("ExpandCanvasQuestion.IntroText"); TaskButton yesTB = new TaskButton( PdnResources.GetImageResource("Icons.ExpandCanvasQuestion.YesTB.Image.png").Reference, PdnResources.GetString("ExpandCanvasQuestion.YesTB.ActionText"), PdnResources.GetString("ExpandCanvasQuestion.YesTB.ExplanationText")); TaskButton noTB = new TaskButton( PdnResources.GetImageResource("Icons.ExpandCanvasQuestion.NoTB.Image.png").Reference, PdnResources.GetString("ExpandCanvasQuestion.NoTB.ActionText"), PdnResources.GetString("ExpandCanvasQuestion.NoTB.ExplanationText")); TaskButton cancelTB = new TaskButton( TaskButton.Cancel.Image, PdnResources.GetString("ExpandCanvasQuestion.CancelTB.ActionText"), PdnResources.GetString("ExpandCanvasQuestion.CancelTB.ExplanationText")); int width96dpi = (TaskDialog.DefaultPixelWidth96Dpi * 3) / 2; TaskButton clickedTB = TaskDialog.Show( owner, formIcon, formTitle, taskImage, false, introText, new TaskButton[] { yesTB, noTB, cancelTB }, yesTB, cancelTB, width96dpi); if (clickedTB == yesTB) { result = DialogResult.Yes; } else if (clickedTB == noTB) { result = DialogResult.No; } else { result = DialogResult.Cancel; } taskImageRA.Dispose(); taskImageRA = null; return(result); }
private void Dispose(bool disposing) { disposed = true; if (disposing) { if (srcArgs != null) { srcArgs.Dispose(); srcArgs = null; } if (dstArgs != null) { dstArgs.Dispose(); dstArgs = null; } } }
private static DialogResult ShowExpandCanvasTaskDialog(IWin32Window owner, Surface thumbnail) { DialogResult yes; Icon icon = PdnResources.GetImageResource("Icons.MenuEditPasteIcon.png").Reference.ToIcon(); string str = PdnResources.GetString("ExpandCanvasQuestion.Title"); RenderArgs args = new RenderArgs(thumbnail); Image bitmap = args.Bitmap; string str2 = PdnResources.GetString("ExpandCanvasQuestion.IntroText"); TaskButton button = new TaskButton(PdnResources.GetImageResource("Icons.ExpandCanvasQuestion.YesTB.Image.png").Reference, PdnResources.GetString("ExpandCanvasQuestion.YesTB.ActionText"), PdnResources.GetString("ExpandCanvasQuestion.YesTB.ExplanationText")); TaskButton button2 = new TaskButton(PdnResources.GetImageResource("Icons.ExpandCanvasQuestion.NoTB.Image.png").Reference, PdnResources.GetString("ExpandCanvasQuestion.NoTB.ActionText"), PdnResources.GetString("ExpandCanvasQuestion.NoTB.ExplanationText")); TaskButton button3 = new TaskButton(PdnResources.GetImageResource("Icons.CancelIcon.png").Reference, PdnResources.GetString("ExpandCanvasQuestion.CancelTB.ActionText"), PdnResources.GetString("ExpandCanvasQuestion.CancelTB.ExplanationText")); int num = (TaskDialog.DefaultPixelWidth96Dpi * 3) / 2; TaskDialog dialog2 = new TaskDialog { Icon = icon, Title = str, TaskImage = bitmap, ScaleTaskImageWithDpi = true, IntroText = str2 }; dialog2.TaskButtons = new TaskButton[] { button, button2, button3 }; dialog2.AcceptButton = button; dialog2.CancelButton = button3; dialog2.PixelWidth96Dpi = num; TaskButton button4 = dialog2.Show(owner); if (button4 == button) { yes = DialogResult.Yes; } else if (button4 == button2) { yes = DialogResult.No; } else { yes = DialogResult.Cancel; } args.Dispose(); args = null; return(yes); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if (this.layerIndex < 1 || this.layerIndex >= historyWorkspace.Document.Layers.Count) { throw new ArgumentException("layerIndex must be greater than or equal to 1, and a valid layer index. layerIndex=" + layerIndex + ", allowableRange=[0," + historyWorkspace.Document.Layers.Count + ")"); } int bottomLayerIndex = this.layerIndex - 1; Rectangle bounds = historyWorkspace.Document.Bounds; PdnRegion region = new PdnRegion(bounds); BitmapHistoryMemento bhm = new BitmapHistoryMemento( null, null, historyWorkspace, bottomLayerIndex, region); BitmapLayer topLayer = (BitmapLayer)historyWorkspace.Document.Layers[this.layerIndex]; BitmapLayer bottomLayer = (BitmapLayer)historyWorkspace.Document.Layers[bottomLayerIndex]; RenderArgs bottomRA = new RenderArgs(bottomLayer.Surface); EnterCriticalRegion(); topLayer.Render(bottomRA, region); bottomLayer.Invalidate(); bottomRA.Dispose(); bottomRA = null; region.Dispose(); region = null; DeleteLayerFunction dlf = new DeleteLayerFunction(this.layerIndex); HistoryMemento dlhm = dlf.Execute(historyWorkspace); CompoundHistoryMemento chm = new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { bhm, dlhm }); return(chm); }
public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { if (this.layerIndex < 1 || this.layerIndex >= historyWorkspace.Document.Layers.Count) { throw new ArgumentException("layerIndex must be greater than or equal to 1, and a valid layer index. layerIndex=" + layerIndex + ", allowableRange=[0," + historyWorkspace.Document.Layers.Count + ")"); } int bottomLayerIndex = this.layerIndex - 1; Rectangle bounds = historyWorkspace.Document.Bounds; PdnRegion region = new PdnRegion(bounds); BitmapHistoryMemento bhm = new BitmapHistoryMemento( null, null, historyWorkspace, bottomLayerIndex, region); BitmapLayer topLayer = (BitmapLayer)historyWorkspace.Document.Layers[this.layerIndex]; BitmapLayer bottomLayer = (BitmapLayer)historyWorkspace.Document.Layers[bottomLayerIndex]; RenderArgs bottomRA = new RenderArgs(bottomLayer.Surface); EnterCriticalRegion(); topLayer.Render(bottomRA, region); bottomLayer.Invalidate(); bottomRA.Dispose(); bottomRA = null; region.Dispose(); region = null; DeleteLayerFunction dlf = new DeleteLayerFunction(this.layerIndex); HistoryMemento dlhm = dlf.Execute(historyWorkspace); CompoundHistoryMemento chm = new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { bhm, dlhm }); return chm; }
protected override void OnDeactivate() { base.OnDeactivate(); if (mouseDown) { PointF lastPoint = (PointF)points[points.Count - 1]; OnStylusUp(new StylusEventArgs(mouseButton, 0, lastPoint.X, lastPoint.Y, 0)); } if (!this.shapeWasCommited) { CommitShape(); } bitmapLayer = null; if (renderArgs != null) { renderArgs.Dispose(); renderArgs = null; } if (outlineSaveRegion != null) { outlineSaveRegion.Dispose(); outlineSaveRegion = null; } if (interiorSaveRegion != null) { interiorSaveRegion.Dispose(); interiorSaveRegion = null; } points = null; }
protected override void Dispose(bool disposing) { if (disposing) { while (this.documents.Count > 0) { this.RemoveDocumentWorkspace(this.documents[this.documents.Count - 1]); } if (this.thumbnailManager != null) { this.thumbnailManager.Dispose(); this.thumbnailManager = null; } foreach (DocumentWorkspace workspace in this.thumbs.Keys) { RenderArgs args = this.thumbs[workspace]; args.ISurface.Dispose(); args.Dispose(); } this.thumbs.Clear(); this.thumbs = null; } base.Dispose(disposing); }
public bool PerformAction() { bool success = true; if (this.documentWorkspace.Selection.IsEmpty || !(this.documentWorkspace.ActiveLayer is BitmapLayer)) { return false; } try { using (new WaitCursorChanger(this.documentWorkspace)) { Utility.GCFullCollect(); PdnRegion selectionRegion = this.documentWorkspace.Selection.CreateRegion(); PdnGraphicsPath selectionOutline = this.documentWorkspace.Selection.CreatePath(); BitmapLayer activeLayer = (BitmapLayer)this.documentWorkspace.ActiveLayer; RenderArgs renderArgs = new RenderArgs(activeLayer.Surface); MaskedSurface maskedSurface = new MaskedSurface(renderArgs.Surface, selectionOutline); SurfaceForClipboard surfaceForClipboard = new SurfaceForClipboard(maskedSurface); Rectangle selectionBounds = Utility.GetRegionBounds(selectionRegion); if (selectionBounds.Width > 0 && selectionBounds.Height > 0) { Surface copySurface = new Surface(selectionBounds.Width, selectionBounds.Height); Bitmap copyBitmap = copySurface.CreateAliasedBitmap(); Bitmap copyOpaqueBitmap = new Bitmap(copySurface.Width, copySurface.Height, PixelFormat.Format24bppRgb); using (Graphics copyBitmapGraphics = Graphics.FromImage(copyBitmap)) { copyBitmapGraphics.Clear(Color.White); } maskedSurface.Draw(copySurface, -selectionBounds.X, -selectionBounds.Y); using (Graphics copyOpaqueBitmapGraphics = Graphics.FromImage(copyOpaqueBitmap)) { copyOpaqueBitmapGraphics.Clear(Color.White); copyOpaqueBitmapGraphics.DrawImage(copyBitmap, 0, 0); } DataObject dataObject = new DataObject(); dataObject.SetData(DataFormats.Bitmap, copyOpaqueBitmap); dataObject.SetData(surfaceForClipboard); int retryCount = 2; while (retryCount >= 0) { try { using (new WaitCursorChanger(this.documentWorkspace)) { Clipboard.SetDataObject(dataObject, true); } break; } catch { if (retryCount == 0) { success = false; Utility.ErrorBox(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.TransferToClipboard")); } else { Thread.Sleep(200); } } finally { --retryCount; } } copySurface.Dispose(); copyBitmap.Dispose(); copyOpaqueBitmap.Dispose(); } selectionRegion.Dispose(); selectionOutline.Dispose(); renderArgs.Dispose(); maskedSurface.Dispose(); } } catch (OutOfMemoryException) { success = false; Utility.ErrorBox(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.OutOfMemory")); } catch (Exception) { success = false; Utility.ErrorBox(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.Generic")); } Utility.GCFullCollect(); return success; }
protected override void OnDeactivate() { base.OnDeactivate(); if (mouseDown) { OnMouseUp(new MouseEventArgs(mouseButton, 0, lastMouseXY.X, lastMouseXY.Y, 0)); } this.RendererList.Remove(this.previewRenderer); this.previewRenderer.Dispose(); this.previewRenderer = null; if (savedSurfaces != null) { if (savedSurfaces != null) { foreach (PlacedSurface ps in savedSurfaces) { ps.Dispose(); } } savedSurfaces.Clear(); savedSurfaces = null; } renderArgs.Dispose();; renderArgs = null; aaPoints = null; renderArgs = null; bitmapLayer = null; if (clipRegion != null) { clipRegion.Dispose(); clipRegion = null; } if (cursorMouseUp != null) { cursorMouseUp.Dispose(); cursorMouseUp = null; } if (cursorMouseDown != null) { cursorMouseDown.Dispose(); cursorMouseDown = null; } if (cursorMouseDownPickColor != null) { cursorMouseDownPickColor.Dispose(); cursorMouseDownPickColor = null; } if (cursorMouseDownAdjustColor != null) { cursorMouseDownAdjustColor.Dispose(); cursorMouseDownAdjustColor = null; } }
public bool PerformAction() { bool success = true; if (this.documentWorkspace.Selection.IsEmpty || !(this.documentWorkspace.ActiveLayer is BitmapLayer)) { return(false); } try { using (new WaitCursorChanger(this.documentWorkspace)) { Utility.GCFullCollect(); PdnRegion selectionRegion = this.documentWorkspace.Selection.CreateRegion(); PdnGraphicsPath selectionOutline = this.documentWorkspace.Selection.CreatePath(); BitmapLayer activeLayer = (BitmapLayer)this.documentWorkspace.ActiveLayer; RenderArgs renderArgs = new RenderArgs(activeLayer.Surface); MaskedSurface maskedSurface = new MaskedSurface(renderArgs.Surface, selectionOutline); SurfaceForClipboard surfaceForClipboard = new SurfaceForClipboard(maskedSurface); Rectangle selectionBounds = Utility.GetRegionBounds(selectionRegion); if (selectionBounds.Width > 0 && selectionBounds.Height > 0) { Surface copySurface = new Surface(selectionBounds.Width, selectionBounds.Height); Bitmap copyBitmap = copySurface.CreateAliasedBitmap(); Bitmap copyOpaqueBitmap = new Bitmap(copySurface.Width, copySurface.Height, PixelFormat.Format24bppRgb); using (Graphics copyBitmapGraphics = Graphics.FromImage(copyBitmap)) { copyBitmapGraphics.Clear(Color.White); } maskedSurface.Draw(copySurface, -selectionBounds.X, -selectionBounds.Y); using (Graphics copyOpaqueBitmapGraphics = Graphics.FromImage(copyOpaqueBitmap)) { copyOpaqueBitmapGraphics.Clear(Color.White); copyOpaqueBitmapGraphics.DrawImage(copyBitmap, 0, 0); } DataObject dataObject = new DataObject(); dataObject.SetData(DataFormats.Bitmap, copyOpaqueBitmap); dataObject.SetData(surfaceForClipboard); int retryCount = 2; while (retryCount >= 0) { try { using (new WaitCursorChanger(this.documentWorkspace)) { Clipboard.SetDataObject(dataObject, true); } break; } catch { if (retryCount == 0) { success = false; Utility.ErrorBox(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.TransferToClipboard")); } else { Thread.Sleep(200); } } finally { --retryCount; } } copySurface.Dispose(); copyBitmap.Dispose(); copyOpaqueBitmap.Dispose(); } selectionRegion.Dispose(); selectionOutline.Dispose(); renderArgs.Dispose(); maskedSurface.Dispose(); } } catch (OutOfMemoryException) { success = false; Utility.ErrorBox(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.OutOfMemory")); } catch (Exception) { success = false; Utility.ErrorBox(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.Generic")); } Utility.GCFullCollect(); return(success); }
private static DialogResult ShowExpandCanvasTaskDialog(IWin32Window owner, Surface thumbnail) { DialogResult result; Icon formIcon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.MenuEditPasteIcon.png").Reference); string formTitle = PdnResources.GetString("ExpandCanvasQuestion.Title"); RenderArgs taskImageRA = new RenderArgs(thumbnail); Image taskImage = taskImageRA.Bitmap; string introText = PdnResources.GetString("ExpandCanvasQuestion.IntroText"); TaskButton yesTB = new TaskButton( PdnResources.GetImageResource("Icons.ExpandCanvasQuestion.YesTB.Image.png").Reference, PdnResources.GetString("ExpandCanvasQuestion.YesTB.ActionText"), PdnResources.GetString("ExpandCanvasQuestion.YesTB.ExplanationText")); TaskButton noTB = new TaskButton( PdnResources.GetImageResource("Icons.ExpandCanvasQuestion.NoTB.Image.png").Reference, PdnResources.GetString("ExpandCanvasQuestion.NoTB.ActionText"), PdnResources.GetString("ExpandCanvasQuestion.NoTB.ExplanationText")); TaskButton cancelTB = new TaskButton( TaskButton.Cancel.Image, PdnResources.GetString("ExpandCanvasQuestion.CancelTB.ActionText"), PdnResources.GetString("ExpandCanvasQuestion.CancelTB.ExplanationText")); int width96dpi = (TaskDialog.DefaultPixelWidth96Dpi * 3) / 2; TaskButton clickedTB = TaskDialog.Show( owner, formIcon, formTitle, taskImage, false, introText, new TaskButton[] { yesTB, noTB, cancelTB }, yesTB, cancelTB, width96dpi); if (clickedTB == yesTB) { result = DialogResult.Yes; } else if (clickedTB == noTB) { result = DialogResult.No; } else { result = DialogResult.Cancel; } taskImageRA.Dispose(); taskImageRA = null; return result; }