Пример #1
0
        public static Document ResizeDocument(Document document, Size newSize, AnchorEdge edge, ColorBgra background)
        {
            Document document2 = new Document(newSize.Width, newSize.Height);

            document2.ReplaceMetadataFrom(document);
            for (int i = 0; i < document.Layers.Count; i++)
            {
                Layer layer = (Layer)document.Layers[i];
                if (layer is BitmapLayer)
                {
                    Layer layer2;
                    try
                    {
                        layer2 = ResizeLayer((BitmapLayer)layer, newSize, edge, background);
                    }
                    catch (OutOfMemoryException)
                    {
                        document2.Dispose();
                        throw;
                    }
                    document2.Layers.Add(layer2);
                }
                else
                {
                    ExceptionUtil.ThrowInvalidOperationException("Canvas Size does not support Layers that are not BitmapLayers");
                }
            }
            return(document2);
        }
Пример #2
0
        public CanvasSizeDialog()
        {
            // This call is required by the Windows Form Designer.
            InitializeComponent();

            this.Icon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.MenuImageCanvasSizeIcon.png").Reference, Utility.TransparentKey);

            this.Text = PdnResources.GetString("CanvasSizeDialog.Text");                             // "Canvas Size";
            this.anchorHeader.Text  = PdnResources.GetString("CanvasSizeDialog.AnchorHeader.Text");  //"Anchor";
            this.newSpaceLabel.Text = PdnResources.GetString("CanvasSizeDialog.NewSpaceLabel.Text"); //"The new space will be filled with the currently selected background color.";

            foreach (string name in Enum.GetNames(typeof(AnchorEdge)))
            {
                AnchorEdge value    = (AnchorEdge)Enum.Parse(typeof(AnchorEdge), name, true);
                string     itemName = this.anchorEdgeNames.EnumValueToLocalizedName(value);
                this.anchorEdgeCB.Items.Add(itemName);

                if (value == this.AnchorEdge)
                {
                    this.anchorEdgeCB.SelectedItem = itemName;
                }
            }

            anchorChooserControl_AnchorEdgeChanged(anchorChooserControl, EventArgs.Empty);
        }
Пример #3
0
        public static Document ResizeDocument(Document document, Size newSize, AnchorEdge edge, ColorBgra background)
        {
            Document newDoc = new Document(newSize.Width, newSize.Height);
            newDoc.ReplaceMetaDataFrom(document);

            for (int i = 0; i < document.Layers.Count; ++i)
            {
                Layer layer = (Layer)document.Layers[i];

                if (layer is BitmapLayer)
                {
                    Layer newLayer;

                    try
                    {
                        newLayer = ResizeLayer((BitmapLayer)layer, newSize, edge, background);
                    }

                    catch (OutOfMemoryException)
                    {
                        newDoc.Dispose();
                        throw;
                    }

                    newDoc.Layers.Add(newLayer);
                }
                else
                {
                    throw new InvalidOperationException("Canvas Size does not support Layers that are not BitmapLayers");
                }
            }

            return newDoc;
        }
Пример #4
0
        public static Document ResizeDocument(Document document, Size newSize, AnchorEdge edge, ColorBgra background)
        {
            Document newDoc = new Document(newSize.Width, newSize.Height);

            newDoc.ReplaceMetaDataFrom(document);

            for (int i = 0; i < document.Layers.Count; ++i)
            {
                Layer layer = (Layer)document.Layers[i];

                if (layer is BitmapLayer)
                {
                    Layer newLayer;

                    try
                    {
                        newLayer = ResizeLayer((BitmapLayer)layer, newSize, edge, background);
                    }

                    catch (OutOfMemoryException)
                    {
                        newDoc.Dispose();
                        throw;
                    }

                    newDoc.Layers.Add(newLayer);
                }
                else
                {
                    throw new InvalidOperationException("Canvas Size does not support Layers that are not BitmapLayers");
                }
            }

            return(newDoc);
        }
