Example #1
0
            public override Widget GetHoveredWidget(MouseContext m)
            {
                (int x, int y) = m.Mouse;

                int yIndex = 0;

                foreach (Widget w in Items)
                {
                    if (yIndex + w.Height > y)
                    {
                        if (x < w.Width)
                        {
                            m.SetRelativeMouse(0, -yIndex);

                            return(w);
                        }
                        break;
                    }

                    yIndex += w.Height;
                }

                // if nothing is hovered over
                return(this);
            }
Example #2
0
 public override Widget GetHoveredWidget(MouseContext m)
 {
     if (Content.HitTest(m.Mouse.X, m.Mouse.Y))
     {
         return(Content);
     }
     else
     {
         return(this);
     }
 }
Example #3
0
        public override Widget GetHoveredWidget(MouseContext m)
        {
            (int x, int y) = m.Mouse;

            if (Content.HitTest(x - 1, y - 1))
            {
                m.SetRelativeMouse(-1, -1);
                return(Content);
            }
            else
            {
                return(this);
            }
        }
Example #4
0
        public override Widget GetHoveredWidget(MouseContext m)
        {
            (int x, int y) = m.Mouse;

            foreach (WidgetWithLocation w in Children)
            {
                if (x >= w.X && y >= w.Y && w.Widget.HitTest(x - w.X, y - w.Y))
                {
                    m.SetRelativeMouse(-w.X, -w.Y);
                    return(w.Widget);
                }
            }

            return(this);
        }
Example #5
0
        public override Widget GetHoveredWidget(MouseContext m)
        {
            (int x, int y) = m.Mouse;

            if (x == ViewportWidth && y == ViewportHeight)
            {
                return(this);
            }
            else if (IsVScrollBarVisible() && x == ViewportWidth)
            {
                return(VScrollBar);
            }
            else if (IsHScrollBarVisible() && y == ViewportHeight)
            {
                return(HScrollBar);
            }
            else
            {
                m.SetRelativeMouse(HorizontalStart, VerticalStart);
                return(Content);
            }
        }
