mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 14:38:34 +01:00
made scroll bar clickable
This commit is contained in:
parent
75f7bbd2f9
commit
f56b7fbeff
2 changed files with 14 additions and 1 deletions
|
@ -93,7 +93,7 @@ namespace MLEM.Ui.Elements {
|
||||||
protected InputHandler Input => this.System.InputHandler;
|
protected InputHandler Input => this.System.InputHandler;
|
||||||
public RootElement Root { get; private set; }
|
public RootElement Root { get; private set; }
|
||||||
public float Scale => this.Root.ActualScale;
|
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 Element Parent { get; private set; }
|
||||||
public bool IsMouseOver { get; private set; }
|
public bool IsMouseOver { get; private set; }
|
||||||
public bool IsSelected { get; private set; }
|
public bool IsSelected { get; private set; }
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using MLEM.Extensions;
|
using MLEM.Extensions;
|
||||||
|
using MLEM.Input;
|
||||||
using MLEM.Textures;
|
using MLEM.Textures;
|
||||||
using MLEM.Ui.Style;
|
using MLEM.Ui.Style;
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ namespace MLEM.Ui.Elements {
|
||||||
}
|
}
|
||||||
public float StepPerScroll = 1;
|
public float StepPerScroll = 1;
|
||||||
public ValueChanged OnValueChanged;
|
public ValueChanged OnValueChanged;
|
||||||
|
private bool isMouseHeld;
|
||||||
|
|
||||||
public ScrollBar(Anchor anchor, Vector2 size, int scrollerHeight, float maxValue) : base(anchor, size) {
|
public ScrollBar(Anchor anchor, Vector2 size, int scrollerHeight, float maxValue) : base(anchor, size) {
|
||||||
this.maxValue = maxValue;
|
this.maxValue = maxValue;
|
||||||
|
@ -44,6 +46,17 @@ namespace MLEM.Ui.Elements {
|
||||||
public override void Update(GameTime time) {
|
public override void Update(GameTime time) {
|
||||||
base.Update(time);
|
base.Update(time);
|
||||||
var moused = this.System.MousedElement;
|
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) {
|
if (moused == this.Parent || moused?.Parent == this.Parent) {
|
||||||
var scroll = this.Input.LastScrollWheel - this.Input.ScrollWheel;
|
var scroll = this.Input.LastScrollWheel - this.Input.ScrollWheel;
|
||||||
if (scroll != 0)
|
if (scroll != 0)
|
||||||
|
|
Loading…
Reference in a new issue