Represents data from a multi-touch gesture over a span of time.
コード例 #1
0
        public new bool ProcessTouch(GestureSample gesture)
        {
            Point localGesturePoint = Spotlight.TranslateScreenVectorToWorldPoint(gesture.Position);

            if (!CanRespond()) return false;

            if (RespondsToWorldTouch(localGesturePoint) || IsFirstResponder())
            {

                switch (gesture.GestureType)
                {
                    case GestureType.FreeDrag:
                        SetCenter(localGesturePoint);
                        BecomeFirstResponder();
                        break;
                    case GestureType.DragComplete:
                        ResignFirstResponder();
                        break;
                    default:
                        return false;
                }
                return true;
            }

            return false;
        }
コード例 #2
0
ファイル: HUD.cs プロジェクト: steveyaz/Warlock
 public bool InteractGesture(GestureSample gesture)
 {
     bool ret = false;
     ret |= m_centerButton.InteractGesture(gesture);
     ret |= m_contextMenu.InteractGesture(gesture);
     return ret;
 }
コード例 #3
0
ファイル: Cutscene.cs プロジェクト: virusmarathe/Portfolio
        /// <summary>
        /// Process a touch gesture and return an indicator of whether or not the user has advanced past this cutscene.
        /// This is abberant behavior from our usual application paradigm because a cutscene it treated as a special case. 
        /// </summary>
        /// <param name="gesture"></param>
        /// <returns>true if the user has touched the Continue button. False otherwise. </returns>
        public override bool ProcessTouch(GestureSample gesture)
        {
            if (continueButton.ProcessTouch(gesture))
            {
                return true;
            }

            switch (gesture.GestureType)
            {
                case GestureType.FreeDrag:
                    offset -= gesture.Delta;
                    motionTarget = Vector2.Zero;
                    EnforceBoundaries();
                    return false;
                case GestureType.Flick:
                    Vector2 normal = gesture.Delta;
                    normal.Normalize();
                    motionTarget = offset - (normal * 200);
                    return false;
                case GestureType.Tap:
                    motionTarget = Vector2.Zero;
                    return false;
                default:
                    return false;

            }
        }
コード例 #4
0
ファイル: Sphere.cs プロジェクト: dreasgrech/FPE3Sandbox
        public void RespondToTouch(GestureSample gesture)
        {
            //if (gesture.GestureType == GestureType.Flick)
            //{
            //    var move = new Vector2(MathHelper.Clamp(gesture.Delta.X, -flickLimit, flickLimit), MathHelper.Clamp(gesture.Delta.Y, -flickLimit, flickLimit));
            //    Body.ApplyLinearImpulse(ConvertUnits.ToSimUnits(move * 50));
            //}

            if (gesture.GestureType == GestureType.Tap)
            {
                if (currentJumpCount >= consecutiveJumps)
                {
                    //return;
                }

                lastJumpTime = DateTime.Now;
                currentJumpCount++;

                if (!isOnGround)
                {
                    //Body.ResetDynamics();
                }
                sphere.Body.ApplyForce(new Vector2(0, -jumpForce));
                //isOnGround = false;
            }
        }
コード例 #5
0
        public static void Update()
        {
            m_Gesture = TouchPanel.IsGestureAvailable ? TouchPanel.ReadGesture() : new GestureSample();

            if (CurrentTouchCollection.Count > 0)
            {
                OldTouchCollection = CurrentTouchCollection;
            }

            CurrentTouchCollection = TouchPanel.GetState();

                    if (CurrentTouchCollection.Count > 0)
                    {
                        while (TouchPanel.IsGestureAvailable)
                        {
                            TouchPanel.ReadGesture();
                        }
                    }

            #if !Windows
            m_LastKeyboardState = m_CurrentKeyboardState;
            m_CurrentKeyboardState = Keyboard.GetState();

            m_LastMouseState = m_CurrentMouseState;
            m_CurrentMouseState = Mouse.GetState();
            #endif
        }
コード例 #6
0
ファイル: ContextMenu.cs プロジェクト: steveyaz/Warlock
        public bool InteractGesture(GestureSample gesture)
        {
            foreach (TextScreenObject contextMenuItem in m_contextMenuItems)
                if (contextMenuItem.InteractGesture(gesture))
                    return true;

            return false;
        }
コード例 #7
0
 public GestureDefinition(GestureType theGestureType, Rectangle theGestureArea)
 {
     Gesture = new GestureSample(theGestureType, new TimeSpan(0),
                                 Vector2.Zero, Vector2.Zero,
                                 Vector2.Zero, Vector2.Zero);
     Type = theGestureType;
     CollisionArea = theGestureArea;
 }