Пример #5
0
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            AnchorEdge initialAnchor = AppSettings.Instance.Workspace.LastCanvasSizeAnchorEdge.Value;
            Document   document      = ResizeDocument(documentWorkspace, initialAnchor, documentWorkspace.ToolSettings.SecondaryColor.Value, true, true);

            if (document != null)
            {
                using (new PushNullToolMode(documentWorkspace))
                {
                    List <HistoryMemento>   actions = new List <HistoryMemento>(2);
                    SelectionHistoryMemento item    = new SelectionHistoryMemento(null, null, documentWorkspace);
                    actions.Add(item);
                    if (document.DpuUnit != MeasurementUnit.Pixel)
                    {
                        AppSettings.Instance.Workspace.LastNonPixelUnits.Value = document.DpuUnit;
                        if (documentWorkspace.AppWorkspace.Units != MeasurementUnit.Pixel)
                        {
                            documentWorkspace.AppWorkspace.Units = document.DpuUnit;
                        }
                    }
                    ReplaceDocumentHistoryMemento memento2 = new ReplaceDocumentHistoryMemento(null, null, documentWorkspace);
                    actions.Add(memento2);
                    documentWorkspace.Document = document;
                    return(new CompoundHistoryMemento(StaticName, StaticImage, actions));
                }
            }
            return(null);
        }
Пример #6
0
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            AnchorEdge initialEdge = SettingNames.GetLastCanvasSizeAnchorEdge();

            Document newDoc = ResizeDocument(
                documentWorkspace.FindForm(),
                documentWorkspace.Document,
                documentWorkspace.Document.Size,
                initialEdge,
                documentWorkspace.AppWorkspace.AppEnvironment.SecondaryColor,
                true,
                true);

            if (newDoc != null)
            {
                using (new PushNullToolMode(documentWorkspace))
                {
                    ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(StaticName, StaticImage, documentWorkspace);
                    documentWorkspace.Document = newDoc;
                    return(rdha);
                }
            }
            else
            {
                return(null);
            }
        }
 private AnchorEdge RegularizeEdge(AnchorEdge edge)
 {
     if (edge.anchorId2 < edge.anchorId1)
     {
         var id = edge.anchorId2;
         edge.anchorId2 = edge.anchorId1;
         edge.anchorId1 = id;
     }
     return(edge);
 }
 public static IdPair <AnchorEdge, AnchorEdgeVisTest> Make(AnchorEdge id)
 {
     return(new IdPair <AnchorEdge, AnchorEdgeVisTest>()
     {
         id = id,
         target = new AnchorEdgeVisTest()
         {
             id = id
         }
     });
 }
        public static void AddSpongyEdges(ICollection <AnchorEdge> spongyEdges, List <AnchorEdge> frozenEdges)
        {
            AnchorEdge[] regularEdges = new AnchorEdge[spongyEdges.Count];
            int          idx          = 0;

            foreach (var edge in spongyEdges)
            {
                regularEdges[idx++] = RegularEdge(edge.anchorId1, edge.anchorId2);
            }
            System.Comparison <AnchorEdge> alphabeticCompare = (x, y) =>
            {
                int cmp1 = x.anchorId1.CompareTo(y.anchorId1);
                if (cmp1 < 0)
                {
                    return(-1);
                }
                if (cmp1 > 0)
                {
                    return(1);
                }
                int cmp2 = x.anchorId2.CompareTo(y.anchorId2);
                return(cmp2);
            };
            System.Array.Sort(regularEdges, alphabeticCompare);

            int spongyIdx = 0;

            for (int frozenIdx = 0; frozenIdx < frozenEdges.Count; ++frozenIdx)
            {
                if (spongyIdx >= regularEdges.Length)
                {
                    break;
                }
                int frozenToSpongy = alphabeticCompare(frozenEdges[frozenIdx], regularEdges[spongyIdx]);
                if (frozenToSpongy >= 0)
                {
                    if (frozenToSpongy > 0)
                    {
                        // insert edge here
                        frozenEdges.Insert(frozenIdx, regularEdges[spongyIdx]);
                    }
                    // If existing frozen is greater, we just inserted (above) spongy, so advance.
                    // If they are equal, we want to skip spongy, so advance.
                    // If existing is lesser, we haven't reached insertion point yet,
                    // so don't advance spongyIdx (stay out of this conditional branch if frozenToSpongy < 0).
                    ++spongyIdx;
                }
            }
            while (spongyIdx < regularEdges.Length)
            {
                frozenEdges.Add(regularEdges[spongyIdx++]);
            }
        }
