protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel) { if (channel == GH_CanvasChannel.Objects && !Owner.Locked && Owner is TransactionalComponent component) { if (component.Status != DB.TransactionStatus.RolledBack && component.Status != DB.TransactionStatus.Uninitialized) { var palette = GH_CapsuleRenderEngine.GetImpliedPalette(Owner); if (palette == GH_Palette.Normal && !Owner.IsPreviewCapable) { palette = GH_Palette.Hidden; } // Errors and warnings should be refelected in Canvas if (palette == GH_Palette.Normal || palette == GH_Palette.Hidden) { var style = GH_CapsuleRenderEngine.GetImpliedStyle(palette, Selected, Owner.Locked, Owner.Hidden); var fill = style.Fill; var edge = style.Edge; var text = style.Text; switch (component.Status) { case DB.TransactionStatus.Uninitialized: palette = GH_Palette.Grey; break; case DB.TransactionStatus.Started: palette = GH_Palette.White; break; case DB.TransactionStatus.RolledBack: /*palette = GH_Palette.Normal;*/ break; case DB.TransactionStatus.Committed: palette = GH_Palette.Black; break; case DB.TransactionStatus.Pending: palette = GH_Palette.Blue; break; case DB.TransactionStatus.Error: palette = GH_Palette.Pink; break; case DB.TransactionStatus.Proceed: palette = GH_Palette.Brown; break; } var replacement = GH_CapsuleRenderEngine.GetImpliedStyle(palette, Selected, Owner.Locked, Owner.Hidden); try { style.Edge = replacement.Edge; style.Fill = replacement.Fill; style.Text = replacement.Text; base.Render(canvas, graphics, channel); } finally { style.Fill = fill; style.Edge = edge; style.Text = text; } return; } } } base.Render(canvas, graphics, channel); }
private void LayoutMenuCollection() { GH_Palette impliedPalette = GH_CapsuleRenderEngine.GetImpliedPalette(base.Owner); GH_PaletteStyle impliedStyle = GH_CapsuleRenderEngine.GetImpliedStyle(impliedPalette, this.Selected, base.Owner.Locked, base.Owner.Hidden); composedCollection.Style = impliedStyle; composedCollection.Palette = impliedPalette; composedCollection.Layout(); }
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); } } } }
/*******************************************/ private void MessageLabelColours(out Color fill, out Color text, out Color edge) { try { // Define the colour of the render to match the component's borders GH_Palette palette = GH_CapsuleRenderEngine.GetImpliedPalette(this.Owner); if (palette == GH_Palette.Normal && !this.Owner.IsPreviewCapable) { palette = GH_Palette.Hidden; } GH_PaletteStyle style = GH_CapsuleRenderEngine.GetImpliedStyle(palette, this.Selected, this.Owner.Locked, this.Owner.Hidden); edge = style.Edge; fill = style.Edge; if (!Visible) { //If message is warning message, set fill to GH wraning colour. //This is only done if the Prototype label is not already on the component, as extra warning colour is then not needed. CallerValueList owner = (this.Owner as CallerValueList); if (owner != null && owner.IsWarningMessage && !Visible) { if (this.Selected) { fill = Color.FromArgb(210, 230, 25); } else { fill = Color.FromArgb(241, 175, 29); } } } //Set text colour to contrast background colour text = GH_GraphicsUtil.ForegroundColour(fill, 200); } catch { fill = Color.Black; text = Color.White; edge = Color.Black; } }
/***************************************************/ /**** 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); } }
protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel) { switch (channel) { case GH_CanvasChannel.Wires: { if (Owner.SourceCount > 0) { RenderIncomingWires(canvas.Painter, Owner.Sources, Owner.WireDisplay); } break; } case GH_CanvasChannel.Objects: { var palette = GH_CapsuleRenderEngine.GetImpliedPalette(Owner); using (var capsule = GH_Capsule.CreateCapsule(Bounds, palette)) { capsule.AddInputGrip(InputGrip.Y); capsule.AddOutputGrip(OutputGrip.Y); capsule.Render(canvas.Graphics, Selected, Owner.Locked, false); } var bounds = Bounds; if (!canvas.Viewport.IsVisible(ref bounds, 10)) { return; } var alpha = GH_Canvas.ZoomFadeLow; if (alpha > 0) { canvas.SetSmartTextRenderingHint(); var style = GH_CapsuleRenderEngine.GetImpliedStyle(palette, this); var textColor = System.Drawing.Color.FromArgb(alpha, style.Text); var captionColor = string.IsNullOrEmpty(Owner.NickName) || !Owner.MutableNickName ? System.Drawing.Color.FromArgb(alpha / 2, style.Text) : textColor; using (var nameFill = new SolidBrush(captionColor)) graphics.DrawString(string.IsNullOrEmpty(Owner.NickName) ? "Filter mask…" : Owner.NickName, GH_FontServer.LargeAdjusted, nameFill, Bounds, GH_TextRenderingConstants.StringFormat(StringAlignment.Center, StringAlignment.Near)); { var clip = ListBounds; clip.Inflate(-2, 0); Brush alternateBrush = null; if (GH_Canvas.ZoomFadeMedium > 0 && Owner.DataType == GH_ParamData.remote) { graphics.FillRectangle(Brushes.White, clip); alternateBrush = Brushes.WhiteSmoke; } else { alternateBrush = new SolidBrush(System.Drawing.Color.FromArgb(70, style.Fill)); } graphics.SetClip(clip); var transform = graphics.Transform; if (!ScrollerBounds.IsEmpty) { graphics.TranslateTransform(0.0f, -((Owner.ListItems.Count * ItemHeight) - clip.Height) * ScrollRatio); } var format = new StringFormat(StringFormatFlags.NoWrap) { LineAlignment = StringAlignment.Center }; var itemBounds = new System.Drawing.Rectangle((int)clip.X, (int)clip.Y, (int)clip.Width, (int)18); int index = 0; foreach (var item in Owner.ListItems) { if (index++ % 2 != 0) { graphics.FillRectangle(alternateBrush, itemBounds); } if (item.Selected) { if (Owner.DataType == GH_ParamData.remote && GH_Canvas.ZoomFadeMedium > 0) { var highlightBounds = itemBounds; highlightBounds.Inflate(-1, -1); GH_GraphicsUtil.RenderHighlightBox(graphics, highlightBounds, 2, true, true); } var markBounds = new RectangleF(itemBounds.X, itemBounds.Y, 22, itemBounds.Height); RenderCheckMark(graphics, markBounds, textColor); } var nameBounds = new RectangleF(itemBounds.X + 22, itemBounds.Y, itemBounds.Width - 22, itemBounds.Height); graphics.DrawString(item.Name, GH_FontServer.StandardAdjusted, Brushes.Black, nameBounds, format); itemBounds.Y += itemBounds.Height; } graphics.Transform = transform; RenderScrollBar(canvas, graphics, style.Text); graphics.ResetClip(); if (GH_Canvas.ZoomFadeMedium > 0 && Owner.DataType == GH_ParamData.remote) { graphics.DrawRectangle(Pens.Black, clip); GH_GraphicsUtil.ShadowHorizontal(graphics, clip.Left, clip.Right, clip.Top); } else { GH_GraphicsUtil.EtchFadingHorizontal(graphics, (int)bounds.Left, (int)bounds.Right, (int)(bounds.Top + 20), (int)(0.8 * alpha), (int)(0.3 * alpha)); GH_GraphicsUtil.EtchFadingHorizontal(graphics, (int)bounds.Left, (int)bounds.Right, (int)(bounds.Bottom - 16), (int)(0.8 * alpha), (int)(0.3 * alpha)); } var footnoteBounds = new RectangleF(bounds.Left, bounds.Bottom - 17, bounds.Width - 3, 17); graphics.DrawString($"{Owner.ListItems.Count} items, {Owner.VolatileDataCount} selected", GH_FontServer.StandardAdjusted, Brushes.Gray, footnoteBounds, GH_TextRenderingConstants.FarCenter); } } return; } } base.Render(canvas, graphics, channel); }
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(); }
private void LayoutStyle() { _collection.Palette = GH_CapsuleRenderEngine.GetImpliedPalette(base.Owner); _collection.Style = GH_CapsuleRenderEngine.GetImpliedStyle(_collection.Palette, this.Selected, base.Owner.Locked, base.Owner.Hidden); _collection.Layout(); }