コード例 #8
0
        public new bool ProcessTouch(GestureSample gesture)
        {
            if (gesture.GestureType != GestureType.FreeDrag) return false;
            if (hidden || !Contains(gesture.Position)) return false;

            SetCenter(gesture.Position);

            return true;
        }
コード例 #9
0
ファイル: CitySplashButton.cs プロジェクト: steveyaz/Warlock
 public void InteractGesture(GestureSample gesture)
 {
     if (gesture.GestureType == GestureType.Tap
         && gesture.Position.X < m_textPosition.X + WarlockGame.m_spriteFont.MeasureString(m_buttonText).X && gesture.Position.X > m_textPosition.X
         && gesture.Position.Y < m_textPosition.Y + WarlockGame.m_spriteFont.MeasureString(m_buttonText).Y && gesture.Position.Y > m_textPosition.Y)
     {
         Execute();
     }
 }
コード例 #10
0
ファイル: Button.cs プロジェクト: virusmarathe/Portfolio
        public override bool ProcessTouch(GestureSample gesture)
        {
            if (hidden) return false;
            if (!base.ProcessTouch(gesture)) return false; //Easy out

            if (gesture.GestureType != GestureType.Tap) return false;

            SetSelected(true);
            return true;
        }
コード例 #11
0
ファイル: GestureListener.cs プロジェクト: ncoder/MonoGame
 /// <summary>
 /// Process the Single Tag into a Gesture
 /// </summary>
 /// <param name='e'>
 /// If set to <c>true</c> e.
 /// </param>
 public override bool OnSingleTapConfirmed(MotionEvent e)
 {
     if ((TouchPanel.EnabledGestures & GestureType.Tap) != 0)
     {
         var gs = new GestureSample(GestureType.Tap, activity.Game.TargetElapsedTime,
             new Vector2(e.GetX(), e.GetY()), Vector2.Zero, Vector2.Zero, Vector2.Zero);
         TouchPanel.GestureList.Enqueue(gs);
     }
     return base.OnSingleTapConfirmed (e);
 }
コード例 #12
0
        internal IMessage Create(GestureSample gestureSample)
        {
            switch (gestureSample.GestureType)
            {
                case GestureType.Tap:
                    return new Message<TapGesture>(new TapGesture(gestureSample));
            }

            return null;
        }
コード例 #13
0
ファイル: ShootManager.cs プロジェクト: koboldul/Cocos2DGame1
        private Vector2 ComputeVelocity(GestureSample gesture)
        {
            Vector2 diff = _currentPosition - _startPosition;

            float magnitude = Math.Min(diff.Length(), 100) * 5;
            diff.Normalize();
            Vector2 result = diff * magnitude;

            return result;
        }
コード例 #14
0
ファイル: ExitCityButton.cs プロジェクト: steveyaz/Warlock
 public bool InteractGesture(GestureSample gesture)
 {
     if (gesture.GestureType == GestureType.Tap
         && gesture.Position.X < ExitButton.X + WarlockGame.TextureDictionary["leavecity"].Width && gesture.Position.X > ExitButton.X
         && gesture.Position.Y < ExitButton.Y + WarlockGame.TextureDictionary["leavecity"].Height && gesture.Position.Y > ExitButton.Y)
     {
         Execute();
         return true;
     }
     return false;
 }
コード例 #15
0
ファイル: ShootManager.cs プロジェクト: koboldul/Cocos2DGame1
        public Vector2 EndShooting(GestureSample gesture)
        {
            Vector2 velocity = ComputeVelocity(gesture);

            _startShootingTime = default(TimeSpan);
            _startPosition = default(Vector2);

            State = GameState.Idle;

            return velocity;
        }
コード例 #16
0
ファイル: ShootManager.cs プロジェクト: koboldul/Cocos2DGame1
        public void Update(GestureSample gesture)
        {
            if (State == GameState.Idle)
            {
                _startShootingTime = gesture.Timestamp;
                _startPosition = new Vector2(gesture.Position.X, gesture.Position.Y);
                State = GameState.Shooting;
            }

            _currentPosition = new Vector2(gesture.Position.X, gesture.Position.Y);
        }
