Example #1
0
 private void InitializeComponent()
 {
     this.menuFileNew                        = new PdnMenuItem();
     this.menuFileOpen                       = new PdnMenuItem();
     this.menuFileOpenRecent                 = new PdnMenuItem();
     this.menuFileOpenRecentSentinel         = new PdnMenuItem();
     this.menuFileAcquire                    = new PdnMenuItem();
     this.menuFileAcquireFromScannerOrCamera = new PdnMenuItem();
     this.menuFileClose                      = new PdnMenuItem();
     this.menuFileSeparator1                 = new ToolStripSeparator();
     this.menuFileSave                       = new PdnMenuItem();
     this.menuFileSaveAs                     = new PdnMenuItem();
     this.menuFileSeparator2                 = new ToolStripSeparator();
     this.menuFilePrint                      = new PdnMenuItem();
     this.menuFileSeparator3                 = new ToolStripSeparator();
     this.menuFileViewPluginLoadErrors       = new PdnMenuItem();
     this.menuFileSeparator4                 = new ToolStripSeparator();
     this.menuFileExit                       = new PdnMenuItem();
     //
     // FileMenu
     //
     this.DropDownItems.AddRange(GetMenuItemsToAdd(true));
     this.Name = "Menu.File";
     this.Text = PdnResources.GetString("Menu.File.Text");
     //
     // menuFileNew
     //
     this.menuFileNew.Name         = "New";
     this.menuFileNew.ShortcutKeys = Keys.Control | Keys.N;
     this.menuFileNew.Click       += new System.EventHandler(this.MenuFileNew_Click);
     //
     // menuFileOpen
     //
     this.menuFileOpen.Name         = "Open";
     this.menuFileOpen.ShortcutKeys = Keys.Control | Keys.O;
     this.menuFileOpen.Click       += new System.EventHandler(this.MenuFileOpen_Click);
     //
     // menuFileOpenRecent
     //
     this.menuFileOpenRecent.Name = "OpenRecent";
     this.menuFileOpenRecent.DropDownItems.AddRange(
         new ToolStripItem[]
     {
         this.menuFileOpenRecentSentinel
     });
     this.menuFileOpenRecent.DropDownOpening += new System.EventHandler(this.MenuFileOpenRecent_DropDownOpening);
     //
     // menuFileOpenRecentSentinel
     //
     this.menuFileOpenRecentSentinel.Text = "sentinel";
     //
     // menuFileAcquire
     //
     this.menuFileAcquire.Name = "Acquire";
     this.menuFileAcquire.DropDownItems.AddRange(
         new ToolStripItem[]
     {
         this.menuFileAcquireFromScannerOrCamera
     });
     this.menuFileAcquire.DropDownOpening += new System.EventHandler(this.MenuFileAcquire_DropDownOpening);
     //
     // menuFileAcquireFromScannerOrCamera
     //
     this.menuFileAcquireFromScannerOrCamera.Name   = "FromScannerOrCamera";
     this.menuFileAcquireFromScannerOrCamera.Click += new System.EventHandler(this.MenuFileAcquireFromScannerOrCamera_Click);
     //
     // menuFileClose
     //
     this.menuFileClose.Name         = "Close";
     this.menuFileClose.Click       += new EventHandler(MenuFileClose_Click);
     this.menuFileClose.ShortcutKeys = Keys.Control | Keys.W;
     //
     // menuFileSave
     //
     this.menuFileSave.Name         = "Save";
     this.menuFileSave.ShortcutKeys = Keys.Control | Keys.S;
     this.menuFileSave.Click       += new System.EventHandler(this.MenuFileSave_Click);
     //
     // menuFileSaveAs
     //
     this.menuFileSaveAs.Name         = "SaveAs";
     this.menuFileSaveAs.ShortcutKeys = Keys.Control | Keys.Shift | Keys.S;
     this.menuFileSaveAs.Click       += new System.EventHandler(this.MenuFileSaveAs_Click);
     //
     // menuFilePrint
     //
     this.menuFilePrint.Name         = "Print";
     this.menuFilePrint.ShortcutKeys = Keys.Control | Keys.P;
     this.menuFilePrint.Click       += new System.EventHandler(this.MenuFilePrint_Click);
     //
     // menuFileViewPluginLoadErrors
     //
     this.menuFileViewPluginLoadErrors.Name   = "ViewPluginLoadErrors";
     this.menuFileViewPluginLoadErrors.Click += new EventHandler(MenuFileViewPluginLoadErrors_Click);
     //
     // menuFileExit
     //
     this.menuFileExit.Name   = "Exit";
     this.menuFileExit.Click += new System.EventHandler(this.MenuFileExit_Click);
 }
        protected override string OnGetHistoryMementoNameForChanges(MoveToolChanges oldChanges, MoveToolChanges newChanges)
        {
            string name = base.Name;
            string historyMementoName = null;

            if ((oldChanges != null) && (newChanges != null))
            {
                if (oldChanges.SecondaryColor != newChanges.SecondaryColor)
                {
                    historyMementoName = TransactedTool <MoveTool, MoveToolChanges> .FoldHistoryMementoName(historyMementoName, name, PdnResources.GetString("TransactedTool.Changed.PrimaryColorOrSecondaryColor.HistoryMementoName"));
                }
                if (oldChanges.SelectionRenderingQuality != newChanges.SelectionRenderingQuality)
                {
                    historyMementoName = TransactedTool <MoveTool, MoveToolChanges> .FoldHistoryMementoName(historyMementoName, name, PdnResources.GetString("TransactedTool.Changed.SelectionRenderingQuality.HistoryMementoName"));
                }
                if (oldChanges.MoveToolResamplingAlgorithm != newChanges.MoveToolResamplingAlgorithm)
                {
                    historyMementoName = TransactedTool <MoveTool, MoveToolChanges> .FoldHistoryMementoName(historyMementoName, name, PdnResources.GetString("TransactedTool.Changed.SampleAllLayers.HistoryMementoName"));
                }
            }
            if (historyMementoName == null)
            {
                switch (((newChanges != null) ? newChanges.EditingMode : oldChanges.EditingMode))
                {
                case TransformEditingMode.None:
                case TransformEditingMode.Custom:
                    historyMementoName = base.Name;
                    goto Label_0111;

                case TransformEditingMode.Rotate:
                    historyMementoName = PdnResources.GetString("MoveTool.HistoryMemento.Rotate");
                    goto Label_0111;

                case TransformEditingMode.Scale:
                    historyMementoName = PdnResources.GetString("MoveTool.HistoryMemento.Scale");
                    goto Label_0111;

                case TransformEditingMode.Translate:
                    historyMementoName = PdnResources.GetString("MoveTool.HistoryMemento.Translate");
                    goto Label_0111;

                case TransformEditingMode.MoveRotationAnchor:
                    historyMementoName = PdnResources.GetString("MoveSelectionTool.HistoryMemento.MoveRotationAnchor");
                    goto Label_0111;
                }
                throw new InternalErrorException(ExceptionUtil.InvalidEnumArgumentException <TransformEditingMode>(newChanges.EditingMode, "newChanges.EditingMode"));
            }
            Label_0111 :;
            return(historyMementoName ?? name);
        }
