예제 #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            System.Drawing.Color        defaultCol    = System.Drawing.Color.Transparent;
            List <System.Drawing.Color> availableCols = new List <System.Drawing.Color>();

            //initialize the picker with default settings
            ColorPicker picker = new ColorPicker();


            //If the user specified a default color, set the picker's selected color.
            if (DA.GetData <System.Drawing.Color>("Default Color", ref defaultCol))
            {
                picker.SelectedColor = HUI_Util.ToMediaColor(defaultCol);
            }


            //if the user specified a list of allowed colors, replace the picker's availableColors list and disable standard colors.
            if (DA.GetDataList <System.Drawing.Color>("Available Colors", availableCols))
            {
                ObservableCollection <ColorItem> cols = new ObservableCollection <ColorItem>();
                foreach (System.Drawing.Color cw in availableCols)
                {
                    Color c = HUI_Util.ToMediaColor(cw);
                    cols.Add(new ColorItem(c, String.Format("{0},{1},{2}", c.R, c.B, c.G)));
                    picker.AvailableColors    = cols;
                    picker.ShowStandardColors = false;
                }
            }


            DA.SetData("Color Picker", new UIElement_Goo(picker, "Color Picker", InstanceGuid, DA.Iteration));
        }
예제 #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <Curve> shapeCrvs = new List <Curve>();

            System.Drawing.Color fillCol = System.Drawing.Color.Transparent;
            double strokeWeight          = 0.0;

            System.Drawing.Color strokeCol = System.Drawing.Color.Transparent;
            double scale  = 1.0;
            int    width  = 0;
            int    height = 0;

            if (!DA.GetDataList <Curve>("Shape", shapeCrvs))
            {
                return;
            }
            //initialize path object
            Path path = new Path();

            DA.GetData <double>("Scale", ref scale);

            //set path data to geometry from curve list
            path.Data = pathGeomFromCrvs(shapeCrvs, scale, false);
            if (DA.GetData <System.Drawing.Color>("Fill Color", ref fillCol))
            {
                path.Fill = new SolidColorBrush(HUI_Util.ToMediaColor(fillCol));
            }

            if (DA.GetData <double>("Stroke Weight", ref strokeWeight))
            {
                path.StrokeThickness = strokeWeight;
            }

            if (DA.GetData <System.Drawing.Color>("Stroke Color", ref strokeCol))
            {
                path.Stroke = new SolidColorBrush(HUI_Util.ToMediaColor(strokeCol));
            }

            //initialize a grid to contain the shapes
            Grid G = new Grid();

            if (DA.GetData <int>("Width", ref width))
            {
                G.Width = width;
            }
            if (DA.GetData <int>("Height", ref height))
            {
                G.Height = height;
            }
            G.Children.Add(path);

            //pass out the grid containing the shape
            DA.SetData("Shape", new UIElement_Goo(G, "Shape", InstanceGuid, DA.Iteration));
        }
예제 #3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            object        ChartObject  = null;
            List <double> listContents = new List <double>();
            List <string> names        = new List <string>();
            bool          Legend       = true;
            bool          Title        = true;

            List <System.Drawing.Color> Col = new List <System.Drawing.Color>();

            System.Drawing.Color fgCol = System.Drawing.Color.Transparent;

            //Get the Chart object and assign it
            if (!DA.GetData <object>("Chart to modify", ref ChartObject))
            {
                return;
            }
            var ChartElem = HUI_Util.GetUIElement <ChartBase>(ChartObject);

            bool hasLegend = DA.GetData <bool>("Legend", ref Legend);
            bool hasTitle  = DA.GetData <bool>("Title", ref Title);
            bool hasColors = DA.GetDataList <System.Drawing.Color>("Colors", Col);

            if (hasColors)
            {
                ResourceDictionaryCollection Palette = new ResourceDictionaryCollection();
                Palette = createResourceDictionary(Col);

                System.Windows.Media.Brush BorderBrush = new SolidColorBrush(HUI_Util.ToMediaColor(Col[0]));
                ChartElem.BorderBrush = BorderBrush;
                ChartElem.Palette     = Palette;
            }

            if (hasLegend)
            {
                Visibility LegendVis = Visibility.Hidden;
                if (Legend)
                {
                    LegendVis = Visibility.Visible;
                }
                ChartElem.ChartLegendVisibility = LegendVis;
            }
            if (hasTitle)
            {
                Visibility TitleVis = Visibility.Hidden;
                if (Title)
                {
                    TitleVis = Visibility.Visible;
                }
                ChartElem.ChartTitleVisibility = TitleVis;
            }
        }
