Exemple #1
0
        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);
        }
Exemple #2
0
        /// <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);
        }
        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);
            }
        }
        /// <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
        }
Exemple #5
0
        /// <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);
        }
Exemple #6
0
        /// <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;
        }
Exemple #7
0
 /// <summary>
 /// Returns true if the stage contains the specified child
 /// </summary>
 /// <param name="child"></param>
 /// <returns></returns>
 public bool Contains(DisplayListMember child)
 {
     return Stage.ContentContains(child);
 }
Exemple #8
0
 override public int GetContentChildIndex(DisplayListMember child)
 {
     //return GetContentChildIndex(child);
     return GetChildIndex(child);
 }
Exemple #9
0
 /// <summary>
 /// Returns true if the stage contains the specified child
 /// </summary>
 /// <param name="child"></param>
 /// <returns></returns>
 public bool HasChild(DisplayListMember child)
 {
     return Stage.HasContentChild(child);
 }
Exemple #10
0
 ///<summary>
 /// Sets stage child index
 ///</summary>
 ///<param name="child"></param>
 ///<param name="index"></param>
 public void SetChildIndex(DisplayListMember child, int index)
 {
     Stage.SetChildIndex(child, index);
 }
Exemple #11
0
 /// <summary>
 /// Adds a popup to popup stage
 /// </summary>
 /// <param name="popup">A popup to add</param>
 /// <param name="modal">Is this a modal popup</param>
 /// <param name="centered">Is the popup centered</param>
 public void AddPopup(DisplayListMember popup, bool modal, bool centered)
 {
     AddPopup(popup, _stage, modal, centered); // application by default
 }
Exemple #12
0
 /// <summary>
 /// Adds a child to the container to the specified index
 /// </summary>
 /// <param name="child">A child</param>
 /// <param name="index">Index</param>
 public DisplayListMember AddChildAt(DisplayListMember child, int index)
 {
     return Stage.AddContentChildAt(child, index);
 }
Exemple #13
0
 ///<summary>
 /// Swaps two children of the stage
 ///</summary>
 ///<param name="firstChild">First child</param>
 ///<param name="secondChild">Second child</param>
 public void SwapChildren(DisplayListMember firstChild, DisplayListMember secondChild)
 {
     Stage.SwapContentChildren(firstChild, secondChild);
 }
Exemple #14
0
 public virtual bool ContentContains(DisplayListMember child)
 {
     return Contains(child);
 }
Exemple #15
0
 // ReSharper disable UnusedMember.Global
 public virtual bool ContentContains(DisplayListMember child, bool includeThisCheck)
 // ReSharper restore UnusedMember.Global
 {
     return Contains(child, includeThisCheck);
 }
Exemple #16
0
 /// <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>
 public void AddPopup(DisplayListMember popup, DisplayObjectContainer parent, bool modal, bool centered)
 {
     AddPopup(popup, parent ?? _stage, modal, centered, false);
 }
Exemple #17
0
 public virtual bool HasContentChild(DisplayListMember child)
 {
     return HasChild(child);
 }
Exemple #18
0
        /// <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;
        }
Exemple #19
0
        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;
        }
Exemple #20
0
 /// <summary>
 /// Adds a popup to popup stage
 /// </summary>
 /// <param name="popup">A popup to add</param>
 public void AddPopup(DisplayListMember popup)
 {
     AddPopup(popup, true); // modal by default
 }
Exemple #21
0
 /// <summary>
 /// Returns true if the stage contains the specified child
 /// </summary>
 /// <param name="child"></param>
 /// <param name="exclusive"></param>
 /// <returns></returns>
 public bool Contains(DisplayListMember child, bool exclusive)
 {
     return Stage.ContentContains(child, exclusive);
 }
Exemple #22
0
        /// <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());
        }
Exemple #23
0
 /// <summary>
 /// Adds the child to a stage
 /// </summary>
 /// <param name="child"></param>
 /// <returns></returns>
 public DisplayListMember AddChild(DisplayListMember child)
 {
     return Stage.AddContentChild(child);
 }
Exemple #24
0
 public virtual DisplayListMember AddContentChildAt(DisplayListMember child, int index)
 {
     return AddChildAt(child, index);
 }
Exemple #25
0
 /// <summary>
 /// Removes a chold from the stage
 /// </summary>
 /// <param name="child"></param>
 /// <returns></returns>
 public DisplayListMember RemoveChild(DisplayListMember child)
 {
     return Stage.RemoveContentChild(child);
 }
Exemple #26
0
 public virtual DisplayListMember RemoveContentChild(DisplayListMember child)
 {
     return RemoveChild(child);
 }
Exemple #27
0
 /// <summary>
 /// Gets stage child index
 /// </summary>
 /// <param name="child">A child</param>
 /// <returns>The position</returns>
 public int GetChildIndex(DisplayListMember child)
 {
     return Stage.GetContentChildIndex(child);
 }
Exemple #28
0
 public virtual void SwapContentChildren(DisplayListMember firstElement, DisplayListMember secondElement)
 {
     SwapChildren(firstElement, secondElement);
 }
Exemple #29
0
 public virtual DisplayListMember AddContentChild(DisplayListMember child)
 {
     return AddChild(child);
 }
Exemple #30
0
 /// <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>
 public void AddPopup(DisplayListMember popup, DisplayObjectContainer parent, bool modal)
 {
     AddPopup(popup, parent ?? _stage, modal, true); // centered by default
 }