/// <summary> /// Adds a popup to popup stage /// </summary> /// <param name="popup">A popup to add</param> /// <param name="parent">Parent component (for position calculations)</param> /// <param name="modal">Is this a modal popup</param> /// <param name="centered">Should popup be centered</param> /// <param name="keepCenter">Should popup stay centered after the screen resize</param> public void AddPopup(DisplayListMember popup, DisplayObjectContainer parent, bool modal, bool centered, bool keepCenter) { #if TRIAL /* HACK CHECK */ Acme acme = (Acme)Framework.GetComponent <Acme>(true); if (null == acme || !acme.gameObject.activeInHierarchy /*active*/ || !acme.enabled) { return; } #endif if (_popups.Contains(popup)) { return; } #if DEBUG if (DebugMode) { Debug.Log("AddPopup"); } #endif List <PopupOption> options = new List <PopupOption> { new PopupOption(PopupOptionType.Parent, parent), new PopupOption(PopupOptionType.Modal, modal), new PopupOption(PopupOptionType.Centered, centered), new PopupOption(PopupOptionType.KeepCenter, keepCenter) }; AddPopup(popup, options.ToArray()); }
/// <summary> /// The function that filters out potential inspector targets that must be Components /// </summary> /// <param name="dlm"></param> /// <returns></returns> private static bool InspectorTargetFilter(DisplayListMember dlm) { var component = dlm as Component; if (null == component) { return(false); } if (!SystemManager.Instance.AltKeyPressed) { return(component.Visible && component.MouseEnabled); } // if Alt key pressed, do show both mouse enabled and mouse disabled components if (component is Stage) { // alow clicking the bottom stage event if there is another stage on top // so alow stages to be turned on/off with MouseEnabled as a switch return(component.Visible && component.MouseEnabled); } return(dlm.Visible); }
/// <summary> /// Updates the supplied depth list using the order list<br/> /// Generally, it removes all the depth values, refills the list, and then sorts by the child Depth value /// </summary> /// <param name="orderList"></param> /// <param name="depthList"></param> // ReSharper disable SuggestBaseTypeForParameter private static void UpdateDrawingList(List <DisplayListMember> orderList, List <DisplayListMember> depthList) // ReSharper restore SuggestBaseTypeForParameter { //Debug.Log(string.Format(" ! -> [orderList: {0}, depthList: {1}]", orderList.Count, depthList.Count)); /** * 1. Empty the list * */ depthList.Clear(); int len = orderList.Count; /** * 2. Fill the list with values from the order list * */ foreach (DisplayListMember displayListMember in orderList) { depthList.Add(displayListMember); } //Debug.Log(" depthList.Count: " + depthList.Count); if (len <= 1) { #if DEBUG if (DebugMode) { Debug.Log(string.Format(" -> [orderList: {0}, depthList: {1}] *", orderList.Count, depthList.Count)); } #endif return; // don't bother } /** * 3. Sort by Depth * */ for (int i = 1; i < len; i++) { for (int j = i; j > 0; j--) { if (depthList[j].Depth < depthList[j - 1].Depth) { _tmp = depthList[j]; depthList[j] = depthList[j - 1]; depthList[j - 1] = _tmp; } //else // break; } } //Debug.Log(ListUtil<DisplayListMember>.Format(depthList)); #if DEBUG if (DebugMode) { Debug.Log(string.Format(" -> [orderList: {0}, depthList: {1}]", orderList.Count, depthList.Count)); } #endif }
public static string CreateUid(DisplayListMember component) { if (null == component) { return(null); } Type type = component.GetType(); int count = 0; // default if (UidDict.ContainsKey(type)) { count = UidDict[type]; } count++; UidDict[type] = count; var name = type.Name; // If the class name ends with a digit (which some autogenerated // classes do), then append an underscore before appending // the counter. int charCode = name[name.Length - 1]; if (charCode >= 48 && charCode <= 57) { name += "_"; } return(string.Format("{0}{1}", name, count)); }
/// <summary> /// Gets a parent chain /// Example: If out component is in a chain Stage-A-B-C-Component, this method returns the list of: Stage, A, B, C. /// </summary> /// <param name="component">Compo</param> /// <param name="reverse">Reverse the chain</param> /// <returns></returns> public static List <DisplayListMember> GetParentChain(DisplayListMember component, bool reverse) { if (null == component) { throw new Exception("Component not defined"); } List <DisplayListMember> list = new List <DisplayListMember>(); DisplayListMember current = component; //list.Add(current); // removed on 2011-09-18 while (!(current is Stage) && null != current.Parent) { current = current.Parent; list.Add(current); } if (reverse) { list.Reverse(); } return(list); }
//private int _uid; internal void RegisterInternal(ref string uid, DisplayListMember component) { if (null == uid) { //uid = _uid++.ToString(); uid = NamingUtil.CreateUid(component); //_uid++.ToString(); } //Debug.Log(uid); if (_systemDict.ContainsKey(uid)) { #if DEBUG if (DebugMode) { Debug.Log(string.Format(ComponentManagerException.IdAlreadyRegistered, uid)); Debug.Break(); } #endif return; //TODO: Examine this error //throw new ComponentManagerException(string.Format(ComponentManagerException.IdAlreadyRegistered, uid)); } _systemDict.Add(uid, component); #if DEBUG if (DebugMode) { Debug.Log(string.Format(@"Component registered [INTERNAL]: [{0}] => {1}", uid, component)); } #endif }
public void Hover(DisplayListMember component) { _hoveredComponent = component; if (null != _stage) { _stage.Hover(component); } }
/// <summary> /// Selects the component from the outside /// </summary> /// <param name="component"></param> public void Select(DisplayListMember component) { _selectedComponent = component; if (null != _stage) { _stage.Select(component); } }
public override DisplayListMember AddChild(DisplayListMember child) { DisplayListMember c = base.AddChild(child); //c.Visible = false; // invisible by default //_childrenChanged = true; //InvalidateProperties(); return(c); }
internal static void BuildAndDispatchMouseEvent(EventDispatcher dispatcher, DisplayListMember targetComponent, string type, Point position, Event unityEvent) { //Debug.Log("BuildAndDispatchMouseEvent"); if (null == dispatcher) { throw new Exception("dispatcher cannot be null"); } if (null == targetComponent) { throw new Exception("targetComponent cannot be null"); } if (!dispatcher.HasEventListener(type) && !targetComponent.HasBubblingEventListener(type)) // optimization { return; // don't bother to build an event } //Debug.Log("unityEvent: " + unityEvent); //var ue = unityEvent ?? Event.current; //Debug.Log("ue: " + ue); //Debug.Log("ue.button: " + ue.button); /** * 1) InvalidateDrawingList the event * */ MouseEvent me = new MouseEvent(type) { Target = targetComponent, CurrentEvent = unityEvent, GlobalPosition = position, LocalPosition = targetComponent.GlobalToLocal(position) }; if (null != MouseProcessor.MouseDownEvent) { // this is not a mouse move event, but rather a mouse drag, because MouseProcessor holds the reference to a mousedown event me.ButtonDown = MouseProcessor.MouseDownEvent.button == 0; me.RightButtonDown = MouseProcessor.MouseDownEvent.button == 1; me.MiddleButtonDown = MouseProcessor.MouseDownEvent.button == 2; } /** * 2) Dispatch from manager * */ dispatcher.DispatchEvent(me); /** * 3) If not canceled, dispatch from component * */ if (!me.Canceled) { me.Bubbles = true; // added 28.1.2012. targetComponent.DispatchEvent(me); } }
override public DisplayListMember RemoveChild(DisplayListMember child) { int index = GetChildIndex(child); DisplayListMember obj = RemoveChildAt(index); //_childrenChanged = true; //InvalidateProperties(); InternalDispatchEvent(CollectionEventKind.REMOVE, obj, index); return(obj); }
public override DisplayListMember AddChildAt(DisplayListMember child, int index) { DisplayListMember obj = base.AddChildAt(child, index); obj.Visible = false; // invisible by default //_childrenChanged = true; //InvalidateProperties(); InternalDispatchEvent(CollectionEventKind.ADD, obj, index); return(obj); }
/// <summary> /// Changes the depth of a single child within the list /// </summary> /// <param name="depthList"></param> /// <param name="child"></param> /// <param name="depth"></param> /// <param name="makeRoom"></param> private static void SetDepth(List <DisplayListMember> depthList, DisplayListMember child, int depth, bool makeRoom) { //Debug.Log("Setting depth: " + depth + " [" + child + "]"); child.Depth = depth; // remove depthList.Remove(child); var index = depthList.FindIndex(delegate(DisplayListMember displayListMember) { return(displayListMember.Depth >= depth); }); if (index == -1) // not found, meaning all depths are lower than the supplied one { index = depthList.Count; } // insert at index depthList.Insert(index, child); var len = depthList.Count; // fix other depths // say depth = 1 // and that we have depths [0, 0, 1, 1, 1, 2, 6, 7] and inserting into the 3rd place (between 0 and 1) // ... [0, 0, *1, 1, 1, 1, 2, 6, 7] ... // we have to get [0, 0, *1, 2, 2, 2, 3, 6, 7] - note that some values are shifted up, but the values of 6, 7 are not because there's no need to //_prevDepth = depth; if (makeRoom) { // needs room? if (depthList.Count == index + 1 || depthList[index + 1].Depth > depth) { return; // this is the last item or the next item has a greater depth } for (int i = index + 1; i < len; i++) // from 3rd place to the end { depthList[index].Depth += 1; //var item2 = depthList[index]; // 2 //if (item2.Depth != _prevDepth) // _prevDepth = item2.Depth; // _prevDepth = 1 //if (item2.Depth == _prevDepth) // 1 == 1 //{ // item2.Depth = _prevDepth + 1; // item2.Depth = 2 //} } } }
/// <summary> /// The function that filters out potential mouse targets that must be Components /// </summary> /// <param name="dlm"></param> /// <returns></returns> private static bool MouseTargetFilter(DisplayListMember dlm) { var component = dlm as Component; if (null == component) { return(false); } // get visible and mouse enabled COMPONENTS return(component.Visible && component.MouseEnabled); }
private static bool Contains(IInvalidationManagerClient parent, DisplayListMember child) { var doc = parent as DisplayObjectContainer; if (null != doc) { // include me in the search! return(doc.Contains(child, true)); // BUG BUG - this was a bug - it was parent.Children.Contains(), which doesn't go deep, only the direct children!!! } return(parent == child); }
public override void SetFocus() { DisplayListMember firstFocusableItem = Children.Find(delegate(DisplayListMember control) { return(((InteractiveComponent)control).FocusEnabled); }); //Debug.Log("firstFocusableItem == null: " + (firstFocusableItem == null)); if (null != firstFocusableItem) { ((InteractiveComponent)firstFocusableItem).SetFocus(); } else { base.SetFocus(); } }
/// <summary> /// We should listen the mouse move events over the component /// If mouse moved over the event, we should check border and draw overlay /// </summary> /// <param name="e"></param> private void ComponentMouseMoveHandler(Event e) { if (!Enabled) { return; } Debug.Log(string.Format("ComponentMouseMoveHandler [{0}, {1}]", e.Phase, e.CurrentTarget)); if (!(e.Target is DisplayListMember)) { return; } DisplayListMember dlm = (DisplayListMember)e.Target; MouseEvent me = (MouseEvent)e; //Container container = _component as Container; //Point coordsInComponentSpace = null != container ? // container.GlobalToContent(dlm.LocalToGlobal(me.LocalPosition)) : // _component.GlobalToLocal(dlm.LocalToGlobal(me.LocalPosition)); Point coordsInComponentSpace = _component.GlobalToLocal(dlm.LocalToGlobal(me.LocalPosition)); // if some component is already being dragged/resized, do not draw borders on hover if (DragManager.IsDragging) { return; } if (_constraintMode) { _constrainedRect = _constraintMetrics.GetConstrainedRectangle(_component.Transform.LocalBounds); DoRenderOverlay = _constrainedRect.Contains(coordsInComponentSpace); } else { DoRenderOverlay = true; } if (DoRenderOverlay) { e.Cancel(); } }
//internal void MouseOutHandler(Event e) internal void MouseOutSlot(params object[] parameters) { //Component comp = (Component)parameters[0]; #if DEBUG if (DebugMode) { Debug.Log("GuiInspector->MouseOutSlot"); } #endif if (Sticky) { return; } _currentComponent = null; HideOverlay(); }
/// <summary> /// Pushes the child to back in a depth list /// </summary> /// <param name="depthList"></param> /// <param name="child"></param> public static void PushToBack(List <DisplayListMember> depthList, DisplayListMember child) { var min = GetMinDepth(depthList); //Debug.Log("min: " + min); if (child.Depth < min) { return; } if (child.Depth == min && IsOnlyChildWithDepth(depthList, child, min)) { return; } SetDepth(depthList, child, GetMinDepth(depthList) - 1, true); }
/// <summary> /// Returns the string presentation of the component /// </summary> /// <param name="displayObject"></param> /// <returns></returns> public static string DisplayListMemberToString(DisplayListMember displayObject) { //Debug.Log("######## DisplayListMemberToString: " + displayObject.GetType() + "/" + displayObject.Name); #region Commented on 20130313 because wiring up ID from the Adapter string result = null; for (DisplayListMember control = displayObject; control != null; control = control.Parent) { // If this object is in the display tree, // stop after we've prepended the topmost Application instance. //if (null != control.Owner // && null != control.Stage // && control.Owner == control.Stage) // break; // Prefer id over name if specified. //string s = "id" in o && o["id"] ? o["id"] : o.name; //string s = control.Uid ?? control.Name; string name = control.Name; if (!string.IsNullOrEmpty(control.Id)) { name = string.Format("{0}[{1}]", name, control.Id); } result = (null == result) ? name : name + "." + result; } return(result); #endregion //string result = displayObject.ToString(); //if (!string.IsNullOrEmpty(displayObject.Id)) // result += string.Format(@" [Id=""{0}""]", displayObject.Id); //return result; }
/// <summary> /// Fires on mouse-overed component change<br/> /// Since in editor overlay we are dealing with adapters, we need to examine if the mouse-overed component is related to any adapter<br/> /// We do that by looking for the adapter via GuiLookup, which finds the adapter in component parent<br/> /// We then examine if the current selection changed. If it did, we are calling the Select method /// </summary> private void MouseOverSlot(params object[] parameters) { Component comp = (Component)parameters[0]; #if DEBUG if (DebugMode) { Debug.Log("DesignerOverlay->MouseOverSlot: " + comp); } #endif if (null == comp) { return; } GameObject go = GuiLookup.GetGameObject(comp); if (null == go) { return; } ComponentAdapter adapter = (ComponentAdapter)go.GetComponent(typeof(ComponentAdapter)); if (null == adapter) { return; } if (null == adapter.Component) { return; } _hoveredComponent = adapter.Component; #if DEBUG if (DebugMode) { Debug.Log("Hover: " + _hoveredComponent); } #endif Hover(_hoveredComponent); }
internal void SpecialClickHandler(Event e) { #if DEBUG if (DebugMode) { Debug.Log("DesignerOverlay->SpecialClickHandler: " + e.Target); } #endif MouseEvent me = (MouseEvent)e; if (me.CurrentEvent.control || me.CurrentEvent.shift) { e.CancelAndStopPropagation(); // disable the actual button click in the capture phase. Sweet ^_^ } GameObject go = GuiLookup.GetGameObject((Component)e.Target); if (null == go) { _hoveredComponent = null; ClickSignal.Emit(null, e); return; } ComponentAdapter adapter = (ComponentAdapter)go.GetComponent(typeof(ComponentAdapter)); if (null == adapter) { _hoveredComponent = null; ClickSignal.Emit(null, e); return; } if (null == adapter.Component) { _hoveredComponent = null; ClickSignal.Emit(null, e); return; } _hoveredComponent = adapter.Component; ClickSignal.Emit(_hoveredComponent, e); }
//private void MouseOverHandler(Event e) private void MouseOverSlot(params object[] parameters) { Component comp = (Component)parameters[0]; #if DEBUG if (DebugMode) { Debug.Log("GuiInspector->MouseOverSlot"); } #endif if (Sticky) { return; } _currentComponent = comp; //_stack.Clear(); ShowOverlay(_currentComponent); }
/// <summary> /// Searchs throughout ALL STAGES for the top-most component /// Starts with the stage in front (with the lowest depth) and goes to higher depths /// Returns as soon as it finds any component /// </summary> /// <param name="coords"></param> /// <param name="filter"></param> /// <param name="stopOnDisabled"></param> /// <param name="stopOnInvisible">Should we stop on invisible component</param> /// <returns></returns> internal static DisplayListMember GetComponentUnderCoordinatesOnAllStages(Point coords, Filter filter, bool stopOnDisabled, bool stopOnInvisible) { //Debug.Log("GetComponentUnderCoordinatesOnAllStages: " + coords); if (null == StageListAsc) { return(null); // could be null on recompile // throw new Exception("StageListAsc is null"); //return null; } DisplayListMember comp = null; int stageCount = StageListAsc.Count; // using the ascending stage list int count = 0; // search from the front stage to the back while (null == comp && count < stageCount) { Stage stage = StageListAsc[count]; count++; if (null != ExcludedStages && ExcludedStages.Contains(stage)) // skip excluded stages { continue; } // search the component on a stage DisplayListMember dlm = GetComponentUnderCoordinates(stage, coords, filter, stopOnDisabled, stopOnInvisible); if (null != dlm) { comp = dlm; // component found, this breaks the while loop } } #if DEBUG if (DebugMode) { Debug.Log(string.Format("ClickManager: GetComponentUnderCoordinatesOnAllStages returns [{0}]", (null != comp) ? comp.ToString() : "*NULL*")); } #endif return(comp); }
internal void KeyUpHandler(UnityEngine.Event e) { #if DEBUG if (DebugMode) { Debug.Log("GuiInspector->KeyUpHandler"); } #endif if (e.keyCode == KeyCode.Escape) { if (null != _currentComponent) { // clear all //_stack.Clear(); _currentComponent = null; Sticky = false; HideOverlay(); } } }
internal void ClickHandler(Event e) { //Debug.Log("GuiInspector->ClickHandler: " + e.Target); #if DEBUG if (DebugMode) { Debug.Log("GuiInspector->ClickHandler"); } #endif MouseEvent me = (MouseEvent)e; if (me.CurrentEvent.control || me.CurrentEvent.shift) { //Debug.Log("Click"); if (Sticky) { // we are in sticky mode if (e.Target == _currentComponent) // clicking the same component resets Sticky { Sticky = false; } else // else set new component as Sticky { _currentComponent = (Component)e.Target; } } else // turn off sticky { Sticky = true; } _sticky = Sticky; // cancel off GUI changes e.CancelAndStopPropagation(); // disable the actual button click in capture phase. Sweet ^_^ } //_stack.Clear(); //ClickSignal.Emit(_currentComponent); //Debug.Log("ClickSignal.NumSlots: " + ClickSignal.NumSlots); }
internal void DoShowOverlay(DisplayObject target) { if (null == target) { return; } DisplayListMember dlm = target as DisplayListMember; // do not analyze anything from this stage if (null != dlm && !GuiInspector.IsInspectable(dlm)) { return; } if (null != _overlay) { _overlay.Visible = true; _overlay.Redraw(target.Transform.GlobalBounds, Bounds, NamingUtil.DisplayListMemberToString((DisplayListMember)target)); } //InspectorDetailsWindow.Instance.Inform(); }
/// <summary> /// Checks if the component has the listener or any of component's ancestors /// have listeners for the supplied event type /// </summary> /// <param name="eventType"></param> /// <param name="target"></param> /// <returns></returns> internal static bool HasBubblingEventListener(string eventType, DisplayListMember target) { /** * 0) Get parent chain * */ List <DisplayListMember> parentChain = ComponentUtil.GetParentChain(target, true); parentChain.Add(target); // add myself /** * 1) Look for at least one subscribed component * */ foreach (DisplayListMember component in parentChain) { if (component.HasEventListener(eventType)) { return(true); } } return(false); // no subscribed components }
/// <summary> /// The function that filters out only scroll-enabled Components /// </summary> /// <param name="dlm"></param> /// <returns></returns> private static bool MouseWheelFilter(DisplayListMember dlm) { //Debug.Log("MouseWheelFilter: " + dlm); var component = dlm as Component; if (null == component) { return(false); } /** * 1. not a candidate - return * */ if (!component.MouseEnabled) // this blocks the Group from mouse wheeling { return(false); } /** * 2. not a candidate - return * */ if (!component.Visible) // || !component.MouseEnabled) { return(false); } ///** // * 2. forced mouse wheel target // * */ //if (component.StopMouseWheelPropagation) // return true; //Debug.Log(" -> passed"); return(true); }
/// <summary> /// Brings the child to front in a depth list /// </summary> /// <param name="depthList"></param> /// <param name="child"></param> public static void BringToFront(List <DisplayListMember> depthList, DisplayListMember child) { //Debug.Log("BringToFront"); var max = GetMaxDepth(depthList); //Debug.Log(string.Format(@"depthList.Count: {0}; max: {1}; child.Depth: {2}; child: {3}", depthList.Count, max, child.Depth, child)); if (child.Depth > max) { return; } //Debug.Log(1); if (child.Depth == max && IsOnlyChildWithDepth(depthList, child, max)) { return; } //Debug.Log(2); SetDepth(depthList, child, GetMaxDepth(depthList) + 1, true); }