Пример #10
0
            /// <summary>
            /// Look up the frozen anchor endpoints and connect them with a line.
            /// </summary>
            /// <param name="edge">Pair of anchor ids.</param>
            /// <param name="resource">The resource to create.</param>
            /// <returns></returns>
            public bool CreateFrozenEdge(AnchorEdge edge, out IdPair <AnchorEdge, ConnectingLine> resource)
            {
                var anchorId1 = edge.anchorId1;
                var anchorId2 = edge.anchorId2;

                var frozenAnchor1Idx = FindInSortedList(anchorId1, frozenResources, frozenAnchorVisualComparer);
                var frozenAnchor2Idx = FindInSortedList(anchorId2, frozenResources, frozenAnchorVisualComparer);

                if (frozenAnchor1Idx < 0 || frozenAnchor2Idx < 0)
                {
                    resource = new IdPair <AnchorEdge, ConnectingLine>()
                    {
                        id = edge, target = null
                    };
                    return(false);
                }
                var frozenAnchor1 = frozenResources[frozenAnchor1Idx];
                var frozenAnchor2 = frozenResources[frozenAnchor2Idx];

                Transform parent1      = frozenAnchor1.target.transform.parent;
                Transform parent2      = frozenAnchor2.target.transform.parent;
                bool      sameFragment = parent1 == parent2;
                Color     color        = Color.blue;
                float     width        = 0.002f;
                Transform parent       = parent1;

                if (!sameFragment)
                {
                    color = Color.yellow;
                    width = 0.004f;
                }

                var edgeVisual = ConnectingLine.Create(parent,
                                                       frozenAnchor1.target.transform, frozenAnchor2.target.transform,
                                                       width, color);

                resource = new IdPair <AnchorEdge, ConnectingLine>()
                {
                    id     = edge,
                    target = edgeVisual
                };
                return(true);
            }
 public static int CompareEdges(AnchorEdge lhs, AnchorEdge rhs)
 {
     if (lhs.anchorId1 < rhs.anchorId1)
     {
         return(-1);
     }
     if (lhs.anchorId1 > rhs.anchorId1)
     {
         return(1);
     }
     if (lhs.anchorId2 < rhs.anchorId2)
     {
         return(-1);
     }
     if (lhs.anchorId2 > rhs.anchorId2)
     {
         return(1);
     }
     return(0);
 }
Пример #12
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (this.mouseDown && e.Button == this.mouseButtonDown)
            {
                int anchorX = (e.X * 3) / this.Width;
                int anchorY = (e.Y * 3) / this.Height;

                if (anchorX == this.hotAnchorButton.X && anchorY == this.hotAnchorButton.Y &&
                    anchorX >= 0 && anchorX <= 2 &&
                    anchorY >= 0 && anchorY <= 2)
                {
                    AnchorEdge newEdge = (AnchorEdge)this.xyToAnchorEdge[anchorY][anchorX];
                    this.AnchorEdge = newEdge;
                    Invalidate();
                }
            }

            this.drawHotPush = false;
            this.mouseDown   = false;
            base.OnMouseUp(e);
        }
Пример #13
0
 /// <summary>
 /// Comparison function for two edges.
 /// </summary>
 /// <remarks>
 /// Alphabetic sort on first endpoint first, then second endpoint.
 /// </remarks>
 /// <param name="lhs">Left hand edge.</param>
 /// <param name="rhs">Right hand edge.</param>
 /// <returns>Comparison int of edges.</returns>
 private static int CompareAnchorEdges(AnchorEdge lhs, AnchorEdge rhs)
 {
     Debug.Assert(lhs.anchorId1 < lhs.anchorId2);
     Debug.Assert(rhs.anchorId1 < rhs.anchorId2);
     if (lhs.anchorId1 < rhs.anchorId1)
     {
         return(-1);
     }
     if (lhs.anchorId1 > rhs.anchorId1)
     {
         return(1);
     }
     if (lhs.anchorId2 < rhs.anchorId2)
     {
         return(-1);
     }
     if (lhs.anchorId2 > rhs.anchorId2)
     {
         return(1);
     }
     return(0);
 }
