Example #1
0
 protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
 {
     if ((int)channel == 10)
     {
         foreach (IGH_Param item in Owner.Params.Input)
         {
             item.Attributes.RenderToCanvas(canvas, (GH_CanvasChannel)10);
         }
     }
     else
     {
         if ((int)channel != 20)
         {
             return;
         }
         RectangleF bounds = base.Bounds;
         bool       flag   = canvas.Viewport.IsVisible(ref bounds, 10f);
         Bounds = bounds;
         if (flag)
         {
             GH_Palette      impliedPalette = GH_CapsuleRenderEngine.GetImpliedPalette((IGH_ActiveObject)(object)base.Owner);
             GH_PaletteStyle impliedStyle   = GH_CapsuleRenderEngine.GetImpliedStyle(impliedPalette, Selected, Owner.Locked, Owner.Hidden);
             GH_Capsule      val            = GH_Capsule.CreateCapsule(base.Bounds, impliedPalette, 5, 30);
             foreach (IGH_Param item2 in Owner.Params.Input)
             {
                 val.AddInputGrip(item2.Attributes.InputGrip.Y);
             }
             val.AddOutputGrip(OutputGrip.Y);
             if (Owner.Message != null)
             {
                 val.RenderEngine.RenderMessage(graphics, Owner.Message, impliedStyle);
             }
             val.Render(graphics, Selected, Owner.Locked, true);
             val.Dispose();
             GH_ComponentAttributes.RenderComponentParameters(canvas, graphics, base.Owner, impliedStyle);
             if (base.Owner.Graph == null)
             {
                 RectangleF bounds2 = base.Bounds;
                 bounds2.X     += inputWidth;
                 bounds2.Width -= inputWidth + outputWidth;
                 bounds2.Inflate(-6f, -6f);
                 GH_GraphContainer.Render_GraphBackground(graphics, bounds2, false);
             }
             else
             {
                 base.Owner.Container.Render(graphics, DrawDomainsTags, base.Owner.Samples);
             }
         }
     }
 }
Example #2
0
        private void RenderComponentBounds(Graphics graphics)
        {
            //点击等效果到这里修改
            GH_Palette ComponentColor = GH_Palette.Normal;
            bool       IsLock         = false;
            bool       IsSelected     = false;

            if (this.Owner.Locked)
            {
                IsLock = true;
            }
            if (this.Owner.Attributes.Selected)
            {
                IsSelected = true;
            }
            if (this.Owner.RuntimeMessageLevel == GH_RuntimeMessageLevel.Error)
            {
                ComponentColor = GH_Palette.Warning;
            }
            if (this.Owner.RuntimeMessageLevel == GH_RuntimeMessageLevel.Warning)
            {
                ComponentColor = GH_Palette.Warning;
            }
            if (this.Owner.Locked)
            {
                ComponentColor = GH_Palette.Locked;
            }

            RectangleF Bounds  = this.Owner.Attributes.Bounds;
            GH_Capsule Capsule = GH_Capsule.CreateCapsule(Bounds, ComponentColor);

            Capsule.AddInputGrip(Bounds.Left, Bounds.Top + Setting.DROPDOWNCOMPONENTHEIGHT / 2);
            Capsule.AddOutputGrip(Bounds.Right, Bounds.Top + Setting.DROPDOWNCOMPONENTHEIGHT / 2);

            Capsule.RenderEngine.RenderGrips(graphics);
            Capsule.Render(graphics, IsSelected, IsLock, false);
            Capsule.Dispose();
        }
