コード例 #1
0
            protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
            {
                Grasshopper.GUI.Canvas.GH_PaletteStyle styleGray = null;

                if (channel == GH_CanvasChannel.Wires)
                {
                    List <Color> wireColours = new List <Color> {
                        Color.FromArgb(150, 0, 50), Color.FromArgb(0, 150, 50), Color.FromArgb(0, 150, 50)
                    };

                    for (int i = 0; i < 3; i++)
                    {
                        foreach (IGH_Param source in Owner.Params.Input[i].Sources)
                        {
                            // First we need to determine the shape of the wire.
                            GraphicsPath path = GH_Painter.ConnectionPath(source.Attributes.OutputGrip, Owner.Params.Input[i].Attributes.InputGrip, GH_WireDirection.right, GH_WireDirection.left);
                            if ((path == null))
                            {
                                continue;
                            }
                            if (Owner.Attributes.Selected)
                            {
                                Pen pen = new Pen(wireColours[i], 3);
                                graphics.DrawPath(pen, path);
                                pen.Dispose();
                                path.Dispose();
                            }
                            else
                            {
                                Pen pen = new Pen(Color.FromArgb(50, wireColours[i]), 1);
                                graphics.DrawPath(pen, path);
                                pen.Dispose();
                                path.Dispose();
                            }
                        }
                    }
                    return;
                }


                if (channel == GH_CanvasChannel.Objects)
                {
                    // Cache the current styles.
                    styleGray = GH_Skin.palette_hidden_standard;
                    GH_Skin.palette_hidden_standard = new GH_PaletteStyle(Color.FromArgb(70, 72, 84), Color.FromArgb(253, 112, 80), Color.FromArgb(253, 112, 80));
                }


                // Allow the base class to render itself.
                base.Render(canvas, graphics, channel);

                if (channel == GH_CanvasChannel.Objects)
                {
                    // Restore the cached styles.
                    GH_Skin.palette_hidden_standard = styleGray;
                }
            }
コード例 #2
0
        public void DrawConnection(PointF pointA, PointF pointB, GH_WireDirection directionA, GH_WireDirection directionB, bool selectedA, bool selectedB, GH_WireType type, Color colorinput, GH_Canvas canvas, Graphics graphics)
        {
            if (ConnectionVisible(pointA, pointB, canvas))
            {
                Color color = colorinput;
                if (selectedA || selectedB)
                {
                    color.SolidenColor(Owner.SelectWireSolid);
                }

                GraphicsPath graphicsPath = new GraphicsPath();
                switch (Owner.WireType)
                {
                case 0:
                    graphicsPath = GH_Painter.ConnectionPath(pointA, pointB, directionA, directionB);
                    break;

                case 1:
                    float moveMent = (pointA.X - pointB.X) * (float)Owner.PolywireParam;
                    moveMent = Math.Max(moveMent, 20);
                    PointF C = new PointF(pointA.X - moveMent, pointA.Y);
                    PointF D = new PointF(pointB.X + moveMent, pointB.Y);
                    graphicsPath.AddLine(pointA, C);
                    graphicsPath.AddLine(C, D);
                    graphicsPath.AddLine(D, pointB);
                    graphicsPath.Reverse();
                    break;

                case 2:
                    graphicsPath.AddLine(pointA, pointB);
                    graphicsPath.Reverse();
                    break;

                default:
                    graphicsPath = GH_Painter.ConnectionPath(pointA, pointB, directionA, directionB);
                    break;
                }

                if (graphicsPath == null)
                {
                    graphicsPath = new GraphicsPath();
                    graphicsPath.AddLine(pointA, pointB);
                }

                Pen pen = GenerateWirePen(pointA, pointB, selectedA, selectedB, type, color, canvas);

                if (selectedA || selectedB)
                {
                    pen.Width += (float)Owner.SelectWireThickness;
                }

                if (pen == null)
                {
                    pen = new Pen(Color.Black);
                }
                try
                {
                    graphics.DrawPath(pen, graphicsPath);
                }
                catch (Exception ex)
                {
                    ProjectData.SetProjectError(ex);
                    Exception ex2 = ex;
                    Tracing.Assert(new Guid("{72303320-11AD-484e-BE32-8BDAA7377BE0}"), "Connection could not be drawn:" + Environment.NewLine + ex2.Message + Environment.NewLine + Environment.NewLine + $"A: ({pointA.X}, {pointA.Y})" + Environment.NewLine + $"B: ({pointB.X}, {pointB.Y})" + Environment.NewLine + $"A_Dir: {directionA}" + Environment.NewLine + $"B_Dir: {directionB}" + Environment.NewLine + $"A_Selected: {selectedA}" + Environment.NewLine + $"B_Selected: {selectedB}" + Environment.NewLine + $"Type: {type}");
                    ProjectData.ClearProjectError();
                }
                graphicsPath.Dispose();
                pen.Dispose();
            }
        }
コード例 #3
0
        protected void NewRenderIncomingWires(IGH_Param param, GH_Canvas canvas, Graphics graphics)
        {
            IEnumerable <IGH_Param> sources = param.Sources;
            GH_ParamWireDisplay     style   = param.WireDisplay;

            if (!param.Attributes.HasInputGrip)
            {
                return;
            }
            bool flag = false;

            if (param.Attributes.Selected)
            {
                flag = true;
            }
            else if (style != 0)
            {
                foreach (IGH_Param source in sources)
                {
                    if (source.Attributes.GetTopLevel.Selected)
                    {
                        flag = true;
                        break;
                    }
                }
            }
            else
            {
                flag = true;
            }

            int count = sources.Count();

            if (count != ParamProxies.Count)
            {
                UpdateParamProxy();
            }
            if (flag)
            {
                if (CentralSettings.CanvasFancyWires)
                {
                    for (int i = 0; i < count; i++)
                    {
                        GH_WireType type = GH_Painter.DetermineWireType(sources.ElementAt(i).VolatileData);
                        DrawConnection(param.Attributes.InputGrip, sources.ElementAt(i).Attributes.OutputGrip, GH_WireDirection.left, GH_WireDirection.right, param.Attributes.Selected, sources.ElementAt(i).Attributes.Selected, type, ParamProxies[i].ShowColor, canvas, graphics);
                    }
                    return;
                }
                for (int i = 0; i < count; i++)
                {
                    DrawConnection(param.Attributes.InputGrip, sources.ElementAt(i).Attributes.OutputGrip, GH_WireDirection.left, GH_WireDirection.right, param.Attributes.Selected, sources.ElementAt(i).Attributes.Selected, GH_WireType.generic, ParamProxies[i].ShowColor, canvas, graphics);
                }
                return;
            }
            switch (style)
            {
            case GH_ParamWireDisplay.faint:
                for (int i = 0; i < count; i++)
                {
                    DrawConnection(param.Attributes.InputGrip, sources.ElementAt(i).Attributes.OutputGrip, GH_WireDirection.left, GH_WireDirection.right, param.Attributes.Selected, sources.ElementAt(i).Attributes.Selected, GH_WireType.faint, ParamProxies[i].ShowColor, canvas, graphics);
                }
                break;

            case GH_ParamWireDisplay.hidden:
            {
                break;
            }
            }
        }