Пример #14
0
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            AnchorEdge initialEdge = PdnSettings.GetLastCanvasSizeAnchorEdge();

            Document newDoc = ResizeDocument(
                documentWorkspace.FindForm(),
                documentWorkspace.Document,
                documentWorkspace.Document.Size,
                initialEdge,
                documentWorkspace.AppWorkspace.AppEnvironment.SecondaryColor,
                true,
                true);

            if (newDoc != null)
            {
                using (new PushNullToolMode(documentWorkspace))
                {
                    if (newDoc.DpuUnit != MeasurementUnit.Pixel)
                    {
                        Settings.CurrentUser.SetString(PdnSettings.LastNonPixelUnits, newDoc.DpuUnit.ToString());

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

                    ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(StaticName, StaticImage, documentWorkspace);
                    documentWorkspace.Document = newDoc;
                    return(rdha);
                }
            }
            else
            {
                return(null);
            }
        }
Пример #15
0
        // returns null to indicate user cancelled, or if initialNewSize = newSize that the user requested,
        // or if there was an error (out of memory)
        public static Document ResizeDocument(IWin32Window parent,
                                              Document document,
                                              Size initialNewSize,
                                              AnchorEdge initialAnchor,
                                              ColorBgra background,
                                              bool loadAndSaveMaintainAspect,
                                              bool saveAnchor)
        {
            using (CanvasSizeDialog csd = new CanvasSizeDialog())
            {
                bool maintainAspect;

                if (loadAndSaveMaintainAspect)
                {
                    maintainAspect = Settings.CurrentUser.GetBoolean(PdnSettings.LastMaintainAspectRatioCS, false);
                }
                else
                {
                    maintainAspect = false;
                }

                csd.OriginalSize      = document.Size;
                csd.OriginalDpuUnit   = document.DpuUnit;
                csd.OriginalDpu       = document.DpuX;
                csd.ImageWidth        = initialNewSize.Width;
                csd.ImageHeight       = initialNewSize.Height;
                csd.LayerCount        = document.Layers.Count;
                csd.AnchorEdge        = initialAnchor;
                csd.Units             = csd.OriginalDpuUnit;
                csd.Resolution        = document.DpuX;
                csd.Units             = PdnSettings.GetLastNonPixelUnits();
                csd.ConstrainToAspect = maintainAspect;

                DialogResult    result     = csd.ShowDialog(parent);
                Size            newSize    = new Size(csd.ImageWidth, csd.ImageHeight);
                MeasurementUnit newDpuUnit = csd.Units;
                double          newDpu     = csd.Resolution;

                // If they cancelled, get out
                if (result == DialogResult.Cancel)
                {
                    return(null);
                }

                // If they clicked OK, then we save the aspect checkbox, and maybe the anchor
                if (loadAndSaveMaintainAspect)
                {
                    Settings.CurrentUser.SetBoolean(PdnSettings.LastMaintainAspectRatioCS, csd.ConstrainToAspect);
                }

                if (saveAnchor)
                {
                    Settings.CurrentUser.SetString(PdnSettings.LastCanvasSizeAnchorEdge, csd.AnchorEdge.ToString());
                }

                if (newSize == document.Size && newDpuUnit == document.DpuUnit && newDpu == document.DpuX)
                {
                    return(null);
                }

                try
                {
                    Utility.GCFullCollect();
                    Document newDoc = ResizeDocument(document, newSize, csd.AnchorEdge, background);
                    newDoc.DpuUnit = newDpuUnit;
                    newDoc.DpuX    = newDpu;
                    newDoc.DpuY    = newDpu;
                    return(newDoc);
                }

                catch (OutOfMemoryException)
                {
                    Utility.ErrorBox(parent, PdnResources.GetString("CanvasSizeAction.ResizeDocument.OutOfMemory"));
                    return(null);
                }

                catch
                {
                    return(null);
                }
            }
        }
