X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=dev4%2Fpsychlops%2Fextention%2Fstandard%2Fwidget.cs;h=92ce8a2807e6eee3fc420b80e62c4461f94286c2;hb=b55ddaa401cfe09614a68299447148a3dd55c406;hp=49c7848140f7b7721812a50e870ffeb9ac1896de;hpb=2d16c7bc232e1d8e0f57404c4b37e3a8db6ab207;p=psychlops%2Fsilverlight.git diff --git a/dev4/psychlops/extention/standard/widget.cs b/dev4/psychlops/extention/standard/widget.cs index 49c7848..92ce8a2 100644 --- a/dev4/psychlops/extention/standard/widget.cs +++ b/dev4/psychlops/extention/standard/widget.cs @@ -8,6 +8,7 @@ using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Browser; +using System.Windows.Data; @@ -15,29 +16,184 @@ using System.Windows.Browser; namespace Psychlops { + /* + class Widget : public Figure { + public: + class Event { + public: + }; + }; + * */ + namespace Widgets { + /* + struct Theme { + static bool initialized__; + static Image default_button, default_horiz_grad; + enum TYPE_TAG { NORMAL, ALERT }; + public: + Color normal_foreground[2], active_foreground[2]; + Color normal_background[2], active_background[2], over_background[2]; + Stroke normal_stroke[2], active_stroke[2]; + Image button_back, *horiz_grad; + + static Theme current; + static void initialize(); + }; + * */ + + /* + class WidgetRect : Widget + { + protected: + HumanInterfaceDevice::ButtonStateHolder mleft; + bool pushed_; + + public: + //Theme *theme; + //Theme::TYPE_TAG theme_type; + public Rectangle area; + public Letters label; + public abstract WidgetRect(); + public virtual const Point getDatum() const; + public virtual WidgetRect& setDatum(const Point&); + public virtual WidgetRect& centering(const Point&); + public double getWidth() const; + public double getHeight() const; + public double getLeft() const; + public double getTop() const; + public double getRight() const; + public double getBottom() const; + public WidgetRect& alignLeft(const double lef); + public WidgetRect& alignTop(const double to_); + public WidgetRect& alignRight(const double rig); + public WidgetRect& alignBottom(const double bot); + + public virtual WidgetRect& set(double wid, double hei); + public virtual WidgetRect& set(std::wstring name); + public virtual WidgetRect& set(std::wstring name, double hei); + public virtual WidgetRect& setLabel(std::wstring s); + public virtual WidgetRect& draw(Drawable &target = *Drawable::prime); + public bool pushed(); + public WidgetRect& pushThis(); + }; + */ + + /* public class Slider { + public string label; + public Rectangle outer; + public Rectangle inner; + public Stroke outer_strk; + + public Slider() + { + set(0, 0); + } + public Slider(double width, double height) + { + set(width, height); + } + public Slider set(double width, double height) + { + outer = new Rectangle(width, height); + outer.fill = Color.gray; + inner = new Rectangle(); + inner.fill = Color.blue; + outer_strk = new Stroke(); + outer_strk.color = Color.white; + outer_strk.thick = 1; + return this; + } + public void checkClick() + { + if (outer.include(Mouse.position)) + { + outer.stroke = outer_strk; + } + } + } + */ + + public class Button + { + public static Color bgcolor; + + internal System.Windows.Controls.Button uibutton; + + public Button(string l) + { + uibutton = new System.Windows.Controls.Button(); + uibutton.Content = l; + } + public void str(string l) { } + } + + public class Slider + { + public static Color bgcolor; + internal System.Windows.UIElement instance; internal System.Windows.Controls.Slider uislider; + internal System.Windows.Controls.TextBlock uilabel; + internal System.Windows.Controls.TextBox uibox; internal string label; internal Interval range; + internal SelfDelegate get_; + internal SelfDelegate set_; + internal double retval; + internal bool setted_; + + static Slider() + { + bgcolor.set(.5,.5, .5, .3); + } - public Slider(string l, Interval r) + public Slider(string l, Interval r, double initialvalue) { + retval = initialvalue; range = r; label = l; + setted_ = false; Psychlops.Widgets.Connector.stackSlider(this); + get_ = new SelfDelegate(get__); + set_ = new SelfDelegate(set__); + while (!setted_) { System.Threading.Thread.Sleep(10); } } 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 delegate void SelfDelegate(System.Windows.Controls.Slider s); + public void get__(System.Windows.Controls.Slider s) { retval = s.Value; } + public void set__(System.Windows.Controls.Slider s) { s.Value = retval; } + + public double getValue() + { + if (uislider != null) { + uislider.Dispatcher.BeginInvoke(get_, uislider); + return retval; + } else { + return 0; + } + } + public void setValue(double v) + { + if (uislider != null) + { + retval = v; + uislider.Dispatcher.BeginInvoke(set_, uislider); + } + } + + public double value + { + get { return getValue(); } + set { setValue(value); } } public bool changed { get; set; } } @@ -110,13 +266,34 @@ namespace Psychlops } - - internal static class Connector + internal static partial class Connector { internal delegate void VoidString(string s); internal delegate void VoidStringObject(String s, System.Object o); - + public class Double02fFormatter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + string formatString = parameter as string; + if (!string.IsNullOrEmpty(formatString)) + { + return string.Format(culture, formatString, value); + } + return string.Format("{0, -8:F}", value); + } + public object ConvertBack(object val, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + string str = val.ToString(); + double result; + var objCultureInfo = new System.Globalization.CultureInfo("en-US"); + if (Double.TryParse(str, System.Globalization.NumberStyles.Number, objCultureInfo, out result)) + { + return result; + } + return val; + } + } delegate void StackSlider_(Slider s); internal static void stackSlider(Slider s) @@ -125,46 +302,49 @@ namespace Psychlops } static void stackSlider__(Slider ss) { - var holder = new System.Windows.Controls.Canvas { Width = 200 }; + var label = new System.Windows.Controls.TextBlock { Text = ss.label }; + label.Foreground = Color.white; + System.Windows.Controls.Canvas.SetLeft(label, 3); + System.Windows.Controls.Canvas.SetTop(label, 3); + ss.uilabel = label; + + var holder = new System.Windows.Controls.Canvas { Width = 200, Height = 50 }; 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, + Minimum = ss.range.begin.value, Maximum = ss.range.end.value, Name = ss.label, + Value = ss.retval, Tag = ss, Width = 200, }; - System.Windows.Controls.Canvas.SetTop(slide, 25); + System.Windows.Controls.Canvas.SetTop(slide, label.ActualHeight - 3); var b = new System.Windows.Data.Binding { Path = new PropertyPath("Value"), Mode = System.Windows.Data.BindingMode.TwoWay, Source = slide, + Converter = new Double02fFormatter() }; 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); + ss.uibox = val; + val.Background = Color.null_color; + val.BorderBrush = Color.null_color; + val.Foreground = Color.white; + val.TextAlignment = TextAlignment.Right; + + holder.Background = Slider.bgcolor; holder.Children.Add(label); - holder.Children.Add(slide); holder.Children.Add(val); + holder.Children.Add(slide); + holder.Height = label.ActualHeight + slide.ActualHeight + val.ActualHeight + 15; ss.instance = holder; Internal.Main.widgetStack.Children.Add(ss.instance); + ss.setted_ = true; } - public static void sliderSet(System.Windows.Controls.Slider s, double v) - { - s.Value = v; - } - } } -} \ No newline at end of file +} +