public FreeformShapeTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            PdnResources.GetImageResource("Icons.FreeformShapeToolIcon.png"),
            PdnResources.GetString("FreeformShapeTool.Name"),
            PdnResources.GetString("FreeformShapeTool.HelpText"))
 {
 }
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            DateTime lastUpdate = DateTime.Now;

            documentWorkspace.History.BeginStepGroup();

            using (new WaitCursorChanger(documentWorkspace))
            {
                documentWorkspace.SuspendToolCursorChanges();

                while (documentWorkspace.History.RedoStack.Count > 0)
                {
                    documentWorkspace.History.StepForward();

                    if ((DateTime.Now - lastUpdate).TotalMilliseconds >= 500)
                    {
                        documentWorkspace.History.EndStepGroup();
                        documentWorkspace.Update();
                        lastUpdate = DateTime.Now;
                        documentWorkspace.History.BeginStepGroup();
                    }
                }

                documentWorkspace.ResumeToolCursorChanges();
            }

            documentWorkspace.History.EndStepGroup();

            Utility.GCFullCollect();
            documentWorkspace.Document.Invalidate();
            documentWorkspace.Update();

            return null;
        }
Beispiel #3
0
 public EllipseTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.EllipseToolIcon.png"),
            PdnResources.GetString("EllipseTool.Name"),
            PdnResources.GetString("EllipseTool.HelpText"))
 {
 }
 public RoundedRectangleTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.RoundedRectangleToolIcon.png"),
            PdnResources.GetString("RoundedRectangleTool.Name"),
            PdnResources.GetString("RoundedRectangleTool.HelpText"))
 {
 }
 public EllipseSelectTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.EllipseSelectToolIcon.png"),
            PdnResources.GetString("EllipseSelectTool.Name"),
            PdnResources.GetString("EllipseSelectTool.HelpText"),
            's',
            ToolBarConfigItems.None)
 {
 }
Beispiel #6
0
 public LassoSelectTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            PdnResources.GetImageResource("Icons.LassoSelectToolIcon.png"),
            PdnResources.GetString("LassoSelectTool.Name"),
            PdnResources.GetString("LassoSelectTool.HelpText"),
            's',
            ToolBarConfigItems.None)
 {
 }
Beispiel #7
0
 public GradientTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            StaticImage,
            StaticName,
            PdnResources.GetString("GradientTool.HelpText"),
            'g',
            false,
            ToolBarConfigItems.Gradient | ToolBarConfigItems.AlphaBlending)
 {
 }
Beispiel #8
0
 public PaintBucketTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.PaintBucketIcon.png"),
            PdnResources.GetString("PaintBucketTool.Name"),
            PdnResources.GetString("PaintBucketTool.HelpText"),
            'f',
            false,
            ToolBarConfigItems.Brush | ToolBarConfigItems.Antialiasing | ToolBarConfigItems.AlphaBlending)
 {
 }
Beispiel #9
0
 public EraserTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.EraserToolIcon.png"),
            PdnResources.GetString("EraserTool.Name"),
            PdnResources.GetString("EraserTool.HelpText"), //"Click and drag to erase a portion of the image",
            'e',
            false,
            ToolBarConfigItems.Pen | ToolBarConfigItems.Antialiasing)
 {
 }
Beispiel #10
0
 public RecolorTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.RecoloringToolIcon.png"),
            PdnResources.GetString("RecolorTool.Name"), 
            PdnResources.GetString("RecolorTool.HelpText"),
            'r',
            false,
            ToolBarConfigItems.Pen | ToolBarConfigItems.Antialiasing | ToolBarConfigItems.Tolerance)
 {
 }
Beispiel #11
0
 public CloneStampTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.CloneStampToolIcon.png"),
            PdnResources.GetString("CloneStampTool.Name"),
            PdnResources.GetString("CloneStampTool.HelpText"),
            'l',
            false,
            ToolBarConfigItems.Pen | ToolBarConfigItems.Antialiasing)
 {
 }
Beispiel #12
0
 public MagicWandTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.MagicWandToolIcon.png"),
            PdnResources.GetString("MagicWandTool.Name"),
            PdnResources.GetString("MagicWandTool.HelpText"), 
            's',
            false,
            ToolBarConfigItems.None)
 {
     LimitToSelection = false;
 }
Beispiel #13
0
 public LineTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.LineToolIcon.png"),
            PdnResources.GetString("LineTool.Name"),
            PdnResources.GetString("LineTool.HelpText"),
            ToolBarConfigItems.None, 
            ToolBarConfigItems.ShapeType)
 {
     this.ForceShapeDrawType = true;
     this.ForcedShapeDrawType = ShapeDrawType.Outline;
 }
 public MoveSelectionTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.MoveSelectionToolIcon.png"),
            MoveSelectionTool.StaticName,
            PdnResources.GetString("MoveSelectionTool.HelpText"), // "Click and drag to move a selected region",
            'm',
            false,
            ToolBarConfigItems.None)
 {
     this.context = new Context();
 }
Beispiel #15
0
 public ZoomTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.ZoomToolIcon.png"),
            PdnResources.GetString("ZoomTool.Name"),
            PdnResources.GetString("ZoomTool.HelpText"),
            'z',
            false,
            ToolBarConfigItems.None)
 {
     this.mouseDown = MouseButtons.None;
 }
 public ColorPickerTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.ColorPickerToolIcon.png"),
            PdnResources.GetString("ColorPickerTool.Name"),
            PdnResources.GetString("ColorPickerTool.HelpText"),
            'p',
            true,
            ToolBarConfigItems.ColorPickerBehavior)
 {
     // initialize any state information you need
     mouseDown = false;
 }
Beispiel #17
0
 public MoveTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.MoveToolIcon.png"),
            MoveTool.StaticName,
            PdnResources.GetString("MoveTool.HelpText"), // "Click and drag to move a selected region",
            'm',
            false,
            ToolBarConfigItems.Resampling)
 {
     this.context = new MoveToolContext();
     this.enableOutline = false;
 }