Пример #16
0
        public static BitmapLayer ResizeLayer(BitmapLayer layer, Size newSize, AnchorEdge anchor, ColorBgra background)
        {
            BitmapLayer newLayer = new BitmapLayer(newSize.Width, newSize.Height);

            // Background
            new UnaryPixelOps.Constant(background).Apply(newLayer.Surface, newLayer.Surface.Bounds);

            // non-background = clear the alpha channel (see-through)
            if (!layer.IsBackground)
            {
                new UnaryPixelOps.SetAlphaChannel(0).Apply(newLayer.Surface, newLayer.Surface.Bounds);
            }

            int topY = 0;
            int leftX = 0;
            int rightX = newSize.Width - layer.Width;
            int bottomY = newSize.Height - layer.Height;
            int middleX = (newSize.Width - layer.Width) / 2;
            int middleY = (newSize.Height - layer.Height) / 2;

            int x = 0;
            int y = 0;

            #region choose x,y from AnchorEdge
            switch (anchor)
            {
                case AnchorEdge.TopLeft:
                    x = leftX;
                    y = topY;
                    break;

                case AnchorEdge.Top:
                    x = middleX;
                    y = topY;
                    break;

                case AnchorEdge.TopRight:
                    x = rightX;
                    y = topY;
                    break;

                case AnchorEdge.Left:
                    x = leftX;
                    y = middleY;
                    break;

                case AnchorEdge.Middle:
                    x = middleX;
                    y = middleY;
                    break;

                case AnchorEdge.Right:
                    x = rightX;
                    y = middleY;
                    break;

                case AnchorEdge.BottomLeft:
                    x = leftX;
                    y = bottomY;
                    break;

                case AnchorEdge.Bottom:
                    x = middleX;
                    y = bottomY;
                    break;

                case AnchorEdge.BottomRight:
                    x = rightX;
                    y = bottomY;
                    break;
            }
            #endregion

            newLayer.Surface.CopySurface(layer.Surface, new Point(x, y));
            newLayer.LoadProperties(layer.SaveProperties());
            return newLayer;
        }
Пример #17
0
        // returns null to indicate user cancelled, or if initialNewSize = newSize that the user requested,
        // or if there was an error (out of memory)
        public static Document ResizeDocument(IWin32Window parent, 
            Document document,
            Size initialNewSize,
            AnchorEdge initialAnchor,
            ColorBgra background,
            bool loadAndSaveMaintainAspect,
            bool saveAnchor)
        {
            using (CanvasSizeDialog csd = new CanvasSizeDialog())
            {
                bool maintainAspect;

                if (loadAndSaveMaintainAspect)
                {
                    maintainAspect = Settings.CurrentUser.GetBoolean(PdnSettings.LastMaintainAspectRatioCS, false);
                }
                else
                {
                    maintainAspect = false;
                }

                csd.OriginalSize = document.Size;
                csd.OriginalDpuUnit = document.DpuUnit;
                csd.OriginalDpu = document.DpuX;
                csd.ImageWidth = initialNewSize.Width;
                csd.ImageHeight = initialNewSize.Height;
                csd.LayerCount = document.Layers.Count;
                csd.AnchorEdge = initialAnchor;
                csd.Units = csd.OriginalDpuUnit;
                csd.Resolution = document.DpuX;
                csd.Units = PdnSettings.GetLastNonPixelUnits();
                csd.ConstrainToAspect = maintainAspect;

                DialogResult result = csd.ShowDialog(parent);
                Size newSize = new Size(csd.ImageWidth, csd.ImageHeight);
                MeasurementUnit newDpuUnit = csd.Units;
                double newDpu = csd.Resolution;

                // If they cancelled, get out
                if (result == DialogResult.Cancel)
                {
                    return null;
                }

                // If they clicked OK, then we save the aspect checkbox, and maybe the anchor
                if (loadAndSaveMaintainAspect)
                {
                    Settings.CurrentUser.SetBoolean(PdnSettings.LastMaintainAspectRatioCS, csd.ConstrainToAspect);
                }

                if (saveAnchor)
                {
                    Settings.CurrentUser.SetString(PdnSettings.LastCanvasSizeAnchorEdge, csd.AnchorEdge.ToString());
                }

                if (newSize == document.Size && newDpuUnit == document.DpuUnit && newDpu == document.DpuX)
                {
                    return null;
                }

                try
                {
                    Utility.GCFullCollect();
                    Document newDoc = ResizeDocument(document, newSize, csd.AnchorEdge, background);
                    newDoc.DpuUnit = newDpuUnit;
                    newDoc.DpuX = newDpu;
                    newDoc.DpuY = newDpu;
                    return newDoc;
                }

                catch (OutOfMemoryException)
                {
                    Utility.ErrorBox(parent, PdnResources.GetString("CanvasSizeAction.ResizeDocument.OutOfMemory"));
                    return null;
                }

                catch
                {
                    return null;
                }
            }
        }
