Click here to Skip to main content
15,896,269 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
/***************************************************************************
 *   CopyRight (C) 2009 by Cristinel Mazarine                              *
 *   Author:   Cristinel Mazarine                                          *
 *   Contact:  cristinel@osec.ro                                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the Crom Free License as published by           *
 *   the SC Crom-Osec SRL; version 1 of the License                        *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   Crom Free License for more details.                                   *
 *                                                                         *
 *   You should have received a copy of the Crom Free License along with   *
 *   this program; if not, write to the contact@osec.ro                    *
 ***************************************************************************/

using System;
using System.Drawing;
using System.Windows.Forms;

namespace Crom.Controls.Docking
{
   /// <summary>
   /// Inner dock preview engine
   /// </summary>
   internal sealed class InnerDockPreviewEngine
   {
      #region Fields
      #region Constants

      private const int                MaxDockPanelSize                 = 300;
      private const int                MinDockPanelSize                 = 100;

      #endregion Constants

      #endregion Fields

      #region Instance

      /// <summary>
      /// Default constructor
      /// </summary>
      private InnerDockPreviewEngine()
      {
      }

      #endregion Instance

      #region Public section

      /// <summary>
      /// Get preview bounds
      /// </summary>
      /// <param name="dock">dock for which to get the preview bounds</param>
      /// <param name="movedPanel">moved panel</param>
      /// <param name="panelUnderMouse">panel under mouse</param>
      /// <param name="freeAreaBounds">free area bounds</param>
      /// <returns>preview bounds</returns>
      public static Rectangle GetPreviewBounds(DockStyle dock, Control movedPanel, Control panelUnderMouse, Rectangle freeAreaBounds)
      {
         Rectangle bounds = freeAreaBounds;
         if (panelUnderMouse != null)
         {
            bounds = panelUnderMouse.RectangleToScreen(panelUnderMouse.ClientRectangle);
         }

         switch (dock)
         {
            case DockStyle.Left:
               return GetInnerLeftPreviewBounds(movedPanel, bounds);

            case DockStyle.Right:
               return GetInnerRightPreviewBounds(movedPanel, bounds);

            case DockStyle.Top:
               return GetInnerTopPreviewBounds(movedPanel, bounds);

            case DockStyle.Bottom:
               return GetInnerBottomPreviewBounds(movedPanel, bounds);

            case DockStyle.Fill:
               return GetInnerFillPreviewBounds(movedPanel, bounds);

            default:
               throw new InvalidOperationException();
         }
      }

      #endregion Public section

      #region Private section

      /// <summary>
      /// Get preview size
      /// </summary>
      /// <param name="movedPanel">moved panel</param>
      /// <param name="marginBounds">free area bounds</param>
      /// <returns>preview size</returns>
      private static int GetPreviewSize(Control movedPanel, DockStyle dock, Rectangle marginBounds)
      {
         if (dock == DockStyle.Left || dock == DockStyle.Right)
         {
            return Math.Min(marginBounds.Width / 2, Math.Max(MinDockPanelSize, movedPanel.Width));
         }

         return Math.Min(marginBounds.Height / 2, Math.Max(MinDockPanelSize, movedPanel.Height));
      }

      /// <summary>
      /// Get outer top preview bounds
      /// </summary>
      /// <param name="movedPanel">moved panel</param>
      /// <param name="marginBounds">free area bounds</param>
      /// <returns>outer top preview bounds</returns>
      private static Rectangle GetInnerTopPreviewBounds(Control movedPanel, Rectangle marginBounds)
      {
         if (marginBounds.IsEmpty == false)
         {
            int size = GetPreviewSize(movedPanel, DockStyle.Top, marginBounds);

            return new Rectangle(marginBounds.Left, marginBounds.Top, marginBounds.Width, size);
         }

         return new Rectangle();
      }

      /// <summary>
      /// Get outer bottom preview bounds
      /// </summary>
      /// <param name="movedPanel">moved panel</param>
      /// <param name="marginBounds">free area bounds</param>
      /// <returns>outer bottom preview bounds</returns>
      private static Rectangle GetInnerBottomPreviewBounds(Control movedPanel, Rectangle marginBounds)
      {
         if (marginBounds.IsEmpty == false)
         {
            int size = GetPreviewSize(movedPanel, DockStyle.Bottom, marginBounds);

            return new Rectangle(marginBounds.Left, marginBounds.Bottom - size, marginBounds.Width, size);
         }

         return new Rectangle();
      }

      /// <summary>
      /// Get outer left preview bounds
      /// </summary>
      /// <param name="movedPanel">moved panel</param>
      /// <param name="marginBounds">free area bounds</param>
      /// <returns>outer left preview bounds</returns>
      private static Rectangle GetInnerLeftPreviewBounds(Control movedPanel, Rectangle marginBounds)
      {
         if (marginBounds.IsEmpty == false)
         {
            int size = GetPreviewSize(movedPanel, DockStyle.Left, marginBounds);

            return new Rectangle(marginBounds.Left, marginBounds.Top, size, marginBounds.Height);
         }

         return new Rectangle();
      }

      /// <summary>
      /// Get outer right preview bounds
      /// </summary>
      /// <param name="movedPanel">moved panel</param>
      /// <param name="marginBounds">free area bounds</param>
      /// <returns>outer right preview bounds</returns>
      private static Rectangle GetInnerRightPreviewBounds(Control movedPanel, Rectangle marginBounds)
      {
         if (marginBounds.IsEmpty == false)
         {
            int size = GetPreviewSize(movedPanel, DockStyle.Right, marginBounds);

            return new Rectangle(marginBounds.Right - size, marginBounds.Top, size, marginBounds.Height);
         }

         return new Rectangle();
      }

      /// <summary>
      /// Get inner fill preview bounds
      /// </summary>
      /// <param name="movedPanel">moved panel</param>
      /// <param name="marginBounds">free area bounds</param>
      /// <returns>bounds</returns>
      private static Rectangle GetInnerFillPreviewBounds(Control movedPanel, Rectangle marginBounds)
      {
         return marginBounds;
      }

      #endregion Private section
   }
}

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