예제 #1
0
        private void InternalSetContent(UIElement value)
        {
            if (_rootVisual == null)
            {
                _rootBorder = new Border();
                var coreServices = Uno.UI.Xaml.Core.CoreServices.Instance;
                coreServices.PutVisualRoot(_rootBorder);
                _rootVisual = coreServices.MainRootVisual;

                if (_rootVisual == null)
                {
                    throw new InvalidOperationException("The root visual could not be created.");
                }

                _mainController.View         = _rootVisual;
                _rootVisual.Frame            = _window.Frame;
                _rootVisual.AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;
            }

            _rootBorder.Child?.RemoveFromSuperview();
            _rootBorder.Child = _content = value;

            // This is required to get the mouse move while not pressed!
            var options = NSTrackingAreaOptions.MouseEnteredAndExited
                          | NSTrackingAreaOptions.MouseMoved
                          | NSTrackingAreaOptions.ActiveInKeyWindow
                          | NSTrackingAreaOptions.EnabledDuringMouseDrag // We want enter/leave events even if the button is pressed
                          | NSTrackingAreaOptions.InVisibleRect;         // Automagicaly syncs the bounds rect
            var trackingArea = new NSTrackingArea(Bounds, options, _rootVisual, null);

            _rootVisual.AddTrackingArea(trackingArea);
        }
        protected override void OnWindowPositionChanged(Rect rcBoundingBox)
        {
            base.OnWindowPositionChanged(rcBoundingBox);

            if (ParentScrollViewer == null)
            {
                return;
            }

            GeneralTransform tr = RootVisual.TransformToDescendant(ParentScrollViewer);
            var scrollRect      = new Rect(new Size(ParentScrollViewer.ViewportWidth, ParentScrollViewer.ViewportHeight));

            var intersect = Rect.Intersect(scrollRect, tr.TransformBounds(rcBoundingBox));

            if (!intersect.IsEmpty)
            {
                tr        = ParentScrollViewer.TransformToDescendant(this);
                intersect = tr.TransformBounds(intersect);
            }
            else
            {
                intersect = new Rect();
            }

            int x1 = (int)Math.Round(intersect.Left);
            int y1 = (int)Math.Round(intersect.Top);
            int x2 = (int)Math.Round(intersect.Right);
            int y2 = (int)Math.Round(intersect.Bottom);

            SetRegion(x1, y1, x2, y2);
        }
예제 #3
0
 public override void Now()
 {
     base.Now();
     _animation = Compositor.CreateScalarKeyFrameAnimation();
     _animation.InsertKeyFrame(0f, _fromValue);
     _animation.InsertKeyFrame(1f, _toValue);
     _animation.Duration = DurationTime;
     RootVisual.StartAnimation("Opacity", _animation);
 }
        public static void NavigateTo(string page)
        {
            if (!page.StartsWith("/"))
            {
                page = "/" + page;
            }

            RootVisual.Navigate(new Uri(page, UriKind.RelativeOrAbsolute));
        }
예제 #5
0
 public void SetConnection(RootVisual visual, int connectedIndex)
 {
     this.Previous       = visual;
     this.ConnectedIndex = connectedIndex;
     if (this.Previous != null)
     {
         this.line.sortingOrder = this.Previous.GetSortingOrder() - 1;
     }
 }
예제 #6
0
        public void ConstructorTest()
        {
            var rootVisual = new RootVisual(_windowConfig);

            Assert.AreEqual(_windowConfig.Top, rootVisual.Top);
            Assert.AreEqual(_windowConfig.Left, rootVisual.Left);
            Assert.AreEqual(_windowConfig.Width, rootVisual.Width);
            Assert.AreEqual(_windowConfig.Height, rootVisual.Height);
            Assert.AreEqual(_windowConfig.State, rootVisual.WindowState);
        }
예제 #7
0
    public void CreateNewVisual(RootVisual parent, int connectedIndex, Vector2 position)
    {
        var visual = Instantiate(prefab);

        visual.transform.SetParent(this.transform, true);
        visual.transform.position = position;
        visual.SetConnection(parent, connectedIndex);
        visual.SetWater(resource.Water);
        _visuals.Add(visual);
    }
예제 #8
0
    private void ExitRetreat()
    {
        gameManager.SetState(GameState.Active);
        rootManager.CreateNewVisual(currentRoot, currentIndex, transform.position);
        currentRoot = rootManager.GetCurrent();
        currentRoot.AddPoint(transform.position);
        currentRoot.AddPoint(transform.position);
        SpawnImpact();

        TriggerInvincible();
    }
