Beispiel #1
0
        private void DisplayDefaultComponent()
        {
            //reset the comonent
            imgBitmap          = null;
            this.scale         = 1;
            this.Owner.Message = null;

            RectangleF rec = GetImgBounds(Bounds, TopOffset, BtmOffset);

            Pen        pen     = new Pen(Color.Gray, 3);
            SolidBrush myBrush = new SolidBrush(Color.Gray);

            Font standardFont = GH_FontServer.Standard; //29
            //Font standardFont4kScreen = new Font(standardFont.Name, 4); //15
            Font standardFontAdjust = GH_FontServer.NewFont(standardFont, (float)Math.Round(120M / standardFont.Height));

            StringFormat myFormat = new StringFormat();

            MyGraphics.FillRectangle(myBrush, Rectangle.Round(rec));
            //graphics.DrawRectangle(pen, Rectangle.Round(imgViewBounds));
            MyGraphics.DrawString("Please use a valid image file path.\nHDR, TIF, PNG, GIF, or JPG image", standardFontAdjust, Brushes.White, new Point((int)rec.X + 12, (int)rec.Y + ((int)rec.Width * 2 / 3) + 10), myFormat);
            MyGraphics.DrawImage(Resources.Ladybug_Viewer_370, new RectangleF(rec.X, rec.Y, rec.Width, rec.Width * 2 / 3));

            myBrush.Dispose();
            myFormat.Dispose();
        }
        protected override void Render(GH_Canvas canvas,
                                       System.Drawing.Graphics graphics,
                                       GH_CanvasChannel channel)
        {
            // Draw base component.
            base.Render(canvas, graphics, channel);
            // Add custom elements.
            if (channel == GH_CanvasChannel.Objects)
            {
                // Add button to connect/disconect.
                GH_Capsule button = GH_Capsule.CreateTextCapsule(this.BoundsButton, this.BoundsButton, GH_Palette.Black,
                                                                 this.component.status ? "Disconnect" : "Connect", 2, 0);
                button.Render(graphics, this.Selected, this.Owner.Locked, false);
                button.Dispose();

                // Add list of Found Devices.
                // IPAddress ipv4Addresse = Array.FindLast(Dns.GetHostEntry(string.Empty).AddressList,
                //                                         a => a.AddressFamily == AddressFamily.InterNetwork);
                string message = "Devices: ";
                if (HoloConnect.deviceFinder.devices.Count > 0)
                {
                    foreach (HoloDevice device in HoloConnect.deviceFinder.devices.Values)
                    {
                        message += "\n" + device.ToString();
                    }
                }
                else
                {
                    message += "(not found)";
                }
                graphics.DrawString(message, GH_FontServer.NewFont(FontFamily.GenericMonospace, 6, FontStyle.Regular),
                                    Brushes.Black, this.BoundsText, GH_TextRenderingConstants.CenterCenter);
            }
        }
