Ejemplo n.º 1
0
        /// <summary>
        /// two phase draw(two SpriteBatch phase):
        /// 1. combobox itself and selected item
        /// 2. opened area and display items draw(if opened area is displayed)
        ///     a. setup up and draw stencil area to stencil buffer for clipping
        ///     b. enable stencil
        ///     c. draw the display items
        ///     d. disable stencil
        /// </summary>
        public override void Draw(float transitionAlpha, float backgroundTransitionAlpha)
        {
            // In case of listbox mode, before calling parent's draw, reset background color, because it will draw unwanted texture for first item in list(texture, that is used normally for closed combobox)
            base.Draw(transitionAlpha, transitionAlpha);

            if (m_selected != null)
                DrawSelectedItemText(transitionAlpha);

            Vector2 position = GetPositionAbsoluteCenterLeft();
            float scrollbarInnerTexturePositionX = position.X + Size.X - m_scrollBarWidth / 2;

            //  The following are used for controlling scroll window range
            int startIndex = 0;
            int endIndex = m_items.Count;

            if (m_showScrollBar)
            {
                startIndex = m_displayItemsStartIndex;
                endIndex = m_displayItemsEndIndex;
            }

            if (m_isOpen)
            {
                MyRectangle2D openedArea = GetOpenedArea();
                DrawOpenedAreaItems(startIndex, endIndex, transitionAlpha);
                if (m_showScrollBar)
                    DrawOpenedAreaScrollbar(scrollbarInnerTexturePositionX, openedArea, transitionAlpha);
            }

            //DebugDraw();
        }
Ejemplo n.º 2
0
        public override bool CheckMouseOver()
        {
            if (m_isOpen)
            {
                int count = (m_showScrollBar) ? m_openAreaItemsCount : m_items.Count;
                for (int i = 0; i < count; i++)
                {
                    Vector2 position = GetOpenItemPosition(i);
                    MyRectangle2D openedArea = GetOpenedArea();
                    Vector2 min = new Vector2(position.X, Math.Max(openedArea.LeftTop.Y, position.Y));
                    Vector2 max = min + new Vector2(Size.X, m_comboboxItemDeltaHeight);

                    var mousePos = MyGuiManager.MouseCursorPosition - GetPositionAbsoluteTopLeft();
                    if ((mousePos.X >= min.X) &&
                        (mousePos.X <= max.X) &&
                        (mousePos.Y >= min.Y) &&
                        (mousePos.Y <= max.Y))
                    {
                        return true;
                    }
                }
            }

            if (m_scrollBarDragging) return false;

            return CheckMouseOver(Size, GetPositionAbsolute(), OriginAlign);
        }
Ejemplo n.º 3
0
        private void DrawChetArea()
        {
            List <MyChatMessage> messages = MyGuiScreenGamePlay.Static.GetChatMessages(8);

            if (messages == null)
            {
                return;
            }

            if (m_stringBuilderForText == null)
            {
                m_stringBuilderForText = new StringBuilder(MyGuiConstants.CHAT_WINDOW_MAX_MESSAGE_LENGTH);
            }
            else
            {
                m_stringBuilderForText.Clear();
            }

            int visibleCount = messages.Count;

            if (visibleCount == 0)
            {
                return;
            }

            // row size
            float rowSize = 0;

            m_stringBuilderForText.Append(messages[0].SenderName.ToString());
            m_stringBuilderForText.Append(": ");
            m_stringBuilderForText.Append(messages[0].Message);
            Vector2 textSize = MyGuiManager.GetNormalizedSize(GetSenderFont(messages[0].SenderRelation), m_stringBuilderForText, MyGuiConstants.CHAT_WINDOW_MESSAGE_SCALE);

            rowSize = textSize.Y;
            m_stringBuilderForText.Clear();

            MyGuiManager.BeginSpriteBatch();
            var offset = new Vector2(VideoMode.MyVideoModeManager.IsTripleHead() ? -1 : 0, 0);

            {
                // Draw texts
                Vector2 notificationPosition = new Vector2(0.305f, 0.756f) + m_positionOffset;
                for (int i = 0; i < visibleCount; i++)
                {
                    m_stringBuilderForText.Append(messages[i].SenderName.ToString());
                    m_stringBuilderForText.Append(": ");
                    MyRectangle2D size = MyGuiManager.DrawString(GetSenderFont(messages[i].SenderRelation), m_stringBuilderForText, notificationPosition + offset,
                                                                 MyGuiConstants.CHAT_WINDOW_MESSAGE_SCALE, MyGuiConstants.CHAT_WINDOW_TEXT_COLOR, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);

                    notificationPosition.X += size.Size.X;
                    MyGuiManager.DrawString(GetSenderFont(messages[i].SenderRelation), messages[i].Message, notificationPosition + offset,
                                            MyGuiConstants.CHAT_WINDOW_MESSAGE_SCALE, MyGuiConstants.CHAT_WINDOW_TEXT_COLOR, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);
                    notificationPosition.Y += rowSize;
                    notificationPosition.X -= size.Size.X;
                    m_stringBuilderForText.Clear();
                }
            }
            MyGuiManager.EndSpriteBatch();
        }
