using System; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Browser; namespace Psychlops { namespace Widgets { public class Slider { internal System.Windows.UIElement instance; internal System.Windows.Controls.Slider uislider; internal string label; internal Interval range; public Slider(string l, Interval r) { range = r; label = l; Psychlops.Widgets.Connector.stackSlider(this); } public static implicit operator double(Slider s) { return s.value; } public double value { get { return uislider.Value; } set { if(uislider!=null) uislider.Dispatcher.BeginInvoke( new Action(Connector.sliderSet) , uislider, value ); } } public bool changed { get; set; } } public class Browser { public class Element { HtmlElement elem; System.Object retval; public Element() { retval = 0; } public static Element byID(string id_tag) { return getElementById(id_tag); } public static Element getElementById(string id_tag) { Element tmp = new Element(); Internal.Main.widgetStack.Dispatcher.BeginInvoke(new Connector.VoidString(tmp.getElementById__), id_tag); return tmp; } void getElementById__(string id_tag) { elem = HtmlPage.Document.GetElementById(id_tag); } public void setProperty(string name, System.Object value) { Internal.Main.widgetStack.Dispatcher.BeginInvoke(new Connector.VoidStringObject(setProperty__), name, value); } public void setProperty__(string name, System.Object value) { elem.SetProperty(name, value); } public static implicit operator double(Element i) { return i.getValueAsDouble(); } public double getValueAsDouble() { double v = 0; getProperty("value"); try { v = double.Parse(retval.ToString()); } catch (FormatException e) { v = 0; } return v; } public static implicit operator string(Element i) { return i.getProperty("value").ToString(); } public System.Object getProperty(string name) { Internal.Main.widgetStack.Dispatcher.BeginInvoke(new Connector.VoidString(getProperty__), name); return retval; } public void getProperty__(string name) { retval = elem.GetProperty(name); } } } internal static class Connector { internal delegate void VoidString(string s); internal delegate void VoidStringObject(String s, System.Object o); delegate void StackSlider_(Slider s); internal static void stackSlider(Slider s) { Internal.Main.widgetStack.Dispatcher.BeginInvoke(new StackSlider_(stackSlider__), s); } static void stackSlider__(Slider ss) { var holder = new System.Windows.Controls.Canvas { Width = 200 }; var val = new System.Windows.Controls.TextBox { Width = 100 }; System.Windows.Controls.Canvas.SetLeft(val, 100); var slide = new System.Windows.Controls.Slider { Minimum = ss.range.begin.val, Maximum = ss.range.end.val, Name = ss.label, Tag = ss, Width = 200, }; System.Windows.Controls.Canvas.SetTop(slide, 25); var b = new System.Windows.Data.Binding { Path = new PropertyPath("Value"), Mode = System.Windows.Data.BindingMode.TwoWay, Source = slide, }; val.SetBinding(TextBox.TextProperty, b); ss.uislider = slide; //var b2 = new System.Windows.Data.Binding //{ // Path = new PropertyPath("value"), // Mode = System.Windows.Data.BindingMode.TwoWay, // Source = ss, //}; //val.SetBinding(System.Windows.Controls.Slider.ValueProperty, b2); var label = new System.Windows.Controls.TextBlock { Text = ss.label }; System.Windows.Controls.Canvas.SetLeft(label, 3); System.Windows.Controls.Canvas.SetTop(label, 3); holder.Children.Add(label); holder.Children.Add(slide); holder.Children.Add(val); ss.instance = holder; Internal.Main.widgetStack.Children.Add(ss.instance); } public static void sliderSet(System.Windows.Controls.Slider s, double v) { s.Value = v; } } } }