Esempio n. 1
0
        private void onTouch(AsTouchEvent _event)
        {
            AsMouse.setCursor(mUseHandCursor && mEnabled && _event.interactsWith(this) ? AsMouseCursor.BUTTON : AsMouseCursor.AUTO);
            AsTouch touch = _event.getTouch(this);

            if (!mEnabled || touch == null)
            {
                return;
            }
            if (touch.getPhase() == AsTouchPhase.BEGAN && !mIsDown)
            {
                mBackground.setTexture(mDownState);
                mContents.setScaleX(mContents.setScaleY(mScaleWhenDown));
                mContents.setX((1.0f - mScaleWhenDown) / 2.0f * mBackground.getWidth());
                mContents.setY((1.0f - mScaleWhenDown) / 2.0f * mBackground.getHeight());
                mIsDown = true;
            }
            else
            {
                if (touch.getPhase() == AsTouchPhase.MOVED && mIsDown)
                {
                    AsRectangle buttonRect = getBounds(getStage());
                    if (touch.getGlobalX() < buttonRect.x - MAX_DRAG_DIST || touch.getGlobalY() < buttonRect.y - MAX_DRAG_DIST || touch.getGlobalX() > buttonRect.x + buttonRect.width + MAX_DRAG_DIST || touch.getGlobalY() > buttonRect.y + buttonRect.height + MAX_DRAG_DIST)
                    {
                        resetContents();
                    }
                }
                else
                {
                    if (touch.getPhase() == AsTouchPhase.ENDED && mIsDown)
                    {
                        resetContents();
                        dispatchEventWith(AsEvent.TRIGGERED, true);
                    }
                }
            }
        }
 private void onTouch(AsTouchEvent _event)
 {
     AsMouse.setCursor(_event.interactsWith(this) ? AsMouseCursor.BUTTON : AsMouseCursor.AUTO);
 }