Click here to Skip to main content
15,885,953 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
/***************************************************************************
 *   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>
   /// Outer dock preview engine
   /// </summary>
   internal sealed class OuterDockPreviewEngine
   {
      #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 OuterDockPreviewEngine()
      {
      }

      #endregion Instance

      #region Public section

      /// <summary>
      /// Get preview bounds
      /// </summary>
      /// <param name="dock">dock for which to get the preview bounds</param>
      /// <param name="host">host</param>
      /// <param name="movedPanel">moved panel</param>
      /// <returns>preview bounds</returns>
      public static Rectangle GetPreviewBounds(DockStyle dock, FormWrapper host, Control movedPanel)
      {
         switch (dock)
         {
            case DockStyle.Left:
               return GetOuterLeftPreviewBounds(host, movedPanel);

            case DockStyle.Right:
               return GetOuterRightPreviewBounds(host, movedPanel);

            case DockStyle.Top:
               return GetOuterTopPreviewBounds(host, movedPanel);

            case DockStyle.Bottom:
               return GetOuterBottomPreviewBounds(host, movedPanel);

            default:
               throw new InvalidOperationException();
         }
      }

      #endregion Public section

      #region Private section

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

         return Math.Max(MinDockPanelSize, Math.Min(MaxDockPanelSize, movedPanel.Height));
      }

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

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

         return new Rectangle();
      }

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

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

         return new Rectangle();
      }

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

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

         return new Rectangle();
      }

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

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

         return new Rectangle();
      }

      #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