Click here to Skip to main content
15,886,026 members
Articles / Containers / Docker

SVG Artiste - An SVG Editor

Rate me:
Please Sign up or sign in to vote.
4.69/5 (23 votes)
3 Aug 2010CPOL14 min read 95.9K   15.4K   93  
A Vector based tool to create and edit SVG images
#region Header

/*  --------------------------------------------------------------------------------------------------------------
 *  I Software Innovations
 *  --------------------------------------------------------------------------------------------------------------
 *  SVG Artieste 2.0
 *  --------------------------------------------------------------------------------------------------------------
 *  File     :       BringToFrontCommand.cs
 *  Author   :       ajaysbritto@yahoo.com
 *  Date     :       20/03/2010
 *  --------------------------------------------------------------------------------------------------------------
 *  Change Log
 *  --------------------------------------------------------------------------------------------------------------
 *  Author	Comments
 */

#endregion Header

namespace Draw.Command
{
    using System.Collections;

    struct State
    {
        #region Fields

        public DrawObject Obj;
        public int Zorder;

        #endregion Fields
    }

    class BringToFrontCommand : ICommand
    {
        #region Fields

        private readonly ArrayList _graphicsList;
        private readonly ArrayList _objectsBroughtForward;
        private readonly ArrayList _zOrderBackup;

        #endregion Fields

        #region Constructors

        public BringToFrontCommand(
            ArrayList graphicsList,
            ArrayList shapesToBringForward)
        {
            _objectsBroughtForward = shapesToBringForward;
            _graphicsList = graphicsList;
            _zOrderBackup = new ArrayList();
        }

        //Disable default constructor
        private BringToFrontCommand()
        {
        }

        #endregion Constructors

        #region Methods

        public void Execute()
        {
            var tempList = new ArrayList();
            int n = _graphicsList.Count;

            // Read source list in reverse order, add every selected item
            // to temporary list and remove it from source list
            for (int i = n - 1; i >= 0; i--)
            {
                if (_objectsBroughtForward.Contains(_graphicsList[i]))
                {
                    State oldState;

                    //Undo Redo -- Start
                    oldState.Obj = ((DrawObject)_graphicsList[i]);
                    oldState.Zorder = i;
                    _zOrderBackup.Add(oldState);
                    //Undo Redo -- End

                    tempList.Add(_graphicsList[i]);
                    _graphicsList.RemoveAt(i);
                }
            }

            // Read temporary list in direct order and insert every item
            // to the beginning of the source list
            n = tempList.Count;

            for (int i = 0; i < n; i++)
            {
                _graphicsList.Insert(0, tempList[i]);
            }
        }

        public void UnExecute()
        {
            for (int i = 0; i < _objectsBroughtForward.Count; i++)
            {
                var state = (State)_zOrderBackup[i];
                _graphicsList.Remove(state.Obj);
                _graphicsList.Insert(state.Zorder, state.Obj);
            }
        }

        #endregion Methods
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
Singapore Singapore
He is a Microsoft technology enthusiast, who wish to create applications which others find useful.He loves making small tools and getting involved in architecting bigger systems.

He is currently working as a professional developer in a software development firm in .Net technologies.

He likes reading technical blogs, contributing to opensource and most importantly, enjoying life.

His ambition is to be an impressive software maker.

Comments and Discussions