예제 #1
0
        protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
        {
            if (channel == GH_CanvasChannel.Objects)
            {
                GH_Capsule capsule = GH_Capsule.CreateCapsule(this.Bounds, GH_Palette.Normal);
                capsule.AddOutputGrip(this.OutputGrip.Y);
                capsule.Render(canvas.Graphics, this.Selected, this.Owner.Locked, this.Owner.Hidden);
                capsule.Dispose();
                int zoomFadeLow = GH_Canvas.ZoomFadeLow;
                if (zoomFadeLow > 0)
                {
                    canvas.SetSmartTextRenderingHint();
                    GH_PaletteStyle impliedStyle = GH_CapsuleRenderEngine.GetImpliedStyle(GH_Palette.Normal, this);
                    Color           color        = Color.FromArgb(zoomFadeLow, impliedStyle.Text);

                    if (this.NameBounds.Width > 0f)
                    {
                        SolidBrush brush = new SolidBrush(color);
                        graphics.DrawString(this.ownerOfThisAttribute.NickName, GH_FontServer.Standard, brush, this.NameBounds, GH_TextRenderingConstants.CenterCenter);
                        brush.Dispose();
                        int x    = Convert.ToInt32(this.NameBounds.Right);
                        int num3 = Convert.ToInt32(this.NameBounds.Top);
                        int num4 = Convert.ToInt32(this.NameBounds.Bottom);
                        GH_GraphicsUtil.EtchFadingVertical(graphics, num3, num4, x, Convert.ToInt32((double)(0.8 * zoomFadeLow)), Convert.ToInt32((double)(0.3 * zoomFadeLow)));
                    }

                    this.RenderDropDown(canvas, graphics, color);
                }
            }
        }
예제 #2
0
        protected override void Render(GH_Canvas canvas, System.Drawing.Graphics graphics, GH_CanvasChannel channel)
        {
            if (channel == GH_CanvasChannel.Objects)
            {
                GH_Capsule capsule = GH_Capsule.CreateCapsule(this.Bounds, GH_Palette.Normal);
                capsule.AddOutputGrip(this.OutputGrip.Y);
                capsule.Render(canvas.Graphics, this.Selected, this.Owner.Locked, this.Owner.Hidden);
                capsule.Dispose();
                int alpha = GH_Canvas.ZoomFadeLow;
                if (alpha > 0)
                {
                    canvas.SetSmartTextRenderingHint();
                    GH_PaletteStyle      style = GH_CapsuleRenderEngine.GetImpliedStyle(GH_Palette.Normal, this);
                    System.Drawing.Color color = System.Drawing.Color.FromArgb(alpha, style.Text);
                    if (this.NameBounds.Width > 0f)
                    {
                        System.Drawing.SolidBrush nameFill = new System.Drawing.SolidBrush(color);
                        graphics.DrawString(this.Owner.NickName, GH_FontServer.Standard, nameFill, this.NameBounds, GH_TextRenderingConstants.CenterCenter);
                        nameFill.Dispose();
                        int x  = System.Convert.ToInt32(this.NameBounds.Right);
                        int y0 = System.Convert.ToInt32(this.NameBounds.Top);
                        int y  = System.Convert.ToInt32(this.NameBounds.Bottom);
                        GH_GraphicsUtil.EtchFadingVertical(graphics, y0, y, x, System.Convert.ToInt32(0.8 * (double)alpha), System.Convert.ToInt32(0.3 * (double)alpha));
                    }

                    // render dropdown only
                    this.RenderDropDown(canvas, graphics, color);
                }
            }
        }
            protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
            {
                GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, GH_Palette.Normal, 100, 0);

                capsule.AddOutputGrip(OutputGrip.Y);
                capsule.Render(graphics, Selected, Owner.Locked, true);
                capsule.Dispose();
                capsule = null;
            }
예제 #4
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);
             }
         }
     }
 }
예제 #5
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();
        }
예제 #6
0
        protected override void Render(GH_Canvas canvas, Sd.Graphics graphics, GH_CanvasChannel channel)
        {
            base.Render(canvas, graphics, channel);
            ImageViewer comp = Owner as ImageViewer;

            if (channel == GH_CanvasChannel.Objects)
            {
                GH_Capsule capsule = GH_Capsule.CreateCapsule(ButtonBounds, GH_Palette.Normal, 0, 0);
                capsule.Render(graphics, Selected, Owner.Locked, true);
                capsule.AddOutputGrip(this.OutputGrip.Y);
                capsule.Dispose();
                capsule = null;

                Sd.StringFormat format = new Sd.StringFormat();
                format.Alignment     = Sd.StringAlignment.Center;
                format.LineAlignment = Sd.StringAlignment.Center;

                Sd.RectangleF textRectangle = ButtonBounds;

                graphics.DrawImage(comp.img, Bounds.X + 2, m_innerBounds.Y - (ButtonBounds.Height - Bounds.Height), comp.img.Width - 4, comp.img.Height - 2);

                format.Dispose();
            }
        }
예제 #7
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);
                }
            }
        }
예제 #8
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();
        }
예제 #9
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;
                }
            }
        }
예제 #10
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);
            }
        }
예제 #11
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();
            }
        }