コード例 #1
0
ファイル: DrawingLine.cs プロジェクト: JackBetts/TrafficCop
        /// <summary>
        /// Create a new instance of the DrawingLine. Will instantiate a new prefab.
        /// </summary>
        public DrawingLine(DrawingTool tool, PointerInput input, Vector3 worldPoint, Color color)
        {
            this.tool = tool;

            rendererInstance = Object.Instantiate(tool.LinePrefab, worldPoint, Quaternion.identity);

            float          pressure   = input.Pressure ?? 1.0f;
            float          curveWidth = tool.SizePressureCurve.Evaluate(pressure);
            AnimationCurve curve      = AnimationCurve.Constant(0.0f, 1.0f, curveWidth);

            rendererInstance.widthCurve = curve;

            rendererInstance.positionCount = 1;
            rendererInstance.SetPosition(0, worldPoint);

            color.a = tool.LineAlpha;
            rendererInstance.startColor = color;
            rendererInstance.endColor   = color;

            lastPosition = worldPoint;
            lineLength   = 0;
        }
コード例 #2
0
        public void VerifyFlyoutClosingBehavior()
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone2))
            {
                Log.Warning("Test is disabled pre-RS2 because CommandBarFlyout is not supported pre-RS2");
                return;
            }

            using (var setup = new CommandBarFlyoutTestSetupHelper())
            {
                Button showCommandBarFlyoutButton = FindElement.ByName <Button>("Show CommandBarFlyout with sub-menu");

                Log.Comment("Tapping on a button to show the CommandBarFlyout.");
                showCommandBarFlyoutButton.Click();

                // Pre-RS5, CommandBarFlyouts always open expanded,
                // so we don't need to tap on the more button in that case.
                if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone5))
                {
                    Log.Comment("Expanding the CommandBar by invoking the more button.");
                    FindElement.ById <Button>("MoreButton").InvokeAndWait();
                }

                // Click item to open flyout
                FindElement.ById <Button>("ProofingButton").Click();

                // Move around over the first item to keep flyout open safely
                // This also verifies that the flyout is open as it would crash otherwise
                PointerInput.Move(FindElement.ByName("FirstFlyoutItem"), 5, 5);
                PointerInput.Move(FindElement.ByName("FirstFlyoutItem"), 6, 5);
                PointerInput.Move(FindElement.ByName("FirstFlyoutItem"), 5, 6);

                // Click outside of the flyout to close it
                InputHelper.Tap(FindElement.ByName <Button>("Show CommandBarFlyout"));

                // Check that the flyout item is not present anymore
                VerifyElement.NotFound("FirstFlyoutItem", FindBy.Name);
            }
        }
コード例 #3
0
        public static void Pan(UIObject obj, Point start, Point end, uint holdDuration = DefaultPanHoldDuration, float panAcceleration = DefaultPanAcceleration, uint dragDuration = DefaultDragDuration, bool waitForIdle = true)
        {
            Log.Comment("Pan on {0}, starting at ({1}, {2}), ending at ({3}, {4}), after holding {5} ms, with acceleration {6}.",
                        obj.GetIdentifier(), start.X, start.Y, end.X, end.Y, holdDuration, panAcceleration);

            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
            {
                using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Drag))
                {
                    Log.Warning("Touch input is not available on OS versions less than RS5. Falling back to mouse input.");
                    PointerInput.Move(start);
                    PointerInput.ClickDrag(end, PointerButtons.Primary, dragDuration);
                }
            }
            else
            {
                if (panAcceleration == 0.0f)
                {
                    using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Drag))
                    {
                        SinglePointGesture.Current.Move(start);
                        SinglePointGesture.Current.PressAndDrag(end, dragDuration, holdDuration);
                    }
                }
                else
                {
                    using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Pan))
                    {
                        SinglePointGesture.Current.Move(start);
                        SinglePointGesture.Current.Pan(end, holdDuration, panAcceleration);
                    }
                }
            }

            if (waitForIdle)
            {
                Wait.ForIdle();
            }
        }