Beispiel #18
0
 public PencilTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.PencilToolIcon.png"),
            PdnResources.GetString("PencilTool.Name"),
            PdnResources.GetString("PencilTool.HelpText"),
            'p',
            true,
            ToolBarConfigItems.AlphaBlending)
 {
     // initialize any state information you need
     mouseDown = false;
 }
Beispiel #19
0
 public PanTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.PanToolIcon.png"),
            PdnResources.GetString("PanTool.Name"),
            PdnResources.GetString("PanTool.HelpText"), 
            'h',
            false,
            ToolBarConfigItems.None)
 {
     autoScroll = false;
     tracking = false;
 }
Beispiel #20
0
 public PaintBrushTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace,
            ImageResource.Get("Icons.PaintBrushToolIcon.png"),
            PdnResources.GetString("PaintBrushTool.Name"),
            PdnResources.GetString("PaintBrushTool.HelpText"),
            'b',
            false,
            ToolBarConfigItems.Brush | ToolBarConfigItems.Pen | ToolBarConfigItems.Antialiasing | ToolBarConfigItems.AlphaBlending)
 {
     // initialize any state information you need
     mouseDown = false;
 }
Beispiel #21
0
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            if (!ScanningAndPrinting.CanPrint)
            {
                Utility.ShowWiaError(documentWorkspace);
                return null;
            }

            using (new PushNullToolMode(documentWorkspace))
            {
                // render image to a bitmap, save it to disk
                Surface scratch = documentWorkspace.BorrowScratchSurface(this.GetType().Name + ".PerformAction()");

                try
                {
                    scratch.Clear();
                    RenderArgs ra = new RenderArgs(scratch);

                    documentWorkspace.Update();

                    using (new WaitCursorChanger(documentWorkspace))
                    {
                        ra.Surface.Clear(ColorBgra.White);
                        documentWorkspace.Document.Render(ra, false);
                    }

                    string tempName = Path.GetTempFileName() + ".bmp";
                    ra.Bitmap.Save(tempName, ImageFormat.Bmp);

                    try
                    {
                        ScanningAndPrinting.Print(documentWorkspace, tempName);
                    }

                    catch (Exception ex)
                    {
                        Utility.ShowWiaError(documentWorkspace);
                        Tracing.Ping(ex.ToString());
                        // TODO: do a "better" error dialog here
                    }

                    // Try to delete the temp file but don't worry if we can't
                    bool result = FileSystem.TryDeleteFile(tempName);
                }

                finally
                {
                    documentWorkspace.ReturnScratchSurface(scratch);
                }
            }

            return null;
        }
 public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
 {
     if (documentWorkspace.ZoomBasis == ZoomBasis.FitToWindow)
     {
         documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
     }
     else
     {
         documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
     } 
     
     return null;
 }
Beispiel #23
0
 public ShapeTool(DocumentWorkspace documentWorkspace,
                  ImageResource toolBarImage,
                  string name,
                  string helpText)
     : this(documentWorkspace,
            toolBarImage,
            name,
            helpText,
            defaultShortcut,
            ToolBarConfigItems.None,
            ToolBarConfigItems.None)
 {
 }
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            if (DialogResult.Yes == Utility.AskYesNo(documentWorkspace,
                PdnResources.GetString("ClearHistory.Confirmation")))
            {
                documentWorkspace.History.ClearAll();

                documentWorkspace.History.PushNewMemento(new NullHistoryMemento(
                    PdnResources.GetString("ClearHistory.HistoryMementoName"),
                    ImageResource.Get("Icons.MenuLayersDeleteLayerIcon.png")));
            }

            return null;
        }
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            bool oldDirtyValue = documentWorkspace.Document.Dirty;

            using (Form lpd = documentWorkspace.ActiveLayer.CreateConfigDialog())
            {
                DialogResult result = Utility.ShowDialog(lpd, documentWorkspace.FindForm());

                if (result == DialogResult.Cancel)
                {
                    documentWorkspace.Document.Dirty = oldDirtyValue;
                }
            }

            return null;
        }
Beispiel #26
0
 public SelectionTool(
     DocumentWorkspace documentWorkspace,
     ImageResource toolBarImage,
     string name,
     string helpText,
     char hotKey,
     ToolBarConfigItems toolBarConfigItems)
     : base(documentWorkspace,
            toolBarImage,
            name,
            helpText,
            hotKey,
            false,
            toolBarConfigItems)
 {
     this.tracking = false;
 }
        private HistoryMemento DoCanvasResize(DocumentWorkspace documentWorkspace, Size newLayerSize)
        {
            HistoryMemento retHA;

            int layerIndex = documentWorkspace.ActiveLayerIndex;

            Size newSize = new Size(Math.Max(newLayerSize.Width, documentWorkspace.Document.Width),
                Math.Max(newLayerSize.Height, documentWorkspace.Document.Height));

            Document newDoc;
            
            try
            {
                using (new WaitCursorChanger(documentWorkspace))
                {
                    Utility.GCFullCollect();

                    newDoc = CanvasSizeAction.ResizeDocument(documentWorkspace.Document, newSize, 
                        AnchorEdge.TopLeft, documentWorkspace.AppWorkspace.AppEnvironment.SecondaryColor);
                }
            }

            catch (OutOfMemoryException)
            {
                Utility.ErrorBox(documentWorkspace, PdnResources.GetString("ImportFromFileAction.AskForCanvasResize.OutOfMemory"));
                newDoc = null;
            }

            if (newDoc == null)
            {
                retHA = null;
            }
            else
            {
                retHA = new ReplaceDocumentHistoryMemento(string.Empty, null, documentWorkspace);

                using (new WaitCursorChanger(documentWorkspace))
                {
                    documentWorkspace.Document = newDoc;
                }

                documentWorkspace.ActiveLayer = (Layer)documentWorkspace.Document.Layers[layerIndex];
            }

            return retHA;
        }