예제 #9
0
        public override void Now()
        {
            base.Now();
            var easing    = Compositor.CreateCubicBezierEasingFunction(new Vector2(0, 1), new Vector2(1, 0));
            var animation = Compositor.CreateVector3KeyFrameAnimation();

            animation.Duration = DurationTime;
            animation.InsertKeyFrame(0, FromValue);
            animation.InsertKeyFrame(1f, ToValue);
            RootVisual.StartAnimation("Offset", animation);
        }
        private void OnNavigate(object param)
        {
            Uri uri = param as Uri;

            if (uri == null && param is string)
            {
                uri = new Uri((string)param, UriKind.Relative);
            }

            if (uri != null)
            {
                RootVisual.Navigate(uri);
            }
        }
예제 #11
0
        private void InternalSetContent(UIElement content)
        {
            if (_rootVisual == null)
            {
                _rootBorder       = new Border();
                _rootScrollViewer = new ScrollViewer()
                {
                    VerticalScrollBarVisibility   = ScrollBarVisibility.Disabled,
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
                    VerticalScrollMode            = ScrollMode.Disabled,
                    HorizontalScrollMode          = ScrollMode.Disabled,
                    Content = _rootBorder
                };
                //TODO Uno: We can set and RootScrollViewer properly in case of WASM
                CoreServices.Instance.PutVisualRoot(_rootScrollViewer);
                _rootVisual = CoreServices.Instance.MainRootVisual;

                if (_rootVisual == null)
                {
                    throw new InvalidOperationException("The root visual could not be created.");
                }
            }

            _rootBorder.Child = _content = content;
            if (content != null)
            {
                if (FeatureConfiguration.FrameworkElement.WasmUseManagedLoadedUnloaded && !_rootVisual.IsLoaded)
                {
                    UIElement.LoadingRootElement(_rootVisual);
                }

                WebAssemblyRuntime.InvokeJS($"Uno.UI.WindowManager.current.setRootContent({_rootVisual.HtmlId});");

                if (FeatureConfiguration.FrameworkElement.WasmUseManagedLoadedUnloaded && !_rootVisual.IsLoaded)
                {
                    UIElement.RootElementLoaded(_rootVisual);
                }
            }
            else
            {
                WebAssemblyRuntime.InvokeJS($"Uno.UI.WindowManager.current.setRootContent();");

                if (FeatureConfiguration.FrameworkElement.WasmUseManagedLoadedUnloaded && _rootVisual.IsLoaded)
                {
                    UIElement.RootElementUnloaded(_rootVisual);
                }
            }

            UpdateRootAttributes();
        }
예제 #12
0
 private void LoadLayoutFromFile(string fileName)
 {
     if (File.Exists(fileName))
     {
         try {
             using (var file = File.OpenText(fileName)) {
                 if (file.BaseStream.Length > 10)
                 {
                     RootVisual.LoadLayout(file.BaseStream);
                 }
             }
         } catch (Exception exc) {
             MessageBox.Show(exc + "");
         }
     }
 }
예제 #13
0
        private void InternalSetContent(UIElement value)
        {
            _rootVisual = new RootVisual(CoreServices.Instance);
            if (_content != null)
            {
                _content.IsWindowRoot     = false;
                _content.IsVisualTreeRoot = false;
            }

            _content = value;

            _content.IsWindowRoot     = true;
            _content.IsVisualTreeRoot = true;

            TryLoadContent();
        }
예제 #14
0
        private void InternalSetContent(UIElement value)
        {
            if (_rootVisual == null)
            {
                _rootBorder = new Border();
                CoreServices.Instance.PutVisualRoot(_rootBorder);
                _rootVisual = CoreServices.Instance.MainRootVisual;

                if (_rootVisual == null)
                {
                    throw new InvalidOperationException("The root visual could not be created.");
                }

                ApplicationActivity.Instance?.SetContentView(_rootVisual);
            }
            _rootBorder.Child = _content = value;
        }
예제 #15
0
        public void CloseRewriteTest()
        {
            var rootVisual = new RootVisual(_windowConfig)
            {
                Height = 200,
                Width  = 500,
                Top    = 1,
                Left   = 1,
                WindowStartupLocation = WindowStartupLocation.CenterOwner,
                WindowState           = WindowState.Normal
            };

            rootVisual.Close();

            Assert.AreEqual(rootVisual.Top, _windowConfig.Top);
            Assert.AreEqual(rootVisual.Left, _windowConfig.Left);
            Assert.AreEqual(rootVisual.Width, _windowConfig.Width);
            Assert.AreEqual(rootVisual.Height, _windowConfig.Height);
            Assert.AreEqual(rootVisual.WindowState, _windowConfig.State);
        }