コード例 #17
0
ファイル: PinchZoom.cs プロジェクト: milesgray/resatiate
        /// <summary>
        /// A helper function which automatically calls GetScaleFactor and GetTranslationDelta and applies them to the
        /// given object position and scale. You can either use this function or call GetScaleFactor and GetTranslationDelta
        /// manually. This function assumes that the origin of your object is at its center, and that the position
        /// given is in screen-space.
        /// </summary>
        /// <param name="gesture">The gesture sample containing the pinch gesture data. The GestureType must be
        /// GestureType.Pinch.</param>
        /// <param name="objectPos">The current position of your object, in screen-space.</param>
        /// <param name="objectScale">The current scale of your object.</param>
        public static void ApplyPinchZoom(GestureSample gesture, ref Vector2 objectPos, ref float objectScale)
        {
            System.Diagnostics.Debug.Assert(gesture.GestureType == GestureType.Pinch);

            float scaleFactor = PinchZoom.GetScaleFactor(gesture.Position, gesture.Position2,
                gesture.Delta, gesture.Delta2);
            Vector2 translationDelta = PinchZoom.GetTranslationDelta(gesture.Position, gesture.Position2,
                gesture.Delta, gesture.Delta2, objectPos, scaleFactor);

            objectScale *= scaleFactor;
            objectPos += translationDelta;
        }
コード例 #18
0
ファイル: ScreenObjectBase.cs プロジェクト: steveyaz/Warlock
 public virtual bool InteractGesture(GestureSample gesture)
 {
     if (TapDelegate != null
         && gesture.GestureType == GestureType.Tap
         && gesture.Position.X < ScreenPosition.X + Size.X && gesture.Position.X > ScreenPosition.X
         && gesture.Position.Y < ScreenPosition.Y + Size.Y && gesture.Position.Y > ScreenPosition.Y)
     {
         TapDelegate();
         return true;
     }
     return false;
 }
コード例 #19
0
        public GestureDefinition(GestureSample theGestureSample)
        {
            Gesture = theGestureSample;
            Type = theGestureSample.GestureType;
            CollisionArea = new Rectangle((int)theGestureSample.Position.X,
                                          (int)theGestureSample.Position.Y, 5, 5);

            Delta = theGestureSample.Delta;
            Delta2 = theGestureSample.Delta2;
            Position = theGestureSample.Position;
            Position2 = theGestureSample.Position2;
        }
コード例 #20
0
ファイル: GestureListener.cs プロジェクト: ValXp/MonoGame
		/// <summary>
		/// convert the DoubleTapEvent to a Gesture
		/// </summary>
		/// <param name='e'>
		/// If set to <c>true</c> e.
		/// </param>
		public override bool OnDoubleTap (MotionEvent e)
		{
			if ((TouchPanel.EnabledGestures & GestureType.DoubleTap) != 0)
			{				
				Vector2 positon = new Vector2(e.GetX(), e.GetY());
				AndroidGameActivity.Game.Window.UpdateTouchPosition(ref positon);
				var gs = new GestureSample(GestureType.DoubleTap, AndroidGameActivity.Game.TargetElapsedTime, 
					positon, Vector2.Zero, Vector2.Zero, Vector2.Zero);
				TouchPanel.GestureList.Enqueue(gs);
			}
			return base.OnDoubleTap (e);
		}
コード例 #21
0
        /// <summary>
        /// Call this to initialize a Behaviour with data supplied in a file.
        /// </summary>
        /// <param name="fileName">The file to load from.</param>
        public override void LoadContent(String fileName)
        {
            base.LoadContent(fileName);

            mGesture = new GestureSample();

            mFxMenuSelect = GameObjectManager.pInstance.pContentManager.Load<SoundEffect>("Audio\\FX\\MenuSelect");

            mGameRestartMsg = new Player.OnGameRestartMessage();
            mGetCurrentStateMsg = new Player.GetCurrentStateMessage();
            mGetCurrentHitCountMsg = new HitCountDisplay.GetCurrentHitCountMessage();
        }
コード例 #22
0
ファイル: Map.cs プロジェクト: steveyaz/Warlock
 public bool InteractGesture(GestureSample gesture)
 {
     switch (gesture.GestureType)
     {
         case GestureType.DoubleTap:
             break;
         case GestureType.Pinch:
             break;
         default:
             break;
     }
     return false;
 }
コード例 #23
0
ファイル: BattleObjectBase.cs プロジェクト: steveyaz/Warlock
 // override this to only interact with the base of the object
 public override bool InteractGesture(GestureSample gesture)
 {
     if (HitPoints > 0
         && TapDelegate != null
         && gesture.GestureType == GestureType.Tap
         && gesture.Position.X < ScreenPosition.X + Size.X && gesture.Position.X > ScreenPosition.X
         && gesture.Position.Y < ScreenPosition.Y + Size.Y && gesture.Position.Y > ScreenPosition.Y)
     {
         TapDelegate();
         return true;
     }
     return false;
 }