Beispiel #28
0
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            if (documentWorkspace.History.RedoStack.Count > 0)
            {
                if (!(documentWorkspace.History.RedoStack[documentWorkspace.History.RedoStack.Count - 1] is NullHistoryMemento))
                {
                    using (new WaitCursorChanger(documentWorkspace.FindForm()))
                    {
                        documentWorkspace.History.StepForward();
                        documentWorkspace.Update();
                    }
                }

                Utility.GCFullCollect();
            }

            return null;
        }
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            HistoryMemento hm = null;
            int index = documentWorkspace.ActiveLayerIndex;

            if (index != 0)
            {
                SwapLayerHistoryMemento slhm = new SwapLayerHistoryMemento(
                    StaticName,
                    StaticImage,
                    documentWorkspace,
                    index,
                    index - 1);

                hm = slhm.PerformUndo();
            }

            return hm;
        }
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            HistoryMemento hm = null;
            int index = documentWorkspace.ActiveLayerIndex;

            if (index != documentWorkspace.Document.Layers.Count - 1)
            {
                SwapLayerFunction slf = new SwapLayerFunction(index, index + 1);
                HistoryMemento slfhm = slf.Execute(documentWorkspace);

                hm = new CompoundHistoryMemento(
                    StaticName,
                    StaticImage,
                    new HistoryMemento[] { slfhm });

                documentWorkspace.ActiveLayer = (Layer)documentWorkspace.Document.Layers[index + 1];
            }

            return hm;
        }
Beispiel #31
0
        /// <summary>
        /// This method is called when the tool is active and a keyboard key is pressed
        /// and released. If you respond to the keyboard key, set e.Handled to true.
        /// </summary>
        protected virtual void OnKeyPress(KeyPressEventArgs e)
        {
            if (!e.Handled && DocumentWorkspace.Focused)
            {
                if (e.KeyChar == swapColorsShortcut)
                {
                    AppWorkspace.Widgets.ColorsForm.SwapUserColors();
                    e.Handled = true;
                }
                else if (e.KeyChar == swapPrimarySecondaryChoice)
                {
                    AppWorkspace.Widgets.ColorsForm.ToggleWhichUserColor();
                    e.Handled = true;
                }
                else if (e.KeyChar == decPenSizeShortcut)
                {
                    AppWorkspace.Widgets.ToolConfigStrip.AddToPenSize(-1.0f);
                    e.Handled = true;
                }
                else if (e.KeyChar == decPenSizeBy5Shortcut && (ModifierKeys & Keys.Control) != 0)
                {
                    AppWorkspace.Widgets.ToolConfigStrip.AddToPenSize(-5.0f);
                    e.Handled = true;
                }
                else if (e.KeyChar == incPenSizeShortcut)
                {
                    AppWorkspace.Widgets.ToolConfigStrip.AddToPenSize(+1.0f);
                    e.Handled = true;
                }
                else if (e.KeyChar == incPenSizeBy5Shortcut && (ModifierKeys & Keys.Control) != 0)
                {
                    AppWorkspace.Widgets.ToolConfigStrip.AddToPenSize(+5.0f);
                    e.Handled = true;
                }
                else
                {
                    ToolInfo[] toolInfos       = DocumentWorkspace.ToolInfos;
                    Type       currentToolType = DocumentWorkspace.GetToolType();
                    int        currentTool     = 0;

                    if (0 != (ModifierKeys & Keys.Shift))
                    {
                        Array.Reverse(toolInfos);
                    }

                    if (char.ToLower(this.HotKey) != char.ToLower(e.KeyChar) ||
                        (DateTime.Now - lastToolSwitch) > toolSwitchReset)
                    {
                        // If it's been a short time since they pressed a tool switching hotkey,
                        // we will start from the beginning of this list. This helps to enable two things:
                        // 1) If multiple tools have the same hotkey, the user may press that hotkey
                        //    to cycle through them
                        // 2) After a period of time, pressing the hotkey will revert to always
                        //    choosing the first tool in that list of tools which have the same hotkey.
                        currentTool = -1;
                    }
                    else
                    {
                        for (int t = 0; t < toolInfos.Length; ++t)
                        {
                            if (toolInfos[t].ToolType == currentToolType)
                            {
                                currentTool = t;
                                break;
                            }
                        }
                    }

                    for (int t = 0; t < toolInfos.Length; ++t)
                    {
                        int      newTool       = (t + currentTool + 1) % toolInfos.Length;
                        ToolInfo localToolInfo = toolInfos[newTool];

                        if (localToolInfo.ToolType == DocumentWorkspace.GetToolType() &&
                            localToolInfo.SkipIfActiveOnHotKey)
                        {
                            continue;
                        }

                        if (char.ToLower(localToolInfo.HotKey) == char.ToLower(e.KeyChar))
                        {
                            if (!this.IsMouseDown)
                            {
                                AppWorkspace.Widgets.ToolsControl.SelectTool(localToolInfo.ToolType);
                            }

                            e.Handled      = true;
                            lastToolSwitch = DateTime.Now;
                            break;
                        }
                    }

                    // If the keypress is still not handled ...
                    if (!e.Handled)
                    {
                        switch (e.KeyChar)
                        {
                        // By default, Esc/Enter clear the current selection if there is any
                        case (char)13:     // Enter
                        case (char)27:     // Escape
                            if (this.mouseDown == 0 && !Selection.IsEmpty)
                            {
                                e.Handled = true;
                                DocumentWorkspace.ExecuteFunction(new DeselectFunction());
                            }

                            break;
                        }
                    }
                }
            }
        }
Beispiel #32
0
 public FloodToolBase(DocumentWorkspace documentWorkspace, ImageResource toolBarImage, string name,
                      string helpText, char hotKey, bool skipIfActiveOnHotKey, ToolBarConfigItems toolBarConfigItems)
     : base(documentWorkspace, toolBarImage, name, helpText, hotKey, skipIfActiveOnHotKey,
            ToolBarConfigItems.Tolerance | toolBarConfigItems)
 {
 }
