Example #1
0
        public GradientHandle(double T, Color Color, HUI_GradientEditor canvas)
        {
            this.T              = T;
            this.Color          = Color;
            this.GradientEditor = canvas;
            this.canvas         = canvas.Children.OfType <Canvas>().FirstOrDefault();
            var     handleSize = 14;
            Ellipse e          = new Ellipse();

            e.Width                = handleSize;
            e.Height               = handleSize;
            e.Stroke               = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            e.StrokeThickness      = 3;
            e.Fill                 = new SolidColorBrush(Color.FromRgb(255, 255, 255));
            e.RenderTransform      = new TranslateTransform(-handleSize / 2.0, -handleSize / 2.0);
            e.MouseLeftButtonUp   += Handle_MouseUp;
            e.MouseLeftButtonDown += Handle_MouseLeftButtonDown;
            e.MouseMove           += Handle_MouseMove;
            e.MouseRightButtonUp  += E_MouseRightButtonUp;

            handleEllipse = e;
            UpdatePosition();
            this.canvas.Children.Add(handleEllipse);
            canvas.SizeChanged += Bounds_SizeChanged;
        }
Example #2
0
        static public object GetElementValue(UIElement u)
        {
            switch (u.GetType().ToString())
            {
            case "System.Windows.Controls.Slider":
                Slider s = u as Slider;
                return(s.Value);

            case "System.Windows.Controls.Button":
                Button b = u as Button;
                return((System.Windows.Input.Mouse.LeftButton == System.Windows.Input.MouseButtonState.Pressed) && b.IsMouseOver);

            case "HumanUI.TrueOnlyButton":
                TrueOnlyButton tob = u as TrueOnlyButton;
                return((System.Windows.Input.Mouse.LeftButton == System.Windows.Input.MouseButtonState.Pressed) && tob.IsMouseOver);

            case "HumanUI.HUI_RhPickButton":
                HUI_RhPickButton rpb = u as HUI_RhPickButton;
                return(rpb.objIDs);

            case "System.Windows.Controls.Label":
                Label l = u as Label;
                return(l.Content);

            case "System.Windows.Controls.ListBox":
                ListBox   lb  = u as ListBox;
                TextBlock lab = lb.SelectedItem as TextBlock;
                if (lab != null)
                {
                    return(lab.Text);
                }
                else
                {
                    return(null);
                }

            case "System.Windows.Controls.ScrollViewer":
                ScrollViewer sv       = u as ScrollViewer;
                ItemsControl ic       = sv.Content as ItemsControl;
                List <bool>  checkeds = new List <bool>();
                var          cbs      = from cbx in ic.Items.OfType <CheckBox>() select cbx;
                foreach (CheckBox chex in cbs)
                {
                    checkeds.Add(chex.IsChecked == true);
                }


                return(checkeds);

            case "System.Windows.Controls.TextBox":
                TextBox tb = u as TextBox;
                return(tb.Text);

            case "System.Windows.Controls.ComboBox":
                ComboBox  cb  = u as ComboBox;
                TextBlock cbi = cb.SelectedItem as TextBlock;
                if (cbi != null)
                {
                    return(cbi.Text);
                }
                else
                {
                    return(null);
                }

            case "Xceed.Wpf.Toolkit.ColorPicker":
                ColorPicker colP = u as ColorPicker;

                //return cbi.Content;
                return(HUI_Util.ToSysColor(colP.SelectedColor));

            case "System.Windows.Controls.ListView":
                ListView      v           = u as ListView;
                var           cbxs        = from cbx in v.Items.OfType <CheckBox>() select cbx;
                List <string> checkedVals = new List <string>();
                foreach (CheckBox chex in cbxs)
                {
                    if (chex.IsChecked == true)
                    {
                        checkedVals.Add(chex.Content.ToString());
                    }
                }

                return(String.Join(",", checkedVals));

            case "System.Windows.Controls.CheckBox":
                CheckBox chb = u as CheckBox;
                return(chb.IsChecked);

            case "System.Windows.Controls.RadioButton":
                RadioButton rb = u as RadioButton;
                return(rb.IsChecked);

            case "System.Windows.Controls.Image":
                Image img = u as Image;

                return(img.Source.ToString());

            case "System.Windows.Controls.Expander":
                Expander exp = u as Expander;
                return(exp.IsExpanded);

            case "System.Windows.Controls.TabControl":
                TabControl tc = u as TabControl;
                TabItem    ti = tc.SelectedItem as TabItem;
                if (ti == null)
                {
                    ti = tc.Items[0] as TabItem;
                }
                return(ti.Header.ToString());

            case "MahApps.Metro.Controls.ToggleSwitch":
                ToggleSwitch ts = u as ToggleSwitch;

                return(ts.IsChecked);

            case "MahApps.Metro.Controls.RangeSlider":
                RangeSlider rs = u as RangeSlider;

                return(new Interval(rs.LowerValue, rs.UpperValue));

            case "De.TorstenMandelkow.MetroChart.ChartBase":
            case "De.TorstenMandelkow.MetroChart.PieChart":
            case "De.TorstenMandelkow.MetroChart.ClusteredBarChart":
            case "De.TorstenMandelkow.MetroChart.ClusteredColumnChart":
            case "De.TorstenMandelkow.MetroChart.DoughnutChart":
            case "De.TorstenMandelkow.MetroChart.RadialGaugeChart":
            case "De.TorstenMandelkow.MetroChart.StackedBarChart":
            case "De.TorstenMandelkow.MetroChart.StackedColumnChart":
                ChartBase chart        = u as ChartBase;
                ChartItem selectedItem = chart.SelectedItem as ChartItem;

                if (selectedItem != null)
                {
                    string response = "";
                    if (!String.IsNullOrEmpty(selectedItem.ClusterCategory))
                    {
                        response += selectedItem.ClusterCategory + ": ";
                    }
                    response += selectedItem.Category;
                    return(response);
                }
                else
                {
                    return(null);
                }

            case "System.Windows.Controls.DataGrid":
                DataGrid datagrid     = u as DataGrid;
                var      SelectedItem = datagrid.SelectedItem;
                //System.Data.DataView dv = datagrid.ItemsSource as System.Data.DataView;
                List <string> result = new List <string>();
                try
                {
                    System.Data.DataRowView drv = SelectedItem as System.Data.DataRowView;
                    result = drv.Row.ItemArray.Cast <string>().ToList();
                    result.RemoveAt(0);
                }
                catch
                {
                }

                return(result);

            case "HumanUI.MDSliderElement":
                MDSliderElement mds = u as MDSliderElement;

                return(mds.SliderPoint);

            case "HumanUI.GraphMapperElement":
                GraphMapperElement gme = u as GraphMapperElement;
                return(gme.GetCurve().ToNurbsCurve());

            case "HumanUI.HUI_GradientEditor":
                HUI_GradientEditor hge = u as HUI_GradientEditor;
                return(hge.Gradient.ToString());

            case "HumanUI.FilePicker":
                FilePicker fp = u as FilePicker;
                return(fp.Path);

            case "HumanUI.ClickableShapeGrid":
                ClickableShapeGrid csg = u as ClickableShapeGrid;
                return(csg.SelectedStates);

            default:
                return(null);
            }
        }
        void RemoveEvents(UIElement u)
        {
            switch (u.GetType().ToString())
            {
            case "System.Windows.Controls.Slider":
                Slider s = u as Slider;
                s.ValueChanged -= ExpireThis;
                return;

            case "System.Windows.Controls.Button":
                Button b = u as Button;
                b.PreviewMouseDown -= ExpireThis;
                b.PreviewMouseUp   -= ExpireThis;
                return;

            case "System.Windows.Controls.DataGrid":
                DataGrid datagrid = u as DataGrid;
                datagrid.SelectedCellsChanged -= ExpireThis;
                return;

            case "HumanUI.TrueOnlyButton":
                TrueOnlyButton tob = u as TrueOnlyButton;
                tob.PreviewMouseDown -= ExpireThis;
                return;

            case "HumanUI.HUI_RhPickButton":
                HUI_RhPickButton rpb = u as HUI_RhPickButton;
                rpb.PickCompleted -= ExpireThis;
                return;

            case "HumanUI.MDSliderElement":
                MDSliderElement mds = u as MDSliderElement;
                mds.PropertyChanged -= ExpireThis;
                return;

            case "HumanUI.GraphMapperElement":
                GraphMapperElement gme = u as GraphMapperElement;
                gme.PropertyChanged -= ExpireThis;
                return;

            case "HumanUI.HUI_GradientEditor":
                HUI_GradientEditor hge = u as HUI_GradientEditor;
                hge.PropertyChanged -= ExpireThis;
                return;

            case "HumanUI.FilePicker":
                FilePicker fp = u as FilePicker;
                fp.PropertyChanged -= ExpireThis;
                return;

            case "HumanUI.ClickableShapeGrid":
                ClickableShapeGrid csg = u as ClickableShapeGrid;
                switch (csg.clickMode)
                {
                case ClickableShapeGrid.ClickMode.ButtonMode:
                    csg.MouseUp   -= ExpireThis;
                    csg.MouseDown -= ExpireThis;
                    return;

                case ClickableShapeGrid.ClickMode.PickerMode:
                case ClickableShapeGrid.ClickMode.ToggleMode:
                    csg.MouseUp -= ExpireThis;
                    return;

                case ClickableShapeGrid.ClickMode.None:
                default:
                    return;
                }

            case "System.Windows.Controls.Label":
                Label l = u as Label;
                return;

            case "System.Windows.Controls.ListBox":
                ListBox lb = u as ListBox;
                lb.SelectionChanged -= ExpireThis;
                return;

            case "System.Windows.Controls.ScrollViewer":
                ScrollViewer sv = u as ScrollViewer;
                ItemsControl ic = sv.Content as ItemsControl;
                ((INotifyCollectionChanged)ic.Items).CollectionChanged -= ExpireThis;
                List <bool> checkeds = new List <bool>();
                var         cbs      = from cbx in ic.Items.OfType <CheckBox>() select cbx;
                foreach (CheckBox chex in cbs)
                {
                    chex.Checked   -= ExpireThis;
                    chex.Unchecked -= ExpireThis;
                }
                return;

            case "System.Windows.Controls.ComboBox":
                ComboBox cb = u as ComboBox;
                cb.SelectionChanged -= ExpireThis;
                return;

            case "System.Windows.Controls.TextBox":
                TextBox       tb   = u as TextBox;
                Panel         p    = tb.Parent as Panel;
                List <Button> btns = p.Children.OfType <Button>().ToList <Button>();

                foreach (Button btn0 in btns)
                {
                    btn0.Click -= ExpireThis;
                }
                tb.TextChanged -= ExpireThis;
                return;

            case "Xceed.Wpf.Toolkit.ColorPicker":
                ColorPicker cp = u as ColorPicker;
                cp.SelectedColorChanged -= ExpireThis;
                return;

            case "System.Windows.Controls.CheckBox":
                CheckBox chb = u as CheckBox;
                chb.Checked   -= ExpireThis;
                chb.Unchecked -= ExpireThis;
                return;

            case "System.Windows.Controls.RadioButton":
                RadioButton rb = u as RadioButton;
                rb.Checked   -= ExpireThis;
                rb.Unchecked -= ExpireThis;
                return;

            case "System.Windows.Controls.Image":
                return;

            case "System.Windows.Controls.Expander":
                Expander exp = u as Expander;
                exp.Expanded  -= ExpireThis;
                exp.Collapsed -= ExpireThis;
                return;

            case "System.Windows.Controls.TabControl":
                TabControl tc = u as TabControl;
                tc.SelectionChanged -= ExpireThis;
                return;

            case "MahApps.Metro.Controls.ToggleSwitch":
                ToggleSwitch ts = u as ToggleSwitch;
                ts.IsCheckedChanged -= ExpireThis;
                return;

            case "MahApps.Metro.Controls.RangeSlider":
                RangeSlider rs = u as RangeSlider;
                rs.RangeSelectionChanged -= ExpireThis;
                return;

            case "De.TorstenMandelkow.MetroChart.ChartBase":
            case "De.TorstenMandelkow.MetroChart.PieChart":
            case "De.TorstenMandelkow.MetroChart.ClusteredBarChart":
            case "De.TorstenMandelkow.MetroChart.ClusteredColumnChart":
            case "De.TorstenMandelkow.MetroChart.DoughnutChart":
            case "De.TorstenMandelkow.MetroChart.RadialGaugeChart":
            case "De.TorstenMandelkow.MetroChart.StackedBarChart":
            case "De.TorstenMandelkow.MetroChart.StackedColumnChart":
                ChartBase chart = u as ChartBase;
                chart.MouseUp -= ExpireThis;
                return;

            default:
                return;
            }
        }