예제 #4
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            UIElement_Goo elementToAdd = null;
            double        thickness    = 5;
            Color         color        = Color.Black;
            double        radius       = 0;

            if (!DA.GetData <UIElement_Goo>("UI Element", ref elementToAdd))
            {
                return;
            }
            if (!DA.GetData("Border Thickness", ref thickness))
            {
                return;
            }
            if (!DA.GetData("Border Color", ref color))
            {
                return;
            }
            if (!DA.GetData("Corner Radius", ref radius))
            {
                return;
            }
            //intitalize the Border
            Border border = new Border
            {
                BorderThickness = new Thickness(thickness),
                BorderBrush     = new SolidColorBrush(HUI_Util.ToMediaColor(color)),
                CornerRadius    = new CornerRadius(radius)
            };

            HUI_Util.removeParent(elementToAdd.element);
            border.Child = elementToAdd.element;


            //pass out the Border object
            DA.SetData("Border", new UIElement_Goo(border, "Border", InstanceGuid, DA.Iteration));
        }
예제 #5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Create a basic object to hold the UI Element prior to type conversion
            object myUIElement = null;

            System.Drawing.Color        defaultCol    = System.Drawing.Color.Transparent;
            List <System.Drawing.Color> availableCols = new List <System.Drawing.Color>();

            if (!DA.GetData <object>(0, ref myUIElement))
            {
                return;
            }

            ColorPicker picker = HUI_Util.GetUIElement <ColorPicker>(myUIElement);


            //If the user specified a default color, set the picker's selected color.
            if (DA.GetData <System.Drawing.Color>("Default Color", ref defaultCol))
            {
                picker.SelectedColor = HUI_Util.ToMediaColor(defaultCol);
            }


            //if the user specified a list of allowed colors, replace the picker's availableColors list and disable standard colors.
            if (DA.GetDataList <System.Drawing.Color>("Available Colors", availableCols))
            {
                ObservableCollection <ColorItem> cols = new ObservableCollection <ColorItem>();
                foreach (System.Drawing.Color cw in availableCols)
                {
                    Color c = HUI_Util.ToMediaColor(cw);
                    cols.Add(new ColorItem(c, String.Format("{0},{1},{2}", c.R, c.B, c.G)));
                    picker.AvailableColors    = cols;
                    picker.ShowStandardColors = false;
                }
            }
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            System.Drawing.Color?fgCol = null;
            System.Drawing.Color?bgCol = null;
            double fontSize            = -1;
            object elem = null;

            if (!DA.GetData("Elements to Adjust", ref elem))
            {
                return;
            }

            var hasfgCol    = DA.GetData("Foreground", ref fgCol);
            var hasbgCol    = DA.GetData("Background", ref bgCol);
            var hasFontSize = DA.GetData("Font Size", ref fontSize);


            //Get the "FrameworkElement" (basic UI element) from an object
            FrameworkElement f        = HUI_Util.GetUIElement <FrameworkElement>(elem);
            Selector         selector = f as Selector;
            ScrollViewer     sv       = f as ScrollViewer;
            ChartBase        cb       = f as ChartBase;


            if (f is Expander exp)
            {
                if (hasfgCol)
                {
                    exp.Foreground = new SolidColorBrush(HUI_Util.ToMediaColor(fgCol.Value));
                }
                if (hasbgCol)
                {
                    exp.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol.Value));
                }
                if (!hasFontSize)
                {
                    return;
                }
                var       header   = exp.Header;
                TextBlock myHeader = null;
                if (header is string headString)
                {
                    myHeader      = new TextBlock();
                    myHeader.Text = headString;
                }
                else
                {
                    myHeader = exp.Header as TextBlock;
                }
                myHeader.FontSize = fontSize;
                exp.Header        = myHeader;
                return;
            }


            // var ChartElem = HUI_Util.GetUIElement<ChartBase>(ChartObject);
            if (f is Grid g)
            {
                foreach (UIElement child in g.Children)
                {
                    ColorTextElement(child, fgCol, bgCol, fontSize);
                }
                if (hasbgCol)
                {
                    g.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol.Value));
                }
            }

            //if it's a panel color its children
            if (f is Panel panel)
            {
                foreach (UIElement child in panel.Children)
                {
                    ColorTextElement(child, fgCol, bgCol, fontSize);
                }
                if (hasbgCol)
                {
                    panel.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol.Value));
                }
            }

            if (f is TabControl tabControl)
            {
                if (hasbgCol)
                {
                    tabControl.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol.Value));
                }
            }

            //if it's a selector, color its items
            else if (selector != null)
            {
                foreach (UIElement child in selector.Items)
                {
                    ColorTextElement(child, fgCol, bgCol, fontSize);
                }
            }

            //if it's an itemscontrol, color its items
            else if (sv != null)
            {
                if (sv.Content is ItemsControl ic)
                {
                    foreach (var item in ic.Items)
                    {
                        if (item is UIElement uie)
                        {
                            ColorTextElement(uie, fgCol, bgCol, fontSize);
                        }
                    }
                }
            }

            //otherwise assume it's just a root level element
            else
            {
                ColorTextElement(f, fgCol, bgCol, fontSize);
            }
        }
        //color a UIElement. Runs through a list of possible types it recognizes and tries to color/format appropriately.
        private static void ColorTextElement(UIElement f, System.Drawing.Color?fgCol, System.Drawing.Color?bgCol, double fontSize)
        {
            // create brushes
            Brush backgroundBrush = new SolidColorBrush();
            Brush foregroundBrush = new SolidColorBrush();

            // if a value exists, create a brush for it
            if (bgCol.HasValue)
            {
                backgroundBrush = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol.Value));
            }
            if (fgCol.HasValue)
            {
                foregroundBrush = new SolidColorBrush(HUI_Util.ToMediaColor(fgCol.Value));
            }

            // Apply brushes where available
            //

            //Try graph
            if (f is ChartBase ChartB)
            {
                if (fgCol.HasValue)
                {
                    ChartB.Foreground = foregroundBrush;
                }
                if (bgCol.HasValue)
                {
                    ChartB.Background = backgroundBrush;
                }
                if (fontSize > 0)
                {
                    ChartB.FontSize = fontSize;
                }
            }
            //Try Label
            if (f is Label l)
            {
                if (fgCol.HasValue)
                {
                    l.Foreground = foregroundBrush;
                }
                if (bgCol.HasValue)
                {
                    l.Background = backgroundBrush;
                }
                if (fontSize > 0)
                {
                    l.FontSize = fontSize;
                }
                return;
            }
            // Try textbox
            if (f is TextBox tb)
            {
                if (fgCol.HasValue)
                {
                    tb.Foreground = foregroundBrush;
                }
                if (bgCol.HasValue)
                {
                    tb.Background = backgroundBrush;
                }
                if (fontSize > 0)
                {
                    tb.FontSize = fontSize;
                }
                return;
            }
            //Try Textblock

            if (f is TextBlock textblock)
            {
                if (fgCol.HasValue)
                {
                    textblock.Foreground = foregroundBrush;
                }
                if (bgCol.HasValue)
                {
                    textblock.Background = backgroundBrush;
                }
                if (fontSize > 0)
                {
                    textblock.FontSize = fontSize;
                }
                return;
            }
            //Try Button

            if (f is Button b)
            {
                if (fgCol.HasValue)
                {
                    b.Foreground = foregroundBrush;
                }
                if (bgCol.HasValue)
                {
                    b.Background = backgroundBrush;
                }
                if (fontSize > 0)
                {
                    b.FontSize = fontSize;
                }
                return;
            }
            //Try Checkbox
            if (f is CheckBox cb)
            {
                if (fgCol.HasValue)
                {
                    cb.Foreground = foregroundBrush;
                }
                if (bgCol.HasValue)
                {
                    cb.Background = backgroundBrush;
                }
                if (fontSize > 0)
                {
                    cb.FontSize = fontSize;
                }
                return;
            }
            //Try RadioButton
            if (f is RadioButton rb)
            {
                if (fgCol.HasValue)
                {
                    rb.Foreground = foregroundBrush;
                }
                if (bgCol.HasValue)
                {
                    rb.Background = backgroundBrush;
                }
                if (fontSize > 0)
                {
                    rb.FontSize = fontSize;
                }
                return;
            }
        }