コード例 #24
0
ファイル: Human.cs プロジェクト: elixir67/Sandbox
        public void HandleInput(GestureSample gestureSample)
        {
            // Process input only if in Human's turn
            if (IsActive)
            {
                // Process any Drag gesture
                if (gestureSample.GestureType == GestureType.FreeDrag)
                {
                    // If drag just began, save the sample for future
                    // calculations and start Aim "animation"
                    if (null == firstSample)
                    {
                        firstSample = gestureSample;
                        Catapult.CurrentState = CatapultState.Aiming;
                    }

                    // save the current gesture sample
                    prevSample = gestureSample;

                    // calculate the delta between first sample and current
                    // sample to present visual sound on screen
                    Vector2 delta = prevSample.Value.Position -
                        firstSample.Value.Position;
                    Catapult.ShotStrength = delta.Length() / maxDragDelta;
                    float baseScale = 0.001f;
                    arrowScale = baseScale * delta.Length();
                    isDragging = true;
                }
                else if (gestureSample.GestureType == GestureType.DragComplete)
                {
                    // calculate velocity based on delta between first and last
                    // gesture samples
                    if (null != firstSample)
                    {
                        Vector2 delta = prevSample.Value.Position -
                            firstSample.Value.Position;
                        Catapult.ShotVelocity = MinShotStrength +
                            Catapult.ShotStrength *
                            (MaxShotStrength - MinShotStrength);
                        Catapult.Fire(Catapult.ShotVelocity);
                        Catapult.CurrentState = CatapultState.Firing;
                    }

                    // turn off dragging state
                    ResetDragState();
                }
            }
        }
コード例 #25
0
ファイル: GestureListener.cs プロジェクト: ValXp/MonoGame
		public override bool OnScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
		{			
			
			if ((TouchPanel.EnabledGestures & GestureType.FreeDrag) != 0)
			{								
				if (!dragging) dragging = true;
		
				Vector2 position = new Vector2(e2.GetX(), e2.GetY());
				Android.Util.Log.Info("MonoGame", position.ToString());
				AndroidGameActivity.Game.Window.UpdateTouchPosition(ref position);
				
				var gs = new GestureSample(GestureType.FreeDrag, AndroidGameActivity.Game.TargetElapsedTime, 
					position, Vector2.Zero, Vector2.Zero, Vector2.Zero);
				TouchPanel.GestureList.Enqueue(gs);
			}
			
			return base.OnScroll (e1, e2, distanceX, distanceY);
		}
コード例 #26
0
        public bool HandleFreeDrag(GestureSample gesture)
        {
            bool draggedMachineComponent = false;
            this.HandleSingleTap(gesture.Position);

            // drags which the selected image
            if (null != this.currentSelected)
            {
                draggedMachineComponent = true;

                currentSelected.dragTo(HudBar.screenToWorld(gesture.Position));

                // move current selected to front of linked list since it is now on "top"
                machineComponentList.Remove(currentSelected);
                machineComponentList.AddLast(currentSelected);
            }

            return draggedMachineComponent;
        }
コード例 #27
0
ファイル: WP7Touch.cs プロジェクト: quandtm/XNInterface
        public void HandleGesture(GestureSample gesture, BaseControl control)
        {
            var r = new RectangleF(control.Position, control.Size);
            if (r.Contains(gesture.Position))
            {
                switch (gesture.GestureType)
                {
                    case GestureType.Tap:
                        control.Trigger();
                        break;

                    case GestureType.DoubleTap:
                        control.Trigger();
                        break;
                }

                for (int i = 0; i < control.Children.Count; ++i)
                    HandleGesture(gesture, control.Children[i]);
            }
        }
コード例 #28
0
        public void UpdateZoom(GestureSample gesture)
        {
            // position: Compute final positions
            Vector2 finalP1 = gesture.Position + gesture.Delta;
            Vector2 finalP2 = gesture.Position2 + gesture.Delta2;

            // we choose to zoom by the smaller of the two X/Y
            float xZoom, yZoom, zoomFactor;
            xZoom = Math.Abs((finalP1.X - finalP2.X) / (gesture.Position.X - gesture.Position2.X));
            yZoom = Math.Abs((finalP1.Y - finalP2.Y) / (gesture.Position.Y - gesture.Position2.Y));
            zoomFactor = Math.Min(xZoom, yZoom);

            // constrain image size to screen size
            if (mPosition.Height < screenSizeY )
                mPosition.Height = screenSizeY ;
            if (mPosition.Width < screenSizeX )
                mPosition.Width = screenSizeX ;

            // constrain position to screen
            //constrainToScreen();

            // filter out small noise
            if (Math.Abs(zoomFactor - 1f) > 0.001f)
            {
                // compute final rec size, make sure aspect ratio is respected
                float newH = mPosition.Height * zoomFactor;
                float newW = newH * mAspectRatio;

                // make sure the image does not disappear completely
                if ((newW > 10) && (newH > 10))
                {
                    // Init center of pitch area: in general this is _NOT_ the image center!!
                    Vector2 initCenter = 0.5f * (gesture.Position + gesture.Position2);
                    SetSizeRatioByPosition(initCenter);
                    mPosition.Width = (int)newW;
                    mPosition.Height = (int)newH;
                    SetPositionByRatio(initCenter);
                }
            }
        }