예제 #16
0
    private void OnRetreatUpdate()
    {
        rigidbody.gravityScale = 0;
        float distLeft = currentRoot.GetDistanceToStart(currentIndex);
        float modifier = 1f;

        if (gameManager.ActiveState == GameState.WinRetreat)
        {
            modifier = Mathf.Lerp(1f, 4f, Mathf.Clamp01(distLeft / 60f));
        }

        float moveDistance = modifier * retreatSpeed * Time.deltaTime;

        while (moveDistance >= 0.001f)
        {
            (RootVisual root, int index) = currentRoot.GetPreviousPoint(currentIndex);
            if (root != null)
            {
                Vector2 target      = root.GetPosition(index);
                Vector2 newPosition = Vector2.MoveTowards(targetPosition, target, moveDistance);

                float distTraveled = Vector2.Distance(newPosition, targetPosition);

                if (newPosition == target || distTraveled == 0)
                {
                    currentIndex = index;
                    currentRoot  = root;
                }
                targetPosition = newPosition;

                moveDistance -= distTraveled;
            }
            else
            {
                gameManager.SetState(GameState.Exit);
                return;
            }
        }

        transform.position = Vector3.Lerp(transform.position, targetPosition, 0.75f);
    }
예제 #17
0
        protected override void OnWindowPositionChanged(Rect rcBoundingBox)
        {
            DpiScale dpiScale = new DpiScale()
            {
                DpiScaleX = RenderSettings.dpiScaleX, DpiScaleY = RenderSettings.dpiScaleY
            };

            base.OnWindowPositionChanged(rcBoundingBox);

            if (ParentScrollViewer == null)
            {
                return;
            }

            Rect             newRect = ScaleRectDownFromDPI(rcBoundingBox, dpiScale);
            GeneralTransform tr      = RootVisual.TransformToDescendant(ParentScrollViewer);
            var scrollRect           = new Rect(new Size(ParentScrollViewer.ViewportWidth, ParentScrollViewer.ViewportHeight));

            var intersect = Rect.Intersect(scrollRect, tr.TransformBounds(newRect));

            if (!intersect.IsEmpty)
            {
                tr        = ParentScrollViewer.TransformToDescendant(this);
                intersect = tr.TransformBounds(intersect);
                intersect = ScaleRectUpToDPI(intersect, dpiScale);
            }
            else
            {
                intersect = new Rect();
            }

            int x1 = (int)Math.Round(intersect.Left);
            int y1 = (int)Math.Round(intersect.Top);
            int x2 = (int)Math.Round(intersect.Right);
            int y2 = (int)Math.Round(intersect.Bottom);

            SetRegion(x1, y1, x2, y2);
        }
예제 #18
0
        private void InternalSetContent(UIElement value)
        {
            if (_rootVisual == null)
            {
                _rootBorder = new Border();
                var coreServices = Uno.UI.Xaml.Core.CoreServices.Instance;
                coreServices.PutVisualRoot(_rootBorder);
                _rootVisual = coreServices.MainRootVisual;

                if (_rootVisual == null)
                {
                    throw new InvalidOperationException("The root visual could not be created.");
                }

                _mainController.View.AddSubview(_rootVisual);
                _rootVisual.Frame            = _mainController.View.Bounds;
                _rootVisual.AutoresizingMask = UIViewAutoresizing.All;
            }

            _rootBorder.Child?.RemoveFromSuperview();
            _rootBorder.Child = null;
            _rootBorder.Child = _content = value;
        }
예제 #19
0
 private void SaveOriginalLayout()
 {
     _originalLayout = new MemoryStream();
     RootVisual.SaveLayout(_originalLayout);
     _originalLayout.Position = 0;
 }
예제 #20
0
 private void SaveLayout(string fileName)
 {
     using (var file = File.CreateText(fileName)) {
         RootVisual.SaveLayout(file.BaseStream, true);
     }
 }
예제 #21
0
 public UnoFocusInputHandler(RootVisual rootVisual)
 {
     _rootVisual          = rootVisual;
     _rootVisual.KeyDown += OnKeyDown;
     _rootVisual.KeyUp   += OnKeyUp;
 }
예제 #22
0
 private void LoadOriginalLayout()
 {
     RootVisual.LoadLayout(_originalLayout);
     _originalLayout.Position = 0;
 }