예제 #8
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <Curve> shapeCrvs = new List <Curve>();
            List <System.Drawing.Color> fillCol   = new List <System.Drawing.Color>();
            List <double> strokeWeights           = new List <double>();
            List <System.Drawing.Color> strokeCol = new List <System.Drawing.Color>();
            double scale  = 1.0;
            int    width  = 0;
            int    height = 0;

            bool hasFill      = DA.GetDataList <System.Drawing.Color>("Fill Color", fillCol);
            bool hasWeight    = DA.GetDataList <double>("Stroke Weight", strokeWeights);
            bool hasStrokeCol = DA.GetDataList <System.Drawing.Color>("Stroke Color", strokeCol);

            DA.GetData <double>("Scale", ref scale);
            if (!DA.GetDataList <Curve>("Shapes", shapeCrvs))
            {
                return;
            }

            //Set up a grid to contain all shapes
            ClickableShapeGrid G = new ClickableShapeGrid();

            G.clickMode = clickMode;
            if (DA.GetData <int>("Width", ref width))
            {
                G.Width = width;
            }
            if (DA.GetData <int>("Height", ref height))
            {
                G.Height = height;
            }


            int i = 0;

            //For all the curves the user inputs
            foreach (Curve c in shapeCrvs)
            {
                //Set up a new path object
                Path path = new Path();
                //create a list to contain the single curve
                List <Curve> crvList = new List <Curve>();
                crvList.Add(c);
                //Set the path's data to the curve
                path.Data = CreateShape_Component.pathGeomFromCrvs(crvList, scale, false);
                //set all the properties
                if (hasFill)
                {
                    path.Fill = new SolidColorBrush(HUI_Util.ToMediaColor(fillCol[i % fillCol.Count]));
                }

                if (hasWeight)
                {
                    path.StrokeThickness = strokeWeights[i % strokeWeights.Count];
                }
                if (hasStrokeCol)
                {
                    path.Stroke = new SolidColorBrush(HUI_Util.ToMediaColor(strokeCol[i % strokeCol.Count]));
                }

                i++;
                //add the path object to the grid
                G.Children.Add(path);
            }

            //Pass out the grid
            DA.SetData("Shape", new UIElement_Goo(G, "Shape", InstanceGuid, DA.Iteration));
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            MainWindow mw = null;



            Point3d startLoc  = Point3d.Unset;
            int     theme     = 0;
            string  colorName = "";

            if (!DA.GetData <MainWindow>("Window", ref mw))
            {
                return;
            }
            //if the user has spec'd a location, move the window
            if (DA.GetData <Point3d>("Starting Location", ref startLoc))
            {
                mw.Left = startLoc.X;
                mw.Top  = startLoc.Y;
            }
            //set the theme
            if (DA.GetData <int>("Theme", ref theme))
            {
                switch (theme)
                {
                case 0:
                    ThemeManager.ChangeAppTheme(mw, "BaseLight");
                    break;

                case 1:
                    ThemeManager.ChangeAppTheme(mw, "BaseDark");
                    break;

                default:
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "That's not a valid theme - only 0 or 1 (light or dark) can be used.");
                    break;
                }
            }

            //set title bar visibility
            bool showTitleBar = true;

            DA.GetData <bool>("Show Title Bar", ref showTitleBar);
            SetTitleBarVisibility(mw, showTitleBar);

            //set background color
            System.Drawing.Color backgroundColor = System.Drawing.Color.Transparent;
            if (DA.GetData <System.Drawing.Color>("Background Color", ref backgroundColor))
            {
                mw.Background = new SolidColorBrush(HUI_Util.ToMediaColor(backgroundColor));
            }

            //set accent color
            if (DA.GetData <string>("Accent Color", ref colorName))
            {
                //get the current accent and theme so that theme can be preserved while accent changes
                Tuple <AppTheme, Accent> currStyle = ThemeManager.DetectAppStyle(mw);

                ThemeManager.ChangeAppStyle(mw, ThemeManager.GetAccent(colorName), currStyle.Item1);
            }
        }
