Esempio n. 1
0
        public override void Update()
        {
            window.Update(); text.Update();

            if (displayState == DisplayState.Opening)
            {
                window.Open();
                if (window.displayState == DisplayState.Opened)
                {
                    text.Open();
                    if (text.displayState == DisplayState.Opened)
                    {
                        displayState = DisplayState.Opened;
                    }
                }
            }
            else if (displayState == DisplayState.Opened)
            {
                //handle user focusing/hovering over button via cursor
                if (Functions.Contains(
                        window.rec_bkg.openedRec,
                        Input.cursorPos.X, Input.cursorPos.Y))
                {
                    window.rec_bkg.color = color_over;
                    text.color           = color_over_text;
                    //pulse text alpha
                    if (text.alpha >= 1.1f)
                    {
                        text.alpha = 0.7f;
                    }
                    else
                    {
                        text.alpha += 0.01f;
                    }
                    //pickup button
                    if (Input.IsLeftMouseBtnPress())
                    {   //check for new left click, start dragging state
                        if (draggable)
                        {
                            beingDragged = true;
                        }
                    }
                }
                else
                {
                    window.rec_bkg.color = color_normal;
                    text.color           = color_normal_text;
                }

                //if button was picked up, match cursor's pos
                if (Input.currentMouseState.LeftButton == ButtonState.Pressed)
                {
                    if (draggable & beingDragged)
                    {
                        MoveTo(
                            (int)Input.cursorPos.X - window.rec_bkg.openedRec.W / 2,
                            (int)Input.cursorPos.Y - window.rec_bkg.openedRec.H / 2);
                    }
                }
                //drop button to screen
                if (Input.currentMouseState.LeftButton == ButtonState.Released)
                {
                    if (draggable & beingDragged)
                    {
                        beingDragged = false;
                    }
                }
            }
            else if (displayState == DisplayState.Closing)
            {
                if (window.displayState == DisplayState.Closed)
                {
                    displayState = DisplayState.Closed;
                }
            }
            else if (displayState == DisplayState.Closed)
            {
            }

            //Debug.WriteLine("obj ds: " + displayState);
            //Debug.WriteLine("window ds: " + window.displayState);
            //Debug.WriteLine("text ds: " + text.displayState);
        }
Esempio n. 2
0
        public override void Update()
        {
            text.Update();
            bkgLineWindow.Update();

            //put the text over the handle each frame
            text.position.X = handle.X - 4;
            text.position.Y = handle.Y - 16;

            if (displayState == DisplayState.Opening)
            {
                if (bkgLineWindow.displayState == DisplayState.Opened)
                {
                    displayState = DisplayState.Opened;
                }
            }
            else if (displayState == DisplayState.Opened)
            {
                //click line always follows clickX each frame
                clickLine.X = clickX;
                //fade click line out overtime
                if (clickLineAlpha > 0.0f)
                {
                    clickLineAlpha -= 0.01f;
                }
                else
                {
                    clickLineAlpha = 0.0f;
                }


                #region Increment currValue, which is what text draws

                if (currValue < value)
                {
                    currValue += 0.01f;
                }
                else if (currValue > value)
                {
                    currValue -= 0.01f;
                }
                else
                {
                    currValue = value;
                }

                #endregion

                #region Move handle to click position over time

                if (handle.X + 2 < clickX)
                {
                    handle.X++;
                    value += 0.01f;
                    //limit value max
                    if (value > 1.0f)
                    {
                        value = 1.0f;
                    }
                    //check for right boundary, limit
                    if (handle.X > bkgLineWindow.rec_bkg.openedRec.X + Width - 2)
                    {
                        handle.X = bkgLineWindow.rec_bkg.openedRec.X + Width - 2;
                        value    = 1.0f; //max
                    }
                    UpdateHandleValue();
                }
                else if (handle.X + 2 > clickX)
                {
                    handle.X--;
                    value -= 0.01f;
                    //limit value min
                    if (value < 0.01f)
                    {
                        value = 0.01f;
                    }
                    //check for left boundary, limit
                    if (handle.X < bkgLineWindow.rec_bkg.openedRec.X)
                    {
                        handle.X = bkgLineWindow.rec_bkg.openedRec.X;
                        value    = 0.01f; //min
                    }
                    UpdateHandleValue();
                }

                #endregion


                //add in user input to move value/handle
                if (Input.IsLeftMouseBtnPress())
                {
                    //user must click inside hitbox to move slider/handle
                    if (!Functions.Contains(hitbox,
                                            Input.cursorPos.X, Input.cursorPos.Y))
                    {
                        return;
                    }

                    //else, store click position, display click line
                    clickX         = (int)Input.cursorPos.X;
                    clickLineAlpha = 1.0f;
                }
            }
            else if (displayState == DisplayState.Closing)
            {
                if (bkgLineWindow.displayState == DisplayState.Closed)
                {
                    displayState = DisplayState.Closed;
                }
            }
            else if (displayState == DisplayState.Closed)
            {
            }
        }