Example #3
0
        protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
        {
            ControlInfo configUI = CreateDefaultConfigUI(props);

            configUI.SetPropertyControlValue(PropertyNames.PencilTipSize, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("PencilSketchEffect.ConfigDialog.PencilTipSizeLabel"));
            configUI.SetPropertyControlValue(PropertyNames.ColorRange, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("PencilSketchEffect.ConfigDialog.RangeLabel"));

            return(configUI);
        }
Example #4
0
        protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
        {
            ControlInfo configUI = CreateDefaultConfigUI(props);

            configUI.SetPropertyControlValue(PropertyNames.Tolerance, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("RedEyeRemoveEffect.ConfigDialog.Amount1Label"));
            configUI.SetPropertyControlValue(PropertyNames.Saturation, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("RedEyeRemoveEffect.ConfigDialog.Amount2Label"));
            configUI.SetPropertyControlValue(PropertyNames.Saturation, ControlInfoPropertyNames.Description, PdnResources.GetString("RedEyeRemoveEffectDialog.UsageHintLabel.Text"));

            return(configUI);
        }
Example #5
0
        protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
        {
            ControlInfo configUI = CreateDefaultConfigUI(props);

            configUI.SetPropertyControlValue(PropertyNames.Thickness, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("OutlineEffect.ConfigDialog.ThicknessLabel"));
            configUI.SetPropertyControlValue(PropertyNames.Intensity, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("OutlineEffect.ConfigDialog.IntensityLabel"));

            return(configUI);
        }
Example #6
0
 public MultiplyShape() : base(PdnResources.GetString("MultiplyShape.Name"), ShapeCategory.Symbols)
 {
 }
Example #7
0
 public CloudCalloutShape() : base(PdnResources.GetString("CloudCalloutShape.Name"), ShapeCategory.Callouts)
 {
 }
Example #8
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);
        }
Example #9
0
        protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
        {
            ControlInfo configUI = CreateDefaultConfigUI(props);

            configUI.SetPropertyControlValue(PropertyNames.Amount, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("TwistEffect.TwistAmount.Text"));
            configUI.SetPropertyControlValue(PropertyNames.Amount, ControlInfoPropertyNames.UseExponentialScale, true);

            configUI.SetPropertyControlValue(PropertyNames.Size, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("TwistEffect.TwistSize.Text"));
            configUI.SetPropertyControlValue(PropertyNames.Size, ControlInfoPropertyNames.SliderSmallChange, 0.05);
            configUI.SetPropertyControlValue(PropertyNames.Size, ControlInfoPropertyNames.SliderLargeChange, 0.25);
            configUI.SetPropertyControlValue(PropertyNames.Size, ControlInfoPropertyNames.UpDownIncrement, 0.01);

            configUI.SetPropertyControlValue(PropertyNames.Offset, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("TwistEffect.Offset.Text"));
            configUI.SetPropertyControlValue(PropertyNames.Offset, ControlInfoPropertyNames.SliderSmallChangeX, 0.05);
            configUI.SetPropertyControlValue(PropertyNames.Offset, ControlInfoPropertyNames.SliderLargeChangeX, 0.25);
            configUI.SetPropertyControlValue(PropertyNames.Offset, ControlInfoPropertyNames.UpDownIncrementX, 0.01);
            configUI.SetPropertyControlValue(PropertyNames.Offset, ControlInfoPropertyNames.SliderSmallChangeY, 0.05);
            configUI.SetPropertyControlValue(PropertyNames.Offset, ControlInfoPropertyNames.SliderLargeChangeY, 0.25);
            configUI.SetPropertyControlValue(PropertyNames.Offset, ControlInfoPropertyNames.UpDownIncrementY, 0.01);

            Surface       sourceSurface = this.EnvironmentParameters.SourceSurface;
            Bitmap        bitmap        = sourceSurface.CreateAliasedBitmap();
            ImageResource imageResource = ImageResource.FromImage(bitmap);

            configUI.SetPropertyControlValue(PropertyNames.Offset, ControlInfoPropertyNames.StaticImageUnderlay, imageResource);

            configUI.SetPropertyControlValue(PropertyNames.Quality, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("TwistEffect.Antialias.Text"));

            return(configUI);
        }