Пример #18
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (this.mouseDown && e.Button == this.mouseButtonDown)
            {
                int anchorX = (e.X * 3) / this.Width;
                int anchorY = (e.Y * 3) / this.Height;

                if (anchorX == this.hotAnchorButton.X && anchorY == this.hotAnchorButton.Y &&
                    anchorX >= 0 && anchorX <= 2 &&
                    anchorY >= 0 && anchorY <= 2)
                {
                    AnchorEdge newEdge = (AnchorEdge)this.xyToAnchorEdge[anchorY][anchorX];
                    this.AnchorEdge = newEdge;
                    Invalidate();
                }
            }

            this.drawHotPush = false;
            this.mouseDown = false;
            base.OnMouseUp (e);
        }
Пример #19
0
 private void anchorEdgeCB_SelectedIndexChanged(object sender, System.EventArgs e)
 {
     AnchorEdge newAnchorEdge = (AnchorEdge)this.anchorEdgeNames.LocalizedNameToEnumValue((string)this.anchorEdgeCB.SelectedItem);
     this.AnchorEdge = newAnchorEdge;
 }
Пример #20
0
        private static Document ResizeDocument(DocumentWorkspace documentWorkspace, AnchorEdge initialAnchor, ColorBgra background, bool loadAndSaveMaintainAspect, bool saveAnchor)
        {
            Document document2;

            CleanupManager.RequestCleanup();
            IWin32Window owner    = documentWorkspace;
            Document     document = documentWorkspace.Document;
            Size         size     = document.Size;

            using (CanvasSizeDialog dialog = new CanvasSizeDialog())
            {
                bool flag;
                if (loadAndSaveMaintainAspect)
                {
                    flag = AppSettings.Instance.Workspace.LastMaintainAspectRatioCS.Value;
                }
                else
                {
                    flag = false;
                }
                dialog.OriginalSize      = document.Size;
                dialog.OriginalDpuUnit   = document.DpuUnit;
                dialog.OriginalDpu       = document.DpuX;
                dialog.ImageWidth        = size.Width;
                dialog.ImageHeight       = size.Height;
                dialog.LayerCount        = document.Layers.Count;
                dialog.AnchorEdge        = initialAnchor;
                dialog.Units             = dialog.OriginalDpuUnit;
                dialog.Resolution        = document.DpuX;
                dialog.Units             = AppSettings.Instance.Workspace.LastNonPixelUnits.Value;
                dialog.ConstrainToAspect = flag;
                DialogResult    result     = dialog.ShowDialog(owner);
                Size            newSize    = new Size(dialog.ImageWidth, dialog.ImageHeight);
                MeasurementUnit units      = dialog.Units;
                double          resolution = dialog.Resolution;
                if (result == DialogResult.Cancel)
                {
                    return(null);
                }
                if (loadAndSaveMaintainAspect)
                {
                    AppSettings.Instance.Workspace.LastMaintainAspectRatioCS.Value = dialog.ConstrainToAspect;
                }
                if (saveAnchor)
                {
                    AppSettings.Instance.Workspace.LastCanvasSizeAnchorEdge.Value = dialog.AnchorEdge;
                }
                if (((newSize == document.Size) && (units == document.DpuUnit)) && (resolution == document.DpuX))
                {
                    document2 = null;
                }
                else
                {
                    try
                    {
                        documentWorkspace.FlushTool();
                        CleanupManager.RequestCleanup();
                        Document document3 = ResizeDocument(document, newSize, dialog.AnchorEdge, background);
                        document3.DpuUnit = units;
                        document3.DpuX    = resolution;
                        document3.DpuY    = resolution;
                        document2         = document3;
                    }
                    catch (OutOfMemoryException exception)
                    {
                        ExceptionDialog.ShowErrorDialog(owner, PdnResources.GetString("CanvasSizeAction.ResizeDocument.OutOfMemory"), exception.ToString());
                        document2 = null;
                    }
                    catch (Exception)
                    {
                        document2 = null;
                    }
                }
            }
            return(document2);
        }
