Exemple #1
0
 protected void AddExpandElement(UI.Element element)
 {
     EffectsTop.Add(new ExpandEffect(element));
     ExpandEffect.Add(new Tuple <UI.Element, double>(element, (double)element.FixedWidth));
     ExpandEffect.Refresh();
     element.FixedWidth = 50;
     element.TextColor  = Color.MultAlpha(element.TextColor, 0);
     AddElement(element);
 }
Exemple #2
0
 protected void AddElement(UI.Element element)
 {
     Frame.Add(element);
 }
Exemple #3
0
    void SelectNext(Vec2 dir)
    {
        if (Elements.Count == 0)
        {
            foreach (var a in Frame.Children)
            {
                if (a is UI.ElementList)
                {
                    foreach (var b in a.Children)
                    {
                        if (!(b is Label))
                        {
                            Elements.Add(b);
                        }
                    }
                }
                else if (!(a is Label))
                {
                    Elements.Add(a);
                }
            }
        }
        if (Selected == null)
        {
            Selected = Elements[0];
            if (Selected.Focusable)
            {
                Selected.Focused = true;
            }
            else
            {
                Selected.Hovered = true;
            }
            return;
        }
        if (Focus != null)
        {
            return;
        }
        Vec2 SelectedVec = Selected.Position;

        if (dir.X == 1)
        {
            if (IsRight(SelectedVec))
            {
                SelectedVec = new Vec2(0, SelectedVec.Y);
            }
            List <UI.Element> t = Elements.FindAll(new Predicate <UI.Element>(Elem => Elem.Position.X > SelectedVec.X));
            t.Sort(new Comparison <UI.Element>(
                       delegate(UI.Element e1, UI.Element e2) { return(e1.Position.X.CompareTo(e2.Position.X)); }));
            t = t.FindAll(new Predicate <UI.Element>(
                              Elem => Elem.Position.X == t[0].Position.X));

            int result = t.BinarySearch(Selected, Comparer <UI.Element> .Create(
                                            delegate(UI.Element e1, UI.Element e2) { return(e2.Position.Y.CompareTo(e1.Position.Y)); }));
            if (result < 0)
            {
                result = ~result == t.Count ? ~result - 1 : ~result;
            }
            Next = t[result];
        }
        if (dir.X == -1)
        {
            if (IsLeft(SelectedVec))
            {
                SelectedVec = new Vec2(App.Width, SelectedVec.Y);
            }
            List <UI.Element> t = Elements.FindAll(new Predicate <UI.Element>(Elem => Elem.Position.X < SelectedVec.X));
            t.Sort(new Comparison <UI.Element>(
                       delegate(UI.Element e1, UI.Element e2) { return(e2.Position.X.CompareTo(e1.Position.X)); }));
            t = t.FindAll(new Predicate <UI.Element>(
                              Elem => Elem.Position.X == t[0].Position.X));

            int result = t.BinarySearch(Selected, Comparer <UI.Element> .Create(
                                            delegate(UI.Element e1, UI.Element e2) { return(e2.Position.Y.CompareTo(e1.Position.Y)); }));
            if (result < 0)
            {
                result = ~result == t.Count ? ~result - 1 : ~result;
            }
            Next = t[result];
        }
        if (dir.Y == 1)
        {
            if (IsTop(SelectedVec))
            {
                SelectedVec = new Vec2(SelectedVec.X, 0);
            }
            List <UI.Element> t = Elements.FindAll(new Predicate <UI.Element>(Elem => Elem.Position.Y > SelectedVec.Y));
            t.Sort(new Comparison <UI.Element>(
                       delegate(UI.Element e1, UI.Element e2) { return(e1.Position.Y.CompareTo(e2.Position.Y)); }));
            t = t.FindAll(new Predicate <UI.Element>(
                              Elem => Elem.Position.Y == t[0].Position.Y));
            int result = t.BinarySearch(Selected, Comparer <UI.Element> .Create(
                                            delegate(UI.Element e1, UI.Element e2) { return(e1.Position.X.CompareTo(e2.Position.X)); }));
            if (result < 0)
            {
                result = ~result == t.Count ? ~result - 1 : ~result;
            }
            Next = t[result];
        }
        if (dir.Y == -1)
        {
            if (IsBot(SelectedVec))
            {
                SelectedVec = new Vec2(SelectedVec.X, App.Height);
            }
            List <UI.Element> t = Elements.FindAll(new Predicate <UI.Element>(Elem => Elem.Position.Y < SelectedVec.Y));
            t.Sort(new Comparison <UI.Element>(
                       delegate(UI.Element e1, UI.Element e2) { return(e2.Position.Y.CompareTo(e1.Position.Y)); }));
            t = t.FindAll(new Predicate <UI.Element>(
                              Elem => Elem.Position.Y == t[0].Position.Y));
            int result = t.BinarySearch(Selected, Comparer <UI.Element> .Create(
                                            delegate(UI.Element e1, UI.Element e2) { return(e1.Position.X.CompareTo(e2.Position.X)); }));
            if (result < 0)
            {
                result = ~result == t.Count ? ~result - 1 : ~result;
            }
            Next = t[result];
        }
        if (Selected.Focusable)
        {
            Selected.Focused = false;
        }
        else
        {
            Selected.Hovered = false;
        }
        if (Next.Focusable)
        {
            Next.Focused = true;
        }
        else
        {
            Next.Hovered = true;
        }
        Selected = Next;
    }