示例#1
0
 internal void Update(GuiElement element)
 {
     lock (Locker)
     {
         _elements.Remove(element);
         _elements.Add(element);
     }
 }
示例#2
0
        internal override void Draw()
        {
            GuiElement lastEl = null;

            if (_needsRearranged)
            {
                lock (Locker)
                {
                    var count = _elements.Count;
                    for (int i = 0; i < count; i++)
                    {
                        var el = _elements[i];

                        var startP = AbsolutePosition;
                        var startS = Vector2.Zero;

                        if (lastEl != null)
                        {
                            startP = lastEl.AbsolutePosition;
                            startS = lastEl.AbsoluteSize * _directionVec;
                        }

                        if (Reversed)
                        {
                            el.AbsolutePosition = startP - _offset - startS;
                        }
                        else
                        {
                            el.AbsolutePosition = startP + _offset + startS;
                        }
                        el.Arrange();

                        el.Children.EnterReadLock();
                        foreach (var child in el.Children)
                        {
                            var chel = child as GuiElement;
                            chel?.Measure();
                        }
                        el.Children.ExitReadLock();

                        lastEl = el;
                    }
                    _needsRearranged = false;
                }
            }

            base.Draw();
        }
示例#3
0
        /// <summary>
        /// Sets the element and property that the animation will be applied to.
        /// </summary>
        public void SetTarget(GuiElement element, string property)
        {
            lock (Locker)
            {
                if (element == null)
                {
                    throw new ArgumentException("The target element cannot be null.");
                }
                if (string.IsNullOrEmpty(property))
                {
                    throw new ArgumentException("The target property cannot be null or empty.");
                }

                var prop       = element.GetType().GetProperty(property);
                var instAttr   = prop?.DeclaringType?.GetCustomAttribute <TypeIdAttribute>();
                var memberAttr = prop?.GetCustomAttribute <InstMemberAttribute>();

                if (prop == null)
                {
                    throw new ArgumentException($"No property found for \"{property}\".");
                }
                if (prop.PropertyType != TargetType)
                {
                    throw new ArgumentException(
                              $"The animation type ({TargetType}) does not match the property type of \"{property}\" ({prop.PropertyType}).");
                }
                if ((memberAttr == null) || (instAttr == null))
                {
                    throw new ArgumentException($"The property {property} of {element} cannot be animated.");
                }

                TargetProperty =
                    Inst.TypeDictionary[element.ClassName].TaggedProperties[
                        Inst.EncodePropertyTag(instAttr.Id, memberAttr.Tag)];
                TargetElement = element;
            }
        }
示例#4
0
        private bool HitTestItem(ref GuiElement el, float x, float y, bool includeZIndexed, out GuiElement result)
        {
            result = null;

            if (el == null || !el.CheckCanDraw() || (el.ZIndex != 0 && !includeZIndexed))
            {
                return(false);
            }

            if (el.LayoutRect.Contains(x, y) && el.IsHitTestVisible & el.BackgroundColour.a > 0)
            {
                result = el;
                return(true);
            }

            var children = el.Children;

            for (int i = 0; i < children.Count; i++)
            {
                GuiElement item;
                var        child = children[i] as GuiElement;
                if (HitTestItem(ref child, x, y, includeZIndexed, out item))
                {
                    result = item;
                    return(true);
                }
            }

            return(false);
        }