Example #3
0
        // render
        protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
        {
            if (channel != Grasshopper.GUI.Canvas.GH_CanvasChannel.Objects)
            {
                return;
            }

            RenderIncomingWires(canvas.Painter, Owner.Sources, Owner.WireDisplay);

            // Define the default palette.
            GH_Palette palette = GH_Palette.Normal;

            // Create a new Capsule
            GH_Capsule capsule = GH_Capsule.CreateCapsule(new RectangleF(this.Pivot, new SizeF(Bounds.Width, 20)), palette);

            capsule.AddInputGrip(this.InputGrip.Y);
            capsule.AddOutputGrip(this.OutputGrip.Y);

            bool validInput = own.getUserInput();

            string componentName;

            if (own.sourceName == "" || own.sourceName == null)
            {
                componentName = "Probabilities";
            }
            else
            {
                componentName = "Probabilities (" + own.sourceName + " )";
            }

            if (binSelected)
            {
                componentName = "Probabilities (" + own.sourceName + " <=" + own.BinRanges[selectedBin][1].ToString() + ")";
            }

            if ((own.evidence == true) && (own.doubleClicked == true))
            {
                Rhino.RhinoApp.WriteLine("db");
                componentName = componentName + " = 100%";
            }
            else if ((own.evidence == true) && (own.doubleClicked == false))
            {
                Rhino.RhinoApp.WriteLine("not db");
                componentName = componentName + " = custom";
            }

            Grasshopper.GUI.Canvas.GH_PaletteStyle styleStandard = null;
            Grasshopper.GUI.Canvas.GH_PaletteStyle styleSelected = null;
            GH_Skin.LoadSkin();

            if (channel == GH_CanvasChannel.Objects)
            {
                // Cache the current styles.
                styleStandard = GH_Skin.palette_normal_standard;
                styleSelected = GH_Skin.palette_normal_selected;


                if (!own.evidence)
                {
                    GH_Skin.palette_normal_selected = GH_Skin.palette_normal_standard;
                }
                else
                {
                    GH_Skin.palette_normal_standard = new GH_PaletteStyle(Color.SkyBlue, Color.DarkBlue, Color.Black);
                    GH_Skin.palette_normal_selected = new GH_PaletteStyle(Color.SkyBlue, Color.DarkBlue, Color.Black);
                }
            }

            GH_Capsule message = GH_Capsule.CreateTextCapsule(
                new RectangleF(new PointF(this.Pivot.X, this.Pivot.Y + 20), new SizeF(Bounds.Width, 20)),
                new RectangleF(new PointF(this.Pivot.X, this.Pivot.Y + 20), new SizeF(Bounds.Width, 20)),
                GH_Palette.Normal,
                componentName
                );

            message.Render(graphics, Selected, Owner.Locked, false);
            message.Dispose();
            message = null;

            if (channel == GH_CanvasChannel.Objects)
            {
                // Restore the cached styles.
                GH_Skin.palette_normal_standard = styleStandard;
                GH_Skin.palette_normal_selected = styleSelected;
            }

            //Render the capsule using the current Selection, Locked and Hidden states.
            //Integer parameters are always hidden since they cannot be drawn in the viewport.
            capsule.Render(graphics, Selected, Owner.Locked, true);

            //Always dispose of a GH_Capsule when you're done with it.
            capsule.Dispose();
            capsule = null;

            //Bounds = _extraBounds;

            int    width = GH_FontServer.StringWidth(Owner.NickName, GH_FontServer.Standard);
            PointF p     = new PointF(this.Pivot.X + width + 19, this.Pivot.Y - 7);

            List <double> probs = own.Probabilities;

            PointF[] pts = getHistoPts(own.Probabilities);

            if (own.draw_flag == "s")
            {
                pts = getPts(probs);
            }

            PointF maxPt = new PointF(0, 0);

            float ptY       = pts[0].Y;
            int   index_max = 0;

            for (int i = 0; i < pts.Length; i++)
            {
                if (pts[i].Y < ptY)
                {
                    ptY       = pts[i].Y;
                    index_max = i;
                }
            }

            maxPt = pts[index_max];

            // Create Pens
            System.Drawing.Pen pen2 = new System.Drawing.Pen(Brushes.Red, 2);
            System.Drawing.Pen pen  = new System.Drawing.Pen(Brushes.Black, 2);
            System.Drawing.Pen pen3 = new System.Drawing.Pen(Brushes.GhostWhite, 1);

            // Create Gradient Brush
            System.Drawing.Drawing2D.LinearGradientBrush lb = new System.Drawing.Drawing2D.LinearGradientBrush
                                                                  (new PointF(maxPt.X, maxPt.Y), new PointF(maxPt.X, this.Pivot.Y), Color.FromArgb(255, 0, 0),
                                                                  Color.FromArgb(255, 255, 255));
            System.Drawing.SolidBrush sb = new System.Drawing.SolidBrush(Color.FromArgb(70, 255, 255, 255));

            // Rui
            // render background bins

            RectangleF[] backgroundBins = getBackgroundBins(own.Probabilities);
            graphics.DrawRectangles(pen3, backgroundBins);
            graphics.FillRectangles(sb, backgroundBins);

            backgroundBinBounds = backgroundBins;

            //Draw Polygon ouline and fill
            graphics.DrawPolygon(pen, pts);
            graphics.FillPolygon(lb, pts);

            // draw text capsules
            RectangleF[] textholderBounds = getTextholder(own.Probabilities);
            GH_Capsule[] textCapsules     = new GH_Capsule[textholderBounds.Length];

            int numbins = textCapsules.Length;

            if (own.BinRanges != null)
            {
                for (int i = 0; i < numbins; i++)
                {
                    //textCapsules[i] = GH_Capsule.CreateTextCapsule(textholderBounds[i], textholderBounds[i], GH_Palette.Normal, "<=" + own.BinRanges[numbins - 1 - i][1], 3, 0);
                    textCapsules[i] = GH_Capsule.CreateTextCapsule(textholderBounds[i], textholderBounds[i], GH_Palette.Normal, Math.Round(own.BinRanges[numbins - 1 - i][0], 2) + "<" + Math.Round(own.BinRanges[numbins - 1 - i][1], 2), 3, 0);
                    textCapsules[i].Render(graphics, Selected, Owner.Locked, false);
                }
            }
        }