예제 #23
0
    private void Awake()
    {
        rootManager       = FindObjectOfType <RootManager>();
        resourceManager   = FindObjectOfType <ResourceManager>();
        rigidbody         = GetComponent <Rigidbody2D>();
        this.IsInvincible = false;

        gameManager = GameManager.GetInstance();

        Vector2 start  = new Vector2(0, 0);
        Vector2 target = Vector2.right;

        targetRotation = rigidbody.rotation;

        if (currentRoot == null)
        {
            currentRoot = rootManager.GetCurrent();
            if (currentRoot == null)
            {
                rootManager.CreateNewVisual(transform.position);
                currentRoot = rootManager.GetCurrent();
                // Create a second point that will be move to the player's location
                currentRoot.AddPoint(transform.position);
                currentIndex = currentRoot.GetPointCount();
                lastPosition = transform.position;
            }
        }

        input = new PlayerInput();
        input.SeedControls.Movement.performed += (ctx) => movementInput = ctx.ReadValue <Vector2>();

        input.SeedControls.Kill.performed += (ctx) =>
        {
            if (gameManager.ActiveState == GameState.Active)
            {
                gameManager.SetState(GameState.Dead);
            }
        };

        input.SeedControls.Select.performed += (ctx) =>
        {
            if (gameManager.ActiveState == GameState.Retreat)
            {
                if (resourceManager.IsWaterDrained == false)
                {
                    gameManager.SetState(GameState.Aim);
                }
            }
            else if (gameManager.ActiveState == GameState.Aim)
            {
                ExitRetreat();
            }
        };

        input.SeedControls.Cancel.performed += (ctx) =>
        {
            if (gameManager.ActiveState == GameState.Aim)
            {
                gameManager.SetState(GameState.Retreat);
            }
        };
    }
예제 #24
0
 public void Dispose()
 {
     RootVisual?.Dispose();
 }
예제 #25
0
        public override void TouchesEnded(NSSet touches, UIEvent evt)
        {
            /* Note: Here we have a mismatching behavior with UWP, if the events bubble natively we're going to get
             *               (with Ctrl_02 is a child of Ctrl_01):
             *                              Ctrl_02: Released
             *                                               Exited
             *                              Ctrl_01: Released
             *                                               Exited
             *
             *              While on UWP we will get:
             *                              Ctrl_02: Released
             *                              Ctrl_01: Released
             *                              Ctrl_02: Exited
             *                              Ctrl_01: Exited
             *
             *              However, to fix this is would mean that we handle all events in managed code, but this would
             *              break lots of control (ScrollViewer) and ability to easily integrate an external component.
             */

            try
            {
                var isHandledOrBubblingInManaged = default(bool);
                foreach (UITouch touch in touches)
                {
                    var pt   = TransientNativePointer.Get(this, touch);
                    var args = new PointerRoutedEventArgs(pt.Id, touch, evt, this);

                    if (!pt.HadMove)
                    {
                        // The event will bubble in managed, so as this flag is "pseudo static", make sure to raise it only once.
                        pt.HadMove = true;

                        // On iOS if the gesture is really fast (like a flick), we can get only 'down' and 'up'.
                        // But on UWP it seems that we always have a least one move (for fingers and pen!), and even internally,
                        // the manipulation events are requiring at least one move to kick-in.
                        // Here we are just making sure to raise that event with the final location.
                        // Note: In case of multi-touch we might raise it unnecessarily, but it won't have any negative impact.
                        // Note: We do not consider the result of that move for the 'isHandledOrBubblingInManaged'
                        //		 as it's kind of un-related to the 'up' itself.
                        var mixedArgs = new PointerRoutedEventArgs(previous: pt.DownArgs, current: args);
                        OnNativePointerMove(mixedArgs);
                    }

                    isHandledOrBubblingInManaged |= OnNativePointerUp(args);

                    if (isHandledOrBubblingInManaged)
                    {
                        // Like for the Down, we need to manually generate an Exited.
                        // This is expected to be done by the RootVisual, except if the "up" has been handled
                        // (in order to ensure the "up" has been fully processed, including gesture recognition).
                        // In that case we need to sent it by our-own directly from teh element that has handled the event.

                        RootVisual.ProcessPointerUp(args, isAfterHandledUp: true);
                    }

                    pt.Release(this);
                }

                if (!isHandledOrBubblingInManaged)
                {
                    // Continue native bubbling up of the event
                    base.TouchesEnded(touches, evt);
                }

                NotifyParentTouchesManagersManipulationEnded();
            }
            catch (Exception e)
            {
                Application.Current.RaiseRecoverableUnhandledException(e);
            }
        }