private void DrawComponentName(Graphics g, RectangleF ContentBox = new RectangleF(), bool IsFullName = true)
        {
            Pen    _Pen   = new Pen(Color.Black, 1);
            Brush  _Brush = _Pen.Brush;
            string Text   = IsFullName? this.ParamComponent.Name: this.ParamComponent.NickName;

            SizeF NameSize = GH_FontServer.MeasureString(Text, GH_FontServer.Large);
            //ContentBox is the property and m_innerBounds is the field
            StringFormat Format = new StringFormat(StringFormatFlags.DirectionVertical);

            Format.Alignment     = StringAlignment.Center;
            Format.LineAlignment = StringAlignment.Center;
            //先存储Graphics的状态
            //对Graphics执行操作
            GraphicsState State = g.Save();

            //修改旋转中心点
            g.TranslateTransform(ContentBox.X + ContentBox.Width / 2, ContentBox.Y + ContentBox.Height / 2);
            g.RotateTransform(-180);
            g.TranslateTransform(-(ContentBox.X + ContentBox.Width / 2), -(ContentBox.Y + ContentBox.Height / 2));
            //回复旋转中心点
            g.DrawString(Text, GH_FontServer.Large, _Brush, ContentBox, Format);
            // 恢复Graphics的状态,否则Parameter Name的绘制将会出错
            g.Restore(State);
            Format.Dispose();
        }
Beispiel #2
0
 public StackPanel(string name, Orientation orientation, bool drawBorder, params GHControl[] items) : base(name, "")
 {
     _orientation = orientation;
     Items        = items;
     _titleHeight = GH_FontServer.MeasureString(Name, SmallFont).Height + Offset * 2;
     _showBorder  = drawBorder;
 }
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();
                }
            }
        }
Beispiel #4
0
 public TabPanel(string name, string description, int activeTab, bool showTitle, bool showHeaderText = true, Bitmap toolTipDiagram = null) : base(name, description, activeTab, toolTipDiagram)
 {
     _tabs           = new Dictionary <string, GHControl[]>();
     _icons          = new Dictionary <string, Image>();
     _values         = new List <int>();
     _showTitle      = showTitle;
     _showHeaderText = showHeaderText;
     _titleHeight    = GH_FontServer.MeasureString(Name, SmallFont).Height + Offset;
 }
 protected HorizontalSlider(string name, string description, object value, float min, float max, bool showTitle, string formatString, string suffix, Bitmap toolTipDiagram = null) : base(name, description, value, toolTipDiagram)
 {
     _format               = new StringFormat();
     _format.Alignment     = StringAlignment.Near;
     _format.LineAlignment = StringAlignment.Near;
     _format.Trimming      = StringTrimming.EllipsisCharacter;
     _min         = min;
     _max         = max;
     FormatString = formatString;
     Suffix       = suffix;
     _showTitle   = showTitle;
     _fontSize    = GH_FontServer.MeasureString(Name, StandardFont).Height;
 }
Beispiel #6
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)));
        }
Beispiel #7
0
        public override void Render(GH_Canvas canvas)
        {
            var document = canvas.Document;

            if (document == null)
            {
                return;
            }
            var zoomFadeMedium = GH_Canvas.ZoomFadeMedium;

            if (zoomFadeMedium == 0)
            {
                return;
            }
            var historyComponent = document.Objects.SingleOrDefault(x => x is UserHistoryComponent) as UserHistoryComponent;

            if (historyComponent == null)
            {
                return;
            }
            var solidBrush = new SolidBrush(Color.FromArgb(zoomFadeMedium, Color.Black));

            foreach (var ghDocumentObject in document.Objects)
            {
                if (ghDocumentObject is IGH_ActiveObject)
                {
                    var historyRecord = historyComponent.GetHistory(ghDocumentObject.ComponentGuid);
                    if (historyRecord == null)
                    {
                        continue;
                    }
                    var bounds = ghDocumentObject.Attributes.Bounds;
                    if (canvas.Viewport.IsVisible(ref bounds, 10f))
                    {
                        var str        = $"{historyRecord.UserName}: {historyRecord.DateTime:dd.MM.yy HH:mm}";
                        var sizeF      = (SizeF)GH_FontServer.MeasureString(str, GH_FontServer.ConsoleSmall);
                        var rectangleF = bounds;
                        rectangleF.Height = sizeF.Height + 2f;
                        rectangleF.Width  = sizeF.Width + 2f;
                        rectangleF.X      = (float)(0.5 * ((double)bounds.Left + (double)bounds.Right) -
                                                    0.5 * (double)rectangleF.Width);
                        rectangleF.Y = bounds.Top - 15f;
                        canvas.Graphics.DrawString(str, GH_FontServer.ConsoleSmall, (Brush)solidBrush, rectangleF, GH_TextRenderingConstants.CenterCenter);
                    }
                }
            }
        }
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
        public NumericUpDown(string name, string description, T value, T min, T max, T smallChange, string formatString = "", Bitmap toolTipDiagram = null) : base(name, description, value, toolTipDiagram)
        {
            FormatString = formatString;
            _smallChange = smallChange;
            _min         = min;
            _max         = max;
            _btnWidh     = GH_FontServer.StringWidth("<", SmallFont);
            _labelWidth  = GH_FontServer.StringWidth("888.888", SmallFont);
            _titleWidth  = GH_FontServer.StringWidth(Name, SmallFont);
            _width       = _labelWidth + 2 * _btnWidh + 2 * Offset + _titleWidth;
            _height      = GH_FontServer.MeasureString("A", SmallFont).Height + 2 * Offset;

            _left  = new PushButton("Up", "Increase", "<");
            _right = new PushButton("Down", "Decrease", ">");
            _label = new PushButton("Value", description, AsString(value), true, null, _labelWidth);
            _left.UpdateSolution   = false; _right.UpdateSolution = false; _label.UpdateSolution = false;
            _left.OnValueChanged  += _left_OnValueChanged;
            _right.OnValueChanged += _right_OnValueChanged;
            _label.OnValueChanged += _label_OnValueChanged;
            _controls              = new GHControl[] { _left, _label, _right };
            timer          = new System.Timers.Timer();
            timer.Interval = 100;
            timer.Elapsed += Timer_Elapsed;
        }
Beispiel #10
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);
            }
        }
Beispiel #11
0
 public RichGraphMapperAttributes(RichGraphMapper owner)
     : base(owner)
 {
     base.Bounds = new Rectangle(0, 0, 100, 100);
     inputWidth  = (outputWidth = GH_FontServer.MeasureString("M", GH_FontServer.Standard).Width);
 }
Beispiel #12
0
 internal override int GetHeight()
 {
     return(2 * Offset + GH_FontServer.MeasureString((string)CurrentValue, SmallFont).Height);
 }