Beispiel #3
0
        /*******************************************/
        /**** Private Methods                   ****/
        /*******************************************/

        private void RenderMessage(Graphics graphics, string message)
        {
            Color fill, text, edge;

            this.MessageLabelColours(out fill, out text, out edge);

            int zoomFadeMedium = GH_Canvas.ZoomFadeMedium;

            if (zoomFadeMedium > 5)
            {
                Rectangle box = new Rectangle((int)Bounds.X, (int)Bounds.Y, (int)Bounds.Width, (int)Bounds.Height);
                box.Inflate(-3, 0);
                box.Y = box.Bottom;
                Font font = GH_FontServer.Standard;

                bool flag = false;
                Size size = GH_FontServer.MeasureString(message, font);
                size.Width += 8;
                if (size.Width > box.Width)
                {
                    double num = (double)box.Width / (double)size.Width;
                    font = GH_FontServer.NewFont(font, Convert.ToSingle((double)font.SizeInPoints * num));
                    size = GH_FontServer.MeasureString(message, font);
                    flag = true;
                }
                box.Height = Math.Max(size.Height, 6);
                GraphicsPath graphicsPath = new GraphicsPath();
                graphicsPath.AddArc(box.Left - 3, box.Top, 6, 6, 270f, 90f);
                graphicsPath.AddArc(box.Left + 3, box.Bottom - 6, 6, 6, 180f, -90f);
                graphicsPath.AddArc(box.Right - 9, box.Bottom - 6, 6, 6, 90f, -90f);
                graphicsPath.AddArc(box.Right - 3, box.Top, 6, 6, 180f, 90f);
                graphicsPath.CloseAllFigures();
                SolidBrush solidBrush = new SolidBrush(Color.FromArgb(zoomFadeMedium, fill));
                Pen        pen        = new Pen(Color.FromArgb(zoomFadeMedium, edge))
                {
                    LineJoin = LineJoin.Bevel
                };
                graphics.FillPath(solidBrush, graphicsPath);
                graphics.DrawPath(pen, graphicsPath);
                pen.Dispose();
                solidBrush.Dispose();
                graphicsPath.Dispose();
                if (graphics.Transform.Elements[0].Equals(1f))
                {
                    graphics.TextRenderingHint = GH_TextRenderingConstants.GH_CrispText;
                }
                else
                {
                    graphics.TextRenderingHint = GH_TextRenderingConstants.GH_SmoothText;
                }
                SolidBrush solidBrush2 = new SolidBrush(Color.FromArgb(zoomFadeMedium, text));
                graphics.DrawString(message, font, solidBrush2, box, GH_TextRenderingConstants.CenterCenter);
                solidBrush2.Dispose();
                if (flag)
                {
                    font.Dispose();
                }
            }
        }
        protected static PointF DrawTimeLine(Graphics graphics, float PtXStart, float PtY)
        {
            float Width  = Frame.Component.SliderWidth - 20;
            float PtXend = PtXStart + Width;

            //draw basic line
            graphics.DrawLine(new Pen(ShareData.SecondaryColor, ShareData.middleThick), new PointF(PtXStart, PtY), new PointF(PtXend, PtY));


            int   count = (int)(Width / 25f);
            float step  = (float)Width / (float)count;

            if (Frame.Component.KeyTimes == null)
            {
                return(new PointF());
            }
            else if (Frame.Component.KeyTimes.Count == 0)
            {
                return(new PointF());
            }
            float startTime = (float)Frame.Component.KeyTimes[0];
            float timeStep  = ((float)Frame.Component.MaxTime - (float)Frame.Component.FrameTimeLast) / (float)count;

            //draw keytime
            for (int n = 0; n <= count; n++)
            {
                PointF loc     = new PointF(PtXStart + n * step, PtY);
                PointF textLoc = new PointF(loc.X - 8, loc.Y + 2);
                string tmStr   = (startTime + n * timeStep).ToString("f1");
                graphics.DrawString(tmStr, GH_FontServer.NewFont(GH_FontServer.Script, 5, FontStyle.Regular), new SolidBrush(ShareData.SecondaryColor), textLoc);

                PointF keyPt = new PointF(loc.X - ShareData.KeyTimeRadius / 2, loc.Y - ShareData.KeyTimeRadius / 2);
                try
                {
                    graphics.DrawEllipse(new Pen(ShareData.SecondaryColor, ShareData.KeyTimeRadius), keyPt.X, keyPt.Y, ShareData.KeyTimeRadius, ShareData.KeyTimeRadius);
                }
                catch
                {
                }
            }

            graphics.DrawString("s", GH_FontServer.NewFont(GH_FontServer.Script, 5, FontStyle.Regular), new SolidBrush(ShareData.SecondaryColor),
                                new PointF(PtXend + 5, PtY + 2));

            //draw right time
            string txtT = Frame.Component.RightTime.ToString("f2") + "s";
            PointF Cloc = new PointF((float)((Frame.Component.RightTime - Frame.Component.KeyTimes[0]) / (Frame.Component.MaxTime - Frame.Component.FrameTimeLast)) * Width + PtXStart, PtY);

            PointF Ptloc = new PointF(Cloc.X - ShareData.KeyPtRadius / 2, Cloc.Y - ShareData.KeyPtRadius / 2);

            graphics.DrawEllipse(new Pen(ShareData.HighLightColor, ShareData.KeyPtRadius), Ptloc.X, Ptloc.Y, ShareData.KeyPtRadius, ShareData.KeyPtRadius);

            PointF txtLoc = new PointF(Cloc.X - 12, Cloc.Y + 5);

            graphics.DrawString(txtT, GH_FontServer.NewFont(GH_FontServer.Script, 7, FontStyle.Bold), new SolidBrush(ShareData.HighLightColor), txtLoc);

            return(Cloc);
        }
Beispiel #5
0
    protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
    {
        base.Render(canvas, graphics, channel);

        if (channel == GH_CanvasChannel.Objects)
        {
            var prototype = GH_FontServer.StandardAdjusted;
            var font      = GH_FontServer.NewFont(prototype, 6f / GH_GraphicsUtil.UiScale);
            var radius    = 3;
            var highlight = !_mouseDown ? 8 : 0;

            using var button = GH_Capsule.CreateTextCapsule(_buttonBounds, _buttonBounds, GH_Palette.Black, _label, font, radius, highlight);
            button.Render(graphics, false, Owner.Locked, false);
        }
    }