예제 #10
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            object ShapeObject = null;

            if (!DA.GetData <object>("Shape to Modify", ref ShapeObject))
            {
                return;
            }
            Grid G = HUI_Util.GetUIElement <Grid>(ShapeObject);

            //change the shape
            if (G != null)
            {
                List <Curve>         shapeCrvs = new List <Curve>();
                System.Drawing.Color fillCol   = System.Drawing.Color.Transparent;
                double strokeWeight            = 0.0;
                System.Drawing.Color strokeCol = System.Drawing.Color.Transparent;
                double scale  = 1.0;
                int    width  = 0;
                int    height = 0;

                //Extract the path from the container grid
                Path path = getPath(G.Children);
                //save the old path
                Path oldpath = path;
                //if the user has supplied new shapes
                if (DA.GetDataList <Curve>("Shape Curve", shapeCrvs))
                {
                    Path newPath = new Path();
                    DA.GetData <double>("Scale", ref scale);
                    //use the method from the orig. component to translate curves into Geometry
                    newPath.Data = Components.UI_Elements.CreateShape_Component.pathGeomFromCrvs(shapeCrvs, scale, true);
                    //remove old path from Grid
                    G.Children.Remove(path);

                    path = newPath;
                    G.Children.Add(path);
                }
                //if the user specified a new fill color
                if (DA.GetData <System.Drawing.Color>("Fill Color", ref fillCol))
                {
                    //set fill
                    path.Fill = new SolidColorBrush(HUI_Util.ToMediaColor(fillCol));
                }
                else
                {
                    //otherwise use the old fill color
                    path.Fill = oldpath.Fill;
                }
                //if user supplied stroke weight
                if (DA.GetData <double>("Stroke Weight", ref strokeWeight))
                {
                    //set the stroke weight
                    path.StrokeThickness = strokeWeight;
                }
                else
                {
                    //otherwise use the old stroke weight
                    path.StrokeThickness = oldpath.StrokeThickness;
                }
                //if the user specified a stroke color
                if (DA.GetData <System.Drawing.Color>("Stroke Color", ref strokeCol))
                {
                    //set the stroke color
                    path.Stroke = new SolidColorBrush(HUI_Util.ToMediaColor(strokeCol));
                }
                else
                {
                    //otherwise use the old stroke color
                    path.Stroke = oldpath.Stroke;
                }

                //if the user specified a new object width
                if (DA.GetData <int>("Width", ref width))
                {
                    //set the grid width
                    G.Width = width;
                }
                else
                {
                    //otherwise use the old grid width
                    G.Width = oldpath.Width;
                }
                //if the user specified a new height
                if (DA.GetData <int>("Height", ref height))
                {
                    //set the height
                    G.Height = height;
                }
                else
                {
                    //otherwise use the old height
                    G.Height = oldpath.Height;
                }
            }
        }