Example #4
0
        protected void RenderComponentCapsule2(GH_Canvas canvas, Graphics graphics, bool drawComponentBaseBox, bool drawComponentNameBox, bool drawJaggedEdges, bool drawParameterGrips, bool drawParameterNames, bool drawZuiElements)
        {
            GH_SwitcherComponent gH_SwitcherComponent = (GH_SwitcherComponent)base.Owner;
            RectangleF           bounds = this.Bounds;

            this.Bounds = (bounds);
            if (!canvas.Viewport.IsVisible(ref bounds, 10f))
            {
                return;
            }
            GH_Palette val = GH_CapsuleRenderEngine.GetImpliedPalette(base.Owner);

            if ((int)val == 0 && !base.Owner.IsPreviewCapable)
            {
                val = GH_Palette.Hidden;
            }
            GH_Capsule val2 = GH_Capsule.CreateCapsule(this.Bounds, val);
            bool       flag = base.Owner.Params.Input
                              .Count == 0;
            bool flag2 = base.Owner.Params.Output
                         .Count == 0;

            val2.SetJaggedEdges(flag, flag2);
            GH_PaletteStyle impliedStyle = GH_CapsuleRenderEngine.GetImpliedStyle(val, this.Selected, base.Owner.Locked, base.Owner.Hidden);

            if (drawParameterGrips)
            {
                foreach (IGH_Param staticInput in gH_SwitcherComponent.StaticData.StaticInputs)
                {
                    val2.AddInputGrip(staticInput.Attributes.InputGrip.Y);
                }
                foreach (IGH_Param dynamicInput in gH_SwitcherComponent.StaticData.DynamicInputs)
                {
                    val2.AddInputGrip(dynamicInput.Attributes.InputGrip.Y);
                }
                foreach (IGH_Param staticOutput in gH_SwitcherComponent.StaticData.StaticOutputs)
                {
                    val2.AddOutputGrip(staticOutput.Attributes.OutputGrip.Y);
                }
                foreach (IGH_Param dynamicOutput in gH_SwitcherComponent.StaticData.DynamicOutputs)
                {
                    val2.AddOutputGrip(dynamicOutput.Attributes.OutputGrip.Y);
                }
            }
            graphics.SmoothingMode = SmoothingMode.HighQuality;
            canvas.SetSmartTextRenderingHint();
            if (GH_Attributes <IGH_Component> .IsIconMode(base.Owner.IconDisplayMode))
            {
                if (drawComponentBaseBox)
                {
                    if (base.Owner.Message != null)
                    {
                        val2.RenderEngine.RenderMessage(graphics, base.Owner.Message, impliedStyle);
                    }
                    val2.Render(graphics, impliedStyle);
                }
                if (drawComponentNameBox && base.Owner.Icon_24x24 != null)
                {
                    if (base.Owner.Locked)
                    {
                        val2.RenderEngine.RenderIcon(graphics, (Image)base.Owner.Icon_24x24_Locked, base.m_innerBounds, 0, 0);
                    }
                    else
                    {
                        val2.RenderEngine.RenderIcon(graphics, (Image)base.Owner.Icon_24x24, base.m_innerBounds, 0, 0);
                    }
                }
            }
            else
            {
                if (drawComponentBaseBox)
                {
                    if (base.Owner.Message != null)
                    {
                        val2.RenderEngine.RenderMessage(graphics, base.Owner.Message, impliedStyle);
                    }
                    val2.Render(graphics, impliedStyle);
                }
                if (drawComponentNameBox)
                {
                    GH_Capsule obj = GH_Capsule.CreateTextCapsule(base.m_innerBounds, base.m_innerBounds, GH_Palette.Black, base.Owner.NickName, StandardFont.largeFont(), GH_Orientation.vertical_center, 3, 6);
                    obj.Render(graphics, this.Selected, base.Owner.Locked, false);
                    obj.Dispose();
                }
            }
            if (drawComponentNameBox && base.Owner.Obsolete && Grasshopper.CentralSettings.CanvasObsoleteTags && (int)canvas.DrawingMode == 0)
            {
                GH_GraphicsUtil.RenderObjectOverlay(graphics, Owner, base.m_innerBounds);
            }
            if (drawParameterNames)
            {
                RenderComponentParameters2(canvas, graphics, base.Owner, impliedStyle);
            }
            if (drawZuiElements)
            {
                this.RenderVariableParameterUI(canvas, graphics);
            }
            val2.Dispose();
        }