コード例 #4
0
        public static void DragDistance(UIObject obj, int distance, Direction direction, uint duration = 4000)
        {
            Log.Comment("Drag {0} {1} pixels in the {2} direction.", obj.GetIdentifier(), distance, direction);
            Point  startPoint       = obj.GetClickablePoint();
            double directionRadians = DirectionToAngle(direction) * Math.PI / 180d;

            Log.Comment("Start Point X:{0} Y:{1}", startPoint.X, startPoint.Y);

            Point end = new Point()
            {
                X = startPoint.X + (int)Math.Round(distance * Math.Cos(directionRadians)),
                Y = startPoint.Y - (int)Math.Round(distance * Math.Sin(directionRadians))
            };

            Log.Comment("End Point X:{0} Y:{1}", end.X, end.Y);

            using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Drag))
            {
                if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
                {
                    Log.Warning("Touch input is not available on OS versions less than RS5. Falling back to mouse input.");
                    Log.Comment("Move input to Start Point.");
                    PointerInput.Move(startPoint);
                    Log.Comment("Begin Drag.");
                    PointerInput.ClickDrag(end, PointerButtons.Primary, duration);
                    Log.Comment("Drag Complete.");
                }
                else
                {
                    Log.Comment("Move input to Start Point.");
                    SinglePointGesture.Current.Move(startPoint);
                    Log.Comment("Begin Drag.");
                    SinglePointGesture.Current.ClickDrag(end, PointerButtons.Primary, duration);
                    Log.Comment("Drag Complete.");
                }
            }
            Wait.ForIdle();
        }
コード例 #5
0
ファイル: DrawingLine.cs プロジェクト: JackBetts/TrafficCop
        /// <summary>
        /// Submit a new point to be added to the line.
        /// </summary>
        /// <remarks>
        /// Will only add a new point if it's beyond the <see cref="DrawingTool.MinVertexDistance"/> defined in
        /// the corresponding <see cref="DrawingTool"/> .
        /// </remarks>
        public void SubmitPoint(PointerInput input, Vector3 worldPoint)
        {
            float distance = Vector3.Distance(worldPoint, lastPosition);

            if (!(distance > tool.MinVertexDistance))
            {
                return;
            }

            rendererInstance.positionCount++;
            rendererInstance.SetPosition(rendererInstance.positionCount - 1,
                                         worldPoint);

            lastPosition = worldPoint;

            float previousLength = lineLength;

            lineLength += distance;

            float curveRescaleValue = previousLength / lineLength;

            float pressure   = input.Pressure ?? 1.0f;
            float curveWidth = tool.SizePressureCurve.Evaluate(pressure);

            // Rescale width curve
            AnimationCurve curve = rendererInstance.widthCurve;

            for (var i = 0; i < curve.length; ++i)
            {
                Keyframe key = curve[i];
                key.time *= curveRescaleValue;
                curve.MoveKey(i, key);
            }

            curve.AddKey(1.0f, curveWidth);

            rendererInstance.widthCurve = curve;
        }
コード例 #6
0
        private void OnReleased(PointerInput input, double time)
        {
            if (!activeGestures.TryGetValue(input.InputId, out var existingGesture))
            {
                // Probably caught by UI, or the input was otherwise lost
                return;
            }

            activeGestures.Remove(input.InputId);
            existingGesture.SubmitPoint(input.Position, time);

            if (IsValidSwipe(ref existingGesture))
            {
                Swiped?.Invoke(new SwipeInput(existingGesture));
            }

            if (IsValidTap(ref existingGesture))
            {
                Tapped?.Invoke(new TapInput(existingGesture));
            }

            DebugInfo(existingGesture);
        }
コード例 #7
0
        // Temporary, for visualizing input from new input system.
        private void DebugInfo(PointerInput input)
        {
            var builder = new StringBuilder();

            builder.AppendFormat("ID: {0}", input.InputId);
            builder.AppendLine();
            builder.AppendFormat("Position: {0}", input.Position);
            builder.AppendLine();

            if (input.Tilt.HasValue)
            {
                builder.AppendFormat("Tilt: {0}", input.Tilt);
                builder.AppendLine();
            }
            if (input.Pressure.HasValue)
            {
                builder.AppendFormat("Pressure: {0}", input.Pressure);
                builder.AppendLine();
            }
            if (input.Tilt.HasValue)
            {
                builder.AppendFormat("Tilt: {0}", input.Tilt);
                builder.AppendLine();
            }
            if (input.Radius.HasValue)
            {
                builder.AppendFormat("Radius: {0}", input.Radius);
                builder.AppendLine();
            }
            if (input.Twist.HasValue)
            {
                builder.AppendFormat("Twist: {0}", input.Twist);
                builder.AppendLine();
            }

            label.text = builder.ToString();
        }