Example #10
0
        protected override ControlInfo OnCreateConfigUI(PropertyCollection properties)
        {
            ControlInfo    info = base.OnCreateConfigUI(properties);
            BooleanSetting enableHardwareAcceleration = base.Section.AppSettings.UI.EnableHardwareAcceleration;

            info.SetPropertyControlValue(enableHardwareAcceleration.Path, ControlInfoPropertyNames.DisplayName, string.Empty);
            info.SetPropertyControlValue(enableHardwareAcceleration.Path, ControlInfoPropertyNames.Description, PdnResources.GetString("SettingsDialog.UI.EnableHardwareAcceleration.Description"));
            BooleanSetting enableAnimations = base.Section.AppSettings.UI.EnableAnimations;

            info.SetPropertyControlValue(enableAnimations.Path, ControlInfoPropertyNames.DisplayName, string.Empty);
            info.SetPropertyControlValue(enableAnimations.Path, ControlInfoPropertyNames.Description, PdnResources.GetString("SettingsDialog.UI.EnableAnimations.Description"));
            BooleanSetting enableAntialiasedSelectionOutline = base.Section.AppSettings.UI.EnableAntialiasedSelectionOutline;

            info.SetPropertyControlValue(enableAntialiasedSelectionOutline.Path, ControlInfoPropertyNames.DisplayName, string.Empty);
            info.SetPropertyControlValue(enableAntialiasedSelectionOutline.Path, ControlInfoPropertyNames.Description, PdnResources.GetString("SettingsDialog.UI.EnableAntialiasedSelectionOutline.Description"));
            BooleanSetting showTaskbarPreviews = base.Section.AppSettings.UI.ShowTaskbarPreviews;

            info.SetPropertyControlValue(showTaskbarPreviews.Path, ControlInfoPropertyNames.DisplayName, string.Empty);
            info.SetPropertyControlValue(showTaskbarPreviews.Path, ControlInfoPropertyNames.Description, PdnResources.GetString("SettingsDialog.UI.ShowTaskbarPreviews.Description"));
            BooleanSetting enableOverscroll = base.Section.AppSettings.UI.EnableOverscroll;

            info.SetPropertyControlValue(enableOverscroll.Path, ControlInfoPropertyNames.DisplayName, string.Empty);
            info.SetPropertyControlValue(enableOverscroll.Path, ControlInfoPropertyNames.Description, PdnResources.GetString("SettingsDialog.UI.Overscroll.Description"));
            BooleanSetting translucentWindows = base.Section.AppSettings.UI.TranslucentWindows;

            info.SetPropertyControlValue(translucentWindows.Path, ControlInfoPropertyNames.DisplayName, string.Empty);
            info.SetPropertyControlValue(translucentWindows.Path, ControlInfoPropertyNames.Description, PdnResources.GetString("SettingsDialog.UI.TranslucentWindows.Description"));
            EnumSetting <AeroColorScheme> aeroColorScheme = base.Section.AppSettings.UI.AeroColorScheme;

            info.SetPropertyControlValue(aeroColorScheme.Path, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("SettingsDialog.UI.AeroColorScheme.DisplayName"));
            PropertyControlInfo info2 = info.FindControlForPropertyName(aeroColorScheme.Path);

            info2.SetValueDisplayName(AeroColorScheme.Blue, PdnResources.GetString("SettingsDialog.UI.AeroColorScheme.Value.Blue"));
            info2.SetValueDisplayName(AeroColorScheme.Light, PdnResources.GetString("SettingsDialog.UI.AeroColorScheme.Value.Light"));
            if (ThemeConfig.EffectiveTheme == PdnTheme.Classic)
            {
                info.SetPropertyControlValue(aeroColorScheme.Path, ControlInfoPropertyNames.Description, PdnResources.GetString("SettingsDialog.UI.AeroColorScheme.Description.ClassicDisabled"));
            }
            CultureInfoSetting language = base.Section.AppSettings.UI.Language;

            info.SetPropertyControlValue(language.Path, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("SettingsDialog.UI.Language.DisplayName"));
            info.SetPropertyControlValue(language.Path, ControlInfoPropertyNames.Description, PdnResources.GetString("SettingsDialog.UI.Language.Description"));
            PropertyControlInfo      info3    = info.FindControlForPropertyName(language.Path);
            StaticListChoiceProperty property = (StaticListChoiceProperty)info3.Property;
            CultureInfo info4 = new CultureInfo("en-US");

            foreach (CultureInfo info5 in property.ValueChoices)
            {
                string nativeName;
                if (info5.Equals(info4))
                {
                    nativeName = info5.Parent.NativeName;
                }
                else
                {
                    nativeName = info5.NativeName;
                }
                info3.SetValueDisplayName(info5, nativeName);
            }
            return(info);
        }
Example #11
0
 public HexagonShape() : base(PdnResources.GetString("HexagonShape.Name"), 6)
 {
 }
Example #12
0
 public void SetIcon(string imageName)
 {
     this.Image = PdnResources.GetImageResource(imageName).Reference;
 }
Example #13
0
        private bool DoEffect(Effect effect, EffectConfigToken token, PdnRegion selectedRegion,
                              PdnRegion regionToRender, Surface originalSurface, out Exception exception)
        {
            exception = null;
            bool oldDirtyValue   = AppWorkspace.ActiveDocumentWorkspace.Document.Dirty;
            bool resetDirtyValue = false;

            bool returnVal = false;

            AppWorkspace.ActiveDocumentWorkspace.EnableOutlineAnimation = false;

            try
            {
                using (ProgressDialog aed = new ProgressDialog())
                {
                    if (effect.Image != null)
                    {
                        aed.Icon = Utility.ImageToIcon(effect.Image, Utility.TransparentKey);
                    }

                    aed.Opacity     = 0.9;
                    aed.Value       = 0;
                    aed.Text        = effect.Name;
                    aed.Description = string.Format(PdnResources.GetString("Effects.ApplyingDialog.Description"), effect.Name);

                    InvalidateTimer.Enabled = true;

                    using (new WaitCursorChanger(AppWorkspace))
                    {
                        HistoryMemento ha     = null;
                        DialogResult   result = DialogResult.None;

                        AppWorkspace.Widgets.StatusBarProgress.ResetProgressStatusBar();
                        AppWorkspace.Widgets.LayerControl.SuspendLayerPreviewUpdates();

                        try
                        {
                            ManualResetEvent     saveEvent = new ManualResetEvent(false);
                            BitmapHistoryMemento bha       = null;

                            // perf bug #1445: save this data in a background thread
                            PdnRegion selectedRegionCopy = selectedRegion.Clone();
                            PaintDotNet.Threading.ThreadPool.Global.QueueUserWorkItem(
                                delegate(object context)
                            {
                                try
                                {
                                    ImageResource image = effect.Image == null ? null : ImageResource.FromImage(effect.Image);
                                    bha = new BitmapHistoryMemento(effect.Name, image, AppWorkspace.ActiveDocumentWorkspace,
                                                                   AppWorkspace.ActiveDocumentWorkspace.ActiveLayerIndex, selectedRegionCopy, originalSurface);
                                }

                                finally
                                {
                                    saveEvent.Set();
                                    selectedRegionCopy.Dispose();
                                    selectedRegionCopy = null;
                                }
                            });

                            Surface activeLayerSurface        = ((BitmapLayer)AppWorkspace.ActiveDocumentWorkspace.ActiveLayer).Surface;
                            int     pixelCount                = activeLayerSurface.Height;
                            int     threadCount               = effect.CheckForEffectFlags(EffectFlags.SingleThreaded) ? 1 : RenderingThreadCount;
                            int     maxTiles                  = TilesPerCpu * threadCount;
                            int     tileCount                 = Math.Min(maxTiles, pixelCount);
                            BackgroundEffectRenderer renderer = new BackgroundEffectRenderer(
                                effect,
                                token,
                                new RenderArgs(activeLayerSurface),
                                new RenderArgs(originalSurface),
                                regionToRender,
                                tileCount,
                                threadCount);

                            renderer.RenderedTile      += new RenderedTileEventHandler(aed.RenderedTileHandler);
                            renderer.RenderedTile      += new RenderedTileEventHandler(RenderedTileHandler);
                            renderer.StartingRendering += new EventHandler(StartingRenderingHandler);
                            renderer.FinishedRendering += new EventHandler(aed.FinishedRenderingHandler);
                            renderer.FinishedRendering += new EventHandler(FinishedRenderingHandler);
                            renderer.Start();

                            result = Utility.ShowDialog(aed, AppWorkspace);

                            if (result == DialogResult.Cancel)
                            {
                                resetDirtyValue = true;

                                using (new WaitCursorChanger(AppWorkspace))
                                {
                                    try
                                    {
                                        renderer.Abort();
                                        renderer.Join();
                                    }

                                    catch (Exception ex)
                                    {
                                        exception = ex;
                                    }

                                    activeLayerSurface.CopySurface(originalSurface);
                                }
                            }

                            InvalidateTimer.Enabled = false;

                            try
                            {
                                renderer.Join();
                            }

                            catch (Exception ex)
                            {
                                exception = ex;
                            }

                            renderer.Dispose();

                            saveEvent.WaitOne();
                            saveEvent.Close();
                            saveEvent = null;

                            ha = bha;
                        }

                        catch (Exception)
                        {
                            using (new WaitCursorChanger(AppWorkspace))
                            {
                                ((BitmapLayer)AppWorkspace.ActiveDocumentWorkspace.ActiveLayer).Surface.CopySurface(originalSurface);
                                ha = null;
                            }
                        }

                        finally
                        {
                            AppWorkspace.Widgets.LayerControl.ResumeLayerPreviewUpdates();
                        }

                        using (PdnRegion simplifiedRenderRegion = Utility.SimplifyAndInflateRegion(selectedRegion))
                        {
                            using (new WaitCursorChanger(AppWorkspace))
                            {
                                AppWorkspace.ActiveDocumentWorkspace.ActiveLayer.Invalidate(simplifiedRenderRegion);
                            }
                        }

                        using (new WaitCursorChanger(AppWorkspace))
                        {
                            if (result == DialogResult.OK)
                            {
                                if (ha != null)
                                {
                                    AppWorkspace.ActiveDocumentWorkspace.History.PushNewMemento(ha);
                                }

                                AppWorkspace.Update();
                                returnVal = true;
                            }
                            else
                            {
                                Utility.GCFullCollect();
                            }
                        }
                    } // using
                }     // using
            }

            finally
            {
                AppWorkspace.ActiveDocumentWorkspace.EnableOutlineAnimation = true;

                if (resetDirtyValue)
                {
                    AppWorkspace.ActiveDocumentWorkspace.Document.Dirty = oldDirtyValue;
                }
            }

            AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBarAsync();
            return(returnVal);
        }