Ejemplo n.º 4
0
        private void DrawOpenedAreaScrollbar(float scrollbarInnerTexturePositionX, MyRectangle2D openedArea, float transitionAlpha)
        {
            var margin = m_styleDef.ScrollbarMargin;

            var pos = GetPositionAbsoluteBottomRight() + new Vector2(-(margin.Right + m_scrollbarTexture.MinSizeGui.X),
                                                                     margin.Top + m_scrollBarCurrentPosition);
            m_scrollbarTexture.Draw(pos, m_scrollBarHeight - m_scrollbarTexture.MinSizeGui.Y, ApplyColorMaskModifiers(ColorMask, Enabled, transitionAlpha));
        }
Ejemplo n.º 5
0
        //  Checks if mouse cursor is over opened combobox area
        bool IsMouseOverOnOpenedArea()
        {
            MyRectangle2D openedArea = GetOpenedArea();
            openedArea.Size.Y += m_dropDownItemSize.Y;

            Vector2 min = openedArea.LeftTop;
            Vector2 max = openedArea.LeftTop + openedArea.Size;

            var mousePos = MyGuiManager.MouseCursorPosition - GetPositionAbsoluteTopLeft();
            return ((mousePos.X >= min.X) &&
                    (mousePos.X <= max.X) &&
                    (mousePos.Y >= min.Y) &&
                    (mousePos.Y <= max.Y));
        }