コード例 #8
0
        public static void DragToTarget(UIObject obj, UIObject obj2, int xOffset = 0, int yOffset = 0)
        {
            Point startPoint = obj.GetClickablePoint();

            Log.Comment("Start Point X:{0} Y:{1}", startPoint.X, startPoint.Y);

            Point end = obj2.GetClickablePoint();

            end.X += xOffset;
            end.Y += yOffset;
            Log.Comment("End Point X:{0} Y:{1}", end.X, end.Y);

            uint dragDuration = 2000;

            using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Drag))
            {
                if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
                {
                    Log.Warning("Touch input is not available on OS versions less than RS5. Falling back to mouse input.");
                    Log.Comment("Move input to Start Point.");
                    PointerInput.Move(startPoint);
                    Log.Comment("Begin Drag.");
                    PointerInput.ClickDrag(end, PointerButtons.Primary, dragDuration);
                    Log.Comment("Drag Complete.");
                }
                else
                {
                    Log.Comment("Move input to Start Point.");
                    SinglePointGesture.Current.Move(startPoint);
                    Log.Comment("Begin Drag.");
                    SinglePointGesture.Current.PressAndDrag(end, dragDuration, 500);
                    Log.Comment("Drag Complete.");
                }
            }
            Wait.ForIdle();
        }
コード例 #9
0
        public static void LeftMouseButtonUp(UIObject obj, int offsetX = 0, int offsetY = 0)
        {
            if (offsetX == 0 && offsetY == 0)
            {
                Log.Comment("Left mouse button up on {0}.", obj.GetIdentifier());
            }
            else
            {
                Log.Comment("Left mouse button up on {0} at offset ({1}, {2}).",
                            obj.GetIdentifier(), offsetX, offsetY);
            }

            using (var waiter = GetWaiterForInputEvent(obj, InputEvent.MouseUp))
            {
                var point = obj.GetClickablePoint();

                point.X += offsetX;
                point.Y += offsetY;

                PointerInput.Move(point);
                PointerInput.Release(PointerButtons.Primary);
            }
            Wait.ForIdle();
        }
コード例 #10
0
        private void JumpBtn_Click(object sender, EventArgs e)
        {
            if (PointerInput.Text == "")
            {
                MessageForm errorForm = new MessageForm("Please enter which card you want to go to");
                errorForm.Show();
            }
            else if (int.Parse(PointerInput.Text) < 0 || int.Parse(PointerInput.Text) > queue.GetQueue.Length)
            {
                MessageForm errorForm = new MessageForm("Please enter a value within the range of your flashcards");
                errorForm.Show();
            }
            else if (queue.GetQueue[int.Parse(PointerInput.Text) - 1] == null)
            {
                MessageForm errorForm = new MessageForm("Your set does not have that many flashcards");
                errorForm.Show();
            }
            else
            {
                int  difference = int.Parse(PointerVal.Text) - int.Parse(PointerInput.Text);
                bool back       = false;
                if (difference < 0)
                {
                    difference = -difference;
                    back       = true;
                }

                for (int i = 0; i < difference; i++)
                {
                    PointerVal.Text = (back ? queue.Forwards() : queue.Backwards()).ToString();
                }

                currentCard = queue.Load();
            }
            PointerInput.Clear();
        }
コード例 #11
0
        protected void OnInput(PointerInput input)
        {
            if (input.State == InputState.Pressed)
            {
                for (int i = 0; i < buttons.Length; ++i)
                {
                    Rectangle area = new Rectangle(Padding, Padding + i * (ButtonHeight + Padding), Width - Padding * 2, ButtonHeight);
                    if (area.Contains(input.Position.ToPoint()))
                    {
                        switch (i)
                        {
                        case 0:
                            Closing = true;
                            break;

                        case 2:
                            Manager.Game.GameState = Core.GameStateEnum.Menu;
                            Closing = true;
                            break;
                        }
                    }
                }
            }
        }
コード例 #12
0
 private Vector3 GetWorldPosFromInput(PointerInput input, float z)
 {
     return(renderCamera.ScreenToWorldPoint(new Vector3(input.Position.x, input.Position.y, z)));
 }
コード例 #13
0
        /// <summary>
        /// Update the various gesture interpreters with the new pointer event data
        /// </summary>
        /// <param name="pointerPoint"></param>
        /// <param name="pointerEventType"></param>
        private void UpdatePointerEvent(PointerPoint pointerPoint, PointerEventType pointerEventType)
        {
            var customGestureTypes = Enum.GetValues(typeof(CustomGestureSettings));

            foreach (CustomGestureSettings gestureType in customGestureTypes)
            {
                // Skip gestures that are not flagged in the GestureSettings
                if (!GestureSettings.HasFlag(gestureType))
                {
                    continue;
                }

                // Check for an existing started gesture to update.
                // If absent, create one.
                if (!_gestureProgress.TryGetValue(gestureType, out IGesture gesture))
                {
                    // Build the appropriate Gesture object based on the configured CustomGestureSettings
                    switch (gestureType)
                    {
                    case CustomGestureSettings.MultiTap:
                        gesture = new MultiTap(_gestureProperties);
                        break;

                    case CustomGestureSettings.None:
                    default:
                        // This gesture type is not supported.
                        continue;
                    }

                    // Add the gesture to the dictionary by type.
                    // There will only ever be one Gesture per type being analysed by this recognizer instance.
                    _gestureProgress.Add(gestureType, gesture);
                }

                // Track all inputs. If new, add it to the dictionary for tracking.
                // If not, update the existing item.
                if (!_inputs.TryGetValue(pointerPoint.PointerId, out PointerInput pointerInput))
                {
                    pointerInput = new PointerInput(pointerPoint, pointerEventType);
                    _inputs.Add(pointerPoint.PointerId, pointerInput);
                }
                else
                {
                    pointerInput.Update(pointerPoint, pointerEventType);
                    _inputs[pointerPoint.PointerId] = pointerInput;
                }

                // Pipe the input data to the gesture
                var inputs = _inputs.Values.ToList();
                switch (pointerEventType)
                {
                case PointerEventType.Down:
                    gesture.Start(inputs);
                    break;

                case PointerEventType.Move:
                    gesture.Move(inputs);
                    break;

                case PointerEventType.Up:
                    var args = gesture.End(inputs);
                    if (args != null)
                    {
                        CompleteGesture(gestureType, args);
                    }
                    break;
                }
            }
        }