Пример #21
0
        public static BitmapLayer ResizeLayer(BitmapLayer layer, Size newSize, AnchorEdge anchor, ColorBgra background)
        {
            BitmapLayer newLayer = new BitmapLayer(newSize.Width, newSize.Height);

            // Background
            new UnaryPixelOps.Constant(background).Apply(newLayer.Surface, newLayer.Surface.Bounds);

            // non-background = clear the alpha channel (see-through)
            if (!layer.IsBackground)
            {
                new UnaryPixelOps.SetAlphaChannel(0).Apply(newLayer.Surface, newLayer.Surface.Bounds);
            }

            int topY    = 0;
            int leftX   = 0;
            int rightX  = newSize.Width - layer.Width;
            int bottomY = newSize.Height - layer.Height;
            int middleX = (newSize.Width - layer.Width) / 2;
            int middleY = (newSize.Height - layer.Height) / 2;

            int x = 0;
            int y = 0;

            #region choose x,y from AnchorEdge
            switch (anchor)
            {
            case AnchorEdge.TopLeft:
                x = leftX;
                y = topY;
                break;

            case AnchorEdge.Top:
                x = middleX;
                y = topY;
                break;

            case AnchorEdge.TopRight:
                x = rightX;
                y = topY;
                break;

            case AnchorEdge.Left:
                x = leftX;
                y = middleY;
                break;

            case AnchorEdge.Middle:
                x = middleX;
                y = middleY;
                break;

            case AnchorEdge.Right:
                x = rightX;
                y = middleY;
                break;

            case AnchorEdge.BottomLeft:
                x = leftX;
                y = bottomY;
                break;

            case AnchorEdge.Bottom:
                x = middleX;
                y = bottomY;
                break;

            case AnchorEdge.BottomRight:
                x = rightX;
                y = bottomY;
                break;
            }
            #endregion

            newLayer.Surface.CopySurface(layer.Surface, new Point(x, y));
            newLayer.LoadProperties(layer.SaveProperties());
            return(newLayer);
        }
 public static bool Create(AnchorEdge source, out IdPair <AnchorEdge, AnchorEdgeVisTest> resource)
 {
     resource = Make(source);
     return(true);
 }
 public static void Update(AnchorEdge source, IdPair <AnchorEdge, AnchorEdgeVisTest> target)
 {
     Assert.AreEqual(source, target.id);
 }
Пример #24
0
        private void anchorEdgeCB_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            AnchorEdge newAnchorEdge = (AnchorEdge)this.anchorEdgeNames.LocalizedNameToEnumValue((string)this.anchorEdgeCB.SelectedItem);

            this.AnchorEdge = newAnchorEdge;
        }