Beispiel #33
0
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            int             newWidth;
            int             newHeight;
            double          newDpu;
            MeasurementUnit newDpuUnit;

            string resamplingAlgorithm = Settings.CurrentUser.GetString(SettingNames.LastResamplingMethod,
                                                                        ResamplingAlgorithm.SuperSampling.ToString());

            ResamplingAlgorithm alg;

            try
            {
                alg = (ResamplingAlgorithm)Enum.Parse(typeof(ResamplingAlgorithm), resamplingAlgorithm, true);
            }

            catch
            {
                alg = ResamplingAlgorithm.SuperSampling;
            }

            bool maintainAspect = Settings.CurrentUser.GetBoolean(SettingNames.LastMaintainAspectRatio, true);

            using (ResizeDialog rd = new ResizeDialog())
            {
                rd.OriginalSize        = documentWorkspace.Document.Size;
                rd.OriginalDpuUnit     = documentWorkspace.Document.DpuUnit;
                rd.OriginalDpu         = documentWorkspace.Document.DpuX;
                rd.ImageHeight         = documentWorkspace.Document.Height;
                rd.ImageWidth          = documentWorkspace.Document.Width;
                rd.ResamplingAlgorithm = alg;
                rd.LayerCount          = documentWorkspace.Document.Layers.Count;
                rd.Units             = rd.OriginalDpuUnit;
                rd.Resolution        = documentWorkspace.Document.DpuX;
                rd.Units             = SettingNames.GetLastNonPixelUnits();
                rd.ConstrainToAspect = maintainAspect;

                DialogResult result = rd.ShowDialog(documentWorkspace);

                if (result == DialogResult.Cancel)
                {
                    return(null);
                }

                Settings.CurrentUser.SetString(SettingNames.LastResamplingMethod, rd.ResamplingAlgorithm.ToString());
                Settings.CurrentUser.SetBoolean(SettingNames.LastMaintainAspectRatio, rd.ConstrainToAspect);
                newDpuUnit = rd.Units;
                newWidth   = rd.ImageWidth;
                newHeight  = rd.ImageHeight;
                newDpu     = rd.Resolution;
                alg        = rd.ResamplingAlgorithm;

                if (newDpuUnit != MeasurementUnit.Pixel)
                {
                    Settings.CurrentUser.SetString(SettingNames.LastNonPixelUnits, newDpuUnit.ToString());

                    if (documentWorkspace.AppWorkspace.Units != MeasurementUnit.Pixel)
                    {
                        documentWorkspace.AppWorkspace.Units = newDpuUnit;
                    }
                }

                // if the new size equals the old size, there's really no point in doing anything
                if (documentWorkspace.Document.Size == new Size(rd.ImageWidth, rd.ImageHeight) &&
                    documentWorkspace.Document.DpuX == newDpu &&
                    documentWorkspace.Document.DpuUnit == newDpuUnit)
                {
                    return(null);
                }
            }

            HistoryMemento ha;

            if (newWidth == documentWorkspace.Document.Width &&
                newHeight == documentWorkspace.Document.Height)
            {
                // Only adjusting Dpu or DpuUnit
                ha = new MetaDataHistoryMemento(StaticName, StaticImage, documentWorkspace);
                documentWorkspace.Document.DpuUnit = newDpuUnit;
                documentWorkspace.Document.DpuX    = newDpu;
                documentWorkspace.Document.DpuY    = newDpu;
            }
            else
            {
                try
                {
                    using (new WaitCursorChanger(documentWorkspace))
                    {
                        ha = new ReplaceDocumentHistoryMemento(StaticName, StaticImage, documentWorkspace);
                    }

                    Document newDocument = new Document(newWidth, newHeight);
                    newDocument.ReplaceMetaDataFrom(documentWorkspace.Document);
                    newDocument.DpuUnit = newDpuUnit;
                    newDocument.DpuX    = newDpu;
                    newDocument.DpuY    = newDpu;
                    ResizeProgressDialog rpd = new ResizeProgressDialog(documentWorkspace, newDocument, documentWorkspace.Document, new Size(newWidth, newHeight), alg);
                    Utility.GCFullCollect();
                    bool result = rpd.DoResize();

                    if (!result)
                    {
                        return(null);
                    }

                    documentWorkspace.Document = newDocument;
                }

                catch (WorkerThreadException ex)
                {
                    if (ex.InnerException is OutOfMemoryException)
                    {
                        Utility.ErrorBox(documentWorkspace, PdnResources.GetString("ResizeAction.PerformAction.OutOfMemory"));
                        return(null);
                    }
                    else
                    {
                        throw;
                    }
                }

                catch (OutOfMemoryException)
                {
                    Utility.ErrorBox(documentWorkspace, PdnResources.GetString("ResizeAction.PerformAction.OutOfMemory"));
                    return(null);
                }
            }

            return(ha);
        }
Beispiel #34
0
 public CopyToClipboardAction(DocumentWorkspace documentWorkspace)
 {
     SystemLayer.Tracing.LogFeature("CopyToClipboardAction");
     this.documentWorkspace = documentWorkspace;
 }
 public MoveSelectedPixelsTool(DocumentWorkspace docWorkspace) : base(docWorkspace, PdnResources.GetImageResource("Icons.MoveToolIcon.png"), PdnResources.GetString("MoveTool.Name"), PdnResources.GetString("MoveTool.HelpText"), 'm', false, ToolBarConfigItems.None | ToolBarConfigItems.Resampling, true)
 {
 }