Example #14
0
        private void HandleEffectException(AppWorkspace appWorkspace, Effect effect, Exception ex)
        {
            try
            {
                AppWorkspace.Widgets.StatusBarProgress.ResetProgressStatusBar();
                AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBar();
            }

            catch (Exception)
            {
            }

            // Figure out if it's a built-in effect, or a plug-in
            if (IsBuiltInEffect(effect))
            {
                // For built-in effects, tear down Paint.NET which will result in a crash log
                throw new ApplicationException("Effect threw an exception", ex);
            }
            else
            {
                Icon formIcon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.BugWarning.png").Reference);

                string formTitle = PdnResources.GetString("Effect.PluginErrorDialog.Title");

                Image taskImage = null;

                string introText = PdnResources.GetString("Effect.PluginErrorDialog.IntroText");

                TaskButton restartTB = new TaskButton(
                    PdnResources.GetImageResource("Icons.RightArrowBlue.png").Reference,
                    PdnResources.GetString("Effect.PluginErrorDialog.RestartTB.ActionText"),
                    PdnResources.GetString("Effect.PluginErrorDialog.RestartTB.ExplanationText"));

                TaskButton doNotRestartTB = new TaskButton(
                    PdnResources.GetImageResource("Icons.WarningIcon.png").Reference,
                    PdnResources.GetString("Effect.PluginErrorDialog.DoNotRestartTB.ActionText"),
                    PdnResources.GetString("Effect.PluginErrorDialog.DoNotRestartTB.ExplanationText"));

                string auxButtonText = PdnResources.GetString("Effect.PluginErrorDialog.AuxButton1.Text");

                void AuxButtonClickHandler(object sender, EventArgs e)
                {
                    using (PdnBaseForm textBoxForm = new PdnBaseForm())
                    {
                        textBoxForm.Name = "EffectCrash";

                        TextBox exceptionBox = new TextBox();

                        textBoxForm.Icon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.WarningIcon.png").Reference);
                        textBoxForm.Text = PdnResources.GetString("Effect.PluginErrorDialog.Title");

                        exceptionBox.Dock      = DockStyle.Fill;
                        exceptionBox.ReadOnly  = true;
                        exceptionBox.Multiline = true;

                        string exceptionText = AppWorkspace.GetLocalizedEffectErrorMessage(effect.GetType().Assembly, effect.GetType(), ex);

                        exceptionBox.Font       = new Font(FontFamily.GenericMonospace, exceptionBox.Font.Size);
                        exceptionBox.Text       = exceptionText;
                        exceptionBox.ScrollBars = ScrollBars.Vertical;

                        textBoxForm.StartPosition = FormStartPosition.CenterParent;
                        textBoxForm.ShowInTaskbar = false;
                        textBoxForm.MinimizeBox   = false;
                        textBoxForm.Controls.Add(exceptionBox);
                        textBoxForm.Width = UI.ScaleWidth(700);

                        textBoxForm.ShowDialog();
                    }
                }

                TaskButton clickedTB = TaskDialog.Show(
                    appWorkspace,
                    formIcon,
                    formTitle,
                    taskImage,
                    true,
                    introText,
                    new TaskButton[] { restartTB, doNotRestartTB },
                    restartTB,
                    doNotRestartTB,
                    TaskDialog.DefaultPixelWidth96Dpi * 2,
                    auxButtonText,
                    AuxButtonClickHandler);

                if (clickedTB == restartTB)
                {
                    // Next, apply restart logic
                    CloseAllWorkspacesAction cawa = new CloseAllWorkspacesAction();
                    cawa.PerformAction(appWorkspace);

                    if (!cawa.Cancelled)
                    {
                        SystemLayer.Shell.RestartApplication();
                        Startup.CloseApplication();
                    }
                }
            }
        }