Ejemplo n.º 6
0
        public override void Draw(float transitionAlpha, float backgroundTransitionAlpha)
        {
            base.Draw(transitionAlpha, backgroundTransitionAlpha);
            var textArea = new MyRectangle2D(m_textPadding.TopLeftOffset, Size - m_textPadding.SizeChange);

            textArea.LeftTop += GetPositionAbsoluteTopLeft() + m_textPadding.TopLeftOffset;
            Vector2 carriageOffset = GetCarriageOffset(CarriagePositionIndex);

            var scissor = new RectangleF(textArea.LeftTop, textArea.Size);

            // Adjust the scissor a little bit, because currently it's hiding the carriage at its left side, and it's
            // too far out on the edges.
            scissor.X -= 0.001f;
            scissor.Y -= 0.001f;

            AdjustScissorRectangle(ref scissor);
            using (MyGuiManager.UsingScissorRectangle(ref scissor))
            {
                DrawSelectionBackgrounds(textArea, backgroundTransitionAlpha);
                DrawText(m_scrollbar.Value);


                //  Draw carriage line
                //  Carriage blinker time is solved here in Draw because I want to be sure it will be drawn even in low FPS
                if (HasFocus && Selectable)
                {
                    //  This condition controls "blinking", so most often is carrier visible and blinks very fast
                    //  It also depends on FPS, but as we have max FPS set to 60, it won't go faster, nor will it omit a "blink".
                    int carriageInterval = m_carriageBlinkerTimer % 20;
                    if ((carriageInterval >= 0) && (carriageInterval <= 15))
                    {
                        MyGuiManager.DrawSpriteBatch(MyGuiConstants.BLANK_TEXTURE,
                                                     textArea.LeftTop + carriageOffset,
                                                     1,
                                                     GetCarriageHeight(),
                                                     ApplyColorMaskModifiers(Vector4.One, Enabled, transitionAlpha),
                                                     MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                    }
                }
                m_carriageBlinkerTimer++;

                if (m_drawScrollbar)
                {
                    m_scrollbar.Draw(ApplyColorMaskModifiers(ColorMask, Enabled, transitionAlpha));
                }
            }
            //m_scrollbar.DebugDraw();
        }
Ejemplo n.º 7
0
        private void DrawSelectionBackgrounds(MyRectangle2D textArea, float transitionAlpha)
        {
            var lines      = Text.ToString().Substring(m_selection.Start, m_selection.Length).Split('\n');
            int currentPos = m_selection.Start;

            foreach (var line in lines)
            {
                Vector2 selectionPos   = textArea.LeftTop + GetCarriageOffset(currentPos);
                Vector2 normalizedSize = GetCarriageOffset(currentPos + line.Length) - GetCarriageOffset(currentPos);
                Vector2 selectionSize  = new Vector2(normalizedSize.X, GetCarriageHeight());
                MyGuiManager.DrawSpriteBatch(MyGuiConstants.BLANK_TEXTURE,
                                             selectionPos,
                                             selectionSize,
                                             ApplyColorMaskModifiers(new Vector4(1, 1, 1, 0.5f), Enabled, transitionAlpha),
                                             MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP
                                             );

                currentPos += line.Length + 1; //+1 because of \n that split cuts out
            }
        }
        public override bool Draw(float backgroundFadeAlpha)
        {
            int deltaTime = MyMinerGame.TotalTimeInMilliseconds - m_drawingBlinkingTextLastTime;

            if (((m_drawingBlinkingTextStatus == true) && (deltaTime > m_blinkingIntervalVisible)) ||
                ((m_drawingBlinkingTextStatus == false) && (deltaTime > m_blinkingIntervalInvisible)))
            {
                m_drawingBlinkingTextStatus   = !m_drawingBlinkingTextStatus;
                m_drawingBlinkingTextLastTime = MyMinerGame.TotalTimeInMilliseconds;
            }

            if (m_drawingBlinkingTextStatus)
            {
                MyRectangle2D rec = MyGuiManager.DrawString(MyGuiManager.GetFontMinerWarsRed(), m_sbInfo,
                                                            m_normalizedCoord,
                                                            1f, Color.White,
                                                            MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
                MyGuiManager.DrawString(MyGuiManager.GetFontMinerWarsRed(), m_sbPressToHide,
                                        new Vector2(m_normalizedCoord.X, m_normalizedCoord.Y + rec.Size.Y),
                                        0.75f, Color.White, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
            }
            return(true);
        }
 private void RefreshTextArea()
 {
     m_textAreaRelative = new MyRectangle2D(MyGuiConstants.TEXTBOX_TEXT_OFFSET, Size - 2 * MyGuiConstants.TEXTBOX_TEXT_OFFSET);
 }
Ejemplo n.º 10
0
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override MyGuiControlBase HandleInput()
        {
            MyGuiControlBase captureInput = base.HandleInput();

            if (captureInput == null && Enabled)
            {
                if (IsMouseOver && MyInput.Static.IsNewPrimaryButtonPressed() && !m_isOpen && !m_scrollBarDragging)
                    return this;

                if (MyInput.Static.IsNewPrimaryButtonReleased() && !m_scrollBarDragging) 
                {
                    if (IsMouseOver && !m_isOpen || IsMouseOverSelectedItem() && m_isOpen) 
                    {
                        MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                        SwitchComboboxMode();
                        captureInput = this;
                    }
                }

                if (HasFocus && (MyInput.Static.IsNewKeyPressed(MyKeys.Enter) ||
                                 MyInput.Static.IsNewKeyPressed(MyKeys.Space)))
                {
                    MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                    if ((m_preselectedKeyboardIndex.HasValue) && (m_preselectedKeyboardIndex.Value < m_items.Count))
                    {
                        if (m_isOpen == false)
                        {
                            SetScrollBarPositionByIndex(m_selected.Key);
                        }
                        else
                        {
                            SelectItemByKey(m_items[m_preselectedKeyboardIndex.Value].Key);
                        }
                    }

                    //  Close but capture focus for this update so parent screen don't receive this ENTER
                    SwitchComboboxMode();
                    captureInput = this;
                }

                //  In listbox mode, the list is always in opened state
                if (m_isOpen == true)
                {
                    #region Handle mouse and scrollbar interaction
                    if (m_showScrollBar == true && MyInput.Static.IsPrimaryButtonPressed() == true)
                    {
                        //  Handles mouse input of dragging the scrollbar up or down
                        Vector2 position = GetPositionAbsoluteCenterLeft();
                        MyRectangle2D openedArea = GetOpenedArea();
                        openedArea.LeftTop += GetPositionAbsoluteTopLeft();
                        float minX = position.X + Size.X - m_scrollBarWidth;
                        float maxX = position.X + Size.X;
                        float minY = position.Y + Size.Y / 2.0f;
                        float maxY = minY + openedArea.Size.Y;

                        // if we are already scrolling, the area used for scrollbar moving will be extended to whole screen
                        if (m_scrollBarDragging)
                        {
                            minX = float.NegativeInfinity;
                            maxX = float.PositiveInfinity;
                            minY = float.NegativeInfinity;
                            maxY = float.PositiveInfinity;
                        }

                        // In case mouse cursor is intersecting scrollbar area, start scroll bar dragging mode
                        if ((MyGuiManager.MouseCursorPosition.X >= minX) && (MyGuiManager.MouseCursorPosition.X <= maxX)
                            && (MyGuiManager.MouseCursorPosition.Y >= minY) && (MyGuiManager.MouseCursorPosition.Y <= maxY))
                        {                           
                            // Are we over thee scroll bar handle?
                            float P0 = m_scrollBarCurrentPosition + (openedArea.LeftTop.Y);
                            if (MyGuiManager.MouseCursorPosition.Y > P0 && MyGuiManager.MouseCursorPosition.Y < P0 + m_scrollBarHeight)
                            {
                                if (m_mousePositionReinit)
                                {
                                    m_mouseOldPosition = MyGuiManager.MouseCursorPosition.Y;
                                    m_mousePositionReinit = false;
                                }

                                float mdeff = MyGuiManager.MouseCursorPosition.Y - m_mouseOldPosition;
                                if (mdeff > float.Epsilon || mdeff < float.Epsilon)
                                {
                                    SetScrollBarPosition(m_scrollBarCurrentNonadjustedPosition + mdeff);
                                }

                                m_mouseOldPosition = MyGuiManager.MouseCursorPosition.Y;
                            }
                            else
                            {
                                // If we are not over the scrollbar handle -> jump:
                                float scrollPositionY = MyGuiManager.MouseCursorPosition.Y - (openedArea.LeftTop.Y) - m_scrollBarHeight / 2.0f;
                                SetScrollBarPosition(scrollPositionY);
                            }

                            m_scrollBarDragging = true;
                        }
                    }
                    #endregion

                    // Reset mouse parameters after it was released now
                    if (MyInput.Static.IsNewPrimaryButtonReleased())
                    {
                        m_mouseOldPosition = MyGuiManager.MouseCursorPosition.Y;
                        m_mousePositionReinit = true;
                    }

                    //  If ESC was pressed while combobox has keyboard focus and combobox was opened, then close combobox but don't send this ESC to parent screen
                    //  Or if user clicked outside of the combobox's area
                    if ((HasFocus && (MyInput.Static.IsNewKeyPressed(MyKeys.Escape) || MyInput.Static.IsJoystickButtonNewPressed(MyJoystickButtonsEnum.J02))) ||
                        (!IsMouseOverOnOpenedArea() && !IsMouseOver && MyInput.Static.IsNewPrimaryButtonReleased())
                        )
                    {
                        MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                        m_isOpen = false;
                    }

                    //  Still capture focus, don't allow parent screen to receive this ESCAPE
                    captureInput = this;

                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //  Mouse controling items in the combobox
                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    if (m_scrollBarDragging == false)
                    {
                        #region Handle item that is under mouse cursor
                        //  Search for item that is under the mouse cursor
                        m_preselectedMouseOverPrevious = m_preselectedMouseOver;
                        m_preselectedMouseOver = null;

                        //  The following are used for controlling scroll window range
                        int startIndex = 0;
                        int endIndex = m_items.Count;
                        float widthOffSet = 0f;
                        if (m_showScrollBar == true)
                        {
                            startIndex = m_displayItemsStartIndex;
                            endIndex = m_displayItemsEndIndex;
                            widthOffSet = 0.025f;
                        }

                        for (int i = startIndex; i < endIndex; i++)
                        {
                            Vector2 position = GetOpenItemPosition(i - m_displayItemsStartIndex);
                            MyRectangle2D openedArea = GetOpenedArea();

                            Vector2 min = new Vector2(position.X, Math.Max(openedArea.LeftTop.Y, position.Y));
                            Vector2 max = min + new Vector2(Size.X - widthOffSet, m_comboboxItemDeltaHeight);
                            var mousePos = MyGuiManager.MouseCursorPosition - GetPositionAbsoluteTopLeft();
                            if ((mousePos.X >= min.X) &&
                                (mousePos.X <= max.X) &&
                                (mousePos.Y >= min.Y) &&
                                (mousePos.Y <= max.Y))
                            {
                                m_preselectedMouseOver = m_items[i];
                            }
                        }

                        if (m_preselectedMouseOver != null && m_preselectedMouseOver != m_preselectedMouseOverPrevious)
                        {
                            MyGuiSoundManager.PlaySound(GuiSounds.MouseOver);
                        }

                        #endregion

                        #region Selecting item in opened combobox area
                        //  Select item when user clicks on it
                        if (MyInput.Static.IsNewPrimaryButtonReleased() == true && m_preselectedMouseOver != null)
                        {
                            SelectItemByKey(m_preselectedMouseOver.Key);

                            MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                            m_isOpen = false;

                            //  Still capture focus, don't allow parent screen to receive this CLICK
                            captureInput = this;
                        }
                        #endregion

                        #region Keyboard and scrollwheel controlling items in combobox

                        if (HasFocus || IsMouseOverOnOpenedArea())
                        {
                            if (m_mouseWheelValueLast == null) m_mouseWheelValueLast = MyInput.Static.MouseScrollWheelValue();

                            if (MyInput.Static.MouseScrollWheelValue() < m_mouseWheelValueLast)
                            {
                                HandleItemMovement(true);
                                captureInput = this;
                            }
                            else if (MyInput.Static.MouseScrollWheelValue() > m_mouseWheelValueLast)
                            {
                                HandleItemMovement(false);
                                captureInput = this;
                            }

                            //  Keyboard and mouse movement
                            if (MyInput.Static.IsNewKeyPressed(MyKeys.Down) || MyInput.Static.IsNewGamepadKeyDownPressed())
                            {
                                HandleItemMovement(true);
                                captureInput = this;
                                if (MyInput.Static.IsNewGamepadKeyDownPressed())
                                    SnapCursorToControl(m_preselectedKeyboardIndex.Value);
                            }
                            else if (MyInput.Static.IsNewKeyPressed(MyKeys.Up) || MyInput.Static.IsNewGamepadKeyUpPressed())
                            {
                                HandleItemMovement(false);
                                captureInput = this;
                                if (MyInput.Static.IsNewGamepadKeyUpPressed())
                                    SnapCursorToControl(m_preselectedKeyboardIndex.Value);
                            }
                            else if (MyInput.Static.IsNewKeyPressed(MyKeys.PageDown))
                            {
                                HandleItemMovement(true, true);
                            }
                            else if (MyInput.Static.IsNewKeyPressed(MyKeys.PageUp))
                            {
                                HandleItemMovement(false, true);
                            }
                            else if (MyInput.Static.IsNewKeyPressed(MyKeys.Home))
                            {
                                HandleItemMovement(true, false, true);
                            }
                            else if (MyInput.Static.IsNewKeyPressed(MyKeys.End))
                            {
                                HandleItemMovement(false, false, true);
                            }
                            else if (MyInput.Static.IsNewKeyPressed(MyKeys.Tab))
                            {
                                //  We want to close the combobox without selecting any item and forward TAB or SHIF+TAB to parent screen so it can navigate to next control
                                if (m_isOpen) SwitchComboboxMode();
                                captureInput = null;
                            }

                            m_mouseWheelValueLast = MyInput.Static.MouseScrollWheelValue();
                        }
                        #endregion
                    }
                    else
                    {
                        // When finished scrollbar dragging, set it to false and enable input capturing again
                        if (MyInput.Static.IsNewPrimaryButtonReleased()) 
                            m_scrollBarDragging = false;
                        captureInput = this;
                    }
                }
            }

            return captureInput;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Draws warning's text if any warning detected
        /// </summary>
        /// <param name="position">Position to draw</param>
        /// <param name="highlight">Highlight multiplicator of text's color</param>
        /// <param name="drawedRectangle">Drawed rectangle</param>
        /// <returns>Returns true if warning's text drawed. Else returns false</returns>/// <returns></returns>
        public bool Draw(Vector2 position, float highlight, out MyRectangle2D? drawedRectangle)
        {
            drawedRectangle = null;

            if (m_canBeTurnedOff && MyConfig.Notifications == false)
                return false;

            foreach (MyHudWarning hudWarning in m_hudWarnings)
            {
                if (hudWarning.Draw(position, highlight, out drawedRectangle))
                {
                    return true;
                }
            }
            return false;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Draws warning's text if any warning detected
 /// </summary>
 /// <param name="position">Position to draw</param>
 /// <param name="highlight">Highlight multiplicator of text's color</param>
 /// <param name="drawedRectangle">Drawed rectangle</param>
 /// <returns>Returns true if warning's text drawed. Else returns false</returns>
 public bool Draw(Vector2 position, float highlight, out MyRectangle2D? drawedRectangle)
 {
     drawedRectangle = null;
     if (m_warningDetected && m_textWarning != null)
     {
         drawedRectangle = m_textWarning.Draw(position, highlight);
     }
     return drawedRectangle != null;
 }
Ejemplo n.º 13
0
        //  Draw the rectangle to stencil buffer, so later when we draw, only pixels with stencil=1 will be rendered
        //  IMPORTANT: Be careful about sprite batch, Begin and End
        public static void DrawStencilMaskRectangleRoundUp(MyRectangle2D rectangle, MyGuiDrawAlignEnum drawAlignEnum)
        {
            // Clear stencil to avoid overflow
            //MyMinerGame.Static.GraphicsDevice.Clear(ClearOptions.Stencil, Color.White, 0.0f, 0);

            //  Call begin with new stencil-mask parameters
            m_spriteBatch.Begin(SpriteSortMode.Deferred, MyStateObjects.StencilMask_Draw_BlendState, SamplerState.LinearWrap,
                MyStateObjects.StencilMask_Draw_DepthStencilState, RasterizerState.CullNone);

            //m_spriteBatch.Begin(SpriteSortMode.Deferred);
            m_spriteBatchUsageCount++;

            //  Render rectangle, but it will get written only into stencil buffer and color will remain untouched
            DrawSpriteBatchRoundUp(GetBlankTexture(), rectangle.LeftTop, rectangle.Size, new Color(0, 0, 0, 255), drawAlignEnum);

            //  Call end so rectangle is rendered in this moment
            m_spriteBatch.End();
            m_spriteBatchUsageCount--;
        }