コード例 #29
0
ファイル: TouchPanel.cs プロジェクト: bobaiep/root-s2
 internal static void EnqueueGesture(GestureSample gesture)
 {
     gestures.Enqueue(gesture);
 }
コード例 #30
0
ファイル: Manager.cs プロジェクト: JacopoV/Tap---Conquer
        private void ManageTouch(GameTime time)
        {
            if (numberOrders(1) < 3)
            {
                while (TouchPanel.IsGestureAvailable)
                {
                    touchGesture = TouchPanel.ReadGesture();
                    if (touchGesture.GestureType == GestureType.FreeDrag)
                    {
                        if (!touchBegin)
                        {
                            // save the state when drag starts
                            arrowOrigin = new Vector2(touchGesture.Position.X, touchGesture.Position.Y);
                            touchDelta = (float)time.ElapsedGameTime.TotalSeconds;
                            touchBegin = true;
                            factoryDestination = null;
                            factoryOrigin = null;
                            factoryReinforcement = null;
                            needReinforcement = false;
                        }
                        // update the current position beause may be the final destination
                        arrowDestination = new Vector2(touchGesture.Position.X, touchGesture.Position.Y);
                        // GLOW FOR EVERY FACTORY
                        foreach (Factory i in factories)
                        {
                            if (i != factoryReinforceSelected && factoryOrigin != null)
                            {
                                if (factoryOrigin.getType() == 1)
                                {
                                    Vector2 factoryPos = i.Center;
                                    float rad = i.getRadius();
                                    if (arrowDestination.X <= factoryPos.X + 30 &&
                                         arrowDestination.X >= factoryPos.X - 30 &&
                                           arrowDestination.Y <= factoryPos.Y + 30 &&
                                             arrowDestination.Y >= factoryPos.Y - 30)
                                    {
                                        touchPartial += (float)time.ElapsedGameTime.TotalSeconds;
                                        //the reinforcement factory
                                        i.loadImageWhenArrowOver();
                                    }
                                    else
                                    {
                                        i.loadImages();
                                    }
                                }
                            }
                        }

                        if (touchPartial - touchDelta > 1 && !needReinforcement)
                        {
                            //need reinforcements
                            arrowReinforcement = new Vector2(touchGesture.Position.X, touchGesture.Position.Y);
                            needReinforcement = true;
                            touchDelta = 0;
                            touchPartial = 0;

                            // GLOW FOR REINFORCEMENT FACTORY
                            foreach (Factory i in factories)
                            {
                                Vector2 factoryPos = i.Center;
                                float rad = i.getRadius();
                                if (arrowReinforcement.X <= factoryPos.X + 30 &&
                                     arrowReinforcement.X >= factoryPos.X - 30 &&
                                       arrowReinforcement.Y <= factoryPos.Y + 30 &&
                                         arrowReinforcement.Y >= factoryPos.Y - 30)
                                {
                                    //the reinforcement factory
                                    if (i.getType() == 1)
                                    {
                                        if (i != factoryOrigin)
                                        {
                                            i.LoadImageReinforce();
                                            factoryReinforceSelected = i;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (touchGesture.GestureType == GestureType.DragComplete)
                    {
                        //flag to stop drawing and launch order
                        touchBegin = false;
                        touchDelta = 0;
                        touchPartial = 0;
                        factoryReinforceSelected = null;
                        //check if the destination is a factory --> launch order
                        manageDestinationFactory();

                    }
                }
            }
        }
コード例 #31
0
ファイル: View.cs プロジェクト: fordream/Sunfish
 public bool IsGestureWithinView(GestureSample gestureSample)
 {
     Rectangle boundingBox = GetBoundingBox ();
     if (gestureSample.GestureType == GestureType.Pinch) {
         return boundingBox.Contains (gestureSample.Position) && boundingBox.Contains (gestureSample.Position2);
     } else {
         return boundingBox.Contains (gestureSample.Position);
     }
 }