1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 20:58:34 +01:00

made scroll bar clickable

This commit is contained in:
Ellpeck 2019-08-13 16:02:29 +02:00
parent 75f7bbd2f9
commit f56b7fbeff
2 changed files with 14 additions and 1 deletions

View file

@ -93,7 +93,7 @@ namespace MLEM.Ui.Elements {
protected InputHandler Input => this.System.InputHandler;
public RootElement Root { get; private set; }
public float Scale => this.Root.ActualScale;
public Vector2 MousePos => this.Input.MousePosition.ToVector2();
public Point MousePos => this.Input.MousePosition;
public Element Parent { get; private set; }
public bool IsMouseOver { get; private set; }
public bool IsSelected { get; private set; }

View file

@ -2,6 +2,7 @@ using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Input;
using MLEM.Textures;
using MLEM.Ui.Style;
@ -35,6 +36,7 @@ namespace MLEM.Ui.Elements {
}
public float StepPerScroll = 1;
public ValueChanged OnValueChanged;
private bool isMouseHeld;
public ScrollBar(Anchor anchor, Vector2 size, int scrollerHeight, float maxValue) : base(anchor, size) {
this.maxValue = maxValue;
@ -44,6 +46,17 @@ namespace MLEM.Ui.Elements {
public override void Update(GameTime time) {
base.Update(time);
var moused = this.System.MousedElement;
if (moused == this && this.Input.IsMouseButtonDown(MouseButton.Left)) {
this.isMouseHeld = true;
} else if (this.isMouseHeld && this.Input.IsMouseButtonUp(MouseButton.Left)) {
this.isMouseHeld = false;
}
if (this.isMouseHeld) {
var internalY = this.MousePos.Y - this.Area.Y;
this.CurrentValue = internalY / (float) this.Area.Height * this.MaxValue;
}
if (moused == this.Parent || moused?.Parent == this.Parent) {
var scroll = this.Input.LastScrollWheel - this.Input.ScrollWheel;
if (scroll != 0)