예제 #11
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            System.Drawing.Color fgCol = System.Drawing.Color.Transparent;
            System.Drawing.Color bgCol = System.Drawing.Color.Transparent;
            double fontSize            = -1;
            object elem = null;

            if (!DA.GetData <object>("Elements to Adjust", ref elem))
            {
                return;
            }

            var hasfgCol    = DA.GetData <System.Drawing.Color>("Foreground", ref fgCol);
            var hasbgCol    = DA.GetData <System.Drawing.Color>("Background", ref bgCol);
            var hasFontSize = DA.GetData <double>("Font Size", ref fontSize);


            //Get the "FrameworkElement" (basic UI element) from an object
            FrameworkElement f = HUI_Util.GetUIElement <FrameworkElement>(elem);

            //try a few casts to see if it's a container
            Grid         g        = f as Grid;
            Panel        panel    = f as Panel;
            Selector     selector = f as Selector;
            ScrollViewer sv       = f as ScrollViewer;
            ChartBase    cb       = f as ChartBase;
            Expander     exp      = f as Expander;


            if (exp != null)
            {
                if (hasfgCol)
                {
                    exp.Foreground = new SolidColorBrush(HUI_Util.ToMediaColor(fgCol));
                }
                if (hasbgCol)
                {
                    exp.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol));
                }
                if (!hasFontSize)
                {
                    return;
                }
                var       header   = exp.Header;
                TextBlock myHeader = null;
                if (header is string)
                {
                    myHeader      = new TextBlock();
                    myHeader.Text = header as string;
                }
                else
                {
                    myHeader = exp.Header as TextBlock;
                }
                myHeader.FontSize = fontSize;
                exp.Header        = myHeader;
                return;
            }

            // var ChartElem = HUI_Util.GetUIElement<ChartBase>(ChartObject);
            if (g != null)
            {
                foreach (UIElement child in g.Children)
                {
                    ColorTextElement(child, fgCol, bgCol, fontSize);
                }
                g.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol));
            }



            //if it's a panel color its children
            if (panel != null)
            {
                foreach (UIElement child in panel.Children)
                {
                    ColorTextElement(child, fgCol, bgCol, fontSize);
                }
                panel.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol));
            }
            //if it's a selector, color its items
            else if (selector != null)
            {
                foreach (UIElement child in selector.Items)
                {
                    ColorTextElement(child, fgCol, bgCol, fontSize);
                }
            }
            //if it's an itemscontrol, color its items
            else if (sv != null)
            {
                ItemsControl ic = sv.Content as ItemsControl;
                if (ic != null)
                {
                    foreach (var item in ic.Items)
                    {
                        UIElement uie = item as UIElement;
                        if (uie != null)
                        {
                            ColorTextElement(uie, fgCol, bgCol, fontSize);
                        }
                    }
                }
            }
            else //otherwise assume it's just a root level element
            {
                ColorTextElement(f, fgCol, bgCol, fontSize);
            }
        }
