public static SharpDX.Vector2 ToSharpDX(MinerWarsMath.Vector2 vector)
 {
     return(new SharpDX.Vector2(vector.X, vector.Y));
 }
Exemple #2
0
        //  Update keyboard/mouse input and return true if application has focus (is active). Otherwise false.
        public bool Update()
        {
            bool ret;
            
            if (MyMinerGame.Static.IsActive == true && 
                ((MinerWars.AppCode.ExternalEditor.MyEditorBase.Static == null && MyMinerGame.Static.Window.NativeWindow.Handle == GetForegroundWindow())
                ||
                (MinerWars.AppCode.ExternalEditor.MyEditorBase.Static != null && !MinerWars.AppCode.ExternalEditor.MyEditorBase.IsEditorActive))
                )
            {
                                

                if (m_previousUpdateWasLostFocus == true)
                {
                    // we sets game mouse cursor to position, when was windows mouse cursor
                    MyMouseState windowsMouseState = MinerWars.AppCode.Toolkit.Input.MyWindowsMouse.GetCurrentState();
                    MyGuiManager.MouseCursorPosition = new MinerWarsMath.Vector2((float)windowsMouseState.X / MyMinerGame.ScreenSize.X, (float)windowsMouseState.Y / MyMinerGame.ScreenSize.Y);                    

                    //  When we return from lost focus, we must set mouse to the middle of the screen, otherwise we will see jump as user moved the mouse while he was out-of-focus
                    if (MyVideoModeManager.IsHardwareCursorUsed()) {
                        if(MyGuiManager.GetScreenWithFocus() != null && MyGuiManager.GetScreenWithFocus().GetDrawMouseCursor() == false)    
                            SetMouseToScreenCenter();                                        
                    } else
                        SetMouseToScreenCenter();
                }

                UpdateStates();

                if (IsNewLeftMouseReleased())
                {
                    var screenCoordinate = MyGuiManager.GetScreenCoordinateFromNormalizedCoordinate(MyGuiManager.MouseCursorPosition);
                    
                    m_leftButtonDoubleClick = MyMinerGame.TotalTimeInMilliseconds - m_lastLeftButtonClickTime < DOUBLE_CLICK_DELAY &&
                        (screenCoordinate - m_lastLeftButtonMousePosition).LengthSquared() < DOUBLE_CLICK_MAXIMUM_DISTANCE_SQUARED;

                    m_lastLeftButtonClickTime = m_leftButtonDoubleClick ? 0 : MyMinerGame.TotalTimeInMilliseconds;
                    m_lastLeftButtonMousePosition = screenCoordinate;
                }
                else
                {
                    m_leftButtonDoubleClick = false;
                }

                //  Set mouse position to the middle of the screen. We must do it here, right after we retrieved latest mouse state, because
                //  if rest of this update method takes lonk time and we set it then, all mouse movement between this place and end of this
                //  method will be lost and user will feel like we are out of sync
                if (MyVideoModeManager.IsHardwareCursorUsed())
                {

                    if (MyGuiManager.GetScreenWithFocus() != null && MyGuiManager.GetScreenWithFocus().GetDrawMouseCursor() == false && !MyGuiManager.InputToNonFocusedScreens)
                    {
                        /*
                        Trace.SendMsgLastCall(MyGuiManager.GetScreenWithFocus().GetFriendlyName());
                        Trace.SendMsgLastCall(MyGuiManager.GetScreenWithFocus().GetDrawMouseCursor().ToString());
                        Trace.SendMsgLastCall("tu");
                        SetMouseToScreenCenter();
                        */
                    }
                }
                else
                    SetMouseToScreenCenter();

                ret = true;
            }
            else
            {
                ret = false;
            }

            m_previousUpdateWasLostFocus = !MyMinerGame.Static.IsActive;

            return ret;
        }