Example #5
0
        protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
        {
            if (channel == GH_CanvasChannel.Wires)
            {
                this.RenderIncomingWires(canvas.Painter, (IEnumerable <IGH_Param>)Owner.Sources, Owner.WireDisplay);
            }
            if (channel != GH_CanvasChannel.Objects)
            {
                return;
            }
            GH_Capsule capsule    = GH_Capsule.CreateCapsule(Bounds, GH_Palette.White);
            GH_Capsule ghCapsule1 = capsule;
            PointF     pointF     = OutputGrip;
            double     y1         = (double)pointF.Y;

            ghCapsule1.AddOutputGrip((float)y1);
            GH_Capsule ghCapsule2 = capsule;

            pointF = InputGrip;
            double y2 = (double)pointF.Y;

            ghCapsule2.AddInputGrip((float)y2);
            capsule.Render(canvas.Graphics, Selected, Owner.Locked, Owner.Hidden);
            capsule.Dispose();
            int zoomFadeLow = GH_Canvas.ZoomFadeLow;

            if (zoomFadeLow > 0)
            {
                canvas.SetSmartTextRenderingHint();
                GH_PaletteStyle impliedStyle = GH_CapsuleRenderEngine.GetImpliedStyle(GH_Palette.White, (IGH_Attributes)this);
                Color           color        = Color.FromArgb(zoomFadeLow, impliedStyle.Text);
                if (NameBounds.Width > 0.0)
                {
                    SolidBrush solidBrush = new SolidBrush(color);
                    graphics.DrawString(Owner.NickName, GH_FontServer.Standard, (Brush)solidBrush, NameBounds, GH_TextRenderingConstants.CenterCenter);
                    solidBrush.Dispose();
                    RectangleF nameBounds = NameBounds;
                    int        int32_1    = Convert.ToInt32(nameBounds.Right);
                    nameBounds = NameBounds;
                    int int32_2 = Convert.ToInt32(nameBounds.Top);
                    nameBounds = NameBounds;
                    int int32_3 = Convert.ToInt32(nameBounds.Bottom);
                    GH_GraphicsUtil.EtchFadingVertical(graphics, int32_2, int32_3, int32_1, Convert.ToInt32(0.8 * (double)zoomFadeLow), Convert.ToInt32(0.3 * (double)zoomFadeLow));
                }
                switch (Owner.ListMode)
                {
                case GH_ValueListMode.CheckList:
                    RenderCheckList(canvas, graphics, color);
                    break;

                case GH_ValueListMode.DropDown:
                    RenderDropDown(canvas, graphics, color);
                    break;

                case GH_ValueListMode.Sequence:
                case GH_ValueListMode.Cycle:
                    RenderSequence(canvas, graphics, color);
                    break;
                }
            }
        }