예제 #12
0
        //color a UIElement. Runs through a list of possible types it recognizes and tries to color/format appropriately.
        private static void ColorTextElement(UIElement f, System.Drawing.Color fgCol, System.Drawing.Color bgCol, double fontSize)
        {
            Brush backgroundBrush = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol));
            Brush foregroundBrush = new SolidColorBrush(HUI_Util.ToMediaColor(fgCol));
            //Try graoh
            ChartBase ChartB = f as ChartBase;

            if (ChartB != null)
            {
                ChartB.Foreground = foregroundBrush;
                ChartB.Background = backgroundBrush;
                if (fontSize > 0)
                {
                    ChartB.FontSize = fontSize;
                }
            }
            //Try Label
            Label l = f as Label;

            if (l != null)
            {
                l.Foreground = foregroundBrush;
                if (bgCol != System.Drawing.Color.Transparent)
                {
                    l.Background = backgroundBrush;
                }
                if (fontSize > 0)
                {
                    l.FontSize = fontSize;
                }
                return;
            }
            // Try textbox
            TextBox tb = f as TextBox;

            if (tb != null)
            {
                tb.Foreground = foregroundBrush;
                if (bgCol != System.Drawing.Color.Transparent)
                {
                    tb.Background = backgroundBrush;
                }
                if (fontSize > 0)
                {
                    tb.FontSize = fontSize;
                }
                return;
            }
            //Try Textblock
            TextBlock textblock = f as TextBlock;

            if (textblock != null)
            {
                textblock.Foreground = foregroundBrush;
                if (bgCol != System.Drawing.Color.Transparent)
                {
                    textblock.Background = backgroundBrush;
                }
                if (fontSize > 0)
                {
                    textblock.FontSize = fontSize;
                }
                return;
            }
            //Try Button
            Button b = f as Button;

            if (b != null)
            {
                b.Foreground = foregroundBrush;
                if (bgCol != System.Drawing.Color.Transparent)
                {
                    b.Background = backgroundBrush;
                }
                if (fontSize > 0)
                {
                    b.FontSize = fontSize;
                }
                return;
            }
            //Try Checkbox
            CheckBox cb = f as CheckBox;

            if (cb != null)
            {
                cb.Foreground = foregroundBrush;
                if (bgCol != System.Drawing.Color.Transparent)
                {
                    cb.Background = backgroundBrush;
                }
                if (fontSize > 0)
                {
                    cb.FontSize = fontSize;
                }
                return;
            }
            //Try RadioButton
            RadioButton rb = f as RadioButton;

            if (rb != null)
            {
                rb.Foreground = foregroundBrush;
                if (bgCol != System.Drawing.Color.Transparent)
                {
                    rb.Background = backgroundBrush;
                }
                if (fontSize > 0)
                {
                    rb.FontSize = fontSize;
                }
                return;
            }
        }
