Пример #1
0
 /// <summary>
 /// This constructor builds a new helpline object with given coordinates.
 /// </summary>
 /// <param name="host">The related control</param>
 /// <param name="helpLine">Properties</param>
 /// <param name="extender">Reference to editor component.</param>
 internal HelpLineBehavior(IHtmlEditor host, HelpLineProperties helpLine, HelpLine extender) : base(host)
 {
     _host = host;
     _host.ReadyStateComplete += new EventHandler(_host_ReadyStateComplete);
     // store the instances to help the behavior to work on multiple extenders
     instance      = instanceCounter++;
     this.extender = extender;
     _snapToGrid   = helpLine.SnapToGrid;
     _snapgrid     = helpLine.SnapGrid;
     // assure a valid value, avoid Div by zero
     if (_snapToGrid && _snapgrid == 0)
     {
         _snapgrid = 16;
     }
     snapZone            = helpLine.SnapZone;
     base.HtmlPaintFlag  = HtmlPainter.Transparent;
     base.HtmlZOrderFlag = HtmlZOrder.AboveContent;
     _style        = new Pen(helpLine.LineColor, (float)helpLine.LineWidth);
     _lineVisible  = helpLine.LineVisible;
     _snapelements = helpLine.SnapElements;
     _lineXEnabled = helpLine.LineXEnabled;
     _lineYEnabled = helpLine.LineYEnabled;
     _crossEnabled = helpLine.CrossEnabled;
     this.x        = helpLine.X;
     this.y        = helpLine.Y;
 }
Пример #2
0
        private HelpLineProperties EnsurePropertiesExists(IHtmlEditor key)
        {
            HelpLineProperties p = (HelpLineProperties)properties[key];

            if (p == null)
            {
                p = new HelpLineProperties();
                properties[key] = p;
            }
            return(p);
        }
Пример #3
0
        /// <summary>
        /// Calculate the snap position based on the given properties.
        /// </summary>
        /// <param name="rect">Snap position.</param>
        /// <param name="pVar">Zone control.</param>
        /// <param name="properties">Read properties that influence the calculation.</param>
        /// <param name="scrollPos">Current scroll position used to correct the snap's position.</param>
        public static void SnapRectToHelpLine(ref System.Drawing.Rectangle rect, SnapZone pVar, HelpLineProperties properties, System.Drawing.Point scrollPos)
        {
            if (properties.SnapElements)
            {
                int x        = properties.X + scrollPos.X;
                int y        = properties.Y + scrollPos.Y;
                int snapzone = properties.SnapZone;
                switch (pVar)
                {
                case SnapZone.None:
                    if (IsBetween(rect.Left, x - snapzone, x + snapzone))
                    {
                        rect.X = x;
                    }
                    if (IsBetween(rect.Right, x - snapzone, x + snapzone))
                    {
                        rect.X = (x - rect.Width);
                    }
                    if (IsBetween(rect.Top, y - snapzone, y + snapzone))
                    {
                        rect.Y = y;
                    }
                    if (IsBetween(rect.Bottom, y - snapzone, y + snapzone))
                    {
                        rect.Y = (y - rect.Height);
                    }
                    return;

                case SnapZone.ZoneTop:
                    if (properties.SnapOnResize && IsBetween(rect.X, y - snapzone, y + snapzone))
                    {
                        rect.Y = properties.Y;
                    }
                    return;

                case SnapZone.ZoneLeft:
                    if (properties.SnapOnResize && IsBetween(rect.Left, x - snapzone, x + snapzone))
                    {
                        rect.X = x;
                    }
                    return;

                case SnapZone.ZoneBottom:
                    if (properties.SnapOnResize && IsBetween(rect.Bottom, y - snapzone, y + snapzone))
                    {
                        rect.Y = (y - rect.Height);
                    }
                    return;

                case SnapZone.ZoneRight:
                    if (properties.SnapOnResize && IsBetween(rect.Right, x - snapzone, x + snapzone))
                    {
                        rect.X = (x - rect.Width);
                    }
                    return;

                case SnapZone.CornerTopLeft:
                    if (properties.SnapOnResize && (IsBetween(rect.Top, y - snapzone, y + snapzone) || IsBetween(rect.Left, x - snapzone, x + snapzone)))
                    {
                        rect.Y = y;
                        rect.X = x;
                    }
                    return;

                case SnapZone.CornerTopRight:
                    if (properties.SnapOnResize && (IsBetween(rect.Top, y - snapzone, y + snapzone) || IsBetween(rect.Right, x - snapzone, x + snapzone)))
                    {
                        rect.Y = y;
                        rect.X = (x - rect.Width);
                    }
                    return;

                case SnapZone.CornerBottomLeft:
                    if (properties.SnapOnResize && (IsBetween(rect.Bottom, properties.Y - snapzone, y + snapzone) || IsBetween(rect.Left, x - snapzone, x + snapzone)))
                    {
                        rect.Y = (y - rect.Height);
                        rect.X = x;
                    }
                    return;

                case SnapZone.CornerBottomRight:
                    if (properties.SnapOnResize && (IsBetween(rect.Bottom, y - snapzone, y + snapzone) || IsBetween(rect.Right, x - snapzone, x + snapzone)))
                    {
                        rect.Y = (y - rect.Height);
                        rect.X = (x - rect.Width);
                    }
                    return;

                default:
                    return;
                }
            }
        }