/// <summary> /// Handle while mouse is down event. /// The Scrollbar entity override this function to handle sliding mark up and down, instead of left-right. /// </summary> /// <param name="input">Input helper instance.</param> override protected void DoWhileMouseDown(InputHelper input) { // if in the middle calculate value based on mouse position if ((input.MousePosition.Y >= _destRect.Y + _frameActualHeight * 0.5) && (input.MousePosition.Y <= _destRect.Bottom - _frameActualHeight * 0.5)) { float val = ((input.MousePosition.Y - _destRect.Y - _frameActualHeight + _markHeight / 2) / (_destRect.Height - _frameActualHeight * 2)); Value = (int)(Min + val * (Max - Min)); } // call event handler WhileMouseDown?.Invoke(this); }
override protected void DoWhileMouseDown() { var mousePos = GetMousePos(p_LastScrollVal.ToVector2()); if ((mousePos.Y >= p_DrawArea.Y + _frameActualHeight * 0.5) && (mousePos.Y <= p_DrawArea.Bottom - _frameActualHeight * 0.5)) { float relativePos = (mousePos.Y - p_DrawArea.Y - _frameActualHeight * 0.5f - _markHeight * 0.5f); float internalHeight = (p_DrawArea.Height - _frameActualHeight) - _markHeight * 0.5f; float relativeVal = (relativePos / internalHeight); Value = (int)Math.Round(Min + relativeVal * (Max - Min)); } WhileMouseDown?.Invoke(this); }
/// <summary> /// Handle while mouse is down event. /// The Scrollbar entity override this function to handle sliding mark up and down, instead of left-right. /// </summary> /// <param name="input">Input helper instance.</param> override protected void DoWhileMouseDown(InputHelper input) { // if in the middle calculate value based on mouse position if ((input.MousePosition.Y >= _destRect.Y + _frameActualHeight * 0.5) && (input.MousePosition.Y <= _destRect.Bottom - _frameActualHeight * 0.5)) { float relativePos = (input.MousePosition.Y - _destRect.Y - _frameActualHeight * 0.5f - _markHeight * 0.5f); float internalHeight = (_destRect.Height - _frameActualHeight) - _markHeight * 0.5f; float relativeVal = (relativePos / internalHeight); Value = (int)System.Math.Round(Min + relativeVal * (Max - Min)); } // call event handler WhileMouseDown?.Invoke(this); }
/// <summary> /// Handle while mouse is down event. /// The Scrollbar entity override this function to handle sliding mark up and down, instead of left-right. /// </summary> override protected void DoWhileMouseDown() { // get mouse position and apply scroll value var mousePos = GetMousePos(_lastScrollVal.ToVector2()); // if in the middle calculate value based on mouse position if ((mousePos.Y >= _destRect.Y + _frameActualHeight * 0.5) && (mousePos.Y <= _destRect.Bottom - _frameActualHeight * 0.5)) { float relativePos = (mousePos.Y - _destRect.Y - _frameActualHeight * 0.5f - _markHeight * 0.5f); float internalHeight = (_destRect.Height - _frameActualHeight) - _markHeight * 0.5f; float relativeVal = (relativePos / internalHeight); Value = (int)System.Math.Round(Min + relativeVal * (Max - Min)); } // call event handler WhileMouseDown?.Invoke(this); }
/// <summary> /// Create the DropDown list. /// </summary> /// <param name="size">List size (refers to the whole size of the list + the header when dropdown list is opened).</param> /// <param name="anchor">Position anchor.</param> /// <param name="offset">Offset from anchor position.</param> /// <param name="skin">Panel skin to use for this DropDown list and header.</param> public DropDown(Vector2 size, Anchor anchor = Anchor.Auto, Vector2?offset = null, PanelSkin skin = PanelSkin.ListBackground) : base(size, anchor, offset) { // default padding of self is 0 Padding = Vector2.Zero; // to get collision right when list is opened UseActualSizeForCollision = true; // create the panel and paragraph used to show currently selected value (what's shown when drop-down is closed) _selectedTextPanel = new Panel(new Vector2(0, SelectedPanelHeight), skin, Anchor.TopLeft); _selectedTextParagraph = UserInterface.DefaultParagraph(string.Empty, Anchor.CenterLeft); _selectedTextParagraph.UseActualSizeForCollision = false; _selectedTextParagraph.UpdateStyle(SelectList.DefaultParagraphStyle); _selectedTextParagraph.UpdateStyle(DefaultParagraphStyle); _selectedTextParagraph.UpdateStyle(DefaultSelectedParagraphStyle); _selectedTextPanel.AddChild(_selectedTextParagraph, true); // create the arrow down icon _arrowDownImage = new Image(Resources.ArrowDown, new Vector2(ArrowSize, ArrowSize), ImageDrawMode.Stretch, Anchor.CenterRight, new Vector2(-10, 0)); _selectedTextPanel.AddChild(_arrowDownImage, true); // create the list component _selectList = new SelectList(size, Anchor.TopCenter, Vector2.Zero, skin); // update list offset and space before _selectList.SetOffset(new Vector2(0, SelectedPanelHeight)); _selectList.SpaceBefore = Vector2.Zero; // add the header and select list as children AddChild(_selectedTextPanel); AddChild(_selectList); // add callback on list value change _selectList.OnValueChange = (Entity entity) => { // hide list ListVisible = false; // set selected text _selectedTextParagraph.Text = (SelectedValue ?? DefaultText); }; // hide the list by default _selectList.Visible = false; // setup the callback to show / hide the list when clicking the dropbox _selectedTextPanel.OnClick = (Entity self) => { // change visibility ListVisible = !ListVisible; }; // set starting text _selectedTextParagraph.Text = (SelectedValue ?? DefaultText); // update styles _selectList.UpdateStyle(DefaultStyle); // make the list events trigger the dropdown events _selectList.OnListChange += (Entity entity) => { OnListChange?.Invoke(this); }; _selectList.OnMouseDown += (Entity entity) => { OnMouseDown?.Invoke(this); }; _selectList.OnMouseReleased += (Entity entity) => { OnMouseReleased?.Invoke(this); }; _selectList.WhileMouseDown += (Entity entity) => { WhileMouseDown?.Invoke(this); }; _selectList.WhileMouseHover += (Entity entity) => { WhileMouseHover?.Invoke(this); }; _selectList.OnClick += (Entity entity) => { OnClick?.Invoke(this); }; _selectList.OnValueChange += (Entity entity) => { OnValueChange?.Invoke(this); }; _selectList.OnMouseEnter += (Entity entity) => { OnMouseEnter?.Invoke(this); }; _selectList.OnMouseLeave += (Entity entity) => { OnMouseLeave?.Invoke(this); }; _selectList.OnMouseWheelScroll += (Entity entity) => { OnMouseWheelScroll?.Invoke(this); }; _selectList.OnStartDrag += (Entity entity) => { OnStartDrag?.Invoke(this); }; _selectList.OnStopDrag += (Entity entity) => { OnStopDrag?.Invoke(this); }; _selectList.WhileDragging += (Entity entity) => { WhileDragging?.Invoke(this); }; _selectList.BeforeDraw += (Entity entity) => { BeforeDraw?.Invoke(this); }; _selectList.AfterDraw += (Entity entity) => { AfterDraw?.Invoke(this); }; _selectList.BeforeUpdate += (Entity entity) => { BeforeUpdate?.Invoke(this); }; _selectList.AfterUpdate += (Entity entity) => { AfterUpdate?.Invoke(this); }; // make the selected value panel trigger the dropdown events _selectedTextPanel.OnMouseDown += (Entity entity) => { OnMouseDown?.Invoke(this); }; _selectedTextPanel.OnMouseReleased += (Entity entity) => { OnMouseReleased?.Invoke(this); }; _selectedTextPanel.WhileMouseDown += (Entity entity) => { WhileMouseDown?.Invoke(this); }; _selectedTextPanel.WhileMouseHover += (Entity entity) => { WhileMouseHover?.Invoke(this); }; _selectedTextPanel.OnClick += (Entity entity) => { OnClick?.Invoke(this); }; _selectedTextPanel.OnValueChange += (Entity entity) => { OnValueChange?.Invoke(this); }; _selectedTextPanel.OnMouseEnter += (Entity entity) => { OnMouseEnter?.Invoke(this); }; _selectedTextPanel.OnMouseLeave += (Entity entity) => { OnMouseLeave?.Invoke(this); }; _selectedTextPanel.OnMouseWheelScroll += (Entity entity) => { OnMouseWheelScroll?.Invoke(this); }; _selectedTextPanel.OnStartDrag += (Entity entity) => { OnStartDrag?.Invoke(this); }; _selectedTextPanel.OnStopDrag += (Entity entity) => { OnStopDrag?.Invoke(this); }; _selectedTextPanel.WhileDragging += (Entity entity) => { WhileDragging?.Invoke(this); }; _selectedTextPanel.BeforeDraw += (Entity entity) => { BeforeDraw?.Invoke(this); }; _selectedTextPanel.AfterDraw += (Entity entity) => { AfterDraw?.Invoke(this); }; _selectedTextPanel.BeforeUpdate += (Entity entity) => { BeforeUpdate?.Invoke(this); }; _selectedTextPanel.AfterUpdate += (Entity entity) => { AfterUpdate?.Invoke(this); }; }