Click here to Skip to main content
15,895,656 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 96.3K   15.4K   93  
A Vector based tool to create and edit SVG images
#region Header

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

#endregion Header

namespace SVGEditor2.UserControls
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    public partial class WorkspaceHolder : Crom.Controls.TabbedDocument.TabPageView
    {
        #region Fields

        Point _start = new Point(-1, -1);
        int _xDiff, _yDiff, _intialScrollBarLocX, _intialScrollBarLocY;

        #endregion Fields

        #region Constructors

        public WorkspaceHolder()
        {
            InitializeComponent();
            svgDrawForm.ZoomDone += SvgDrawFormZoomDone;
            svgDrawForm.MousePan += SvgDrawFormMousePan;
            svgDrawForm.GridChange += SvgDrawFormGridChange;
            svgDrawForm.ScrollMade += SvgDrawFormScrollMade;
            rulerControl_left.HooverValue += RulerControlLeftHooverValue;
            rulerControl_top.HooverValue += RulerControlTopHooverValue;
        }

        #endregion Constructors

        #region Delegates

        public delegate void OnMouseMovementCaptured(object sender, Lyquidity.UtilityLibrary.Controls.RulerControl.HooverValueEventArgs e);

        #endregion Delegates

        #region Methods

        private void AdjustRuler()
        {
            rulerControl_left.StartValue = svgDrawForm.VerticalScroll.Value / rulerControl_left.ZoomFactor;
            rulerControl_top.StartValue = svgDrawForm.HorizontalScroll.Value / rulerControl_left.ZoomFactor;
        }

        void RulerControlLeftHooverValue(object sender, Lyquidity.UtilityLibrary.Controls.RulerControl.HooverValueEventArgs e)
        {
            label_mouseX.Text = @"y" + (((int)e.Value));
        }

        void RulerControlTopHooverValue(object sender, Lyquidity.UtilityLibrary.Controls.RulerControl.HooverValueEventArgs e)
        {
            label_mouseY.Text = @"x" + (((int)e.Value));
        }

        void SvgDrawFormGridChange(object sender, EventArgs e)
        {
            svgDrawForm.SetGridDivs(rulerControl_top.Divisions,
                rulerControl_left.Divisions);

            if (sender != null)
            {
                if (sender.GetType().ToString() == "System.Windows.Forms.NumericUpDown")
                {
                    var ctl = (NumericUpDown)(sender);
                    rulerControl_left.Divisions = (int)ctl.Value;
                    rulerControl_top.Divisions = (int)ctl.Value;
                }
            }
        }

        void SvgDrawFormMousePan(object sender, MouseEventArgs e)
        {
            Point currentPosition = MousePosition;

            if (e.Button == MouseButtons.Left)
            {
                if ((_start.X == -1) && (_start.Y == -1))
                {
                    _start = currentPosition;
                    _intialScrollBarLocX = svgDrawForm.HorizontalScroll.Value;
                    _intialScrollBarLocY = svgDrawForm.VerticalScroll.Value;
                    System.Diagnostics.Debug.Print("Start :" + _start.X + " " + _start.Y);
                }
                else
                {
                    _xDiff = _start.X - currentPosition.X;
                    _yDiff = _start.Y - currentPosition.Y;

                    if (svgDrawForm.HorizontalScroll.Visible)
                    {
                        if (svgDrawForm.HorizontalScroll.Value + _xDiff + _intialScrollBarLocX >= 0)
                        {
                            svgDrawForm.HorizontalScroll.Value = _xDiff + _intialScrollBarLocX;
                        }
                        else
                        {
                            svgDrawForm.HorizontalScroll.Value = 0;
                        }
                    }

                    if (svgDrawForm.VerticalScroll.Visible)
                    {
                        if (svgDrawForm.VerticalScroll.Value + _yDiff + _intialScrollBarLocY >= 0)
                        {
                            svgDrawForm.VerticalScroll.Value = _yDiff + _intialScrollBarLocY;
                        }
                        else
                        {
                            svgDrawForm.VerticalScroll.Value = 0;
                        }
                    }
                }
            }
            else
            {
                _start.X = -1; _start.Y = -1;
            }

            AdjustRuler();
        }

        void SvgDrawFormScrollMade(object sender, ScrollEventArgs e)
        {
            AdjustRuler();
        }

        void SvgDrawFormZoomDone(object sender, EventArgs e)
        {
            rulerControl_left.ZoomFactor = (float)sender;
            rulerControl_top.ZoomFactor = (float)sender;
            SvgDrawFormScrollMade(null, null);
        }

        private void SvgFormHolderResize(object sender, EventArgs e)
        {
            svgDrawForm.Top = rulerControl_top.Height;
            svgDrawForm.Left = rulerControl_left.Width;
            svgDrawForm.Width = ClientRectangle.Width - 40;
            svgDrawForm.Height = ClientRectangle.Height - 25;
            SvgDrawFormGridChange(null, null);
        }

        #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