Example #6
0
        //protected override void Layout()
        //{
        //    // Compute the width of the NickName of the owner (plus some extra padding),
        //    // then make sure we have at least 80 pixels.
        //    int width = GH_FontServer.StringWidth(Owner.NickName, GH_FontServer.Standard);
        //    width = Math.Max(width + 10, 80);

        //    // The height of our object is always 60 pixels
        //    int height = 60;

        //    // Assign the width and height to the Bounds property.
        //    // Also, make sure the Bounds are anchored to the Pivot
        //    Bounds = new RectangleF(Pivot, new SizeF(width, height));

        //    int paramNameWidth = GH_FontServer.StringWidth(Owner.Params.Input[0].NickName, GH_FontServer.Standard) + 8;

        //    var componentBox = new RectangleF(new PointF(Pivot.X + paramNameWidth, Pivot.Y), new SizeF(width - paramNameWidth, height));

        //    LayoutInputParams(Owner, componentBox);
        //    LayoutOutputParams(Owner, componentBox);
        //}

        protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
        {
            // Render the component capsule and any additional text on top of it.
            if (channel == GH_CanvasChannel.Objects)
            {
                // Define the default palette.
                GH_Palette palette = GH_Palette.Blue;

                Color color = Color.LightCoral;
                //Color color = Color.MediumSpringGreen;
                //Color color = Color.DeepPink;
                bool usePalette = false;
                if (Selected)
                {
                    usePalette = true;
                }

                // Adjust color based on the Owner's worst case messaging level.
                switch (Owner.RuntimeMessageLevel)
                {
                case GH_RuntimeMessageLevel.Warning:
                    palette    = GH_Palette.Warning;
                    usePalette = true;
                    break;

                case GH_RuntimeMessageLevel.Error:
                    palette    = GH_Palette.Error;
                    usePalette = true;
                    break;
                }

                // Create a new Capsule without text or icon.
                GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, palette);

                foreach (IGH_Param p in Owner.Params.Input)
                {
                    capsule.AddInputGrip(p.Attributes.InputGrip.Y);
                }

                foreach (IGH_Param p in Owner.Params.Output)
                {
                    capsule.AddOutputGrip(p.Attributes.OutputGrip.Y);
                }


                if (usePalette)
                {
                    capsule.Render(graphics, Selected, Owner.Locked, true);
                }
                else
                {
                    capsule.Render(graphics, color);
                }

                var icon  = Owner.Icon_24x24;
                var point = new PointF(
                    m_innerBounds.X,
                    m_innerBounds.Y + m_innerBounds.Height / 2 - icon.Height / 2
                    );

                graphics.DrawImage(icon, point);

                var modifierIcon = Grasshopper.GUI.GH_StandardIcons.FlattenIcon_24x24;

                // Always dispose of a GH_Capsule when you're done with it.
                capsule.Dispose();
                capsule = null;

                // Now it's time to draw the text on top of the capsule.
                // First we'll draw the Owner NickName using a standard font and a black brush.
                // We'll also align the NickName in the center of the Bounds.
                StringFormat format = new StringFormat();
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;
                format.Trimming      = StringTrimming.EllipsisCharacter;

                //Our entire capsule is 60 pixels high, and we'll draw
                // three lines of text, each 20 pixels high.
                RectangleF textRectangle = Bounds;
                textRectangle.Height = 20;

                format.Alignment = StringAlignment.Far;
                foreach (IGH_Param p in Owner.Params.Input)
                {
                    textRectangle = p.Attributes.Bounds;
                    graphics.DrawString(p.NickName, GH_FontServer.Standard, Brushes.Black, textRectangle, format);
                }

                format.Alignment = StringAlignment.Near;
                foreach (IGH_Param p in Owner.Params.Output)
                {
                    textRectangle = p.Attributes.Bounds;
                    graphics.DrawString(p.NickName, GH_FontServer.Standard, Brushes.Black, textRectangle, format);
                }

                // Always dispose of any GDI+ object that implement IDisposable.
                format.Dispose();


                ////we should render this component's parameters after rendering the component
                //foreach (IGH_Param p in Owner.Params.Input)
                //    p.Attributes.RenderToCanvas(canvas, channel);
            }
            else
            {
                base.Render(canvas, graphics, channel);
            }
        }
