/// <summary>
 /// Adjusts offsets of graphic object.
 /// </summary>
 /// <param name="graphicObject">Graphic object to process</param>
 /// <param name="dx">Displacement along the x-axis</param>
 /// <param name="dy">Displacement along the y-axis</param>
 /// <param name="resDx">Resulting displacement along the x-axis</param>
 /// <param name="resDy">Resulting displacement along the y-axis</param>
 public void AdjustOffsets(IGraphicObject graphicObject, int dx, int dy, out int resDx, out int resDy)
 {
     if (graphicObject == null)
     {
         throw new ArgumentNullException(nameof(graphicObject));
     }
     var boundRect = graphicObject.GetBoundRectangle();
     boundRect.Offset(dx, dy);
     if (dx < 0)
     {
         resDx = boundRect.Left < 0 ? dx - boundRect.Left : dx;
     }
     else
     {
         resDx = boundRect.Right > Width ? dx - (boundRect.Right - Width) : dx;
     }
     if (dy < 0)
     {
         resDy = boundRect.Top < 0 ? dy - boundRect.Top : dy;
     }
     else
     {
         resDy = boundRect.Bottom > Height ? dy - (boundRect.Bottom - Height) : dy;
     }
 } 
Exemplo n.º 2
0
        /// <summary>
        /// Some sort of optimization. Checks if current graphic object is covered by selected one.
        /// </summary>
        /// <param name="graphicObject">Object for check</param>
        /// <returns>Return true if current graphic object is covered by selected on otherwise - false</returns>
        private bool IsCoverBySelectedObject(IGraphicObject graphicObject)
        {
            lock (_selectedObjectLock)
            {
                if (_selectedGraphicObject == null ||
                    graphicObject == _selectedGraphicObject)
                {
                    return false;
                }
                var selectedBoundRect = _selectedGraphicObject.GetBoundRectangle();
                var boundRect = graphicObject.GetBoundRectangle();

                var union = Rectangle.Union(selectedBoundRect, boundRect);
                if (union == selectedBoundRect)
                {
                    return true;
                }
                return false;
            }
           
        }