Пример #1
0
        public void SetTouchCapture(Actor actor, int pointer)
        {
            if (pointer < 0 || pointer >= _touchCapture.Length)
                throw new ArgumentOutOfRangeException("pointer");

            Actor oldTouchCapture = _touchCapture[pointer];
            _touchCapture[pointer] = actor;

            if (oldTouchCapture != null) {
                TouchEventArgs ev = Pools<TouchEventArgs>.Obtain();
                ev.RoutedEvent = LostTouchCaptureEvent;
                ev.Pointer = pointer;

                bool cancel = oldTouchCapture.RaiseEvent(ev);
                Pools<TouchEventArgs>.Release(ev);

                if (cancel)
                    return;
            }

            if (actor != null) {
                TouchEventArgs ev = Pools<TouchEventArgs>.Obtain();
                ev.RoutedEvent = GotTouchCaptureEvent;
                ev.Pointer = pointer;

                if (actor.RaiseEvent(ev))
                    SetTouchCapture(oldTouchCapture, pointer);

                Pools<TouchEventArgs>.Release(ev);
            }
        }
Пример #2
0
        public bool IsAscendentOf(Actor actor)
        {
            if (actor == null)
                throw new ArgumentNullException("actor");

            while (true) {
                if (actor == null)
                    return false;
                if (actor == this)
                    return true;
                actor = actor.Parent;
            }
        }
Пример #3
0
        public void SetScrollFocus(Actor actor)
        {
            if (_scrollFocus == actor)
                return;

            Actor oldScrollFocus = _scrollFocus;
            _scrollFocus = actor;

            if (oldScrollFocus != null) {
                ScrollFocusChangedEventArgs eva = Pools<ScrollFocusChangedEventArgs>.Obtain();
                eva.RoutedEvent = LostScrollFocusEvent;
                eva.NewFocus = actor;
                eva.OldFocus = oldScrollFocus;

                bool cancel = oldScrollFocus.RaiseEvent(eva);
                Pools<ScrollFocusChangedEventArgs>.Release(eva);

                if (cancel)
                    return;
            }

            if (actor != null) {
                ScrollFocusChangedEventArgs eva = Pools<ScrollFocusChangedEventArgs>.Obtain();
                eva.RoutedEvent = GotScrollFocusEvent;
                eva.NewFocus = actor;
                eva.OldFocus = oldScrollFocus;

                if (actor.RaiseEvent(eva))
                    SetScrollFocus(oldScrollFocus);

                Pools<ScrollFocusChangedEventArgs>.Release(eva);
            }
        }
Пример #4
0
        public Vector2 LocalToDescendantCoordinates(Actor descendant, Vector2 localCoords)
        {
            if (Parent == null)
                throw new ArgumentException("Child is not a descendant: " + descendant);
            if (Parent != this)
                localCoords = LocalToDescendantCoordinates(Parent, localCoords);

            return descendant.ParentToLocalCoordinates(localCoords);
        }
Пример #5
0
        public bool SwapActor(Actor first, Actor second)
        {
            int firstIndex = Children.IndexOf(first);
            int secondIndex = Children.IndexOf(second);

            return SwapActor(firstIndex, secondIndex);
        }
Пример #6
0
        private Actor FireEnterAndExit(Actor overLast, int screenX, int screenY, int pointer)
        {
            Vector2 stageCoords = ScreenToStageCoordinates(new Vector2(screenX, screenY));
            Actor over = Hit(stageCoords.X, stageCoords.Y, true);
            if (over == overLast)
                return overLast;

            TouchEventArgs ev = Pools<TouchEventArgs>.Obtain();
            ev.Stage = this;
            ev.StagePosition = stageCoords;
            ev.Pointer = pointer;

            if (overLast != null) {
                ev.RoutedEvent = TouchLeaveEvent;
                ev.RelatedActor = over;
                overLast.RaiseEvent(ev);
            }

            if (over != null) {
                ev.RoutedEvent = TouchEnterEvent;
                ev.RelatedActor = overLast;
                over.RaiseEvent(ev);
            }

            Pools<TouchEventArgs>.Release(ev);

            return over;
        }
Пример #7
0
        public virtual void AddActorAt(int index, Actor actor)
        {
            actor.Remove();
            if (index >= Children.Count)
                Children.Add(actor);
            else
                Children.Insert(index, actor);

            actor.Parent = this;
            actor.Stage = Stage;
            ChildrenChanged();
        }
Пример #8
0
 private static void LostTouchCaptureClass(Actor sender, TouchEventArgs e)
 {
     if (sender != null)
         sender.OnLostTouchCapture(e);
 }
Пример #9
0
 private static void PreviewKeyUpClass(Actor sender, KeyEventArgs e)
 {
     if (sender != null)
         sender.OnPreviewKeyUp(e);
 }
Пример #10
0
 private static void LostKeyboardFocusClass(Actor sender, KeyboardFocusChangedEventArgs e)
 {
     if (sender != null)
         sender.OnLostKeyboardFocus(e);
 }
