BoxDiagrams.DiagramControl.HitTest C# (CSharp) Method

HitTest() private method

private HitTest ( Loyc.Geometry.Point mouseLoc ) : Util.WinForms.HitTestResult
mouseLoc Loyc.Geometry.Point
return Util.WinForms.HitTestResult
		internal Util.WinForms.HitTestResult HitTest(PointT mouseLoc)
		{
			var mouseSS = ToShapeSpace(mouseLoc); // SS=Shape Space
			var htRadiusSS = ToShapeSpace(HitTestRadius);
			Util.WinForms.HitTestResult best = null;
			bool bestSel = false;
			int bestZOrder = 0;
			foreach (IShapeWidget shapeW in WidgetsOnScreen(mouseLoc))
			{
				var shape = shapeW as Shape;
				var result = shapeW.HitTest(mouseSS, htRadiusSS, GetSelType(shapeW as Shape));
				if (result != null)
				{
					Debug.Assert(result.Shape == shapeW);
					bool resultSel = shape == null || _selectedShapes.Contains(shape);
					int zOrder = shape != null ? shape.HitTestZOrder : int.MaxValue;
					// Prefer to hit test against an already-selected shape (unless 
					// it's a panel) or a non-Shape widget, otherwise the thing with 
					// the highest Z-order.
					if (shape != null && shape.IsPanel)
						resultSel = false;
					if (best == null || (resultSel && !bestSel) || (bestSel == resultSel && bestZOrder < zOrder))
					{
						best = result;
						bestSel = resultSel;
						bestZOrder = zOrder;
					}
				}
			}
			return best;
		}