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 override MyGuiControlBase HandleInput() { MyGuiControlBase baseResult = base.HandleInput(); if (HasFocus && Selectable) { // Move left if ((MyInput.Static.IsKeyPress(MyKeys.Left))) { if ((IsEnoughDelay(MyMultilineTextKeys.LEFT, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY))) { if (MyInput.Static.IsAnyCtrlKeyPressed()) { CarriagePositionIndex = GetPreviousSpace(); } else { CarriagePositionIndex--; } UpdateLastKeyPressTimes(MyMultilineTextKeys.LEFT); if (MyInput.Static.IsAnyShiftKeyPressed()) { m_selection.SetEnd(this); } else { m_selection.Reset(this); } } return(this); } // Move right if ((MyInput.Static.IsKeyPress(MyKeys.Right))) { if ((IsEnoughDelay(MyMultilineTextKeys.RIGHT, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY))) { if (MyInput.Static.IsAnyCtrlKeyPressed()) { CarriagePositionIndex = GetNextSpace(); } else { ++CarriagePositionIndex; } UpdateLastKeyPressTimes(MyMultilineTextKeys.RIGHT); if (MyInput.Static.IsAnyShiftKeyPressed()) { m_selection.SetEnd(this); } else { m_selection.Reset(this); } } return(this); } // Move Down if ((MyInput.Static.IsKeyPress(MyKeys.Down))) { if ((IsEnoughDelay(MyMultilineTextKeys.DOWN, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY))) { CarriagePositionIndex = GetIndexUnderCarriage(CarriagePositionIndex); UpdateLastKeyPressTimes(MyMultilineTextKeys.DOWN); if (MyInput.Static.IsAnyShiftKeyPressed()) { m_selection.SetEnd(this); } else { m_selection.Reset(this); } } return(this); } // Move Up if ((MyInput.Static.IsKeyPress(MyKeys.Up))) { if ((IsEnoughDelay(MyMultilineTextKeys.UP, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY))) { CarriagePositionIndex = GetIndexOverCarriage(CarriagePositionIndex); UpdateLastKeyPressTimes(MyMultilineTextKeys.UP); if (MyInput.Static.IsAnyShiftKeyPressed()) { m_selection.SetEnd(this); } else { m_selection.Reset(this); } } return(this); } //Copy if (MyInput.Static.IsNewKeyPressed(MyKeys.C) && IsEnoughDelay(MyMultilineTextKeys.C, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY) && MyInput.Static.IsAnyCtrlKeyPressed()) { UpdateLastKeyPressTimes(MyMultilineTextKeys.C); m_selection.CopyText(this); } //Select All if (MyInput.Static.IsNewKeyPressed(MyKeys.A) && IsEnoughDelay(MyMultilineTextKeys.A, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY) && MyInput.Static.IsAnyCtrlKeyPressed()) { m_selection.SelectAll(this); return(this); } } //scroll bool captured = false; var deltaWheel = MyInput.Static.DeltaMouseScrollWheelValue(); if (IsMouseOver && deltaWheel != 0) { m_scrollbar.ChangeValue(-0.0005f * deltaWheel); captured = true; } if (m_drawScrollbar) { bool capturedScrollbar = m_scrollbar.HandleInput(); if (capturedScrollbar || captured) { return(this); } } if (IsMouseOver && m_label.HandleInput(GetPositionAbsoluteTopLeft(), m_scrollbar.Value)) { return(this); } if (Selectable) { if (MyInput.Static.IsNewLeftMousePressed()) { if (IsMouseOver) { m_selection.Dragging = true; CarriagePositionIndex = GetCarriagePositionFromMouseCursor(); if (MyInput.Static.IsAnyShiftKeyPressed()) { m_selection.SetEnd(this); } else { m_selection.Reset(this); } return(this); } else { m_selection.Reset(this); } } else if (MyInput.Static.IsNewLeftMouseReleased()) { m_selection.Dragging = false; } //user holding the mouse button else if (m_selection.Dragging) { //If inside, we update selection and move the carriage (dragging what you want to select) if (IsMouseOver) { CarriagePositionIndex = GetCarriagePositionFromMouseCursor(); m_selection.SetEnd(this); } //Otherwise, do the "scroll along with selection" effect else if (HasFocus) { Vector2 mousePos = MyGuiManager.MouseCursorPosition; Vector2 positionTopLeft = GetPositionAbsoluteTopLeft(); if (mousePos.Y < positionTopLeft.Y) { m_scrollbar.ChangeValue(Position.Y - mousePos.Y); } else if (mousePos.Y > positionTopLeft.Y + Size.Y) { m_scrollbar.ChangeValue(mousePos.Y - positionTopLeft.Y - Size.Y); } } } } return(baseResult); }
/// <summary> /// GR: Individual controls should reset toolbar postion if needed. /// Do no do in refresh of toolbar becaues it may happen often and cause bugs (autoscrolling to top every few frames when not intended) /// </summary> public void ScrollToolbarToTop() { m_scrollBar.ChangeValue(0); }
public override MyGuiControlBase HandleInput() { MyGuiControlBase baseResult = base.HandleInput(); if (HasFocus && Selectable) { // Move left switch (m_keyThrottler.GetKeyStatus(MyKeys.Left)) { case ThrottledKeyStatus.PRESSED_AND_WAITING: return(this); case ThrottledKeyStatus.PRESSED_AND_READY: if (MyInput.Static.IsAnyCtrlKeyPressed()) { CarriagePositionIndex = GetPreviousSpace(); } else { CarriagePositionIndex--; } if (MyInput.Static.IsAnyShiftKeyPressed()) { m_selection.SetEnd(this); } else { m_selection.Reset(this); } return(this); } // Move right switch (m_keyThrottler.GetKeyStatus(MyKeys.Right)) { case ThrottledKeyStatus.PRESSED_AND_WAITING: return(this); case ThrottledKeyStatus.PRESSED_AND_READY: if (MyInput.Static.IsAnyCtrlKeyPressed()) { CarriagePositionIndex = GetNextSpace(); } else { ++CarriagePositionIndex; } if (MyInput.Static.IsAnyShiftKeyPressed()) { m_selection.SetEnd(this); } else { m_selection.Reset(this); } return(this); } // Move Down switch (m_keyThrottler.GetKeyStatus(MyKeys.Down)) { case ThrottledKeyStatus.PRESSED_AND_WAITING: return(this); case ThrottledKeyStatus.PRESSED_AND_READY: CarriagePositionIndex = GetIndexUnderCarriage(CarriagePositionIndex); if (MyInput.Static.IsAnyShiftKeyPressed()) { m_selection.SetEnd(this); } else { m_selection.Reset(this); } return(this); } // Move Up switch (m_keyThrottler.GetKeyStatus(MyKeys.Up)) { case ThrottledKeyStatus.PRESSED_AND_WAITING: return(this); case ThrottledKeyStatus.PRESSED_AND_READY: CarriagePositionIndex = GetIndexOverCarriage(CarriagePositionIndex); if (MyInput.Static.IsAnyShiftKeyPressed()) { m_selection.SetEnd(this); } else { m_selection.Reset(this); } return(this); } //Copy if (m_keyThrottler.IsNewPressAndThrottled(MyKeys.C) && MyInput.Static.IsAnyCtrlKeyPressed()) { m_selection.CopyText(this); } //Select All if (m_keyThrottler.IsNewPressAndThrottled(MyKeys.A) && MyInput.Static.IsAnyCtrlKeyPressed()) { m_selection.SelectAll(this); return(this); } } //scroll bool captured = false; var deltaWheel = MyInput.Static.DeltaMouseScrollWheelValue(); if (IsMouseOver && deltaWheel != 0) { m_scrollbar.ChangeValue(-0.0005f * deltaWheel); captured = true; } if (m_drawScrollbar) { bool capturedScrollbar = m_scrollbar.HandleInput(); if (capturedScrollbar || captured) { return(this); } } if (IsMouseOver && m_label.HandleInput(GetPositionAbsoluteTopLeft(), m_scrollbar.Value)) { return(this); } if (Selectable) { if (MyInput.Static.IsNewLeftMousePressed()) { if (IsMouseOver) { m_selection.Dragging = true; CarriagePositionIndex = GetCarriagePositionFromMouseCursor(); if (MyInput.Static.IsAnyShiftKeyPressed()) { m_selection.SetEnd(this); } else { m_selection.Reset(this); } return(this); } else { m_selection.Reset(this); } } else if (MyInput.Static.IsNewLeftMouseReleased()) { m_selection.Dragging = false; } //user holding the mouse button else if (m_selection.Dragging) { //If inside, we update selection and move the carriage (dragging what you want to select) if (IsMouseOver) { CarriagePositionIndex = GetCarriagePositionFromMouseCursor(); m_selection.SetEnd(this); } //Otherwise, do the "scroll along with selection" effect else if (HasFocus) { Vector2 mousePos = MyGuiManager.MouseCursorPosition; Vector2 positionTopLeft = GetPositionAbsoluteTopLeft(); if (mousePos.Y < positionTopLeft.Y) { m_scrollbar.ChangeValue(Position.Y - mousePos.Y); } else if (mousePos.Y > positionTopLeft.Y + Size.Y) { m_scrollbar.ChangeValue(mousePos.Y - positionTopLeft.Y - Size.Y); } } } } return(baseResult); }