예제 #13
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //placeholder variable to hold the generic element object
            object ShapeObject = null;


            if (!DA.GetData <object>("Shape to Modify", ref ShapeObject))
            {
                return;
            }

            //Get grid container out of generic object
            ClickableShapeGrid G         = HUI_Util.GetUIElement <ClickableShapeGrid>(ShapeObject);
            List <bool>        oldStates = new List <bool>(G.SelectedStates.ToArray());

            //change the shape
            if (G != null)
            {
                List <Curve> shapeCrvs = new List <Curve>();
                List <System.Drawing.Color> fillCol   = new List <System.Drawing.Color>();
                List <double> strokeWeights           = new List <double>();
                List <System.Drawing.Color> strokeCol = new List <System.Drawing.Color>();
                double scale   = 1.0;
                int    width   = 0;
                int    height  = 0;
                Path   oldpath = getPath(G.Children);


                bool hasWeight    = false;
                bool hasStrokeCol = false;
                bool hasFill      = false;

                DA.GetData <double>("Scale", ref scale);

                //Populate variables and store boolean results for later use.
                hasFill      = DA.GetDataList <System.Drawing.Color>("Fill Colors", fillCol);
                hasWeight    = DA.GetDataList <double>("Stroke Weights", strokeWeights);
                hasStrokeCol = DA.GetDataList <System.Drawing.Color>("Stroke Colors", strokeCol);

                //If the user has specified new shapes:
                if (DA.GetDataList <Curve>("Shape Curves", shapeCrvs))
                {
                    //G.Children.Clear();

                    //remove all shape children
                    var itemsToRemove = G.Children.OfType <FrameworkElement>()
                                        .Where(c => (c is Shape)).ToList();

                    itemsToRemove
                    .ForEach(g => G.Children.Remove(g));

                    int i = 0;
                    //for all the curves
                    foreach (Curve c in shapeCrvs)
                    {
                        Path         path    = new Path();
                        List <Curve> crvList = new List <Curve>();
                        //We're passing a single curve as a list so that the multiple curves are not interpreted as "composite" -
                        //and therefore would be unable to be styled separately.
                        crvList.Add(c);

                        // Get Geometry from rhino curve objects. Note that "rebase" is set to false - so that relative position of
                        // multiple curves is preserved. This is the primary difference with the setShape component (as well as list access)
                        path.Data = Components.UI_Elements.CreateShape_Component.pathGeomFromCrvs(crvList, scale, false);
                        if (hasFill)
                        {
                            path.Fill = new SolidColorBrush(HUI_Util.ToMediaColor(fillCol[i % fillCol.Count])); //hacky fix to approximate longest list matching
                        }
                        else
                        {
                            path.Fill = oldpath.Fill;
                        }

                        if (hasWeight)
                        {
                            path.StrokeThickness = strokeWeights[i % strokeWeights.Count]; //hacky fix to approximate longest list matching
                        }
                        else
                        {
                            path.StrokeThickness = oldpath.StrokeThickness;
                        }
                        if (hasStrokeCol)
                        {
                            path.Stroke = new SolidColorBrush(HUI_Util.ToMediaColor(strokeCol[i % strokeCol.Count])); //hacky fix to approximate longest list matching
                        }
                        else
                        {
                            path.Stroke = oldpath.Stroke;
                        }

                        i++;
                        //Add the new path to the Grid
                        G.Children.Add(path);
                    }
                }



                //If the user has specified new dimensions for the container, update its dimensions, otherwise use the old ones.
                if (DA.GetData <int>("Width", ref width))
                {
                    G.Width = width;
                }
                else
                {
                    G.Width = oldpath.Width;
                }
                if (DA.GetData <int>("Height", ref height))
                {
                    G.Height = height;
                }
                else
                {
                    G.Height = oldpath.Height;
                }
            }

            if (G.Children.Count == oldStates.Count && G.clickMode == ClickableShapeGrid.ClickMode.ToggleMode)
            {
                G.SelectedStates = oldStates;
                G.UpdateAppearance();
            }
        }