예제 #1
0
파일: Touch.cs 프로젝트: barronds/XNARTS
        public void Update(GameTime game_time)
        {
            mCurrentGameTime = game_time;

            // cache touches every update in case it's expensive to get
            mTouches = Microsoft.Xna.Framework.Input.Touch.TouchPanel.GetState();

            // gather what is needed to update triggers first
            eContactChange count_change = UpdateTouchCount();

            // update state machine last, possibly in new state
            mStateMachine.Update(count_change);
        }
예제 #2
0
        protected override bool OnTouch(Microsoft.Xna.Framework.Input.Touch.TouchCollection touchs)
        {
            Vector2 lt = this.scenepos - (Orient) * this.scenescale;
            Vector2 rb = lt + this.scenescale * Size;

            List <Vector2> poss = new List <Vector2>();
            //if (bTouch == false)
            bool    ntouchup = false;
            Vector2 npos     = Vector2.Zero;

            {//检测位置
                foreach (var t in touchs)
                {
                    if (t.State == Microsoft.Xna.Framework.Input.Touch.TouchLocationState.Pressed || t.State == Microsoft.Xna.Framework.Input.Touch.TouchLocationState.Moved)
                    {
                        if (lt.X <= t.Position.X && t.Position.X <= rb.X &&
                            lt.Y <= t.Position.Y && t.Position.Y <= rb.Y)
                        {
                            poss.Add(t.Position);
                        }
                    }
                    if (t.State == Microsoft.Xna.Framework.Input.Touch.TouchLocationState.Released)
                    {
                        if (lt.X <= t.Position.X && t.Position.X <= rb.X &&
                            lt.Y <= t.Position.Y && t.Position.Y <= rb.Y)
                        {
                            npos     = t.Position;
                            ntouchup = true;
                        }
                    }
                }
            }

            if (poss.Count > 0)
            {
                foreach (var v in poss)
                {
                    npos += v;
                }
                npos /= poss.Count;
            }
            if (bTouch == false && poss.Count > 0)//按下
            {
                oldpos = npos;
                bTouch = true;
                return(true);
            }
            else if (bTouch == true && poss.Count == 0)
            {
                if (ntouchup && !bdrag)
                {
                    if ((npos - oldpos).Length() < 5)
                    {
                        for (int i = 0; i < UIItem.Count; i++)
                        {
                            Vector2 slt = UIItem[i].scenepos - (UIItem[i].Orient) * UIItem[i].scenescale;
                            Vector2 srb = slt + UIItem[i].scenescale * UIItem[i].Size;
                            if (slt.Y <= npos.Y && npos.Y <= srb.Y)
                            {
                                SelectedIndex = i;
                                break;
                            }
                        }

                        return(true);
                    }
                    //松开
                    oldpos = npos;
                }
                else
                {
                    //离开
                }
                bTouch = false;
                bdrag  = false;
            }
            else if (poss.Count > 0) //drag
            {
                if ((npos - oldpos).Length() > 3)
                {
                    bdrag = true;

                    dragpos -= npos.Y - oldpos.Y;
                    UpdatePos();
                    oldpos = npos;
                }
                return(true);
            }

            //处理选中逻辑
            return(false);
        }
예제 #3
0
        protected override bool OnTouch(Microsoft.Xna.Framework.Input.Touch.TouchCollection touchs)
        {
            Vector2 lt       = this.scenepos - (Orient) * this.scenescale;
            Vector2 rb       = lt + this.scenescale * Size;
            bool    ntouch   = false;
            bool    ntouchup = false;

            foreach (var t in touchs)
            {
                if (t.State == Microsoft.Xna.Framework.Input.Touch.TouchLocationState.Pressed || t.State == Microsoft.Xna.Framework.Input.Touch.TouchLocationState.Moved)
                {
                    if (lt.X <= t.Position.X && t.Position.X <= rb.X &&
                        lt.Y <= t.Position.Y && t.Position.Y <= rb.Y)
                    {
                        ntouch = true;
                        break;
                    }
                }
                if (t.State == Microsoft.Xna.Framework.Input.Touch.TouchLocationState.Released || t.State == Microsoft.Xna.Framework.Input.Touch.TouchLocationState.Invalid)
                {
                    if (lt.X <= t.Position.X && t.Position.X <= rb.X &&
                        lt.Y <= t.Position.Y && t.Position.Y <= rb.Y)
                    {
                        ntouchup = true;
                        break;
                    }
                }
            }
            if (ntouch == true && bTouch == false)
            {
                //按下
                bTouch = true;
                if (onTouchDown != null)
                {
                    onTouchDown(btntag);
                }
                return(true);
            }
            if (ntouchup == true && bTouch == true)
            {
                //弹起
                bTouch = false;
                if (onTouchUp != null)
                {
                    onTouchUp(btntag);
                }
                return(true);
            }
            if (ntouch == false && ntouchup == false)
            {
                if (onTouchLeft != null)
                {
                    onTouchLeft(btntag);
                }
            }
            bTouch = ntouch;
            imgTouch.needUpdate = true;
            if (imgNormal.Children != null)
            {
                foreach (var i in imgNormal.Children)
                {
                    i.needUpdate = true;
                }
            }
            imgNormal.needUpdate = true;
            if (imgTouch.Children != null)
            {
                foreach (var i in imgTouch.Children)
                {
                    i.needUpdate = true;
                }
            }
            return(false);
        }
예제 #4
0
 public override void updateButton(GameTime gameTime, Microsoft.Xna.Framework.Input.Touch.TouchCollection touches)
 {
     base.updateButton(gameTime, touches);
 }