Beispiel #6
0
            protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
            {
                this.Bounds = baseRect;

                base.Render(canvas, graphics, channel);

                if (channel == GH_CanvasChannel.First && Owner.showGraphics != null)
                {
                    if (Owner.showGraphics.OnPingDocument() == Owner.OnPingDocument())
                    {
                        RenderCanvas.HighLightCom(graphics, Owner.showGraphics, 2);
                    }
                }


                if (channel == GH_CanvasChannel.Objects && Frame.Component != null && Owner.Params.Input[0].SourceCount > 0)
                {
                    finalDict = new List <RectangleF>();

                    if (Owner.GetValue("ShowGraphOnThis", @default: true) && Frame.Component.ShowGraphOnEvent)
                    {
                        float X = Owner.Attributes.Bounds.X + Owner.Attributes.Bounds.Width / 2 - Frame.Component.SliderWidth / 2 + 10;
                        float Y = Owner.Attributes.Bounds.Y - 20;

                        RenderCanvas.DrawGraph(graphics, Owner.keyPoints, X, Y, Owner.GraphHeight, Owner.eventThing, out finalDict, out maxRect);


                        PointF txtLoc = new PointF(X, Y - Owner.GraphHeight - 25);
                        graphics.DrawString(Owner.NickName, GH_FontServer.NewFont(GH_FontServer.Script, 9, FontStyle.Bold), new SolidBrush(ShareData.ThemeColor), txtLoc);
                    }
                    else
                    {
                        PointF txtLoc = new PointF(Owner.Attributes.Bounds.X, Owner.Attributes.Bounds.Y - 15);
                        graphics.DrawString(Owner.NickName, GH_FontServer.NewFont(GH_FontServer.Script, 9, FontStyle.Bold), new SolidBrush(ShareData.ThemeColor), txtLoc);
                    }
                }
                if (maxRect != new RectangleF())
                {
                    thisRect = RectangleF.Union(baseRect, maxRect);
                }
                else
                {
                    thisRect = baseRect;
                }
                this.Bounds = thisRect;
            }
        public static void DrawGraph(Graphics graphics, Dictionary <int, double> dict, float PtXStart, float PtY, int height, List <Event> mapperNum, out List <RectangleF> outDict, out RectangleF maxRect)
        {
            PointF pt1 = DrawTimeLine(graphics, PtXStart, PtY);

            outDict = new List <RectangleF>();
            maxRect = RectangleF.Empty;

            if (dict.Count > 1)
            {
                PointF pt2 = DrawGraphCurve(graphics, dict, PtXStart, PtY, height, mapperNum, out outDict, out maxRect);
                graphics.DrawLine(new Pen(ShareData.HighLightColor, ShareData.middleThick), pt1, pt2);
            }
            else
            {
                PointF TxtLoc = new PointF(PtXStart, PtY - height);
                graphics.DrawString("Please drag the Frame Slider!", GH_FontServer.NewFont(GH_FontServer.Script, 9, FontStyle.Bold), new SolidBrush(ShareData.ThemeColor), TxtLoc);
            }
        }
Beispiel #8
0
        public static int MessageBoxHeight(string str, int boxWidth)
        {
            if (str == null || str == "")
            {
                return(0);
            }

            Font font = GH_FontServer.StandardAdjusted;
            Size size = GH_FontServer.MeasureString(str, font);

            boxWidth += 8;
            if (size.Width > boxWidth)
            {
                double num = (double)boxWidth / (double)size.Width;
                font = GH_FontServer.NewFont(font, Convert.ToSingle((double)font.SizeInPoints * num));
                size = GH_FontServer.MeasureString(str, font);
            }
            return(Math.Max(size.Height, 6));
        }
