예제 #1
0
        private bool IsControlUnderCursor(MyGuiControlBase control)
        {
            Vector2?size = control.GetSize();

            if (size != null)
            {
                Vector2 min           = control.GetPosition() - size.Value / 2;
                Vector2 max           = control.GetPosition() + size.Value / 2;
                Vector2 mousePosition = MyGuiManager.MouseCursorPosition - GetPosition();

                return(mousePosition.X >= min.X && mousePosition.X <= max.X &&
                       mousePosition.Y >= min.Y && mousePosition.Y <= max.Y);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        //StringBuilder m_drawPositionSb = new StringBuilder();
        private void DrawControlDebugPosition(MyGuiControlBase control)
        {
            m_drawPositionSb.Clear();
            m_drawPositionSb.Append("[");
            m_drawPositionSb.Append(control.GetPosition().X.ToString("0.0000"));
            m_drawPositionSb.Append(",");
            m_drawPositionSb.Append(control.GetPosition().Y.ToString("0.0000"));
            m_drawPositionSb.Append("]");
            float   scale = 0.7f;
            Vector2 size  = MyGuiManager.GetNormalizedSizeFromScreenSize(MyGuiManager.GetFontMinerWarsBlue().MeasureString(m_drawPositionSb, scale));
            Vector4 color = new Vector4(0f, 0f, 0f, 0.5f);

            MyGuiManager.DrawSpriteBatch(MyGuiManager.GetBlankTexture(), control.GetPosition() + control.GetParent().GetPositionAbsolute(),
                                         size, new Color(color),
                                         MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);

            MyGuiManager.DrawString(MyGuiManager.GetFontMinerWarsBlue(),
                                    m_drawPositionSb,
                                    control.GetPosition() + control.GetParent().GetPositionAbsolute(), scale,
                                    Color.Green,
                                    MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
        }
예제 #3
0
        private bool HandleControlMoving(MyGuiInput input)
        {
            bool dragging = false;

            if (input.IsLeftMousePressed())
            {
                // if we dragging control, then we set it new position by mouse
                if (m_draggingControl != null)
                {
                    m_draggingControl.SetPosition(MyGuiManager.MouseCursorPosition - m_draggingControl.GetParent().GetPositionAbsolute() - m_draggingControlOffset);
                    dragging = true;
                }
                // if we are not dragging control, then we try find it
                else
                {
                    MyGuiControlBase controlToDrag = null;
                    // first we try find control, which has mouse over
                    controlToDrag = GetMouseOverControl();
                    // if there is no control which has mouse over, then we try find control, which is under mouse cursor (because some controls has no mouse over all time)
                    if (controlToDrag == null)
                    {
                        controlToDrag = GetControlUnderMouseCursor();
                    }

                    // if we found any contorl to drag, then we set it to dragging control
                    if (controlToDrag != null)
                    {
                        m_draggingControl       = controlToDrag;
                        m_draggingControlOffset = MyGuiManager.MouseCursorPosition - m_draggingControl.GetParent().GetPositionAbsolute() - controlToDrag.GetPosition();
                        dragging = true;
                    }
                }
            }
            else
            {
                m_draggingControl = null;
                if (input.IsNewLeftMouseReleased())
                {
                    dragging = true;
                }
            }

            return(dragging);
        }
예제 #4
0
        private bool IsControlUnderCursor(MyGuiControlBase control)
        {
            Vector2? size = control.GetSize();
            if (size != null)
            {
                Vector2 min = control.GetPosition() - size.Value / 2;
                Vector2 max = control.GetPosition() + size.Value / 2;
                Vector2 mousePosition = MyGuiManager.MouseCursorPosition - GetPosition();

                return (mousePosition.X >= min.X && mousePosition.X <= max.X &&
                        mousePosition.Y >= min.Y && mousePosition.Y <= max.Y);
            }
            else
            {
                return false;
            }
        }
예제 #5
0
        //StringBuilder m_drawPositionSb = new StringBuilder();
        private void DrawControlDebugPosition(MyGuiControlBase control)
        {
            m_drawPositionSb.Clear();
            m_drawPositionSb.Append("[");
            m_drawPositionSb.Append(control.GetPosition().X.ToString("0.0000"));
            m_drawPositionSb.Append(",");
            m_drawPositionSb.Append(control.GetPosition().Y.ToString("0.0000"));
            m_drawPositionSb.Append("]");
            float scale = 0.7f;
            Vector2 size = MyGuiManager.GetNormalizedSizeFromScreenSize(MyGuiManager.GetFontMinerWarsBlue().MeasureString(m_drawPositionSb, scale));
            Vector4 color = new Vector4(0f, 0f, 0f, 0.5f);

            MyGuiManager.DrawSpriteBatch(MyGuiManager.GetBlankTexture(), control.GetPosition() + control.GetParent().GetPositionAbsolute(),
                                         size, new Color(color),
                                         MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);

            MyGuiManager.DrawString(MyGuiManager.GetFontMinerWarsBlue(),
                                                m_drawPositionSb,
                                                control.GetPosition() + control.GetParent().GetPositionAbsolute(), scale,
                                                Color.Green,
                                                MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
        }