Пример #11
0
 private static void LostScrollFocusClass(Actor sender, ScrollFocusChangedEventArgs e)
 {
     if (sender != null)
         sender.OnLostScrollFocus(e);
 }
Пример #12
0
 private static void KeyDownClass(Actor sender, KeyEventArgs e)
 {
     if (sender != null)
         sender.OnKeyDown(e);
 }
Пример #13
0
        public Vector2 LocalToAscendantCoordinates(Actor ascendant, Vector2 localCoords)
        {
            Actor actor = this;
            while (actor.Parent != null) {
                localCoords = actor.LocalToParentCoordinates(localCoords);
                actor = actor.Parent;

                if (actor == ascendant)
                    break;
            }

            return localCoords;
        }
Пример #14
0
        public bool IsDescendentOf(Actor actor)
        {
            if (actor == null)
                throw new ArgumentNullException("actor");

            Actor parent = this;
            while (true) {
                if (parent == null)
                    return false;
                if (parent == actor)
                    return true;
                parent = parent.Parent;
            }
        }
Пример #15
0
 public void Unfocus(Actor actor)
 {
     if (_scrollFocus != null && _scrollFocus.IsDescendentOf(actor))
         _scrollFocus = null;
     if (_keyboardFocus != null && _keyboardFocus.IsDescendentOf(actor))
         _keyboardFocus = null;
 }
Пример #16
0
 private static void PreviewMouseMoveClass(Actor sender, MouseEventArgs e)
 {
     if (sender != null)
         sender.OnPreviewMouseMove(e);
 }
Пример #17
0
 public void UnfocusAll()
 {
     _scrollFocus = null;
     _keyboardFocus = null;
     ReleaseTouchCapture();
 }
Пример #18
0
 private static void PreviewTouchUpClass(Actor sender, TouchEventArgs e)
 {
     if (sender != null)
         sender.OnPreviewTouchUp(e);
 }
Пример #19
0
        public virtual void AddActorAfter(Actor actorAfter, Actor actor)
        {
            actor.Remove();
            int index = Children.IndexOf(actorAfter);
            if (index == Children.Count)
                Children.Add(actor);
            else
                Children.Insert(index + 1, actor);

            actor.Parent = this;
            actor.Stage = Stage;
            ChildrenChanged();
        }
Пример #20
0
 private static void ScrollClass(Actor sender, ScrollEventArgs e)
 {
     if (sender != null)
         sender.OnScroll(e);
 }
Пример #21
0
 public virtual void AddActorBefore(Actor actorBefore, Actor actor)
 {
     actor.Remove();
     int index = Children.IndexOf(actorBefore);
     Children.Insert(index, actor);
     actor.Parent = this;
     actor.Stage = Stage;
     ChildrenChanged();
 }
Пример #22
0
        public void Act(float delta)
        {
            // Update over actors. Done in act() because actors may change position, which can fire enter/exit without an input event.
            for (int pointer = 0, n = _pointerOverActors.Length; pointer < n; pointer++) {
                Actor overLast = _pointerOverActors[pointer];

                // Check if pointer is gone.
                if (!_pointerTouched[pointer]) {
                    if (overLast != null) {
                        _pointerOverActors[pointer] = null;
                        Vector2 stageCoords = ScreenToStageCoordinates(new Vector2(_pointerScreen[pointer].X, _pointerScreen[pointer].Y));

                        // Exit over last
                        TouchEventArgs ev = Pools<TouchEventArgs>.Obtain();
                        ev.RoutedEvent = TouchLeaveEvent;
                        ev.Stage = this;
                        ev.StagePosition = stageCoords;
                        ev.RelatedActor = overLast;
                        ev.Pointer = pointer;

                        overLast.RaiseEvent(ev);
                        Pools<TouchEventArgs>.Release(ev);
                    }
                    continue;
                }

                // Update over actor for the pointer
                _pointerOverActors[pointer] = FireEnterAndExit(overLast, _pointerScreen[pointer].X, _pointerScreen[pointer].Y, pointer);
            }

            // Update over actor the mouse on the desktop
            // ApplicationType type = Gdx.app.getType();
            // if (type == ApplicationType.Desktop || type == ApplicationType.Applet || type == ApplicationType.WebGL)
            _mouseOverActor = FireEnterAndExit(_mouseOverActor, _mouseScreenX, _mouseScreenY, -1);

            Root.Act(delta);
        }
Пример #23
0
        public virtual bool RemoveActor(Actor actor)
        {
            if (!Children.Remove(actor))
                return false;

            if (Stage != null)
                Stage.Unfocus(actor);

            actor.Parent = null;
            actor.Stage = null;
            ChildrenChanged();

            return true;
        }
Пример #24
0
 public void AddActor(Actor actor)
 {
     Root.AddActor(actor);
 }
Пример #25
0
 public virtual void AddActor(Actor actor)
 {
     actor.Remove();
     Children.Add(actor);
     actor.Parent = this;
     actor.Stage = Stage;
     ChildrenChanged();
 }
Пример #26
0
 private static void TouchLeaveClass(Actor sender, TouchEventArgs e)
 {
     if (sender != null)
         sender.OnTouchLeave(e);
 }