From 1e64adb6af5e16d980605c4f9a825c89fd95400e Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 18 Aug 2014 23:50:50 +0000 Subject: [PATCH] InputRoll - Column change callback --- .../tools/TAStudio/InputRoll.cs | 109 ++++++++++++++++-- 1 file changed, 98 insertions(+), 11 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/InputRoll.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/InputRoll.cs index dd48ab5d46..d6a5b79c83 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/InputRoll.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/InputRoll.cs @@ -59,6 +59,7 @@ namespace BizHawk.Client.EmuHawk this.Controls.Add(VBar); this.Controls.Add(HBar); RecalculateScrollBars(); + Columns.ChangedCallback = ColumnChangedCallback; } protected override void Dispose(bool disposing) @@ -685,6 +686,11 @@ namespace BizHawk.Client.EmuHawk #region Helpers + private void ColumnChangedCallback() + { + RecalculateScrollBars(); + } + private void RecalculateScrollBars() { if (NeedsVScrollbar) @@ -692,11 +698,11 @@ namespace BizHawk.Client.EmuHawk VBar.Visible = true; if (HorizontalOrientation) { - VBar.Maximum = Columns.Count; + VBar.Maximum = (Columns.Count * CellHeight) - Height; } else { - VBar.Maximum = ItemCount; + VBar.Maximum = (ItemCount * CellHeight) - Height; } } else @@ -709,11 +715,11 @@ namespace BizHawk.Client.EmuHawk HBar.Visible = true; if (HorizontalOrientation) { - HBar.Maximum = ItemCount; + HBar.Maximum = (ItemCount * CellHeight) - Height; } else { - HBar.Maximum = Columns.Count; + HBar.Maximum = (Columns.Count * CellHeight) - Height; } } else @@ -954,15 +960,96 @@ namespace BizHawk.Client.EmuHawk public class RollColumns : List { - public void Add(string name, string text, int width, RollColumn.InputType type = RollColumn.InputType.Text) + public Action ChangedCallback { get; set; } + + private void DoChangeCallback() { - Add(new RollColumn + if (ChangedCallback != null) { - Name = name, - Text = text, - Width = width, - Type = type - }); + ChangedCallback(); + } + } + + public new void Add(RollColumn column) + { + if (this.Any(c => c.Name == column.Name)) + { + throw new InvalidOperationException("A column with this name already exists."); + } + + base.Add(column); + ChangedCallback(); + } + + public new void AddRange(IEnumerable collection) + { + foreach(var column in collection) + { + if (this.Any(c => c.Name == column.Name)) + { + throw new InvalidOperationException("A column with this name already exists."); + } + } + + base.AddRange(collection); + ChangedCallback(); + } + + public new void Insert(int index, RollColumn column) + { + if (this.Any(c => c.Name == column.Name)) + { + throw new InvalidOperationException("A column with this name already exists."); + } + + base.Insert(index, column); + ChangedCallback(); + } + + public new void InsertRange(int index, IEnumerable collection) + { + foreach (var column in collection) + { + if (this.Any(c => c.Name == column.Name)) + { + throw new InvalidOperationException("A column with this name already exists."); + } + } + + base.InsertRange(index, collection); + ChangedCallback(); + } + + public new bool Remove(RollColumn column) + { + var result = base.Remove(column); + ChangedCallback(); + return result; + } + + public new int RemoveAll(Predicate match) + { + var result = base.RemoveAll(match); + ChangedCallback(); + return result; + } + + public new void RemoveAt(int index) + { + base.RemoveAt(index); + ChangedCallback(); + } + + public new void RemoveRange(int index, int count) + { + base.RemoveRange(index, count); + ChangedCallback(); + } + + public new void Clear() + { + base.Clear(); + ChangedCallback(); } public IEnumerable Groups