Пример #25
0
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            // Clear background
            e.Graphics.Clear(SystemColors.Control);

            // Draw each part
            Point selection = (Point)this.anchorEdgeToXy[this.anchorEdge];

            double controlCenterX = (double)this.Width / 2.0;
            double controlCenterY = (double)this.Height / 2.0;

            Pen linePen            = new Pen(SystemColors.WindowText, (((float)Width + (float)Height) / 2.0f) / 64.0f);
            AdjustableArrowCap cap = new AdjustableArrowCap((float)Width / 32.0f, (float)Height / 32.0f, true);

            linePen.CustomEndCap = cap;

            Point mousePoint   = PointToClient(Control.MousePosition);
            int   mouseAnchorX = (int)Math.Floor(((float)mousePoint.X * 3.0f) / (float)this.Width);
            int   mouseAnchorY = (int)Math.Floor(((float)mousePoint.Y * 3.0f) / (float)this.Height);

            for (int y = 0; y < 3; ++y)
            {
                for (int x = 0; x < 3; ++x)
                {
                    AnchorEdge edge   = this.xyToAnchorEdge[y][x];
                    Point      offset = (Point)this.anchorEdgeToXy[edge];
                    Point      vector = new Point(offset.X - selection.X, offset.Y - selection.Y);

                    int left   = (this.Width * x) / 3;
                    int top    = (this.Height * y) / 3;
                    int right  = Math.Min(this.Width - 1, (this.Width * (x + 1)) / 3);
                    int bottom = Math.Min(this.Height - 1, (this.Height * (y + 1)) / 3);
                    int width  = right - left;
                    int height = bottom - top;

                    if (vector.X == 0 && vector.Y == 0)
                    {
                        ButtonRenderer.DrawButton(e.Graphics, new Rectangle(left, top, width, height), PushButtonState.Pressed);
                        e.Graphics.DrawImage(this.centerImage, left + 3, top + 3, width - 6, height - 6);
                    }
                    else
                    {
                        PushButtonState state;

                        if (drawHotPush && x == this.hotAnchorButton.X && y == this.hotAnchorButton.Y)
                        {
                            state = PushButtonState.Pressed;
                        }
                        else
                        {
                            state = PushButtonState.Normal;

                            if (!mouseDown && mouseAnchorX == x && mouseAnchorY == y)
                            {
                                state = PushButtonState.Hot;
                            }
                        }

                        ButtonRenderer.DrawButton(e.Graphics, new Rectangle(left, top, width, height), state);

                        if (vector.X <= 1 && vector.X >= -1 && vector.Y <= 1 && vector.Y >= -1)
                        {
                            double vectorMag = Math.Sqrt((double)((vector.X * vector.X) + (vector.Y * vector.Y)));
                            double normalX   = (double)vector.X / vectorMag;
                            double normalY   = (double)vector.Y / vectorMag;

                            Point center = new Point((left + right) / 2, (top + bottom) / 2);

                            Point start = new Point(center.X - (width / 4) * vector.X, center.Y - (height / 4) * vector.Y);
                            Point end   = new Point(
                                start.X + (int)(((double)width / 2.0) * normalX),
                                start.Y + (int)(((double)height / 2.0) * normalY));

                            PixelOffsetMode oldPOM = e.Graphics.PixelOffsetMode;
                            e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
                            e.Graphics.DrawLine(linePen, start, end);
                            e.Graphics.PixelOffsetMode = oldPOM;
                        }
                    }
                }
            }

            linePen.Dispose();
            base.OnPaint(e);
        }
Пример #26
0
        public static BitmapLayer ResizeLayer(BitmapLayer layer, Size newSize, AnchorEdge anchor, ColorBgra background)
        {
            BitmapLayer layer2 = new BitmapLayer(newSize.Width, newSize.Height);

            new UnaryPixelOps.Constant(background).Apply(layer2.Surface, layer2.Surface.Bounds);
            if (!layer.IsBackground)
            {
                new UnaryPixelOps.SetAlphaChannel(0).Apply(layer2.Surface, layer2.Surface.Bounds);
            }
            int num  = 0;
            int num2 = 0;
            int num3 = newSize.Width - layer.Width;
            int num4 = newSize.Height - layer.Height;
            int num5 = (newSize.Width - layer.Width) / 2;
            int num6 = (newSize.Height - layer.Height) / 2;
            int x    = 0;
            int y    = 0;

            switch (anchor)
            {
            case AnchorEdge.TopLeft:
                x = num2;
                y = num;
                break;

            case AnchorEdge.Top:
                x = num5;
                y = num;
                break;

            case AnchorEdge.TopRight:
                x = num3;
                y = num;
                break;

            case AnchorEdge.Left:
                x = num2;
                y = num6;
                break;

            case AnchorEdge.Middle:
                x = num5;
                y = num6;
                break;

            case AnchorEdge.Right:
                x = num3;
                y = num6;
                break;

            case AnchorEdge.BottomLeft:
                x = num2;
                y = num4;
                break;

            case AnchorEdge.Bottom:
                x = num5;
                y = num4;
                break;

            case AnchorEdge.BottomRight:
                x = num3;
                y = num4;
                break;
            }
            layer2.Surface.CopySurface(layer.Surface, new Point(x, y));
            layer2.LoadProperties(layer.SaveProperties());
            return(layer2);
        }