Example #15
0
 public FlipDocumentVerticalFunction()
     : base(StaticName,
            PdnResources.GetImageResource("Icons.MenuImageFlipVerticalIcon.png"),
            FlipType.Vertical)
 {
 }
Example #16
0
 public ReliefEffect()
     : base(PdnResources.GetString("ReliefEffect.Name"),
            PdnResources.GetImage("Icons.ReliefEffect.png"),
            true)
 {
 }
Example #17
0
 private void InitializeComponent()
 {
     this.menuWindowResetWindowLocations = new PdnMenuItem();
     this.menuWindowSeperator1           = new ToolStripSeparator();
     this.menuWindowTranslucent          = new PdnMenuItem();
     this.menuWindowSeperator2           = new ToolStripSeparator();
     this.menuWindowTools       = new PdnMenuItem();
     this.menuWindowHistory     = new PdnMenuItem();
     this.menuWindowLayers      = new PdnMenuItem();
     this.menuWindowColors      = new PdnMenuItem();
     this.menuWindowSeparator3  = new ToolStripSeparator();
     this.menuWindowOpenMdiList = new PdnMenuItem();
     this.menuWindowNextTab     = new PdnMenuItem();
     this.menuWindowPreviousTab = new PdnMenuItem();
     //
     // WindowMenu
     //
     this.DropDownItems.AddRange(
         new ToolStripItem[]
     {
         this.menuWindowResetWindowLocations,
         this.menuWindowSeperator1,
         this.menuWindowTranslucent,
         this.menuWindowSeperator2,
         this.menuWindowTools,
         this.menuWindowHistory,
         this.menuWindowLayers,
         this.menuWindowColors,
         this.menuWindowSeparator3,
         this.menuWindowOpenMdiList,
         this.menuWindowNextTab,
         this.menuWindowPreviousTab
     });
     this.Name = "Menu.Window";
     this.Text = PdnResources.GetString("Menu.Window.Text");
     //
     // menuWindowResetWindowLocations
     //
     this.menuWindowResetWindowLocations.Name   = "ResetWindowLocations";
     this.menuWindowResetWindowLocations.Click += new System.EventHandler(this.MenuWindowResetWindowLocations_Click);
     //
     // menuWindowTranslucent
     //
     this.menuWindowTranslucent.Name   = "Translucent";
     this.menuWindowTranslucent.Click += new System.EventHandler(this.MenuWindowTranslucent_Click);
     //
     // menuWindowTools
     //
     this.menuWindowTools.Name         = "Tools";
     this.menuWindowTools.ShortcutKeys = Keys.F5;
     this.menuWindowTools.Click       += new System.EventHandler(this.MenuWindowTools_Click);
     //
     // menuWindowHistory
     //
     this.menuWindowHistory.Name         = "History";
     this.menuWindowHistory.ShortcutKeys = Keys.F6;
     this.menuWindowHistory.Click       += new System.EventHandler(this.MenuWindowHistory_Click);
     //
     // menuWindowLayers
     //
     this.menuWindowLayers.Name         = "Layers";
     this.menuWindowLayers.ShortcutKeys = Keys.F7;
     this.menuWindowLayers.Click       += new System.EventHandler(this.MenuWindowLayers_Click);
     //
     // menuWindowColors
     //
     this.menuWindowColors.Name         = "Colors";
     this.menuWindowColors.ShortcutKeys = Keys.F8;
     this.menuWindowColors.Click       += new System.EventHandler(this.MenuWindowColors_Click);
     //
     // menuWindowOpenMdiList
     //
     this.menuWindowOpenMdiList.Name         = "OpenMdiList";
     this.menuWindowOpenMdiList.ShortcutKeys = Keys.Control | Keys.Q;
     this.menuWindowOpenMdiList.Click       += new EventHandler(MenuWindowOpenMdiList_Click);
     //
     // menuWindowNextTab
     //
     this.menuWindowNextTab.Name         = "NextTab";
     this.menuWindowNextTab.ShortcutKeys = Keys.Control | Keys.Tab;
     this.menuWindowNextTab.Click       += new EventHandler(MenuWindowNextTab_Click);
     //
     // menuWindowPreviousTab
     //
     this.menuWindowPreviousTab.Name         = "PreviousTab";
     this.menuWindowPreviousTab.ShortcutKeys = Keys.Control | Keys.Shift | Keys.Tab;
     this.menuWindowPreviousTab.Click       += new EventHandler(MenuWindowPreviousTab_Click);
 }
Example #18
0
        private void RenderGradient()
        {
            ColorBgra startColor = AppEnvironment.PrimaryColor;
            ColorBgra endColor   = AppEnvironment.SecondaryColor;

            if (this.shouldSwapColors)
            {
                if (AppEnvironment.GradientInfo.AlphaOnly)
                {
                    // In transparency mode, the color values don't matter. We just need to reverse
                    // and invert the alpha values.
                    byte startAlpha = startColor.A;
                    startColor.A = (byte)(255 - endColor.A);
                    endColor.A   = (byte)(255 - startAlpha);
                }
                else
                {
                    Utility.Swap(ref startColor, ref endColor);
                }
            }

            PointF startPointF = this.startPoint;
            PointF endPointF   = this.endPoint;

            if (this.shouldConstrain)
            {
                if (this.mouseNub == this.startNub)
                {
                    ConstrainPoints(endPointF, ref startPointF);
                }
                else
                {
                    ConstrainPoints(startPointF, ref endPointF);
                }
            }

            RestoreSavedRegion();

            Surface   surface    = ((BitmapLayer)DocumentWorkspace.ActiveLayer).Surface;
            PdnRegion clipRegion = DocumentWorkspace.Selection.CreateRegion();

            SaveRegion(clipRegion, clipRegion.GetBoundsInt());

            RenderGradient(surface, clipRegion, AppEnvironment.GetCompositingMode(), startPointF, startColor, endPointF, endColor);

            using (PdnRegion simplified = Utility.SimplifyAndInflateRegion(clipRegion, Utility.DefaultSimplificationFactor, 0))
            {
                DocumentWorkspace.ActiveLayer.Invalidate(simplified);
            }

            clipRegion.Dispose();

            // Set up status bar text
            double          angle                = -180.0 * Math.Atan2(endPointF.Y - startPointF.Y, endPointF.X - startPointF.X) / Math.PI;
            MeasurementUnit units                = AppWorkspace.Units;
            double          offsetXPhysical      = Document.PixelToPhysicalX(endPointF.X - startPointF.X, units);
            double          offsetYPhysical      = Document.PixelToPhysicalY(endPointF.Y - startPointF.Y, units);
            double          offsetLengthPhysical = Math.Sqrt(offsetXPhysical * offsetXPhysical + offsetYPhysical * offsetYPhysical);

            string numberFormat;
            string unitsAbbreviation;

            if (units != MeasurementUnit.Pixel)
            {
                string unitsAbbreviationName = "MeasurementUnit." + units.ToString() + ".Abbreviation";
                unitsAbbreviation = PdnResources.GetString(unitsAbbreviationName);
                numberFormat      = "F2";
            }
            else
            {
                unitsAbbreviation = string.Empty;
                numberFormat      = "F0";
            }

            string unitsString = PdnResources.GetString("MeasurementUnit." + units.ToString() + ".Plural");

            string statusText = string.Format(
                this.helpTextWhileAdjustingFormat,
                offsetXPhysical.ToString(numberFormat),
                unitsAbbreviation,
                offsetYPhysical.ToString(numberFormat),
                unitsAbbreviation,
                offsetLengthPhysical.ToString("F2"),
                unitsString,
                angle.ToString("F2"));

            SetStatus(this.toolIcon, statusText);

            // Make sure everything is on screen.
            Update();
        }