Beispiel #36
0
        public override HistoryMemento PerformAction(DocumentWorkspace docWorkspace)
        {
            int                 newWidth;
            int                 newHeight;
            MeasurementUnit     newDpuUnit;
            double              newDpu;
            ResamplingAlgorithm algorithm = AppSettings.Instance.Workspace.LastResamplingMethod.Value;

            if (algorithm == ResamplingAlgorithm.SuperSampling)
            {
                algorithm = ResamplingAlgorithm.Fant;
            }
            bool flag = AppSettings.Instance.Workspace.LastMaintainAspectRatio.Value;

            using (ResizeDialog dialog = new ResizeDialog())
            {
                dialog.OriginalSize        = docWorkspace.Document.Size;
                dialog.OriginalDpuUnit     = docWorkspace.Document.DpuUnit;
                dialog.OriginalDpu         = docWorkspace.Document.DpuX;
                dialog.ImageHeight         = docWorkspace.Document.Height;
                dialog.ImageWidth          = docWorkspace.Document.Width;
                dialog.ResamplingAlgorithm = algorithm;
                dialog.LayerCount          = docWorkspace.Document.Layers.Count;
                dialog.Units             = dialog.OriginalDpuUnit;
                dialog.Resolution        = docWorkspace.Document.DpuX;
                dialog.Units             = AppSettings.Instance.Workspace.LastNonPixelUnits.Value;
                dialog.ConstrainToAspect = flag;
                if (dialog.ShowDialog(docWorkspace) == DialogResult.Cancel)
                {
                    return(null);
                }
                AppSettings.Instance.Workspace.LastResamplingMethod.Value    = dialog.ResamplingAlgorithm;
                AppSettings.Instance.Workspace.LastMaintainAspectRatio.Value = dialog.ConstrainToAspect;
                newDpuUnit = dialog.Units;
                newWidth   = dialog.ImageWidth;
                newHeight  = dialog.ImageHeight;
                newDpu     = dialog.Resolution;
                algorithm  = dialog.ResamplingAlgorithm;
                if (newDpuUnit != MeasurementUnit.Pixel)
                {
                    AppSettings.Instance.Workspace.LastNonPixelUnits.Value = newDpuUnit;
                    if (docWorkspace.AppWorkspace.Units != MeasurementUnit.Pixel)
                    {
                        docWorkspace.AppWorkspace.Units = newDpuUnit;
                    }
                }
                if (((docWorkspace.Document.Size == new Size(dialog.ImageWidth, dialog.ImageHeight)) && (docWorkspace.Document.DpuX == newDpu)) && (docWorkspace.Document.DpuUnit == newDpuUnit))
                {
                    return(null);
                }
            }
            if ((newWidth == docWorkspace.Document.Width) && (newHeight == docWorkspace.Document.Height))
            {
                MetadataHistoryMemento memento2 = new MetadataHistoryMemento(StaticName, PdnResources.GetImageResource(StaticImageName), docWorkspace);
                docWorkspace.Document.DpuUnit = newDpuUnit;
                docWorkspace.Document.DpuX    = newDpu;
                docWorkspace.Document.DpuY    = newDpu;
                return(memento2);
            }
            docWorkspace.FlushTool();
            using (TaskProgressDialog progressDialog = new TaskProgressDialog())
            {
        public override void PerformAction(AppWorkspace appWorkspace)
        {
            DocumentWorkspace originalDW = appWorkspace.ActiveDocumentWorkspace;

            int oldLatency = 10;

            try
            {
                oldLatency = appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency;
                appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency = 0;
            }

            catch (NullReferenceException)
            {
                // See bug #2544
            }

            List <DocumentWorkspace> unsavedDocs = new List <DocumentWorkspace>();

            foreach (DocumentWorkspace dw in appWorkspace.DocumentWorkspaces)
            {
                if (dw.Document != null && dw.Document.Dirty)
                {
                    unsavedDocs.Add(dw);
                }
            }

            if (unsavedDocs.Count == 1)
            {
                CloseWorkspaceAction cwa = new CloseWorkspaceAction(unsavedDocs[0]);
                cwa.PerformAction(appWorkspace);
                this.Cancelled = cwa.Cancelled;
            }
            else if (unsavedDocs.Count > 1)
            {
                using (UnsavedChangesDialog dialog = new UnsavedChangesDialog())
                {
                    dialog.DocumentClicked += (s, e2) => { appWorkspace.ActiveDocumentWorkspace = e2.Data; };

                    dialog.Documents = unsavedDocs.ToArray();

                    if (appWorkspace.ActiveDocumentWorkspace.Document.Dirty)
                    {
                        dialog.SelectedDocument = appWorkspace.ActiveDocumentWorkspace;
                    }

                    Form mainForm = appWorkspace.FindForm();
                    if (mainForm != null)
                    {
                        if (mainForm is PdnBaseForm asPDF)
                        {
                            asPDF.RestoreWindow();
                        }
                    }

                    DialogResult dr = Utility.ShowDialog(dialog, appWorkspace);

                    switch (dr)
                    {
                    case DialogResult.Yes:
                    {
                        foreach (DocumentWorkspace dw in unsavedDocs)
                        {
                            appWorkspace.ActiveDocumentWorkspace = dw;
                            bool result = dw.DoSave();

                            if (result)
                            {
                                appWorkspace.RemoveDocumentWorkspace(dw);
                            }
                            else
                            {
                                this.Cancelled = true;
                                break;
                            }
                        }
                    }
                    break;

                    case DialogResult.No:
                        this.Cancelled = false;
                        break;

                    case DialogResult.Cancel:
                        this.Cancelled = true;
                        break;

                    default:
                        throw new InvalidEnumArgumentException();
                    }
                }
            }

            try
            {
                appWorkspace.Widgets.DocumentStrip.ThumbnailUpdateLatency = oldLatency;
            }

            catch (NullReferenceException)
            {
                // See bug #2544
            }

            if (this.Cancelled)
            {
                if (appWorkspace.ActiveDocumentWorkspace != originalDW &&
                    !originalDW.IsDisposed)
                {
                    appWorkspace.ActiveDocumentWorkspace = originalDW;
                }
            }
            else
            {
                UI.SuspendControlPainting(appWorkspace);

                foreach (DocumentWorkspace dw in appWorkspace.DocumentWorkspaces)
                {
                    appWorkspace.RemoveDocumentWorkspace(dw);
                }

                UI.ResumeControlPainting(appWorkspace);
                appWorkspace.Invalidate(true);
            }
        }
Beispiel #38
0
 protected void Update()
 {
     DocumentWorkspace.Update();
 }
Beispiel #39
0
        /// <summary>
        /// This method is called when the tool is active and a keyboard key is pressed
        /// and released that is not representable with a regular Unicode chararacter.
        /// An example would be the arrow keys.
        /// </summary>
        protected virtual void OnKeyPress(Keys key)
        {
            Point dir = Point.Empty;

            if (key != lastKey)
            {
                lastKeyboardMove = DateTime.MinValue;
            }

            lastKey = key;

            switch (key)
            {
            case Keys.Left:
                --dir.X;
                break;

            case Keys.Right:
                ++dir.X;
                break;

            case Keys.Up:
                --dir.Y;
                break;

            case Keys.Down:
                ++dir.Y;
                break;
            }

            if (!dir.Equals(Point.Empty))
            {
                long span = DateTime.Now.Ticks - lastKeyboardMove.Ticks;

                if ((span * 4) > TimeSpan.TicksPerSecond)
                {
                    keyboardMoveRepeats = 0;
                    keyboardMoveSpeed   = 1;
                }
                else
                {
                    keyboardMoveRepeats++;

                    if (keyboardMoveRepeats > 15 && (keyboardMoveRepeats % 4) == 0)
                    {
                        keyboardMoveSpeed++;
                    }
                }

                lastKeyboardMove = DateTime.Now;

                int offset = (int)(Math.Ceiling(DocumentWorkspace.ScaleFactor.Ratio) * (double)keyboardMoveSpeed);
                Cursor.Position = new Point(Cursor.Position.X + offset * dir.X, Cursor.Position.Y + offset * dir.Y);

                Point location = DocumentWorkspace.PointToScreen(Point.Truncate(DocumentWorkspace.DocumentToClient(PointF.Empty)));

                PointF stylusLocF = new PointF((float)Cursor.Position.X - (float)location.X, (float)Cursor.Position.Y - (float)location.Y);
                Point  stylusLoc  = new Point(Cursor.Position.X - location.X, Cursor.Position.Y - location.Y);

                stylusLoc  = DocumentWorkspace.ScaleFactor.UnscalePoint(stylusLoc);
                stylusLocF = DocumentWorkspace.ScaleFactor.UnscalePoint(stylusLocF);

                DocumentWorkspace.PerformDocumentMouseMove(new StylusEventArgs(lastButton, 1, stylusLocF.X, stylusLocF.Y, 0, 1.0f));
                DocumentWorkspace.PerformDocumentMouseMove(new MouseEventArgs(lastButton, 1, stylusLoc.X, stylusLoc.Y, 0));
            }
        }
Beispiel #40
0
 protected object GetStaticData()
 {
     return(DocumentWorkspace.GetStaticToolData(this.GetType()));
 }
 public ContextHistoryMemento(DocumentWorkspace documentWorkspace, Context context, string name, ImageResource image)
     : base(documentWorkspace, name, image)
 {
     this.Data = new OurHistoryMementoData(context);
 }
Beispiel #42
0
 public PanTool(DocumentWorkspace documentWorkspace)
     : base(documentWorkspace, PdnResources.GetImageResource("Icons.PanToolIcon.png"), PdnResources.GetString("PanTool.Name"), PdnResources.GetString("PanTool.HelpText"), 'r', false, ToolBarConfigItems.All)
 {
 }
Beispiel #43
0
        private HistoryMemento ImportOneLayer(DocumentWorkspace documentWorkspace, BitmapLayer layer)
        {
            HistoryMemento        retHA;
            List <HistoryMemento> historyMementos = new List <HistoryMemento>();
            bool success = true;

            if (success)
            {
                if (!documentWorkspace.Selection.IsEmpty)
                {
                    HistoryMemento ha = new DeselectFunction().Execute(documentWorkspace);
                    historyMementos.Add(ha);
                }
            }

            if (success)
            {
                if (layer.Width > documentWorkspace.Document.Width ||
                    layer.Height > documentWorkspace.Document.Height)
                {
                    HistoryMemento ha = DoCanvasResize(documentWorkspace, layer.Size);

                    if (ha == null)
                    {
                        success = false;
                    }
                    else
                    {
                        historyMementos.Add(ha);
                    }
                }
            }

            if (success)
            {
                if (layer.Size != documentWorkspace.Document.Size)
                {
                    BitmapLayer newLayer;

                    try
                    {
                        using (new WaitCursorChanger(documentWorkspace))
                        {
                            Utility.GCFullCollect();

                            newLayer = CanvasSizeAction.ResizeLayer((BitmapLayer)layer, documentWorkspace.Document.Size,
                                                                    AnchorEdge.TopLeft, ColorBgra.White.NewAlpha(0));
                        }
                    }

                    catch (OutOfMemoryException)
                    {
                        Utility.ErrorBox(documentWorkspace, PdnResources.GetString("ImportFromFileAction.ImportOneLayer.OutOfMemory"));
                        success  = false;
                        newLayer = null;
                    }

                    if (newLayer != null)
                    {
                        layer.Dispose();
                        layer = newLayer;
                    }
                }
            }

            if (success)
            {
                NewLayerHistoryMemento nlha = new NewLayerHistoryMemento(string.Empty, null, documentWorkspace, documentWorkspace.Document.Layers.Count);
                documentWorkspace.Document.Layers.Add(layer);
                historyMementos.Add(nlha);
            }

            if (success)
            {
                HistoryMemento[] has = historyMementos.ToArray();
                retHA = new CompoundHistoryMemento(string.Empty, null, has);
            }
            else
            {
                Rollback(historyMementos);
                retHA = null;
            }

            return(retHA);
        }
Beispiel #44
0
        /// <summary>
        /// Presents a user interface and performs the operations required for importing an entire document.
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        /// <remarks>
        /// This function will take ownership of the Document given to it, and will Dispose() of it.
        /// </remarks>
        private HistoryMemento ImportDocument(DocumentWorkspace documentWorkspace, Document document, out Rectangle lastLayerBounds)
        {
            List <HistoryMemento> historyMementos = new List <HistoryMemento>();

            bool[] selected;

            selected = new bool[document.Layers.Count];
            for (int i = 0; i < selected.Length; ++i)
            {
                selected[i] = true;
            }

            lastLayerBounds = Rectangle.Empty;

            if (selected != null)
            {
                List <Layer> layers = new List <Layer>();

                for (int i = 0; i < selected.Length; ++i)
                {
                    if (selected[i])
                    {
                        layers.Add((Layer)document.Layers[i]);
                    }
                }

                foreach (Layer layer in layers)
                {
                    document.Layers.Remove(layer);
                }

                document.Dispose();
                document = null;

                foreach (Layer layer in layers)
                {
                    lastLayerBounds = layer.Bounds;
                    HistoryMemento ha = ImportOneLayer(documentWorkspace, (BitmapLayer)layer);

                    if (ha != null)
                    {
                        historyMementos.Add(ha);
                    }
                    else
                    {
                        Rollback(historyMementos);
                        historyMementos.Clear();
                        break;
                    }
                }
            }

            if (document != null)
            {
                document.Dispose();
                document = null;
            }

            if (historyMementos.Count > 0)
            {
                HistoryMemento[] has = historyMementos.ToArray();
                return(new CompoundHistoryMemento(string.Empty, null, has));
            }
            else
            {
                lastLayerBounds = Rectangle.Empty;
                return(null);
            }
        }
Beispiel #45
0
 public PushNullToolMode(DocumentWorkspace documentWorkspace)
 {
     this.documentWorkspace = documentWorkspace;
     this.documentWorkspace.PushNullTool();
 }
Beispiel #46
0
 public RectangleSelectTool(DocumentWorkspace documentWorkspace) : base(documentWorkspace, PdnResources.GetImageResource("Icons.RectangleSelectToolIcon.png"), PdnResources.GetString("RectangleSelectTool.Name"), PdnResources.GetString("RectangleSelectTool.HelpText"), 's', ToolBarConfigItems.None | ToolBarConfigItems.SelectionDrawMode)
 {
 }
Beispiel #47
0
 public MagicWandTool(DocumentWorkspace documentWorkspace) : base(documentWorkspace, PdnResources.GetImageResource("Icons.MagicWandToolIcon.png"), PdnResources.GetString("MagicWandTool.Name"), PdnResources.GetString("MagicWandTool.HelpText"), 's', false, ToolBarConfigItems.FloodMode | ToolBarConfigItems.SampleImageOrLayer | ToolBarConfigItems.SelectionCombineMode | ToolBarConfigItems.Tolerance)
 {
     this.onUIGestureRegion = new ProtectedRegion("OnUIGesture*", ProtectedRegionOptions.None);
 }
Beispiel #48
0
 public CloseWorkspaceAction(DocumentWorkspace closeMe)
 {
     this.closeMe   = closeMe;
     this.cancelled = false;
 }
Beispiel #49
0
 public ToolHistoryMemento(DocumentWorkspace documentWorkspace, string name, ImageResource image)
     : base(name, image)
 {
     this.documentWorkspace = documentWorkspace;
     this.toolType          = documentWorkspace.GetToolType();
 }
 public TransactedToolEditHistoryMemento(DocumentWorkspace docWorkspace, string name, ImageResource image, TChanges previousChanges) : base(docWorkspace, name, image)
 {
     this.previousChanges = previousChanges;
 }
Beispiel #51
0
        private void Done()
        {
            if (Tracking)
            {
                // Truth table for what we should do based on three flags:
                //  append  | moved | tooQuick | result                             | optimized expression to yield true
                // ---------+-------+----------+-----------------------------------------------------------------------
                //     F    |   T   |    T     | clear selection                    | !append && (!moved || tooQuick)
                //     F    |   T   |    F     | emit new selected area             | !append && moved && !tooQuick
                //     F    |   F   |    T     | clear selection                    | !append && (!moved || tooQuick)
                //     F    |   F   |    F     | clear selection                    | !append && (!moved || tooQuick)
                //     T    |   T   |    T     | append to selection                | append && moved
                //     T    |   T   |    F     | append to selection                | append && moved
                //     T    |   F   |    T     | reset selection                    | append && !moved
                //     T    |   F   |    F     | reset selection                    | append && !moved
                //
                // append   --> If the user was holding control, then true. Else false.
                // moved    --> If they never moved the mouse, false. Else true.
                // tooQuick --> If they held the mouse button down for more than 50ms, false. Else true.
                //
                // "Clear selection" means to result in no selected area. If the selection area was previously empty,
                //    then no HistoryMemento is emitted. Otherwise a Deselect HistoryMemento is emitted.
                //
                // "Reset selection" means to reset the selected area to how it was before interaction with the tool,
                //    without a HistoryMemento.

                PointF[] polygon = CreateSelectionPolygon();
                HasMoved &= (polygon.Length > 1);

                // They were "too quick" if they weren't doing a selection for more than 50ms
                // This takes care of the case where someone wants to click to deselect, but accidentally moves
                // the mouse. This happens VERY frequently.
                bool tooQuick = Utility.TicksToMs((DateTime.Now - StartTime).Ticks) <= 50;

                // If their selection was completedly out of bounds, it will be clipped
                bool clipped = (polygon.Length == 0);

                // What the user drew had no effect on the selection, e.g. subtraction where there was nothing in the first place
                bool noEffect = false;

                WhatToDo whatToDo;

                // If their selection gets completely clipped (i.e. outside the image canvas),
                // then result in a no-op
                if (Append)
                {
                    if (!HasMoved || clipped || noEffect)
                    {
                        whatToDo = WhatToDo.Reset;
                    }
                    else
                    {
                        whatToDo = WhatToDo.Emit;
                    }
                }
                else
                {
                    if (HasMoved && !tooQuick && !clipped && !noEffect)
                    {
                        whatToDo = WhatToDo.Emit;
                    }
                    else
                    {
                        whatToDo = WhatToDo.Clear;
                    }
                }

                switch (whatToDo)
                {
                case WhatToDo.Clear:
                    if (WasNotEmpty)
                    {
                        // emit a deselect history action
                        UndoAction.Name  = DeselectFunction.StaticName;
                        UndoAction.Image = DeselectFunction.StaticImage;
                        HistoryStack.PushNewMemento(UndoAction);
                    }

                    Selection.Reset();
                    break;

                case WhatToDo.Emit:
                    // emit newly selected area
                    UndoAction.Name = Name;
                    HistoryStack.PushNewMemento(UndoAction);
                    Selection.CommitContinuation();
                    break;

                case WhatToDo.Reset:
                    // reset selection, no HistoryMemento
                    Selection.ResetContinuation();
                    break;
                }

                DocumentWorkspace.ResetOutlineWhiteOpacity();
                NewSelectionRenderer.ResetOutlineWhiteOpacity();
                NewSelection.Reset();
                NewSelectionRenderer.Visible = false;

                Tracking = false;

                DocumentWorkspace.EnableSelectionOutline = true;
                DocumentWorkspace.InvalidateSurface(Utility.RoundRectangle(DocumentWorkspace.VisibleDocumentRectangleF));
            }
        }
Beispiel #52
0
 public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
 {
     documentWorkspace.ZoomOut();
     return(null);
 }
Beispiel #53
0
 protected BrushToolBase(DocumentWorkspace documentWorkspace, ImageResource toolBarImage, string name, string helpText, char hotKey, bool skipIfActiveOnHotKey, ToolBarConfigItems toolBarConfigItems) : base(documentWorkspace, toolBarImage, name, helpText, hotKey, skipIfActiveOnHotKey, (((toolBarConfigItems | (ToolBarConfigItems.None | ToolBarConfigItems.PenWidth)) | (ToolBarConfigItems.None | ToolBarConfigItems.PenHardness)) | ToolBarConfigItems.Antialiasing) | (ToolBarConfigItems.None | ToolBarConfigItems.SelectionRenderingQuality), false)
 {
     this.txHandler = new BitmapLayerTransactionHandler <TDerived, TChanges>((TDerived)this);
 }
Beispiel #54
0
        private void Workspace_CompositionUpdated(object sender, EventArgs e)
        {
            DocumentWorkspace dw = (DocumentWorkspace)sender;

            QueueThumbnailUpdate(dw);
        }
 public TransactedToolHistoryMementoBase(DocumentWorkspace docWorkspace, string name, ImageResource image) : base(docWorkspace, name, image)
 {
 }
 /// <summary>
 /// Implement this to provide an action. You must return a HistoryMemento so that you
 /// can be undone. However, you should return null if you didn't do anything that
 /// affected the document.
 /// </summary>
 /// <returns>A HistoryMemento object that will be placed onto the HistoryStack.</returns>
 public abstract HistoryMemento PerformAction(DocumentWorkspace documentWorkspace);
Beispiel #57
0
        private bool ProcessMessage(string message)
        {
            if (IsDisposed)
            {
                return(false);
            }

            bool result = SplitMessage(message, out ArgumentAction action, out string actionParm);

            if (!result)
            {
                return(true);
            }

            switch (action)
            {
            case ArgumentAction.NoOp:
                result = true;
                break;

            case ArgumentAction.Open:
                Activate();

                if (IsCurrentModalForm && Enabled)
                {
                    result = this.appWorkspace.OpenFileInNewWorkspace(actionParm);
                }

                break;

            case ArgumentAction.OpenUntitled:
                Activate();

                if (!string.IsNullOrEmpty(actionParm) && IsCurrentModalForm && Enabled)
                {
                    result = this.appWorkspace.OpenFileInNewWorkspace(actionParm, false);

                    if (result)
                    {
                        this.appWorkspace.ActiveDocumentWorkspace.SetDocumentSaveOptions(null, null, null);
                        this.appWorkspace.ActiveDocumentWorkspace.Document.Dirty = true;
                    }
                }

                break;

            case ArgumentAction.Print:
                Activate();

                if (!string.IsNullOrEmpty(actionParm) && IsCurrentModalForm && Enabled)
                {
                    result = this.appWorkspace.OpenFileInNewWorkspace(actionParm);

                    if (result)
                    {
                        DocumentWorkspace dw = this.appWorkspace.ActiveDocumentWorkspace;
                        PrintAction       pa = new PrintAction();
                        dw.PerformAction(pa);
                        CloseWorkspaceAction cwa = new CloseWorkspaceAction(dw);
                        this.appWorkspace.PerformAction(cwa);

                        if (this.appWorkspace.DocumentWorkspaces.Length == 0)
                        {
                            Startup.CloseApplication();
                        }
                    }
                }
                break;

            default:
                throw new InvalidEnumArgumentException();
            }

            return(result);
        }
Beispiel #58
0
 public HistoryStack(DocumentWorkspace documentWorkspace)
 {
     this.documentWorkspace = documentWorkspace;
     this.undoStack         = new SegmentedList <HistoryMemento>();
     this.redoStack         = new SegmentedList <HistoryMemento>();
 }
Beispiel #59
0
        private bool IsOverflow(MouseEventArgs e)
        {
            PointF clientPt = DocumentWorkspace.DocumentToClient(new PointF(e.X, e.Y));

            return(clientPt.X < -16384 || clientPt.Y < -16384);
        }
Beispiel #60
0
 protected void SetStaticData(object data)
 {
     DocumentWorkspace.SetStaticToolData(this.GetType(), data);
 }