コード例 #14
0
 public bool PointerInGui(PointerInput pointer)
 {
     return(GuiAt(pointer.Position) != null);
 }
コード例 #15
0
 protected virtual void OnInput(PointerInput input)
 {
 }
コード例 #16
0
ファイル: Gui.cs プロジェクト: RisaI/mff-totem
        protected override void OnInput(PointerInput input)
        {
            base.OnInput(input);

            switch (input.State)
            {
            case InputState.Pressed:
                if (ItemArea.Contains(input.Position.ToPoint()))
                {
                    int  offset   = 0;
                    bool selected = false;
                    for (int i = 0; i < Inventory.Items.Count; ++i)
                    {
                        var rect = new Rectangle(ItemArea.X + 2, ItemArea.Y + 2 + offset, ItemArea.Width - 4, selectedItem == i ? ITEM_HEIGHT_OPENED : ITEM_HEIGHT_CLOSED);
                        if (rect.Contains(input.Position.ToPoint()))
                        {
                            selected = true;
                            if (selectedItem == i)
                            {
                                var buttonSize = new Point((rect.Width / 3 - 12), (int)(ITEM_HEIGHT_OPENED - ITEM_HEIGHT_CLOSED - 8));
                                if (new Rectangle(rect.Right - 2 - buttonSize.X, rect.Bottom - 2 - buttonSize.Y, buttonSize.X, buttonSize.Y).Contains(input.Position.ToPoint()))
                                {
                                    //Drop
                                    Inventory.DropItem(i);
                                    selectedItem = -1;
                                }
                                else if (Inventory.Items[i].Usable && new Rectangle(rect.Center.X - buttonSize.X / 2, rect.Bottom - 2 - buttonSize.Y, buttonSize.X, buttonSize.Y).Contains(input.Position.ToPoint()))
                                {
                                    //Use
                                }
                                else if (Inventory.Items[i].Slot != EquipSlot.None && new Rectangle(rect.Left + 2, rect.Bottom - 2 - buttonSize.Y, buttonSize.X, buttonSize.Y).Contains(input.Position.ToPoint()))
                                {
                                    //Equip
                                    Inventory.EquipItem(i);
                                    selectedItem = -1;
                                }
                            }
                            else
                            {
                                selectedItem = i;
                            }
                            break;
                        }
                        offset += 2 + (selectedItem == i ? ITEM_HEIGHT_OPENED : ITEM_HEIGHT_CLOSED);
                    }
                    if (!selected)
                    {
                        selectedItem = -1;
                    }
                }
                else
                {
                    bool selected = false;
                    for (int i = 0; i < Inventory.Equip.Length; ++i)
                    {
                        if (EquipArea(i).Contains(input.Position.ToPoint()))
                        {
                            selected = true;
                            if (Inventory.Equip[i] != null)
                            {
                                selectedEquip = i;
                            }
                            else
                            {
                                selectedEquip = -1;
                            }
                        }
                    }

                    if (!selected && selectedEquip >= 0)
                    {
                        if (EquipButtons(0).Contains(input.Position.ToPoint()))
                        {
                            Inventory.UnequipItem(selectedEquip);
                        }

                        /*else if (Player.Inventory.Equip[selectedEquip].Usable && equipButtons[1].Contains(input.Position))
                         * {
                         *  //Player.Inventory.UseItemFromInventory
                         * }*/
                        else if (EquipButtons(2).Contains(input.Position.ToPoint()))
                        {
                            //Inventory.DropEquip(selectedEquip);
                        }
                        selectedEquip = -1;
                    }
                }
                break;
            }
        }