Exemplo n.º 1
0
        public RectangleF LayoutComponentBox2(IGH_Component owner)
        {
            GH_SwitcherComponent gH_SwitcherComponent = (GH_SwitcherComponent)owner;
            int val = Math.Max(gH_SwitcherComponent.StaticData.GetComponentInputSection().Count, gH_SwitcherComponent.StaticData.GetComponentOutputSection().Count) * 20;

            val = Math.Max(val, 24);
            int num = 24;

            if (!GH_Attributes <IGH_Component> .IsIconMode(owner.IconDisplayMode))
            {
                val = Math.Max(val, GH_Convert.ToSize((SizeF)GH_FontServer.MeasureString(owner.NickName, StandardFont.largeFont())).Width + 6);
            }
            return(GH_Convert.ToRectangle(new RectangleF(owner.Attributes.Pivot.X - 0.5f * (float)num, owner.Attributes.Pivot.Y - 0.5f * (float)val, num, val)));
        }
Exemplo n.º 2
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static void RenderPrototypeLabel <T>(this GH_Attributes <T> attributes, Graphics graphics, RectangleF labelBounds, bool jaggedLeft, bool jaggedRight, bool drawStrips = true) where T : IGH_ActiveObject, IGH_PreviewObject
        {
            Color           colour;
            GH_Palette      palette;
            GH_PaletteStyle style;

            try
            {
                // Define the colour of the render to match teh component's borders
                palette = GH_CapsuleRenderEngine.GetImpliedPalette(attributes.Owner);
                if (palette == GH_Palette.Normal && !attributes.Owner.IsPreviewCapable)
                {
                    palette = GH_Palette.Hidden;
                }
                style = GH_CapsuleRenderEngine.GetImpliedStyle(palette, attributes.Selected, attributes.Owner.Locked, attributes.Owner.Hidden);

                colour = style.Edge;
            }
            catch (Exception)
            {
                //Fallback to using black if the above crashes for any reason
                colour  = Color.Black;
                palette = GH_Palette.Normal;
                style   = new GH_PaletteStyle(colour, colour);
            }

            // Define render parameters
            Font font    = GH_FontServer.StandardBold;
            Pen  linePen = new Pen(colour);

            linePen.Width = labelBounds.Height / 2;
            string labelText  = "Prototype";
            SizeF  stringSize = GH_FontServer.MeasureString(labelText, font);

            stringSize.Height -= 4;
            Color yellowBackground = Color.FromArgb(255, 209, 2);


            // Decide if we render strips or a simple line around the label
            if (drawStrips)
            {
                //Base capsule
                GH_Capsule capsule = GH_Capsule.CreateCapsule(attributes.Bounds, palette);
                capsule.SetJaggedEdges(jaggedLeft, jaggedRight);

                float extraWidthBotRect = 10;

                // Define region to draw into
                Region     clip         = new Region(capsule.OutlineShape); //Outline of the base capsule
                RectangleF botRectangle = new RectangleF(labelBounds.Location.X - extraWidthBotRect / 2, labelBounds.Y, labelBounds.Width + extraWidthBotRect, labelBounds.Height);
                clip.Intersect(botRectangle);                               //Intersect base capsule region with bottom rectangle
                graphics.SetClip(clip, CombineMode.Replace);

                //Draw the yellow background
                graphics.FillRectangle(new SolidBrush(yellowBackground), botRectangle);

                //Define the box around the text to cull
                int zoomFadeMedium = GH_Canvas.ZoomFadeLow;


                float textHeight = stringSize.Height;
                float textWidth  = stringSize.Width;
                stringSize.Width  = Math.Max(textWidth, textHeight * 6.1f); //To exactly hit the corners of the box, for 45degree angle, box should have aspectratio 1:6
                stringSize.Height = Math.Max(textHeight, textWidth / 6.1f); //To give a slight breathingspace, a aspectratio of 1:6.1 is set here
                RectangleF textBox = new RectangleF(
                    new PointF(labelBounds.X + (labelBounds.Width - stringSize.Width) / 2, labelBounds.Y + (labelBounds.Height - stringSize.Height
                                                                                                            ) / 2),
                    stringSize);
                if (zoomFadeMedium > 5)
                {
                    clip.Exclude(textBox);
                }
                graphics.SetClip(clip, CombineMode.Replace);

                //Set up parameters for stripes
                float width           = textBox.Width / 6;
                float sqrt2           = (float)Math.Sqrt(2);
                Pen   stripPen        = new Pen(colour, width / sqrt2); //45degree stripes
                int   additionalSpace = (int)linePen.Width;
                float textBoxCentre   = textBox.X + textBox.Width / 2;
                float y1     = labelBounds.Y + labelBounds.Height + additionalSpace;
                float y2     = labelBounds.Y - additionalSpace;
                float deltaY = y1 - y2;
                //Draw stripes to the right
                for (float dx = -deltaY / 2; dx < botRectangle.Width; dx += width * 2)
                {
                    graphics.DrawLine(stripPen, textBoxCentre + dx, y1, textBoxCentre + dx + deltaY, y2);
                }
                //Draw stripes to the left
                for (float dx = -deltaY / 2 - width * 2; dx > -botRectangle.Width; dx -= width * 2)
                {
                    graphics.DrawLine(stripPen, textBoxCentre + dx, y1, textBoxCentre + dx + deltaY, y2);
                }

                // Clear the region filter
                graphics.ResetClip();

                if (zoomFadeMedium > 5)
                {
                    RectangleF textRenderBounds = labelBounds;
                    textRenderBounds.Y -= 1;
                    // Draw the label
                    graphics.DrawString("Prototype", font, new SolidBrush(Color.FromArgb(zoomFadeMedium, colour)), textRenderBounds, GH_TextRenderingConstants.CenterCenter);
                }
                float zoom = graphics.Transform.Elements[0];
                capsule.RenderEngine.RenderOutlines(graphics, zoom, style);
            }
            else
            {
                // Draw the lines aroudn the label
                float y = labelBounds.Y + labelBounds.Height / 2;
                graphics.DrawLine(linePen, labelBounds.X + 1, y, labelBounds.X + (labelBounds.Width - stringSize.Width) / 2 - 4, y);
                graphics.DrawLine(linePen, labelBounds.X + (labelBounds.Width - stringSize.Width) / 2 + stringSize.Width + 4, y, labelBounds.X + labelBounds.Width - 1, y);

                // Draw the label
                graphics.DrawString("Prototype", font, new SolidBrush(colour), labelBounds, GH_TextRenderingConstants.CenterCenter);
            }
        }
Exemplo n.º 3
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();
        }