using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace MrAG { public partial class Gui { public class Slider : Base { public Color BorderColor = Color.Gray; public Color BackColor = Color.DarkGray; public Color SliderColor = Color.Blue; public Color LineColor = Color.Red; public int BorderSize; public int Padding = 4; public int LineSize = 2; public int SliderSize = 6; public Action OnValueChange; private int _value; public int Value{ get { return this._value; } set{ int oldval = this._value; if (value > this.MaxValue) this._value = this.MaxValue; else if (value < 0) this._value = 0; else this._value = value; if (oldval != this._value && this.OnValueChange != null) this.OnValueChange.Invoke(); } } private int _maxvalue = 100; public int MaxValue { get { return this._maxvalue; } set{ if (value < 0) return; this._maxvalue = value; if (this._value > this._maxvalue) this._value = this._maxvalue; } } public override void Update() { if (!this.IsActive() || !this.HasFocus) return; int x = MrAG.Gui.CurMouseState.X - (this.X + this.BorderSize + this.Padding - (this.SliderSize / 2)); this.Value = (int)Math.Round((((double)x / (double)(this.Width - (this.BorderSize * 2) - (this.Padding * 2))) * this.MaxValue)); if (this.Value < 0) this.Value = 0; if (this.Value > this.MaxValue) this.Value = this.MaxValue; base.Update(); } public override void DoScrollUp() { this.Value++; base.DoScrollUp(); } public override void DoScrollDown() { this.Value--; base.DoScrollDown(); } public override void Draw() { MrAG.Draw.Box(this.X + this.BorderSize, this.Y + this.BorderSize, this.Width - (this.BorderSize * 2), this.Height - (this.BorderSize * 2), this.BackColor); MrAG.Draw.OutlinedBox(this.X, this.Y, this.Width, this.Height, this.BorderSize, this.BorderColor); MrAG.Draw.Box(this.X + this.BorderSize + this.Padding, this.Y + (this.Height / 2) - (this.LineSize / 2), this.Width - (this.BorderSize * 2) - (this.Padding * 2), this.LineSize, this.LineColor); MrAG.Draw.Box(this.X + this.BorderSize + this.Padding + (int)(((double)this.Value / (double)this.MaxValue) * (this.Width - (this.BorderSize * 2) - (this.Padding * 2))) - (this.SliderSize / 2), this.Y + (this.Height / 2) - (this.SliderSize / 2), this.SliderSize, this.SliderSize, this.SliderColor); base.Draw(); } } } }