Example #6
0
 /// <summary>
 /// Updates relative mouse position and returns Widget directly under mouse.
 /// </summary>
 public abstract Widget GetHoveredWidget(MouseContext m);
        /// <summary>
        /// Update is called once per frame.
        /// </summary>
        protected virtual void Update()
        {
            DebugEx.VeryVeryVerbose("WindowScript.Update()");

            bool leftMouseButtonPressed = InputControl.GetMouseButtonDown(MouseButton.Left);

            if (IsFramePresent())
            {
                switch (mMouseState)
                {
                    case MouseState.NoState:
                    {
                        if (mMouseLocation != MouseLocation.Outside)
                        {
                            bool isInsideButtons = false;

                            float mouseX = Mouse.scaledX;
                            float mouseY = Mouse.scaledY;

                            if (mMinimizeGameObject != null)
                            {
                                RectTransform buttonTransform = mMinimizeGameObject.transform as RectTransform;
                                Vector3[] corners = Utils.GetWindowCorners(buttonTransform);

                                if (
                                    mouseX >= corners[0].x
                                    &&
                                    mouseX <= corners[3].x
                                    &&
                                    mouseY >= corners[0].y
                                    &&
                                    mouseY <= corners[3].y
                                   )
                                {
                                    isInsideButtons = true;

                                    mMinimizeGameObject.transform.SetAsLastSibling();
                                }
                            }

                            if (mMaximizeGameObject != null)
                            {
                                RectTransform buttonTransform = mMaximizeGameObject.transform as RectTransform;
                                Vector3[] corners = Utils.GetWindowCorners(buttonTransform);

                                if (
                                    mouseX >= corners[0].x
                                    &&
                                    mouseX <= corners[3].x
                                    &&
                                    mouseY >= corners[0].y
                                    &&
                                    mouseY <= corners[3].y
                                   )
                                {
                                    isInsideButtons = true;

                                    mMaximizeGameObject.transform.SetAsLastSibling();
                                }
                            }

                            if (mCloseGameObject != null)
                            {
                                RectTransform buttonTransform = mCloseGameObject.transform as RectTransform;
                                Vector3[] corners = Utils.GetWindowCorners(buttonTransform);

                                if (
                                    mouseX >= corners[0].x
                                    &&
                                    mouseX <= corners[3].x
                                    &&
                                    mouseY >= corners[0].y
                                    &&
                                    mouseY <= corners[3].y
                                   )
                                {
                                    isInsideButtons = true;

                                    mCloseGameObject.transform.SetAsLastSibling();
                                }
                            }

                            switch (mState)
                            {
                                case WindowState.NoState:
                                {
#if !CURSORLESS_PLATFORM
                                    MouseLocation oldLocation = mMouseLocation;
#endif

                                    if (isInsideButtons)
                                    {
                                        mMouseLocation = MouseLocation.Inside;
                                    }
                                    else
                                    {
                                        if (mResizable)
                                        {
                                            if (mouseY <= mY + SHADOW_WIDTH + RESIZING_GAP)
                                            {
                                                if (mouseX <= mX + mBorderLeft)
                                                {
                                                    mMouseLocation = MouseLocation.NorthWest;
                                                }
                                                else
                                                if (mouseX < mX + mWidth - mBorderRight)
                                                {
                                                    mMouseLocation = MouseLocation.North;
                                                }
                                                else
                                                {
                                                    mMouseLocation = MouseLocation.NorthEast;
                                                }
                                            }
                                            else
                                            if (mouseY <= mY + mBorderTop)
                                            {
                                                if (mouseX <= mX + mBorderLeft)
                                                {
                                                    mMouseLocation = MouseLocation.West;
                                                }
                                                else
                                                if (mouseX < mX + mWidth - mBorderRight)
                                                {
                                                    mMouseLocation = MouseLocation.Header;
                                                }
                                                else
                                                {
                                                    mMouseLocation = MouseLocation.East;
                                                }
                                            }
                                            else
                                            if (mouseY < mY + mHeight - mBorderBottom)
                                            {
                                                if (mouseX <= mX + mBorderLeft)
                                                {
                                                    mMouseLocation = MouseLocation.West;
                                                }
                                                else
                                                if (mouseX < mX + mWidth - mBorderRight)
                                                {
                                                    mMouseLocation = MouseLocation.Inside;
                                                }
                                                else
                                                {
                                                    mMouseLocation = MouseLocation.East;
                                                }
                                            }
                                            else
                                            {
                                                if (mouseX <= mX + mBorderLeft)
                                                {
                                                    mMouseLocation = MouseLocation.SouthWest;
                                                }
                                                else
                                                if (mouseX < mX + mWidth - mBorderRight)
                                                {
                                                    mMouseLocation = MouseLocation.South;
                                                }
                                                else
                                                {
                                                    mMouseLocation = MouseLocation.SouthEast;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (mouseY <= mY + mBorderTop)
                                            {
                                                mMouseLocation = MouseLocation.Header;
                                            }
                                            else
                                            {
                                                mMouseLocation = MouseLocation.Inside;
                                            }
                                        }
                                    }

#if !CURSORLESS_PLATFORM
                                    if (mResizable && oldLocation != mMouseLocation)
                                    {
                                        switch (mMouseLocation)
                                        {
                                            case MouseLocation.North:
                                            case MouseLocation.South:
                                            {
                                                Cursor.SetCursor(Assets.Common.Cursors.northSouth.texture, new Vector2(16f * Utils.canvasScale, 16f * Utils.canvasScale), CursorMode.Auto);
                                            }
                                            break;

                                            case MouseLocation.West:
                                            case MouseLocation.East:
                                            {
                                                Cursor.SetCursor(Assets.Common.Cursors.eastWest.texture, new Vector2(16f * Utils.canvasScale, 16f * Utils.canvasScale), CursorMode.Auto);
                                            }
                                            break;

                                            case MouseLocation.NorthWest:
                                            case MouseLocation.SouthEast:
                                            {
                                                Cursor.SetCursor(Assets.Common.Cursors.northWestSouthEast.texture, new Vector2(16f * Utils.canvasScale, 16f * Utils.canvasScale), CursorMode.Auto);
                                            }
                                            break;

                                            case MouseLocation.NorthEast:
                                            case MouseLocation.SouthWest:
                                            {
                                                Cursor.SetCursor(Assets.Common.Cursors.northEastSouthWest.texture, new Vector2(16f * Utils.canvasScale, 16f * Utils.canvasScale), CursorMode.Auto);
                                            }
                                            break;

                                            case MouseLocation.Header:
                                            case MouseLocation.Inside:
                                            {
                                                RemoveCursor();
                                            }
                                            break;

                                            case MouseLocation.Outside:
                                            {
                                                DebugEx.ErrorFormat("Incorrect mouse location: {0}", mMouseLocation);
                                            }
                                            break;

                                            default:
                                            {
                                                DebugEx.ErrorFormat("Unknown mouse location: {0}", mMouseLocation);
                                            }
                                            break;
                                        }
                                    }
#endif
                                }
                                break;

                                case WindowState.Minimized:
                                {
                                    if (isInsideButtons)
                                    {
                                        mMouseLocation = MouseLocation.Inside;
                                    }
                                    else
                                    {
                                        mMouseLocation = MouseLocation.Header;
                                    }
                                }
                                break;

                                case WindowState.Maximized:
                                {
                                    if (isInsideButtons)
                                    {
                                        mMouseLocation = MouseLocation.Inside;
                                    }
                                    else
                                    {
                                        if (mouseY <= mBorderTop - SHADOW_WIDTH - MAXIMIZED_OFFSET)
                                        {
                                            mMouseLocation = MouseLocation.Header;
                                        }
                                        else
                                        {
                                            mMouseLocation = MouseLocation.Inside;
                                        }
                                    }
                                }
                                break;

                                case WindowState.FullScreen:
                                {
                                    DebugEx.ErrorFormat("Incorrect window state: {0}", mState);
                                }
                                break;

                                default:
                                {
                                    DebugEx.ErrorFormat("Unknown window state: {0}", mState);
                                }
                                break;
                            }

                            switch (mMouseLocation)
                            {
                                case MouseLocation.Header:
                                {
                                    if (leftMouseButtonPressed)
                                    {
                                        StartDragging();
                                    }
                                }
                                break;

                                case MouseLocation.North:
                                case MouseLocation.South:
                                case MouseLocation.West:
                                case MouseLocation.East:
                                case MouseLocation.NorthWest:
                                case MouseLocation.SouthEast:
                                case MouseLocation.NorthEast:
                                case MouseLocation.SouthWest:
                                {
                                    if (mResizable && mState == WindowState.NoState)
                                    {
                                        if (leftMouseButtonPressed)
                                        {
                                            mMouseState = MouseState.Resizing;

                                            mMouseContext = new MouseContext(mouseX, mouseY, x, y, width, height, mWindowTransform.offsetMin.x, -mWindowTransform.offsetMax.y);
                                        }
                                    }
                                }
                                break;

                                case MouseLocation.Inside:
                                {
                                    // Nothing
                                }
                                break;

                                case MouseLocation.Outside:
                                {
                                    DebugEx.ErrorFormat("Incorrect mouse location: {0}", mMouseLocation);
                                }
                                break;

                                default:
                                {
                                    DebugEx.ErrorFormat("Unknown mouse location: {0}", mMouseLocation);
                                }
                                break;
                            }
                        }
                    }
                    break;

                    case MouseState.Dragging:
                    {
                        float mouseX = Mouse.scaledX;
                        float mouseY = Mouse.scaledY;

                        #region Calculate new position
                        float screenWidth  = Utils.scaledScreenWidth;
                        float screenHeight = Utils.scaledScreenHeight;

                        if (mState == WindowState.Maximized)
                        {
                            if (
                                mouseX == mMouseContext.previousMouseX
                                &&
                                mouseY == mMouseContext.previousMouseY
                               )
                            {
                                if (InputControl.GetMouseButtonUp(MouseButton.Left))
                                {
                                    mMouseState   = MouseState.NoState;
                                    mMouseContext = null;
                                }

                                return;
                            }

                            state = WindowState.NoState;
                            mMouseContext.previousX = mMouseContext.previousMouseX - (mMouseContext.previousMouseX / screenWidth) * width;
                            mMouseContext.previousY = 0;
                        }

                        float newX = 0f;
                        float newY = 0f;

                        switch (mState)
                        {
                            case WindowState.NoState:
                            {
                                newX = mMouseContext.previousX + mouseX - mMouseContext.previousMouseX;
                                newY = mMouseContext.previousY + mouseY - mMouseContext.previousMouseY;
                            }
                            break;

                            case WindowState.Minimized:
                            {
                                newX = mMouseContext.previousRectX + mouseX - mMouseContext.previousMouseX + SHADOW_WIDTH;
                                newY = mMouseContext.previousRectY + mouseY - mMouseContext.previousMouseY + SHADOW_WIDTH;
                            }
                            break;

                            case WindowState.Maximized:
                            case WindowState.FullScreen:
                            {
                                DebugEx.ErrorFormat("Incorrect window state: {0}", mState);
                            }
                            break;

                            default:
                            {
                                DebugEx.ErrorFormat("Unknown window state: {0}", mState);
                            }
                            break;
                        }

                        float windowWidth = mWindowTransform.sizeDelta.x - 2 * SHADOW_WIDTH;

                        if (newX + windowWidth < DRAGGING_GAP)
                        {
                            newX = -windowWidth + DRAGGING_GAP;
                        }
                        else
                        if (newX > screenWidth - DRAGGING_GAP)
                        {
                            newX = screenWidth - DRAGGING_GAP;
                        }

                        if (newY < -mBorderTop + DRAGGING_GAP + SHADOW_WIDTH)
                        {
                            newY = -mBorderTop + DRAGGING_GAP + SHADOW_WIDTH;
                        }
                        else
                        if (newY > screenHeight - DRAGGING_GAP)
                        {
                            newY = screenHeight - DRAGGING_GAP;
                        }

                        switch (mState)
                        {
                            case WindowState.NoState:
                            {
                                x = newX;
                                y = newY;
                            }
                            break;

                            case WindowState.Minimized:
                            {
                                newX -= SHADOW_WIDTH;
                                newY -= SHADOW_WIDTH;
                                windowWidth += 2 * SHADOW_WIDTH;
                                float windowHeight = mWindowTransform.sizeDelta.y;

                                mWindowTransform.offsetMin = new Vector2(
                                                                           newX
                                                                         , -newY - windowHeight
                                                                        );

                                mWindowTransform.offsetMax = new Vector2(
                                                                           newX + windowWidth
                                                                         , -newY
                                                                        );
                            }
                            break;

                            case WindowState.Maximized:
                            case WindowState.FullScreen:
                            {
                                DebugEx.ErrorFormat("Incorrect window state: {0}", mState);
                            }
                            break;

                            default:
                            {
                                DebugEx.ErrorFormat("Unknown window state: {0}", mState);
                            }
                            break;
                        }
                        #endregion

                        #region Show/Hide replacement
                        bool replacementVisible = false;

                        if (mouseX < DRAGGING_GAP)
                        {
                            if (mResizable)
                            {
                                replacementVisible = true;

                                if (
                                    mReplacementGameObject == null
                                    ||
                                    mReplacementTransform.anchorMin != new Vector2(0f, 0f)
                                    ||
                                    mReplacementTransform.anchorMax != new Vector2(0f, 1f)
                                   )
                                {
                                    CreateReplacementStretchLeft();
                                }
                            }
                        }
                        else
                        if (mouseX > screenWidth - DRAGGING_GAP)
                        {
                            if (mResizable)
                            {
                                replacementVisible = true;

                                if (
                                    mReplacementGameObject == null
                                    ||
                                    mReplacementTransform.anchorMin != new Vector2(1f, 0f)
                                    ||
                                    mReplacementTransform.anchorMax != new Vector2(1f, 1f)
                                    )
                                {
                                    CreateReplacementStretchRight();
                                }
                            }
                        }
                        else
                        if (mouseY < DRAGGING_GAP)
                        {
                            if (mAllowMaximize)
                            {
                                replacementVisible = true;

                                if (
                                    mReplacementGameObject == null
                                    ||
                                    mReplacementTransform.anchorMin != new Vector2(0f, 0f)
                                    ||
                                    mReplacementTransform.anchorMax != new Vector2(1f, 1f)
                                    )
                                {
                                    CreateReplacementStretchStretch();
                                }
                            }
                        }

                        if (!replacementVisible)
                        {
                            DestroyReplacement();
                        }
                        #endregion

                        if (InputControl.GetMouseButtonUp(MouseButton.Left))
                        {
                            if (mReplacementGameObject != null)
                            {
                                if (mouseX < DRAGGING_GAP)
                                {
                                    width  = screenWidth / 2;
                                    height = screenHeight;
                                    x      = 0;
                                    y      = 0;
                                }
                                else
                                if (mouseX > screenWidth - DRAGGING_GAP)
                                {
                                    width  = screenWidth / 2;
                                    height = screenHeight;
                                    x      = screenWidth - width;
                                    y      = 0;
                                }
                                else
                                if (mouseY < DRAGGING_GAP)
                                {
                                    state = WindowState.Maximized;
                                }
                            }

                            DestroyReplacement();

                            mMouseState   = MouseState.NoState;
                            mMouseContext = null;

                            Vector3[] corners = Utils.GetWindowCorners(mWindowTransform);

                            if (
                                mouseX < corners[0].x + SHADOW_WIDTH || mouseX > corners[3].x - SHADOW_WIDTH
                                ||
                                mouseY < corners[0].y + SHADOW_WIDTH || mouseY > corners[3].y - SHADOW_WIDTH
                               )
                            {
                                mMouseLocation = MouseLocation.Outside;
                            }
                        }
                    }
                    break;

                    case MouseState.Resizing:
                    {
                        float mouseX = Mouse.scaledX;
                        float mouseY = Mouse.scaledY;

                        #region Calculate new geometry
                        float screenWidth  = Utils.scaledScreenWidth;
                        float screenHeight = Utils.scaledScreenHeight;

                        #region West
                        if (
                            mMouseLocation == MouseLocation.West
                            ||
                            mMouseLocation == MouseLocation.NorthWest
                            ||
                            mMouseLocation == MouseLocation.SouthWest
                           )
                        {
                            float newX     = mMouseContext.previousX     + mouseX - mMouseContext.previousMouseX;
                            float newWidth = mMouseContext.previousWidth - mouseX + mMouseContext.previousMouseX;

                            if (newWidth < MINIMAL_WIDTH)
                            {
                                newX     -= MINIMAL_WIDTH - newWidth;
                                newWidth  = MINIMAL_WIDTH;
                            }

                            if (mMinimumWidth != 0 && newWidth < mMinimumWidth)
                            {
                                newX     -= mMinimumWidth - newWidth;
                                newWidth  = mMinimumWidth;
                            }

                            if (mMaximumWidth != 0 && newWidth > mMaximumWidth)
                            {
                                newX     -= mMaximumWidth - newWidth;
                                newWidth  = mMaximumWidth;
                            }

                            if (newX > screenWidth - DRAGGING_GAP)
                            {
                                newWidth += newX - (screenWidth - DRAGGING_GAP);
                                newX      = screenWidth - DRAGGING_GAP;
                            }

                            x     = newX;
                            width = newWidth;
                        }
                        #endregion
                        else
                        #region East
                        if (
                            mMouseLocation == MouseLocation.East
                            ||
                            mMouseLocation == MouseLocation.NorthEast
                            ||
                            mMouseLocation == MouseLocation.SouthEast
                           )
                        {
                            float newWidth = mMouseContext.previousWidth + mouseX - mMouseContext.previousMouseX;

                            if (mMouseContext.previousX + newWidth < DRAGGING_GAP)
                            {
                                newWidth = -mMouseContext.previousX + DRAGGING_GAP;
                            }

                            width = newWidth;
                        }
                        #endregion

                        #region North
                        if (
                            mMouseLocation == MouseLocation.North
                            ||
                            mMouseLocation == MouseLocation.NorthWest
                            ||
                            mMouseLocation == MouseLocation.NorthEast
                           )
                        {
                            float newY      = mMouseContext.previousY      + mouseY - mMouseContext.previousMouseY;
                            float newHeight = mMouseContext.previousHeight - mouseY + mMouseContext.previousMouseY;

                            if (newHeight < MINIMAL_HEIGHT)
                            {
                                newY      -= MINIMAL_HEIGHT - newHeight;
                                newHeight  = MINIMAL_HEIGHT;
                            }

                            if (mMinimumHeight != 0 && newHeight < mMinimumHeight)
                            {
                                newY      -= mMinimumHeight - newHeight;
                                newHeight  = mMinimumHeight;
                            }

                            if (mMaximumHeight != 0 && newHeight > mMaximumHeight)
                            {
                                newY      -= mMaximumHeight - newHeight;
                                newHeight  = mMaximumHeight;
                            }

                            if (newY < -mBorderTop + DRAGGING_GAP + SHADOW_WIDTH)
                            {
                                newHeight -= -mBorderTop + DRAGGING_GAP + SHADOW_WIDTH - newY;
                                newY       = -mBorderTop + DRAGGING_GAP + SHADOW_WIDTH;
                            }
                            else
                            if (newY > screenHeight - DRAGGING_GAP)
                            {
                                newHeight += newY - (screenHeight - DRAGGING_GAP);
                                newY       = screenHeight - DRAGGING_GAP;
                            }

                            y      = newY;
                            height = newHeight;
                        }
                        #endregion
                        else
                        #region South
                        if (
                            mMouseLocation == MouseLocation.South
                            ||
                            mMouseLocation == MouseLocation.SouthWest
                            ||
                            mMouseLocation == MouseLocation.SouthEast
                           )
                        {
                            height = mMouseContext.previousHeight + mouseY - mMouseContext.previousMouseY;
                        }
                        #endregion
                        #endregion

                        #region Show/Hide replacement
                        bool replacementVisible = false;

                        if (mouseY < DRAGGING_GAP)
                        {
                            if (
                                mMouseLocation == MouseLocation.North
                                ||
                                mMouseLocation == MouseLocation.NorthWest
                                ||
                                mMouseLocation == MouseLocation.NorthEast
                               )
                            {
                                replacementVisible = true;

                                if (mReplacementGameObject == null)
                                {
                                    CreateReplacementStretchVertical();
                                }
                                else
                                if (
                                    mMouseLocation == MouseLocation.NorthWest
                                    ||
                                    mMouseLocation == MouseLocation.NorthEast
                                   )
                                {
                                    mReplacementTransform.offsetMin = new Vector2(mWindowTransform.offsetMin.x, mReplacementTransform.offsetMin.y);
                                    mReplacementTransform.offsetMax = new Vector2(mWindowTransform.offsetMax.x, mReplacementTransform.offsetMax.y);
                                }
                            }
                        }
                        else
                        if (mouseY > screenHeight - DRAGGING_GAP)
                        {
                            if (
                                mMouseLocation == MouseLocation.South
                                ||
                                mMouseLocation == MouseLocation.SouthWest
                                ||
                                mMouseLocation == MouseLocation.SouthEast
                               )
                            {
                                replacementVisible = true;

                                if (mReplacementGameObject == null)
                                {
                                    CreateReplacementStretchVertical();
                                }
                                else
                                if (
                                    mMouseLocation == MouseLocation.SouthWest
                                    ||
                                    mMouseLocation == MouseLocation.SouthEast
                                   )
                                {
                                    mReplacementTransform.offsetMin = new Vector2(mWindowTransform.offsetMin.x, mReplacementTransform.offsetMin.y);
                                    mReplacementTransform.offsetMax = new Vector2(mWindowTransform.offsetMax.x, mReplacementTransform.offsetMax.y);
                                }
                            }
                        }

                        if (!replacementVisible)
                        {
                            DestroyReplacement();
                        }
                        #endregion

                        if (InputControl.GetMouseButtonUp(MouseButton.Left))
                        {
                            if (mReplacementGameObject != null)
                            {
                                y      = 0;
                                height = screenHeight;
                            }

                            DestroyReplacement();

                            mMouseState   = MouseState.NoState;
                            mMouseContext = null;

                            if (mouseX < mX + SHADOW_WIDTH || mouseX > mX + mWidth  - SHADOW_WIDTH
                                ||
                                mouseY < mY + SHADOW_WIDTH || mouseY > mY + mHeight - SHADOW_WIDTH)
                            {
#if !CURSORLESS_PLATFORM
                                RemoveCursor();
#endif

                                mMouseLocation = MouseLocation.Outside;
                            }
                        }
                    }
                    break;

                    default:
                    {
                        DebugEx.ErrorFormat("Unknown mouse state: {0}", mMouseState);
                    }
                    break;
                }
            }

            if (leftMouseButtonPressed)
            {
                List<RaycastResult> hits = new List<RaycastResult>();
                Mouse.RaycastAll(hits);

                bool isOk       = true;
                bool isSelected = false;

                if (hits.Count > 0)
                {
                    Transform curTransform = hits[0].gameObject.transform;

                    while (curTransform != null)
                    {
                        if (curTransform == transform)
                        {
                            isSelected = true;

                            break;
                        }

                        if (curTransform.GetComponent<WindowScript>() != null)
                        {
                            break;
                        }

                        if (curTransform.GetComponent<PopupMenuAreaScript>() != null)
                        {
                            isOk = false;

                            break;
                        }

                        curTransform = curTransform.parent;
                    }
                }

                if (isOk)
                {
                    SetSelected(isSelected);
                }
            }
        }
        /// <summary>
        /// Starts dragging mode.
        /// </summary>
        protected void StartDragging()
        {
            DebugEx.Verbose("WindowScript.StartDragging()");

            float mouseX = Mouse.scaledX;
            float mouseY = Mouse.scaledY;

            mMouseState = MouseState.Dragging;

            mMouseContext = new MouseContext(mouseX, mouseY, x, y, width, height, mWindowTransform.offsetMin.x, -mWindowTransform.offsetMax.y);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Common.UI.Windows.WindowScript"/> class.
        /// </summary>
        public WindowScript()
            : base()
        {
            DebugEx.Verbose("Created WindowScript object");

            sInstances.Add(this);

            mFrame           = WindowFrameType.Window;
            mState           = WindowState.NoState;
            mX               = -SHADOW_WIDTH;
            mY               = -SHADOW_WIDTH;
            mWidth           = 0f;
            mHeight          = 0f;
            mBackgroundColor = Assets.Common.Windows.Colors.background;
            mResizable       = true;
            mMinimumWidth    = 0f;
            mMinimumHeight   = 0f;
            mMaximumWidth    = 0f;
            mMaximumHeight   = 0f;
            mAllowMinimize   = true;
            mAllowMaximize   = true;
            mAllowClose      = true;
            mTokenId         = R.sections.WindowTitles.strings.Count;

            mWindowTransform        = null;
            mBorderGameObject       = null;
            mBorderImage            = null;
            mTitleGameObject        = null;
            mTitleText              = null;
            mMinimizeGameObject     = null;
            mMinimizeImage          = null;
            mMaximizeGameObject     = null;
            mMaximizeImage          = null;
            mCloseGameObject        = null;
            mCloseImage             = null;
            mContentTransform       = null;
            mContentBackgroundImage = null;
            mReplacementGameObject  = null;
            mReplacementTransform   = null;
            mBorderLeft             = 0f;
            mBorderTop              = 0f;
            mBorderRight            = 0f;
            mBorderBottom           = 0f;
            mMouseLocation          = MouseLocation.Outside;
            mMouseState             = MouseState.NoState;
            mMouseContext           = null;

            Hide();
        }
Example #10
0
 public void ExecuteClick(MouseContext context)
 {
     Common.Click(true, Common.LEFT_BUTTON);
     Common.Click(false, Common.LEFT_BUTTON);
 }
Example #11
0
 public void ExecuteClick(MouseContext context)
 {
     Common.RightClickUp((uint)context.Position.X, (uint)context.Position.Y);
     Thread.Sleep(delay);
     Common.RightClickDown((uint)context.Position.X, (uint)context.Position.Y);
 }
Example #12
0
            public UIContext(Gui gui)
            {
                _instance = this;
                _keyboard = Create<KeyboardContext>();
                _mouse = Add(new MouseContext(gui));
                //Create<GamePadContext>();

                var handler = Add(new ComponentHandler());
                handler.Handle<IToolUI>(AddToolUI, ui => _toolUis.Remove(ui));
                handler.Handle<IGameUI>(AddGameUI, ui => _gameUis.Remove(ui));

                ToolMode = new ToggleComponent(SetToolMode, SetGameMode);
            }
Example #13
0
        protected override void HandleInput(GameTime gameTime)
        {
            IInputContext   input = Engine.InputContext;
            MouseContext    mouse = input.Mouse;
            KeyboardContext key   = input.Keyboard;

            if (mouse.WheelDelta != 0)
            {
                _h += -mouse.WheelDelta * gameTime.ElapsedGameTime.TotalSeconds * _h * 0.0843f;
            }

            if (mouse.WasLeftButtonPressed)
            {
                // start drag
                previousPoint = mouse.Location;
            }

            if (mouse.IsLeftButtonDown && !mouse.IsRightButtonDown)
            {
                // dragging
                float diffX = mouse.Location.X - previousPoint.X;
                float diffY = mouse.Location.Y - previousPoint.Y;

                Longitude -= diffX * 0.016f * HeightAboveGround * 2f;
                if (Longitude > 180)
                {
                    Longitude = -180 + (Longitude - 180);
                }
                if (Longitude < -180)
                {
                    Longitude = 180 + (Longitude - -180);
                }

                Latitude += diffY * 0.016f * HeightAboveGround * 2f;
                if (Latitude > 85)
                {
                    Latitude = 85;
                }
                if (Latitude < -85)
                {
                    Latitude = -85;
                }

                previousPoint = mouse.Location;
            }
            else if (!mouse.IsRightButtonDown)
            {
                previousPoint = Vector2.Zero;
            }

            if (mouse.WasRightButtonPressed)
            {
                previousPoint = mouse.Location;
            }

            if (mouse.IsRightButtonDown && !mouse.IsLeftButtonDown)
            {
                // dragging
                float diffX = mouse.Location.X - previousPoint.X;
                float diffY = mouse.Location.Y - previousPoint.Y;

                Rotate(diffX, diffY);

                previousPoint = mouse.Location;
            }
            else if (!mouse.IsLeftButtonDown)
            {
                previousPoint = Vector2.Zero;
            }
        }