Example #7
0
        private void RenderSpecial(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
        {
            // Render all the wires that connect the Owner to all its Sources.
            if (channel == GH_CanvasChannel.Wires)
            {
                RenderIncomingWires(canvas.Painter, Owner.Params.Input, GH_ParamWireDisplay.@default);
                return;
            }

            // Render the parameter capsule and any additional text on top of it.
            if (channel == GH_CanvasChannel.Objects)
            {
                // Define the default palette.
                GH_Palette palette = GH_Palette.Blue;

                Color color      = Color.DarkSalmon;
                bool  usePalette = false;
                if (Selected)
                {
                    usePalette = true;
                }

                // Adjust color based on the Owner's worst case messaging level.
                switch (Owner.RuntimeMessageLevel)
                {
                case GH_RuntimeMessageLevel.Warning:
                    palette    = GH_Palette.Warning;
                    usePalette = true;
                    break;

                case GH_RuntimeMessageLevel.Error:
                    palette    = GH_Palette.Error;
                    usePalette = true;
                    break;
                }

                //canvas.Select
                // Create a new Capsule without text or icon.
                GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, palette);

                foreach (IGH_Param p in Owner.Params.Input)
                {
                    capsule.AddInputGrip(p.Attributes.InputGrip.Y);
                }

                foreach (IGH_Param p in Owner.Params.Output)
                {
                    capsule.AddOutputGrip(p.Attributes.OutputGrip.Y);
                }

                //Image icon = Owner.Icon_24x24;
                //var component = (GH_Component)Owner;
                //var icon = component.Ico

                if (usePalette)
                {
                    capsule.Render(graphics, Selected, Owner.Locked, true);
                }
                else
                {
                    capsule.Render(graphics, Color.DarkSalmon);
                }

                //if (Owner.IconDisplayMode == GH_IconDisplayMode.icon)
                //    graphics.DrawIcon(Owner., m_innerBounds);
                // Always dispose of a GH_Capsule when you're done with it.
                capsule.Dispose();
                capsule = null;

                GH_Capsule innerCapsule = GH_Capsule.CreateTextCapsule(m_innerBounds, m_innerBounds, GH_Palette.Grey, Owner.NickName);
                innerCapsule.Render(graphics, Selected, Owner.Locked, true);
                innerCapsule.Dispose();
                innerCapsule = null;

                // Now it's time to draw the text on top of the capsule.
                // First we'll draw the Owner NickName using a standard font and a black brush.
                // We'll also align the NickName in the center of the Bounds.
                StringFormat format = new StringFormat();
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;
                format.Trimming      = StringTrimming.EllipsisCharacter;

                // Our entire capsule is 60 pixels high, and we'll draw
                // three lines of text, each 20 pixels high.
                RectangleF textRectangle = Bounds;
                textRectangle.Height = 20;

                // Draw the NickName in a Standard Grasshopper font.
                var component = (Boa_AlgorithmComponent)Owner;
                graphics.DrawString(component.Algorithm.GetDimensionsString(), GH_FontServer.Standard, Brushes.Black, textRectangle, format);

                format.Alignment = StringAlignment.Far;
                foreach (IGH_Param p in Owner.Params.Input)
                {
                    textRectangle = p.Attributes.Bounds;
                    graphics.DrawString(p.NickName, GH_FontServer.Standard, Brushes.Black, textRectangle, format);
                }

                format.Alignment = StringAlignment.Near;
                foreach (IGH_Param p in Owner.Params.Output)
                {
                    textRectangle = p.Attributes.Bounds;
                    graphics.DrawString(p.NickName, GH_FontServer.Standard, Brushes.Black, textRectangle, format);
                }
                // Now we need to draw the median and mean information.
                // Adjust the formatting and the layout rectangle.
                //format.Alignment = StringAlignment.Near;
                //textRectangle.Inflate(-5, 0);

                //textRectangle.Y += 20;
                //graphics.DrawString(String.Format("Median: {0}", Owner.MedianValue), _
                //                    GH_FontServer.StandardItalic, Brushes.Black, _
                //                    textRectangle, format);

                //textRectangle.Y += 20;
                //graphics.DrawString(String.Format("Mean: {0:0.00}", Owner.MeanValue), _
                //                    GH_FontServer.StandardItalic, Brushes.Black, _
                //                    textRectangle, format);

                //// Always dispose of any GDI+ object that implement IDisposable.
                format.Dispose();
            }
        }