Beispiel #9
0
            protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
            {
                Bounds = baseRect;
                base.Render(canvas, graphics, channel);


                //Show Top Text
                if (channel == GH_CanvasChannel.Overlay && Owner.ShowLabel)
                {
                    float  size        = (float)Owner.LabelSize / Grasshopper.Instances.ActiveCanvas.Viewport.Zoom;
                    string showMessage = (Owner.ShowFrame ? "Frame:" + Owner.RightFrame.ToString() + "  " : "") + (Owner.ShowTime ? "Time:" + Owner.RightTime.ToString("f2") + "s  " : "")
                                         + (Owner.ShowPercent ? Owner.PercentStr : "") + (Owner.ShowRemain ? Owner.RemainStr : "");
                    graphics.DrawString(showMessage, GH_FontServer.NewFont(GH_FontServer.Script, size, FontStyle.Regular),
                                        new SolidBrush(ShareData.ThemeColor), Grasshopper.Instances.ActiveCanvas.Viewport.VisibleRegion.X, Grasshopper.Instances.ActiveCanvas.Viewport.VisibleRegion.Y);
                }

                //Render Button
                if (channel == GH_CanvasChannel.Objects)
                {
                    GH_Palette pale = Owner.Locked ? GH_Palette.Locked : GH_Palette.Normal;

                    GH_Capsule PlayCapsule = GH_Capsule.CreateTextCapsule(PlayButtonRect, PlayButtonRect, pale, "Play");
                    if (Owner.Play)
                    {
                        PlayCapsule.Render(graphics, ShareData.ThemeColor);
                    }
                    else
                    {
                        PlayCapsule.Render(graphics, this.Selected, Owner.Locked, Owner.Hidden);
                    }
                    PlayCapsule.Dispose();

                    GH_Capsule ShootCapsule = GH_Capsule.CreateTextCapsule(ShootButtonRect, ShootButtonRect, pale, "Shoot");
                    if (Owner.shoot)
                    {
                        ShootCapsule.Render(graphics, ShareData.ThemeColor);
                    }
                    else
                    {
                        ShootCapsule.Render(graphics, this.Selected, Owner.Locked, Owner.Hidden);
                    }
                    ShootCapsule.Dispose();

                    if (Owner.ShowGraph && Owner.FrameObject != null)
                    {
                        if (Owner.FrameObject.OnPingDocument() == Owner.OnPingDocument())
                        {
                            float PtXStart;
                            float PtY;
                            GoButtons     = new List <RectangleF>();
                            ToEventButton = new List <List <RectangleF> >();

                            Frame.Component = Frame.Component ?? Owner;

                            PtXStart = Owner.Attributes.Bounds.X + Owner.Attributes.Bounds.Width / 2 - Frame.Component.SliderWidth / 2 + 10 + 40;
                            PtY      = Owner.Attributes.Bounds.Y - 20;

                            foreach (EventOperation eveOperation in Owner.ClearComponent)
                            {
                                if (!eveOperation.ShowGraphOnSlider)
                                {
                                    continue;
                                }

                                List <RectangleF> relayDict = new List <RectangleF>();
                                RenderCanvas.DrawGraph(graphics, eveOperation.keyPoints, PtXStart, PtY, eveOperation.GraphHeight, eveOperation.eventThing, out relayDict, out maxRect);
                                ToEventButton.Add(relayDict);


                                RectangleF buttonRect = new RectangleF(PtXStart - 80, PtY - eveOperation.GraphHeight - ShareData.GraphCurveThickness,
                                                                       60, eveOperation.GraphHeight + ShareData.GraphCurveThickness);

                                GoButtons.Add(buttonRect);

                                if (this.maxRect != new RectangleF())
                                {
                                    maxRect = RectangleF.Union(maxRect, buttonRect);
                                }
                                PtY -= ShareData.GraphDistance + eveOperation.GraphHeight;

                                //Split String
                                int      maxlen    = (int)((float)buttonRect.Width / 3.75f);
                                string[] listArray = eveOperation.NickName.Split(' ');
                                string   showTxt   = listArray[0];
                                string   joinStr   = "";
                                for (int n = 1; n < listArray.Length; n++)
                                {
                                    if (listArray[n].Length > maxlen)
                                    {
                                        if (joinStr.Length > 0)
                                        {
                                            showTxt += "\n" + joinStr;
                                        }
                                        showTxt += "\n" + listArray[n];

                                        joinStr = "";
                                    }
                                    else if (listArray[n].Length + joinStr.Length > maxlen)
                                    {
                                        showTxt += "\n" + joinStr;
                                        joinStr  = listArray[n];
                                    }
                                    else
                                    {
                                        joinStr += " " + listArray[n];
                                    }
                                }
                                if (joinStr.Length > 0)
                                {
                                    showTxt += "\n" + joinStr;
                                }

                                int        deep       = (int)((float)buttonRect.Height / 3);
                                GH_Capsule gH_Capsule = GH_Capsule.CreateTextCapsule(buttonRect, buttonRect, GH_Palette.Blue, showTxt,
                                                                                     GH_FontServer.NewFont(GH_FontServer.Script, 6, FontStyle.Regular), GH_Orientation.horizontal_center, 5, deep);
                                gH_Capsule.Render(graphics, ShareData.ThemeColor);
                                gH_Capsule.Dispose();
                            }
                        }

                        if (this.maxRect != new RectangleF())
                        {
                            thisRect = RectangleF.Union(new RectangleF(this.baseRect.X, this.baseRect.Y, this.baseRect.Width, this.baseRect.Height + 30), this.maxRect);
                        }
                        else
                        {
                            thisRect = new RectangleF(this.baseRect.X, this.baseRect.Y, this.baseRect.Width, this.baseRect.Height + 30);
                        }
                    }
                }

                if (channel == GH_CanvasChannel.First && Owner.FrameObject != null)
                {
                    Rectangle rect = GH_Convert.ToRectangle(Owner.FrameObject.Attributes.Bounds);
                    rect.Inflate(ShareData.FrameWidth, ShareData.FrameWidth);
                    GH_Capsule gH_Capsule = GH_Capsule.CreateCapsule(rect, GH_Palette.Pink, ShareData.FrameWidth, 5);
                    gH_Capsule.Render(graphics, ShareData.ThemeColor);
                    gH_Capsule.Dispose();
                }

                this.Bounds = this.thisRect;
            }
        protected static PointF DrawGraphCurve(Graphics graphics, Dictionary <int, double> dict, float PtXStart, float PtY, int height, List <Event> mapperNum, out List <RectangleF> OutList, out RectangleF MaxRext)
        {
            float Width  = Frame.Component.SliderWidth - 20;
            float PtXend = PtXStart + Width;

            PtY -= ShareData.GraphCurveThickness;

            MaxRext = new RectangleF(PtXStart, PtY - height, Width, height);

            double min = double.MaxValue;
            double max = double.MinValue;

            foreach (double value in dict.Values)
            {
                min = min < value ? min : value;
                max = max > value ? max : value;
            }

            if (max - min < 1E-12)
            {
                max += 1E-12;
            }

            List <RectangleF> relayDict = new List <RectangleF>();
            float             rectY     = PtY - height;

            foreach (Event map in mapperNum)
            {
                float rectX     = (float)((map.timedomain.T0 - Frame.Component.KeyTimes[0]) / (Frame.Component.MaxTime - Frame.Component.KeyTimes[0]) * (double)Width) + PtXStart;
                float rectWidth = (float)((map.timedomain.T1 - map.timedomain.T0) / (Frame.Component.MaxTime - Frame.Component.KeyTimes[0]) * (double)Width);

                RectangleF sectRect = new RectangleF(rectX, rectY, rectWidth, height);
                relayDict.Add(sectRect);


                graphics.DrawRectangle(new Pen(new SolidBrush(ShareData.QuarterThemeColor), 3), rectX, rectY, rectWidth, height);
                graphics.FillRectangle(new SolidBrush(ShareData.QuarterThemeColor), sectRect);

                graphics.DrawString(map.NickName, GH_FontServer.NewFont(GH_FontServer.Script, 6, FontStyle.Bold), new SolidBrush(ShareData.HalfThemeColor), new PointF(rectX + 2, rectY + 3));
            }
            OutList = relayDict;

            List <PointF> pts = new List <PointF>();

            foreach (KeyValuePair <int, double> row in dict)
            {
                if (row.Key > Frame.Component.MaxFrame)
                {
                    continue;
                }
                float xPt = (float)row.Key / (float)Frame.Component.MaxFrame * Width + PtXStart;
                float yPt = (float)(PtY - (row.Value - min) / (max - min) * height);
                pts.Add(new PointF(xPt, yPt));
            }
            if (pts.Count == 1)
            {
                return(new PointF());
            }

            //DrawCurve
            pts.Sort((m, n) => m.X.CompareTo(n.X));
            graphics.DrawLines(new Pen(ShareData.ThemeColor, ShareData.GraphCurveThickness), pts.ToArray());



            float HptX = (float)Frame.Component.RightFrame / (float)Frame.Component.MaxFrame * Width + PtXStart;
            float HptY = (float)(PtY - (dict[Frame.Component.RightFrame] - min) / (max - min) * height);

            graphics.DrawEllipse(new Pen(ShareData.HighLightColor, ShareData.KeyPtRadius), HptX - ShareData.KeyPtRadius / 2, HptY - ShareData.KeyPtRadius / 2, ShareData.KeyPtRadius, ShareData.KeyPtRadius);

            string text   = dict[Frame.Component.RightFrame].ToString("f2");
            PointF txtLoc = new PointF(HptX - 15, HptY - 18);

            graphics.DrawString(text, GH_FontServer.NewFont(GH_FontServer.Script, 9, FontStyle.Bold), new SolidBrush(ShareData.HighLightColor), txtLoc);

            return(new PointF(HptX, HptY));
        }