Example #4
0
        static public void TrySetElementValue(UIElement u, object o)
        {
            try
            {
                switch (u.GetType().ToString())
                {
                case "System.Windows.Controls.Slider":
                    Slider s = u as Slider;
                    //System.Windows.Forms.MessageBox.Show(o.GetType().ToString());

                    s.Value = (double)o;
                    return;

                case "System.Windows.Controls.ListBox":
                    ListBox lb = u as ListBox;
                    lb.SelectedIndex = getSelectedItemIndex(lb, (string)o);
                    return;

                case "System.Windows.Controls.TextBox":
                    TextBox tb = u as TextBox;
                    tb.Text = (string)o;
                    return;

                case "System.Windows.Controls.ComboBox":
                    ComboBox cb = u as ComboBox;
                    cb.SelectedIndex = getSelectedItemIndex(cb, (string)o);
                    return;

                case "Xceed.Wpf.Toolkit.ColorPicker":
                    ColorPicker          colP   = u as ColorPicker;
                    System.Drawing.Color sysCol = (System.Drawing.Color)o;
                    colP.SelectedColor = HUI_Util.ToMediaColor(sysCol);
                    return;

                case "System.Windows.Controls.ScrollViewer":
                    //it's a checklist
                    ScrollViewer sv        = u as ScrollViewer;
                    List <bool>  valueList = (List <bool>)o;
                    ItemsControl ic        = sv.Content as ItemsControl;
                    var          cbs       = from cbx in ic.Items.OfType <CheckBox>() select cbx;
                    int          i         = 0;
                    foreach (CheckBox chex in cbs)
                    {
                        chex.IsChecked = valueList[i];
                        i++;
                    }

                    return;

                case "System.Windows.Controls.CheckBox":
                    CheckBox chb = u as CheckBox;
                    chb.IsChecked = (bool)o;
                    return;

                case "MahApps.Metro.Controls.ToggleSwitch":
                    ToggleSwitch ts = u as ToggleSwitch;
                    ts.IsChecked = (bool)o;
                    return;

                case "MahApps.Metro.Controls.RangeSlider":
                    RangeSlider rs         = u as RangeSlider;
                    var         valueRange = (Interval)o;
                    rs.UpperValue = valueRange.Max;
                    rs.LowerValue = valueRange.Min;
                    return;

                case "System.Windows.Controls.RadioButton":
                    RadioButton rb = u as RadioButton;
                    rb.IsChecked = (bool)o;
                    return;

                case "System.Windows.Controls.DataGrid":
                    DataGrid      datagrid            = u as DataGrid;
                    List <string> selectedRowContents = (List <string>)o;
                    try
                    {
                        DataView dv = datagrid.ItemsSource as DataView;
                        foreach (DataRowView drv in dv)
                        {
                            var items = drv.Row.ItemArray.Cast <string>().ToList();
                            items.RemoveAt(0);     //get rid of hidden index column
                            bool selectRow = true;
                            for (int counter = 0; counter < items.Count; counter++)
                            {
                                if (selectedRowContents[counter] != items[counter])
                                {
                                    selectRow = false;
                                    break;
                                }
                            }
                            if (selectRow)
                            {
                                datagrid.SelectedItem = drv;
                            }
                        }
                    }
                    catch
                    {
                    }
                    return;

                case "HumanUI.MDSliderElement":
                    MDSliderElement mds = u as MDSliderElement;
                    mds.SliderPoint = (Rhino.Geometry.Point3d)o;
                    return;

                case "HumanUI.GraphMapperElement":
                    GraphMapperElement gme = u as GraphMapperElement;

                    gme.SetByCurve((Rhino.Geometry.NurbsCurve)o);
                    return;

                case "HumanUI.HUI_GradientEditor":
                    HUI_GradientEditor hge      = u as HUI_GradientEditor;
                    HUI_Gradient       gradient = HUI_Gradient.FromString((string)o);
                    hge.Gradient = gradient;
                    return;

                case "HumanUI.FilePicker":
                    FilePicker fp = u as FilePicker;
                    fp.Path = (string)o;
                    return;

                default:
                    return;
                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.ToString());
            }
        }