Example #19
0
        protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
        {
            ControlInfo configUI = CreateDefaultConfigUI(props);

            configUI.SetPropertyControlValue(PropertyNames.Scale, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("CloudsEffect.ConfigDialog.ScaleLabel"));

            configUI.SetPropertyControlValue(PropertyNames.Power, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("CloudsEffect.ConfigDialog.RoughnessLabel"));
            configUI.SetPropertyControlValue(PropertyNames.Power, ControlInfoPropertyNames.SliderLargeChange, 0.25);
            configUI.SetPropertyControlValue(PropertyNames.Power, ControlInfoPropertyNames.SliderSmallChange, 0.05);
            configUI.SetPropertyControlValue(PropertyNames.Power, ControlInfoPropertyNames.UpDownIncrement, 0.01);

            PropertyControlInfo blendOpControl = configUI.FindControlForPropertyName(PropertyNames.BlendOp);

            blendOpControl.ControlProperties[ControlInfoPropertyNames.DisplayName].Value = PdnResources.GetString("CloudsEffect.ConfigDialog.BlendModeHeader.Text");

            Type[] blendOpTypes = UserBlendOps.GetBlendOps();
            foreach (Type blendOpType in blendOpTypes)
            {
                string blendOpDisplayName = UserBlendOps.GetBlendOpFriendlyName(blendOpType);
                blendOpControl.SetValueDisplayName(blendOpType, blendOpDisplayName);
            }

            configUI.SetPropertyControlType(PropertyNames.Seed, PropertyControlType.IncrementButton);
            configUI.SetPropertyControlValue(PropertyNames.Seed, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("CloudsEffect.ConfigDialog.SeedHeader.Text"));
            configUI.SetPropertyControlValue(PropertyNames.Seed, ControlInfoPropertyNames.ButtonText, PdnResources.GetString("CloudsEffect.ConfigDialog.ReseedButton.Text"));
            configUI.SetPropertyControlValue(PropertyNames.Seed, ControlInfoPropertyNames.Description, PdnResources.GetString("CloudsEffect.ConfigDialog.UsageLabel"));

            return(configUI);
        }
 public RoundedRectangleShape() : base(PdnResources.GetString("RoundedRectangleShape.Name"))
 {
     this.sync = new object();
 }
Example #21
0
 public EllipticalCalloutShape() : base(PdnResources.GetString("EllipticalCalloutShape.Name"), ShapeCategory.Callouts)
 {
 }
Example #22
0
        protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
        {
            ControlInfo configUI = CreateDefaultConfigUI(props);

            configUI.SetPropertyControlValue(PropertyNames.Angle, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("MotionBlurEffectConfigDialog.AngleHeader.Text"));
            configUI.SetPropertyControlType(PropertyNames.Angle, PropertyControlType.AngleChooser);
            configUI.SetPropertyControlValue(PropertyNames.Centered, ControlInfoPropertyNames.DisplayName, string.Empty);
            configUI.SetPropertyControlValue(PropertyNames.Centered, ControlInfoPropertyNames.Description, PdnResources.GetString("MotionBlurEffectConfigDialog.CenteredCheckBox.Text"));
            configUI.SetPropertyControlValue(PropertyNames.Distance, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("MotionBlurEffectConfigDialog.DistanceHeader.Text"));

            return(configUI);
        }
Example #23
0
        protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
        {
            ControlInfo configUI = CreateDefaultConfigUI(props);

            configUI.SetPropertyControlValue(PropertyNames.InkOutline, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("InkSketchEffect.ConfigDialog.InkOutlineLabel"));
            configUI.SetPropertyControlValue(PropertyNames.Coloring, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("InkSketchEffect.ConfigDialog.ColoringLabel"));

            return(configUI);
        }
        protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
        {
            ControlInfo configUI = CreateDefaultConfigUI(props);

            configUI.SetPropertyControlValue(PropertyNames.Brightness, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("BrightnessAndContrastAdjustment.Brightness"));
            configUI.SetPropertyControlValue(PropertyNames.Contrast, ControlInfoPropertyNames.DisplayName, PdnResources.GetString("BrightnessAndContrastAdjustmnet.Contrast"));

            return(configUI);
        }
 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)
 {
 }
