/// <summary> /// Looks for a stack of components under the specified coordinates inside of the parent component /// Does the top-down processing: from parent to children /// Returns the top-most rendered component on given coordinates (on a single stage) /// Notes: /// 1. The returned list must be refersed in order to get the top component at the beginning of the list! /// 2. This is a recursive operation /// </summary> /// <param name="dlm">Parent component</param> /// <param name="coords">Coordinates</param> /// <param name="filter">Filter</param> /// <param name="stopOnDisabled">Should the process stop if component disabled</param> /// <param name="stopOnInvisible">Should the process stop if component not visible></param> /// <param name="list">The list passed by reference</param> /// <returns></returns> private static void GetComponentStackUnderCoordinates(DisplayListMember dlm, Point coords, Filter filter, bool stopOnDisabled, bool stopOnInvisible, ref List<DisplayListMember> list) { var component = dlm as InteractiveComponent; //Debug.Log("GetComponentStackUnderCoordinates: " + dlm); if (null != component) { if (stopOnInvisible && !dlm.Visible) // invisible return; if (stopOnDisabled && !component.Enabled) // disabled return; } _containsPoint = dlm.ContainsPoint(coords, false); //Debug.Log(" _containsPoint: " + dlm); if (_containsPoint && PassesFilter(dlm, filter)) { //Debug.Log(" PassesFilter: " + dlm); list.Add(dlm); } Group @group = dlm as Group; // in the case of container check the children if (null != @group) { if (!_containsPoint /*&& container.QClipContent*/) return; // the click was inside the container bounds, or container isn't clipping // check the children for clicks if (@group.MouseChildren) { foreach(DisplayListMember d in @group.QDrawingList) { //Component child = d as Component; //if (null != child) //{ /* Recursive call! */ //DisplayListMember c = GetComponentUnderCoordinates(d, coords, filter, stopOnDisabled); GetComponentStackUnderCoordinates(d, coords, filter, stopOnDisabled, stopOnInvisible, ref list); //Debug.Log(" -> " + c); //if (null != c) // list.Add(c); //} } } } else // simple component { DisplayObjectContainer doc = dlm as DisplayObjectContainer; // the click was inside the container bounds, or container isn't clipping // check the children for clicks if (null != doc && doc.QNumberOfChildren > 0 && doc.MouseChildren) { foreach (DisplayListMember d in doc.QDrawingList) { GetComponentStackUnderCoordinates(d, coords, filter, stopOnDisabled, stopOnInvisible, ref list); //DisplayListMember c = GetComponentUnderCoordinates(d, coords, filter, stopOnDisabled); //if (null != c) // list.Add(c); } } } }
/// <summary> /// Looks for a front-most component inside of the parent component /// Goes top-down, from parent to children /// Returns the front-most rendered component on given coordinates (on a single stage) /// NOTE: RECURSIVE!!! /// </summary> /// <param name="dlm"></param> /// <param name="coords">Coordinates to test</param> /// <param name="filter">Filter</param> /// <param name="stopOnDisabled">Should we stop on disabled component</param> /// <param name="stopOnInvisible">Should we stop on invisible component</param> /// <returns></returns> // ReSharper disable SuggestBaseTypeForParameter private static DisplayListMember GetComponentUnderCoordinates(DisplayListMember dlm, Point coords, Filter filter, bool stopOnDisabled, bool stopOnInvisible) // ReSharper restore SuggestBaseTypeForParameter { //Debug.Log("GetComponentUnderCoordinates: " + dlm); InteractiveComponent component = dlm as InteractiveComponent; if (null != component) { if (stopOnInvisible && !component.Visible) // invisible return null; if (stopOnDisabled && !component.Enabled) // disabled return null; } DisplayListMember output = null; _containsPoint = dlm.ContainsPoint(coords, false); if (_containsPoint && PassesFilter(dlm, filter)) { output = component; } GroupBase group = dlm as GroupBase; if (null != group) { if (!_containsPoint && group.ClipAndEnableScrolling) return output; if (group.MouseChildren) { foreach (DisplayListMember d in group.QDrawingList) { /* Recursive call! */ DisplayListMember c = GetComponentUnderCoordinates(d, coords, filter, stopOnDisabled, stopOnInvisible); if (null != c) output = c; } } } else // simple component { var doc = dlm as DisplayObjectContainer; if (null != doc) { if (doc.MouseChildren/* && doc.QNumberOfChildren > 0*/) { foreach (DisplayListMember d in doc.QDrawingList) { /* Recursive call! */ DisplayListMember c = GetComponentUnderCoordinates(d, coords, filter, stopOnDisabled, stopOnInvisible); if (null != c) output = c; } } } } return output; }