public void DrawDraged(Vector2 position, float transitionAlpha) { if ((m_icon != null) || Text != null) { if (m_icon != null) { string texture = m_icon; if (texture == null) { // texture is still being loaded on other thread DrawLoadingIcon(Vector4.One, GetIconPosition(), transitionAlpha); } else { MyGUIHelper.OutsideBorder(position + GetIconPosition(), m_iconSize, 2, MyGuiConstants.THEMED_GUI_LINE_COLOR); MyGuiManager.DrawSpriteBatch(m_icon, position + GetIconPosition(), m_iconSize, Color.White, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP); } } else if (Text != null) { var leftTop = position + GetTextPosition(); var size = MyGuiManager.MeasureString(MyFontEnum.Blue, Text, 0.8f); MyGUIHelper.OutsideBorder(leftTop, size, 2, MyGuiConstants.THEMED_GUI_LINE_COLOR); MyGUIHelper.FillRectangle(leftTop, size, TreeView.GetColor(MyGuiConstants.TREEVIEW_SELECTED_ITEM_COLOR, transitionAlpha)); Color textColor = TreeView.GetColor(MyGuiConstants.CONTROL_MOUSE_OVER_BACKGROUND_COLOR_MULTIPLIER, transitionAlpha); MyGuiManager.DrawString(MyFontEnum.Blue, Text, position + GetTextPosition(), 0.8f, textColor, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP); } } }
public void Draw(float transitionAlpha) { if (!Visible || !TreeView.Contains(m_currentOrigin, m_currentSize)) { return; } bool isHighlighted = TreeView.HooveredItem == this; Vector2 expandIconPosition = GetExpandIconPosition(); Vector2 iconPosition = GetIconPosition(); Vector2 textPosition = GetTextPosition(); Vector4 baseColor = Enabled ? Vector4.One : MyGuiConstants.TREEVIEW_DISABLED_ITEM_COLOR; if (TreeView.FocusedItem == this) { Color selectedColor = TreeView.GetColor(MyGuiConstants.TREEVIEW_SELECTED_ITEM_COLOR * baseColor, transitionAlpha); if (TreeView.WholeRowHighlight()) { MyGUIHelper.FillRectangle(new Vector2(TreeView.GetPosition().X, m_currentOrigin.Y), new Vector2(TreeView.GetBodySize().X, m_currentSize.Y), selectedColor); } else { MyGUIHelper.FillRectangle(m_currentOrigin, m_currentSize, selectedColor); } } if (GetItemCount() > 0) { Vector4 expandColor = (isHighlighted) ? baseColor * MyGuiConstants.CONTROL_MOUSE_OVER_BACKGROUND_COLOR_MULTIPLIER : baseColor; MyGuiManager.DrawSpriteBatch(IsExpanded ? m_collapseIcon : m_expandIcon, m_currentOrigin + expandIconPosition, m_expandIconSize, TreeView.GetColor(expandColor, transitionAlpha), MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP); } if (m_icon == null) { // texture is still being loaded on other thread DrawLoadingIcon(baseColor, iconPosition, transitionAlpha); } else { MyGuiManager.DrawSpriteBatch(m_icon, m_currentOrigin + iconPosition, m_iconSize, TreeView.GetColor(baseColor, transitionAlpha), MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP); } Vector4 textColor = (isHighlighted) ? MyGuiConstants.CONTROL_MOUSE_OVER_BACKGROUND_COLOR_MULTIPLIER * baseColor : MyGuiConstants.TREEVIEW_TEXT_COLOR * baseColor; MyGuiManager.DrawString(MyFontEnum.Blue, Text, m_currentOrigin + textPosition, 0.8f, TreeView.GetColor(textColor, transitionAlpha), MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP); if (IconTexts != null) { IconTexts.Draw(m_currentOrigin + iconPosition, m_iconSize, transitionAlpha, isHighlighted); } }
public void FocusItem(MyTreeViewItem item) { if (item != null) { Vector2 offset = MyGUIHelper.GetOffset(m_body.GetPosition(), m_body.GetSize(), item.GetPosition(), item.GetSize()); m_vScrollbar.ChangeValue(-offset.Y); m_hScrollbar.ChangeValue(-offset.X); } FocusedItem = item; }
public void Draw(float transitionAlpha) { var scissor = new RectangleF(m_body.GetPosition(), m_body.GetSize()); using (MyGuiManager.UsingScissorRectangle(ref scissor)) { m_body.Draw(transitionAlpha); } Color borderColor = MyGuiControlBase.ApplyColorMaskModifiers(MyGuiConstants.TREEVIEW_VERTICAL_LINE_COLOR, true, transitionAlpha); MyGUIHelper.OutsideBorder(m_position, m_size, 2, borderColor); m_vScrollbar.Draw(Color.White); m_hScrollbar.Draw(Color.White); }
public bool HandleInput(MyTreeViewItem treeViewItem) { bool captured = false; if (DraggedItem == null) { if (MyGUIHelper.Contains(treeViewItem.GetPosition(), treeViewItem.GetSize(), MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y) && treeViewItem.TreeView.Contains(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y)) { if (MyInput.Static.IsNewLeftMousePressed()) { Dragging = false; DraggedItem = treeViewItem; StartDragPosition = MyGuiManager.MouseCursorPosition; captured = true; } } } return(captured); }
public bool Contains(float x, float y) { return(MyGUIHelper.Contains(m_body.GetPosition(), m_body.GetSize(), x, y)); }
public bool Contains(Vector2 position, Vector2 size) { return(MyGUIHelper.Intersects(m_body.GetPosition(), m_body.GetSize(), position, size)); }
public bool HandleInputEx(bool hasKeyboardActiveControl) { if (!Visible) { return(false); } bool captured = false; // Hoover item if mouse cursor is inside its area if (TreeView.Contains(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y) && MyGUIHelper.Contains(m_currentOrigin, m_currentSize, MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y)) { TreeView.HooveredItem = this; } if (Enabled && DragDrop != null) { captured = DragDrop.HandleInput(this); } // Single click - expand or focus item if (MyInput.Static.IsNewLeftMouseReleased()) { if (GetItemCount() > 0 && MyGUIHelper.Contains(m_currentOrigin + GetExpandIconPosition(), m_expandIconSize, MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y)) { IsExpanded = !IsExpanded; captured = true; MyGuiSoundManager.PlaySound(GuiSounds.MouseClick); } else if (TreeView.HooveredItem == this) { TreeView.FocusItem(this); captured = true; MyGuiSoundManager.PlaySound(GuiSounds.MouseClick); } } // Double click - launch Action event if (Enabled && /*!captured && MyInput.Static.IsNewLeftMouseDoubleClick() && */ TreeView.HooveredItem == this) { if (Action != null) { DoAction(); } else if (GetItemCount() > 0) { IsExpanded = !IsExpanded; } captured = true; } // Right click - launch RightClick event if (/*!captured && */ MyInput.Static.IsNewRightMousePressed() && TreeView.HooveredItem == this) { if (RightClick != null) { RightClick(this, EventArgs.Empty); } captured = true; MyGuiSoundManager.PlaySound(GuiSounds.MouseClick); } return(captured); }