Example #26
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            historyWorkspace.VerifyAccess();
            BitmapLayer       layer               = (BitmapLayer)historyWorkspace.Document.Layers[this.layerIndex];
            Surface           layerSurface        = layer.Surface;
            TileMathHelper    tileMathHelper      = new TileMathHelper(layerSurface.Width, layerSurface.Height, this.rendererTileEdgeLog2);
            TileMathHelper    tileGroupMathHelper = new TileMathHelper(layerSurface.Width, layerSurface.Height, this.rendererTileEdgeLog2 + 3);
            HistoryMemento    actionHM            = null;
            ManualResetEvent  taskFinishedEvent   = new ManualResetEvent(false);
            ThreadTask <Unit> commitTask          = historyWorkspace.TaskManager.StartNewThreadTask(delegate(Task task) {
                SegmentedList <RectInt32> list = tileGroupMathHelper.EnumerateTilesClippedToSourceRect(this.rendererClipRect).ToSegmentedList <RectInt32>();
                ListUtil.FisherYatesShuffle <RectInt32>(list);
                ConcurrentQueue <ISurface <ColorBgra> > queue = new ConcurrentQueue <ISurface <ColorBgra> >();
                ConcurrentQueue <RectInt32> changedTiles      = new ConcurrentQueue <RectInt32>();
                ConcurrentQueue <TupleStruct <RectInt32, ISurface <ColorBgra> > > changedTileGroups = new ConcurrentQueue <TupleStruct <RectInt32, ISurface <ColorBgra> > >();
                double progressIncrement = 1.0 / ((double)Math.Max(1, list.Count));
                task.Progress            = 0.0;
                Work.ParallelForEach <RectInt32>(WaitType.Blocking, list, delegate(RectInt32 tileGroupRect) {
                    ISurface <ColorBgra> dst = RetryManager.RunMemorySensitiveOperation <ISurfaceRef <ColorBgra> >(() => SurfaceAllocator.Bgra.Allocate <ColorBgra>(tileGroupRect.Size, AllocationOptions.ZeroFillNotRequired));
                    this.renderer.Render(dst, tileGroupRect.Location);
                    bool flag = false;
                    foreach (RectInt32 num in tileMathHelper.EnumerateTilesClippedToSourceRect(tileGroupRect))
                    {
                        RectInt32 bounds = RectInt32.Offset(num, -tileGroupRect.Location);
                        using (ISurface <ColorBgra> surface2 = layerSurface.CreateWindow(num))
                        {
                            using (ISurface <ColorBgra> surface3 = dst.CreateWindow <ColorBgra>(bounds))
                            {
                                if (!SurfaceBgraUtil.ArePixelsEqual(surface2, surface3))
                                {
                                    flag = true;
                                    changedTiles.Enqueue(num);
                                }
                            }
                        }
                    }
                    if (flag)
                    {
                        changedTileGroups.Enqueue(TupleStruct.Create <RectInt32, ISurface <ColorBgra> >(tileGroupRect, dst));
                    }
                    else
                    {
                        DisposableUtil.Free <ISurface <ColorBgra> >(ref dst);
                    }
                    task.IncrementProgressBy(progressIncrement);
                }, WorkItemQueuePriority.Normal, null);
                task.Progress = null;
                if (changedTiles.Count == 0)
                {
                    actionHM = null;
                }
                else
                {
                    SegmentedList <RectInt32> scans = new SegmentedList <RectInt32>(changedTiles.Count, 7);
                    scans.AddRange(changedTiles);
                    ScansHelpers.SortScansByTopLeft(scans);
                    ScansHelpers.ConsolidateSortedScansInPlace(scans);
                    actionHM = new BitmapHistoryMemento(this.historyMementoName, this.historyMementoImage, historyWorkspace, this.layerIndex, scans);
                    this.EnterCriticalRegion();
                    Work.ParallelForEach <TupleStruct <RectInt32, ISurface <ColorBgra> > >(WaitType.Blocking, changedTileGroups, delegate(TupleStruct <RectInt32, ISurface <ColorBgra> > tileInfo) {
                        using (ISurface <ColorBgra> surface = layerSurface.CreateWindow(tileInfo.Item1))
                        {
                            tileInfo.Item2.Render(surface, PointInt32.Zero);
                        }
                        tileInfo.Item2.Dispose();
                    }, WorkItemQueuePriority.Normal, null);
                    foreach (RectInt32 num in scans)
                    {
                        layer.Invalidate(num);
                    }
                }
            }, ApartmentState.MTA);

            commitTask.ResultAsync <Unit>().Receive(delegate(Result <Unit> r) {
                taskFinishedEvent.Set();
            }).Observe();
            if (!taskFinishedEvent.WaitOne(this.delayUntilProgressDialogMs))
            {
                string headerText       = PdnResources.GetString("ApplyRendererToBitmapLayerHistoryFunction.ProgressDialog.HeaderText");
                string headerTextFormat = PdnResources.GetString("ApplyRendererToBitmapLayerHistoryFunction.ProgressDialog.HeaderText.Format");
                using (TaskProgressDialog progressDialog = new TaskProgressDialog())
                {
                    Action updateHeaderText = delegate {
                        progressDialog.VerifyAccess();
                        if (!progressDialog.IsDisposed)
                        {
                            string text1;
                            double?progress = commitTask.Progress;
                            if (!progress.HasValue)
                            {
                                text1 = headerText;
                            }
                            else
                            {
                                text1 = string.Format(headerTextFormat, (progress.Value * 100.0).ToString("N0"));
                            }
                            progressDialog.HeaderText = text1;
                        }
                    };
                    progressDialog.Text             = this.historyMementoName;
                    progressDialog.Icon             = this.historyMementoImage.Reference.ToIcon();
                    progressDialog.CloseOnFinished  = true;
                    progressDialog.ShowCancelButton = false;
                    progressDialog.Task             = commitTask;
                    updateHeaderText();
                    commitTask.ProgressChanged += delegate(object s, ValueEventArgs <double?> e) {
                        PdnSynchronizationContext.Instance.EnsurePosted(updateHeaderText);
                    };
                    progressDialog.ShowDialog(historyWorkspace.Window);
                }
            }
            if (!commitTask.TaskResult.IsError)
            {
                return(actionHM);
            }
            if (commitTask.TaskResult.Error is OutOfMemoryException)
            {
                throw new OutOfMemoryException(null, commitTask.TaskResult.Error);
            }
            throw new AggregateException(null, commitTask.TaskResult.Error);
        }
Example #27
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);
        }