Example #8
0
        protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
        {
            if (channel == GH_CanvasChannel.Wires)
            {
                RenderIncomingWires(canvas.Painter, Owner.Sources, Owner.WireDisplay);
            }


            if (channel == GH_CanvasChannel.Objects)
            {
                base.Render(canvas, graphics, channel);

                GH_Palette palette = GH_Palette.Normal;

                switch (Owner.RuntimeMessageLevel)
                {
                case GH_RuntimeMessageLevel.Warning:
                    palette = GH_Palette.Warning;
                    break;

                case GH_RuntimeMessageLevel.Error:
                    palette = GH_Palette.Error;
                    break;
                }

                GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, palette);
                capsule.AddInputGrip(InputGrip.Y);
                capsule.Render(graphics, Selected, Owner.Locked, true);

                capsule.Dispose();

                StringFormat format = new StringFormat();
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;
                format.Trimming      = StringTrimming.EllipsisCharacter;

                RectangleF textRectangle = Bounds;
                textRectangle.Height = 20;

                graphics.DrawString(Owner.NickName, GH_FontServer.Standard, Brushes.Black, textRectangle, format);



                int displayWidth  = (int)(Bounds.Width - padding * 2);
                int displayHeight = (int)(Bounds.Height - padding * 4);

                System.Drawing.Point position         = new System.Drawing.Point((int)(Bounds.X + padding), (int)(Bounds.Y + padding * 3));
                Rectangle            PatternRectangle = new Rectangle(position.X, position.Y, displayWidth, displayHeight);
                graphics.DrawRectangle(new Pen(Color.White), PatternRectangle);

                IGH_Structure data = Owner.VolatileData;
                if (data.PathCount != 0)
                {
                    GH_Path          path   = data.get_Path(0);
                    List <GH_Number> branch = data.get_Branch(path) as List <GH_Number>;

                    int   patternSize = branch.Count;
                    float width       = (float)Math.Ceiling(Math.Sqrt((double)patternSize));

                    if (displayWidth > displayHeight)
                    {
                        displaySize = displayHeight;
                    }
                    else
                    {
                        displaySize = displayWidth;
                    }

                    float rectSize = (float)(displaySize / width);

                    RectangleF[] rectangles = new RectangleF[patternSize];

                    for (int i = 0; i < patternSize; i++)
                    {
                        PointF pos = new PointF((float)(Bounds.X + padding), (float)(Bounds.Y + padding * 3));
                        pos = new PointF(pos.X + rectSize * (float)Math.Floor(i % width), pos.Y + rectSize * (float)Math.Floor(i / width));
                        RectangleF content = new RectangleF(pos.X, pos.Y, rectSize, rectSize);
                        rectangles[i] = content;
                        SolidBrush brush;

                        if ((int)branch[i].Value == 0)
                        {
                            brush = new SolidBrush(Color.White);
                        }
                        else if ((int)branch[i].Value == 1)
                        {
                            brush = new SolidBrush(Color.Black);
                        }
                        else
                        {
                            brush = new SolidBrush(Color.Orange);
                        }

                        graphics.FillRectangle(brush, rectangles[i]);
                    }
                }

                format.Dispose();
            }
        }