aboutsummaryrefslogtreecommitdiff
path: root/Super Polarity/Widget.cs
diff options
context:
space:
mode:
authorBen Beltran <ben@nsovocal.com>2013-11-18 21:51:56 -0600
committerBen Beltran <ben@nsovocal.com>2013-11-18 21:51:56 -0600
commit74c155708d85abfc2cf227c08de4f27003015b3f (patch)
tree2e7f6fdad12ae6509832b0e5ee497af7ed72e5e2 /Super Polarity/Widget.cs
parent38c7d3f9eb7d63937c6654ff5dd6046ce02dd59c (diff)
I have the worst commits ever.
Diffstat (limited to 'Super Polarity/Widget.cs')
-rw-r--r--Super Polarity/Widget.cs58
1 files changed, 58 insertions, 0 deletions
diff --git a/Super Polarity/Widget.cs b/Super Polarity/Widget.cs
new file mode 100644
index 0000000..65c3fd2
--- /dev/null
+++ b/Super Polarity/Widget.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace SuperPolarity
+{
+ class Widget
+ {
+ public IList<Widget> Children;
+ public Dictionary<string, List<Action<float>>> Listeners;
+
+ public virtual void AppendChild(Widget widget)
+ {
+ Children.Add(widget);
+ }
+
+ public virtual void Bind(string eventName, Action<float> eventListener)
+ {
+ List<Action<float>> newListenerList;
+ List<Action<float>> listenerList;
+ bool foundListeners;
+
+ if (!Listeners.ContainsKey(eventName))
+ {
+ newListenerList = new List<Action<float>>();
+ Listeners.Add(eventName, newListenerList);
+ }
+
+ foundListeners = Listeners.TryGetValue(eventName, out listenerList);
+
+ listenerList.Add(eventListener);
+ }
+
+ public virtual void Unbind(string eventName, Action<float> eventListener)
+ {
+ // NOT YET IMPLEMENTED;
+ }
+
+ public virtual void Dispatch(string eventName, float value)
+ {
+ List<Action<float>> listenerList;
+ bool foundListeners;
+
+ foundListeners = Listeners.TryGetValue(eventName, out listenerList);
+
+ if (!foundListeners)
+ {
+ return;
+ }
+
+ foreach (Action<float> method in listenerList)
+ {
+ method(value);
+ }
+ }
+ }
+}