Example #28
0
 public Star4PointShape() : base(PdnResources.GetString("Star4PointShape.Name"), 4, 0.25)
 {
 }
        public override void PerformAction(AppWorkspace appWorkspace)
        {
            if (appWorkspace == null)
            {
                throw new ArgumentNullException("appWorkspace");
            }

            DocumentWorkspace dw;

            if (this.closeMe == null)
            {
                dw = appWorkspace.ActiveDocumentWorkspace;
            }
            else
            {
                dw = this.closeMe;
            }

            if (dw != null)
            {
                if (dw.Document == null)
                {
                    appWorkspace.RemoveDocumentWorkspace(dw);
                }
                else if (!dw.Document.Dirty)
                {
                    appWorkspace.RemoveDocumentWorkspace(dw);
                }
                else
                {
                    appWorkspace.ActiveDocumentWorkspace = dw;

                    TaskButton saveTB = new TaskButton(
                        PdnResources.GetImageResource("Icons.MenuFileSaveIcon.png").Reference,
                        PdnResources.GetString("CloseWorkspaceAction.SaveButton.ActionText"),
                        PdnResources.GetString("CloseWorkspaceAction.SaveButton.ExplanationText"));

                    TaskButton dontSaveTB = new TaskButton(
                        PdnResources.GetImageResource("Icons.MenuFileCloseIcon.png").Reference,
                        PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ActionText"),
                        PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ExplanationText"));

                    TaskButton cancelTB = new TaskButton(
                        PdnResources.GetImageResource("Icons.CancelIcon.png").Reference,
                        PdnResources.GetString("CloseWorkspaceAction.CancelButton.ActionText"),
                        PdnResources.GetString("CloseWorkspaceAction.CancelButton.ExplanationText"));

                    string title           = PdnResources.GetString("CloseWorkspaceAction.Title");
                    string introTextFormat = PdnResources.GetString("CloseWorkspaceAction.IntroText.Format");
                    string introText       = string.Format(introTextFormat, dw.GetFriendlyName());

                    Image thumb = appWorkspace.GetDocumentWorkspaceThumbnail(dw);

                    if (thumb == null)
                    {
                        thumb = new Bitmap(32, 32);
                    }

                    Bitmap taskImage = new Bitmap(thumb.Width + 2, thumb.Height + 2, PixelFormat.Format32bppArgb);

                    using (Graphics g = Graphics.FromImage(taskImage))
                    {
                        g.Clear(Color.Transparent);

                        g.DrawImage(
                            thumb,
                            new Rectangle(1, 1, thumb.Width, thumb.Height),
                            new Rectangle(0, 0, thumb.Width, thumb.Height),
                            GraphicsUnit.Pixel);

                        Utility.DrawDropShadow1px(g, new Rectangle(0, 0, taskImage.Width, taskImage.Height));
                    }

                    Form mainForm = appWorkspace.FindForm();
                    if (mainForm != null)
                    {
                        PdnBaseForm asPDF = mainForm as PdnBaseForm;

                        if (asPDF != null)
                        {
                            asPDF.RestoreWindow();
                        }
                    }

                    Icon          warningIcon;
                    ImageResource warningIconImageRes = PdnResources.GetImageResource("Icons.WarningIcon.png");

                    if (warningIconImageRes != null)
                    {
                        Image warningIconImage = warningIconImageRes.Reference;
                        warningIcon = Utility.ImageToIcon(warningIconImage, false);
                    }
                    else
                    {
                        warningIcon = null;
                    }

                    TaskButton clickedTB = TaskDialog.Show(
                        appWorkspace,
                        warningIcon,
                        title,
                        taskImage,
                        false,
                        introText,
                        new TaskButton[] { saveTB, dontSaveTB, cancelTB },
                        saveTB,
                        cancelTB,
                        340);

                    if (clickedTB == saveTB)
                    {
                        if (dw.DoSave())
                        {
                            this.cancelled = false;
                            appWorkspace.RemoveDocumentWorkspace(dw);
                        }
                        else
                        {
                            this.cancelled = true;
                        }
                    }
                    else if (clickedTB == dontSaveTB)
                    {
                        this.cancelled = false;
                        appWorkspace.RemoveDocumentWorkspace(dw);
                    }
                    else
                    {
                        this.cancelled = true;
                    }
                }
            }

            Utility.GCFullCollect();
        }
Example #30
0
        private void MenuFileOpenRecent_DropDownOpening(object sender, System.EventArgs e)
        {
            AppWorkspace.MostRecentFiles.LoadMruList();
            MostRecentFile[] filesReverse = AppWorkspace.MostRecentFiles.GetFileList();
            MostRecentFile[] files        = new MostRecentFile[filesReverse.Length];
            int i;

            for (i = 0; i < filesReverse.Length; ++i)
            {
                files[files.Length - i - 1] = filesReverse[i];
            }

            foreach (ToolStripItem mi in menuFileOpenRecent.DropDownItems)
            {
                mi.Click -= new EventHandler(MenuFileOpenRecentFile_Click);
            }

            menuFileOpenRecent.DropDownItems.Clear();

            i = 0;

            foreach (MostRecentFile mrf in files)
            {
                string menuName;

                if (i < 9)
                {
                    menuName = "&";
                }
                else
                {
                    menuName = "";
                }

                menuName += (1 + i).ToString() + " " + Path.GetFileName(mrf.FileName);
                ToolStripMenuItem mi = new ToolStripMenuItem(menuName);
                mi.Click       += new EventHandler(MenuFileOpenRecentFile_Click);
                mi.ImageScaling = ToolStripItemImageScaling.None;
                mi.Image        = (Image)mrf.Thumb.Clone();
                menuFileOpenRecent.DropDownItems.Add(mi);
                ++i;
            }

            if (menuFileOpenRecent.DropDownItems.Count == 0)
            {
                ToolStripMenuItem none = new ToolStripMenuItem(PdnResources.GetString("Menu.File.OpenRecent.None"));
                none.Enabled = false;
                menuFileOpenRecent.DropDownItems.Add(none);
            }
            else
            {
                ToolStripSeparator separator = new ToolStripSeparator();
                menuFileOpenRecent.DropDownItems.Add(separator);

                ToolStripMenuItem clearList = new ToolStripMenuItem();
                clearList.Text = PdnResources.GetString("Menu.File.OpenRecent.ClearThisList");
                menuFileOpenRecent.DropDownItems.Add(clearList);
                Image deleteIcon = PdnResources.GetImageResource("Icons.MenuEditEraseSelectionIcon.png").Reference;
                clearList.ImageTransparentColor = Utility.TransparentKey;
                clearList.ImageAlign            = ContentAlignment.MiddleCenter;
                clearList.ImageScaling          = ToolStripItemImageScaling.None;
                int    iconSize = AppWorkspace.MostRecentFiles.IconSize;
                Bitmap bitmap   = new Bitmap(iconSize + 2, iconSize + 2);

                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    g.Clear(clearList.ImageTransparentColor);

                    Point offset = new Point((bitmap.Width - deleteIcon.Width) / 2,
                                             (bitmap.Height - deleteIcon.Height) / 2);

                    g.CompositingMode = CompositingMode.SourceCopy;
                    g.DrawImage(deleteIcon, offset.X, offset.Y, deleteIcon.Width, deleteIcon.Height);
                }

                clearList.Image  = bitmap;
                clearList.Click += new EventHandler(ClearList_Click);
            }
        }