protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel) { if (channel == GH_CanvasChannel.Objects) { GH_CapsuleRenderEngine.RenderOutputGrip(graphics, canvas.Viewport.Zoom, OutputGrip, true); for (int col = 0; col < 3; col++) { for (int row = 0; row < 3; row++) { int value = Value(col, row); Rectangle button = Button(col, row); GH_Palette palette = GH_Palette.White; if (value == Owner.Value) { palette = GH_Palette.Blue; } GH_Capsule capsule = GH_Capsule.CreateTextCapsule(button, button, palette, value.ToString(), 0, 0); capsule.Render(graphics, Selected, Owner.Locked, true); capsule.Dispose(); } } } }
public ButtonRenderSet(Color?[] colors, Font font, int cornerRadius = 6, int highLight = 0, GH_Palette normalPalette = GH_Palette.Hidden) { this.Colors = colors; this.Font = font; this.CornerRadius = cornerRadius; this.HighLight = highLight; this.normalPalette = normalPalette; }
private static void doCapsule(Graphics g, RectangleF bounds, GH_Palette palette, Color color) { GH_Capsule capsule = GH_Capsule.CreateCapsule(bounds, palette, 3, 6); capsule.Render(g, color); capsule.Dispose(); capsule = null; }
public static void RenderButtonIcon_Obsolete(Graphics graphics, GH_Component Owner, RectangleF bound, bool on, Bitmap onMap, Bitmap offMap, int cornerRadius = 6, GH_Palette normalPalette = GH_Palette.Normal) { GH_Palette palette = Owner.RuntimeMessages(GH_RuntimeMessageLevel.Error).Count > 0 ? GH_Palette.Error : Owner.RuntimeMessages(GH_RuntimeMessageLevel.Warning).Count > 0 ? GH_Palette.Warning : normalPalette; GH_PaletteStyle impliedStyle = GH_CapsuleRenderEngine.GetImpliedStyle(palette, Owner.Attributes.Selected, Owner.Locked, Owner.Hidden); GH_Capsule cap = GH_Capsule.CreateCapsule(bound, palette, cornerRadius, 0); cap.Render(graphics, on ? onMap : offMap, impliedStyle); }
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(); }
public static void RenderButtonText_Obsolete(Graphics graphics, GH_Component Owner, RectangleF bound, bool on, string text, Color onColor, Color offColor, Font font, int cornerRadius = 6, GH_Palette normalPalette = GH_Palette.Normal) { GH_Palette palette = Owner.RuntimeMessages(GH_RuntimeMessageLevel.Error).Count > 0 ? GH_Palette.Error : Owner.RuntimeMessages(GH_RuntimeMessageLevel.Warning).Count > 0 ? GH_Palette.Warning : normalPalette; GH_PaletteStyle impliedStyle = GH_CapsuleRenderEngine.GetImpliedStyle(palette, Owner.Attributes.Selected, Owner.Locked, Owner.Hidden); GH_Capsule cap = GH_Capsule.CreateCapsule(bound, palette, cornerRadius, 0); cap.Render(graphics, impliedStyle); Brush brush = new SolidBrush(on ? onColor : offColor); graphics.DrawString(text, font, brush, bound); }
protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel) { base.Render(canvas, graphics, channel); var demBounds = (RectangleF) GH_Convert.ToRectangle(new RectangleF(new PointF(this.Pivot.X + 60, this.Pivot.Y), (SizeF) new Size(W - 60 - 80, H))); GH_Palette palette = GH_Palette.White; GH_Capsule capsule = GH_Capsule.CreateCapsule(demBounds, palette); capsule.Render(graphics, Selected, Owner.Locked, true); capsule.Dispose(); capsule = null; StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Center; format.Trimming = StringTrimming.EllipsisCharacter; // Content rectangle RectangleF textRectangle = demBounds; textRectangle.Height = 20; for (int i = 0; i < BimVisualiserData.Instance.NameList.Count; i++) { _boundingBoxes.Insert(i, textRectangle); // Max entries value (it would be nice extending the Bounds if more) if (i == 25) { break; } if (i == BimVisualiserData.Instance.Selected) { graphics.DrawString(BimVisualiserData.Instance.NameList[i], GH_FontServer.Standard, Brushes.DodgerBlue, textRectangle, format); } else { graphics.DrawString(BimVisualiserData.Instance.NameList[i], GH_FontServer.Standard, Brushes.Black, textRectangle, format); } format.Alignment = StringAlignment.Near; //textRectangle.Inflate(-5, 0); textRectangle.Y += 20; } // Always dispose of any GDI+ object that implement IDisposable. format.Dispose(); }
public static void ButtonIconRender(Graphics graphics, GH_CanvasChannel channel, IButtonIcon button) { if (channel == GH_CanvasChannel.Objects) { graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; GH_Palette palette = button.RenderSet.normalPalette; GH_PaletteStyle impliedStyle = GetPaletteStype(button, out palette); GH_Capsule cap = GH_Capsule.CreateCapsule(button.Bounds, palette, button.RenderSet.CornerRadius, button.RenderSet.HighLight); cap.Render(graphics, button.Icon, impliedStyle); } }
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 switchColor(string button) { if (button == "X") { if (xColor == GH_Palette.Black) { xColor = GH_Palette.Grey; } else { xColor = GH_Palette.Black; } } else if (button == "Y") { if (yColor == GH_Palette.Black) { yColor = GH_Palette.Grey; } else { yColor = GH_Palette.Black; } } else if (button == "Z") { if (zColor == GH_Palette.Black) { zColor = GH_Palette.Grey; } else { zColor = GH_Palette.Black; } } else if (button == "RX") { if (rxColor == GH_Palette.Black) { rxColor = GH_Palette.Grey; } else { rxColor = GH_Palette.Black; } } }
public static void ButtonStringRender(Graphics graphics, GH_CanvasChannel channel, IButtonString owner) { if (channel == GH_CanvasChannel.Objects) { graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; GH_Palette palette = owner.RenderSet.normalPalette; GH_PaletteStyle impliedStyle = GetPaletteStype(owner, out palette); GH_Capsule cap = GH_Capsule.CreateCapsule(owner.Bounds, palette, owner.RenderSet.CornerRadius, owner.RenderSet.HighLight); cap.Render(graphics, impliedStyle); Brush brush = new SolidBrush(owner.RightColor); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; graphics.DrawString(owner.Name, owner.RenderSet.Font, brush, owner.Bounds, format); } }
/*******************************************/ 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; } }
private void RenderComponentBounds(Graphics graphics) { //点击等效果到这里修改 GH_Palette ComponentColor = GH_Palette.Normal; bool IsLock = false; bool IsSelected = false; if (this.Owner.Locked) { IsLock = true; } if (this.Owner.Attributes.Selected) { IsSelected = true; } if (this.Owner.RuntimeMessageLevel == GH_RuntimeMessageLevel.Error) { ComponentColor = GH_Palette.Warning; } if (this.Owner.RuntimeMessageLevel == GH_RuntimeMessageLevel.Warning) { ComponentColor = GH_Palette.Warning; } if (this.Owner.Locked) { ComponentColor = GH_Palette.Locked; } RectangleF Bounds = this.Owner.Attributes.Bounds; GH_Capsule Capsule = GH_Capsule.CreateCapsule(Bounds, ComponentColor); Capsule.AddInputGrip(Bounds.Left, Bounds.Top + Setting.DROPDOWNCOMPONENTHEIGHT / 2); Capsule.AddOutputGrip(Bounds.Right, Bounds.Top + Setting.DROPDOWNCOMPONENTHEIGHT / 2); Capsule.RenderEngine.RenderGrips(graphics); Capsule.Render(graphics, IsSelected, IsLock, false); Capsule.Dispose(); }
private void switchColor(string button) { if (button == "MX") { if (xColor == GH_Palette.Black) { xColor = GH_Palette.Grey; } else { xColor = GH_Palette.Black; } } else if (button == "MY") { if (yColor == GH_Palette.Black) { yColor = GH_Palette.Grey; } else { yColor = GH_Palette.Black; } } else if (button == "MZ") { if (zColor == GH_Palette.Black) { zColor = GH_Palette.Grey; } else { zColor = GH_Palette.Black; } } Owner.ExpireSolution(true); }
private void switchColor(string button) { if (button == "Run") { if (xColor == GH_Palette.Black) { xColor = GH_Palette.Grey; } else { xColor = GH_Palette.Black; } } //else if (button == "Run Test") //{ // if (yColor == GH_Palette.Black) { yColor = GH_Palette.Grey; } // else { yColor = GH_Palette.Black; } //} //else if (button == "AboveLimit") //{ // if (zColor == GH_Palette.Black) { zColor = GH_Palette.Grey; } // else { zColor = GH_Palette.Black; } //} }
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 override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel) { if (channel == GH_CanvasChannel.Wires) { RenderIncomingWires(canvas.Painter, Owner.Sources, Owner.WireDisplay); } if (channel == GH_CanvasChannel.Objects) { base.Render(canvas, graphics, channel); GH_Palette palette = GH_Palette.Normal; switch (Owner.RuntimeMessageLevel) { case GH_RuntimeMessageLevel.Warning: palette = GH_Palette.Warning; break; case GH_RuntimeMessageLevel.Error: palette = GH_Palette.Error; break; } GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, palette); capsule.AddInputGrip(InputGrip.Y); capsule.Render(graphics, Selected, Owner.Locked, true); capsule.Dispose(); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; format.Trimming = StringTrimming.EllipsisCharacter; RectangleF textRectangle = Bounds; textRectangle.Height = 20; graphics.DrawString(Owner.NickName, GH_FontServer.Standard, Brushes.Black, textRectangle, format); int displayWidth = (int)(Bounds.Width - padding * 2); int displayHeight = (int)(Bounds.Height - padding * 4); System.Drawing.Point position = new System.Drawing.Point((int)(Bounds.X + padding), (int)(Bounds.Y + padding * 3)); Rectangle PatternRectangle = new Rectangle(position.X, position.Y, displayWidth, displayHeight); graphics.DrawRectangle(new Pen(Color.White), PatternRectangle); IGH_Structure data = Owner.VolatileData; if (data.PathCount != 0) { GH_Path path = data.get_Path(0); List <GH_Number> branch = data.get_Branch(path) as List <GH_Number>; int patternSize = branch.Count; float width = (float)Math.Ceiling(Math.Sqrt((double)patternSize)); if (displayWidth > displayHeight) { displaySize = displayHeight; } else { displaySize = displayWidth; } float rectSize = (float)(displaySize / width); RectangleF[] rectangles = new RectangleF[patternSize]; for (int i = 0; i < patternSize; i++) { PointF pos = new PointF((float)(Bounds.X + padding), (float)(Bounds.Y + padding * 3)); pos = new PointF(pos.X + rectSize * (float)Math.Floor(i % width), pos.Y + rectSize * (float)Math.Floor(i / width)); RectangleF content = new RectangleF(pos.X, pos.Y, rectSize, rectSize); rectangles[i] = content; SolidBrush brush; if ((int)branch[i].Value == 0) { brush = new SolidBrush(Color.White); } else if ((int)branch[i].Value == 1) { brush = new SolidBrush(Color.Black); } else { brush = new SolidBrush(Color.Orange); } graphics.FillRectangle(brush, rectangles[i]); } } format.Dispose(); } }
// render protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel) { if (channel != Grasshopper.GUI.Canvas.GH_CanvasChannel.Objects) { return; } RenderIncomingWires(canvas.Painter, Owner.Sources, Owner.WireDisplay); // Define the default palette. GH_Palette palette = GH_Palette.Normal; // Create a new Capsule GH_Capsule capsule = GH_Capsule.CreateCapsule(new RectangleF(this.Pivot, new SizeF(Bounds.Width, 20)), palette); capsule.AddInputGrip(this.InputGrip.Y); capsule.AddOutputGrip(this.OutputGrip.Y); bool validInput = own.getUserInput(); string componentName; if (own.sourceName == "" || own.sourceName == null) { componentName = "Probabilities"; } else { componentName = "Probabilities (" + own.sourceName + " )"; } if (binSelected) { componentName = "Probabilities (" + own.sourceName + " <=" + own.BinRanges[selectedBin][1].ToString() + ")"; } if ((own.evidence == true) && (own.doubleClicked == true)) { Rhino.RhinoApp.WriteLine("db"); componentName = componentName + " = 100%"; } else if ((own.evidence == true) && (own.doubleClicked == false)) { Rhino.RhinoApp.WriteLine("not db"); componentName = componentName + " = custom"; } Grasshopper.GUI.Canvas.GH_PaletteStyle styleStandard = null; Grasshopper.GUI.Canvas.GH_PaletteStyle styleSelected = null; GH_Skin.LoadSkin(); if (channel == GH_CanvasChannel.Objects) { // Cache the current styles. styleStandard = GH_Skin.palette_normal_standard; styleSelected = GH_Skin.palette_normal_selected; if (!own.evidence) { GH_Skin.palette_normal_selected = GH_Skin.palette_normal_standard; } else { GH_Skin.palette_normal_standard = new GH_PaletteStyle(Color.SkyBlue, Color.DarkBlue, Color.Black); GH_Skin.palette_normal_selected = new GH_PaletteStyle(Color.SkyBlue, Color.DarkBlue, Color.Black); } } GH_Capsule message = GH_Capsule.CreateTextCapsule( new RectangleF(new PointF(this.Pivot.X, this.Pivot.Y + 20), new SizeF(Bounds.Width, 20)), new RectangleF(new PointF(this.Pivot.X, this.Pivot.Y + 20), new SizeF(Bounds.Width, 20)), GH_Palette.Normal, componentName ); message.Render(graphics, Selected, Owner.Locked, false); message.Dispose(); message = null; if (channel == GH_CanvasChannel.Objects) { // Restore the cached styles. GH_Skin.palette_normal_standard = styleStandard; GH_Skin.palette_normal_selected = styleSelected; } //Render the capsule using the current Selection, Locked and Hidden states. //Integer parameters are always hidden since they cannot be drawn in the viewport. capsule.Render(graphics, Selected, Owner.Locked, true); //Always dispose of a GH_Capsule when you're done with it. capsule.Dispose(); capsule = null; //Bounds = _extraBounds; int width = GH_FontServer.StringWidth(Owner.NickName, GH_FontServer.Standard); PointF p = new PointF(this.Pivot.X + width + 19, this.Pivot.Y - 7); List <double> probs = own.Probabilities; PointF[] pts = getHistoPts(own.Probabilities); if (own.draw_flag == "s") { pts = getPts(probs); } PointF maxPt = new PointF(0, 0); float ptY = pts[0].Y; int index_max = 0; for (int i = 0; i < pts.Length; i++) { if (pts[i].Y < ptY) { ptY = pts[i].Y; index_max = i; } } maxPt = pts[index_max]; // Create Pens System.Drawing.Pen pen2 = new System.Drawing.Pen(Brushes.Red, 2); System.Drawing.Pen pen = new System.Drawing.Pen(Brushes.Black, 2); System.Drawing.Pen pen3 = new System.Drawing.Pen(Brushes.GhostWhite, 1); // Create Gradient Brush System.Drawing.Drawing2D.LinearGradientBrush lb = new System.Drawing.Drawing2D.LinearGradientBrush (new PointF(maxPt.X, maxPt.Y), new PointF(maxPt.X, this.Pivot.Y), Color.FromArgb(255, 0, 0), Color.FromArgb(255, 255, 255)); System.Drawing.SolidBrush sb = new System.Drawing.SolidBrush(Color.FromArgb(70, 255, 255, 255)); // Rui // render background bins RectangleF[] backgroundBins = getBackgroundBins(own.Probabilities); graphics.DrawRectangles(pen3, backgroundBins); graphics.FillRectangles(sb, backgroundBins); backgroundBinBounds = backgroundBins; //Draw Polygon ouline and fill graphics.DrawPolygon(pen, pts); graphics.FillPolygon(lb, pts); // draw text capsules RectangleF[] textholderBounds = getTextholder(own.Probabilities); GH_Capsule[] textCapsules = new GH_Capsule[textholderBounds.Length]; int numbins = textCapsules.Length; if (own.BinRanges != null) { for (int i = 0; i < numbins; i++) { //textCapsules[i] = GH_Capsule.CreateTextCapsule(textholderBounds[i], textholderBounds[i], GH_Palette.Normal, "<=" + own.BinRanges[numbins - 1 - i][1], 3, 0); textCapsules[i] = GH_Capsule.CreateTextCapsule(textholderBounds[i], textholderBounds[i], GH_Palette.Normal, Math.Round(own.BinRanges[numbins - 1 - i][0], 2) + "<" + Math.Round(own.BinRanges[numbins - 1 - i][1], 2), 3, 0); textCapsules[i].Render(graphics, Selected, Owner.Locked, false); } } }
private void RenderSpecial(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel) { // Render all the wires that connect the Owner to all its Sources. if (channel == GH_CanvasChannel.Wires) { RenderIncomingWires(canvas.Painter, Owner.Params.Input, GH_ParamWireDisplay.@default); return; } // Render the parameter capsule and any additional text on top of it. if (channel == GH_CanvasChannel.Objects) { // Define the default palette. GH_Palette palette = GH_Palette.Blue; Color color = Color.DarkSalmon; bool usePalette = false; if (Selected) { usePalette = true; } // Adjust color based on the Owner's worst case messaging level. switch (Owner.RuntimeMessageLevel) { case GH_RuntimeMessageLevel.Warning: palette = GH_Palette.Warning; usePalette = true; break; case GH_RuntimeMessageLevel.Error: palette = GH_Palette.Error; usePalette = true; break; } //canvas.Select // Create a new Capsule without text or icon. GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, palette); foreach (IGH_Param p in Owner.Params.Input) { capsule.AddInputGrip(p.Attributes.InputGrip.Y); } foreach (IGH_Param p in Owner.Params.Output) { capsule.AddOutputGrip(p.Attributes.OutputGrip.Y); } //Image icon = Owner.Icon_24x24; //var component = (GH_Component)Owner; //var icon = component.Ico if (usePalette) { capsule.Render(graphics, Selected, Owner.Locked, true); } else { capsule.Render(graphics, Color.DarkSalmon); } //if (Owner.IconDisplayMode == GH_IconDisplayMode.icon) // graphics.DrawIcon(Owner., m_innerBounds); // Always dispose of a GH_Capsule when you're done with it. capsule.Dispose(); capsule = null; GH_Capsule innerCapsule = GH_Capsule.CreateTextCapsule(m_innerBounds, m_innerBounds, GH_Palette.Grey, Owner.NickName); innerCapsule.Render(graphics, Selected, Owner.Locked, true); innerCapsule.Dispose(); innerCapsule = null; // Now it's time to draw the text on top of the capsule. // First we'll draw the Owner NickName using a standard font and a black brush. // We'll also align the NickName in the center of the Bounds. StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; format.Trimming = StringTrimming.EllipsisCharacter; // Our entire capsule is 60 pixels high, and we'll draw // three lines of text, each 20 pixels high. RectangleF textRectangle = Bounds; textRectangle.Height = 20; // Draw the NickName in a Standard Grasshopper font. var component = (Boa_AlgorithmComponent)Owner; graphics.DrawString(component.Algorithm.GetDimensionsString(), GH_FontServer.Standard, Brushes.Black, textRectangle, format); format.Alignment = StringAlignment.Far; foreach (IGH_Param p in Owner.Params.Input) { textRectangle = p.Attributes.Bounds; graphics.DrawString(p.NickName, GH_FontServer.Standard, Brushes.Black, textRectangle, format); } format.Alignment = StringAlignment.Near; foreach (IGH_Param p in Owner.Params.Output) { textRectangle = p.Attributes.Bounds; graphics.DrawString(p.NickName, GH_FontServer.Standard, Brushes.Black, textRectangle, format); } // Now we need to draw the median and mean information. // Adjust the formatting and the layout rectangle. //format.Alignment = StringAlignment.Near; //textRectangle.Inflate(-5, 0); //textRectangle.Y += 20; //graphics.DrawString(String.Format("Median: {0}", Owner.MedianValue), _ // GH_FontServer.StandardItalic, Brushes.Black, _ // textRectangle, format); //textRectangle.Y += 20; //graphics.DrawString(String.Format("Mean: {0:0.00}", Owner.MeanValue), _ // GH_FontServer.StandardItalic, Brushes.Black, _ // textRectangle, format); //// Always dispose of any GDI+ object that implement IDisposable. format.Dispose(); } }
private void switchColor(string button) { if (button == "Run") { if (displayed == GH_Palette.Black) { displayed = GH_Palette.Grey; } else { displayed = GH_Palette.Black; } } if (button == "setColor") { if (setcolor == GH_Palette.Black) { setcolor = GH_Palette.Grey; xColor = GH_Palette.Grey; yColor = GH_Palette.Grey; VonMisesColor = GH_Palette.Grey; rxColor = GH_Palette.Grey; ryColor = GH_Palette.Grey; } else { setcolor = GH_Palette.Black; } } if (button == "X" && setcolor == GH_Palette.Black) { if (xColor == GH_Palette.Black) { xColor = GH_Palette.Grey; } else { xColor = GH_Palette.Black; yColor = GH_Palette.Grey; VonMisesColor = GH_Palette.Grey; rxColor = GH_Palette.Grey; ryColor = GH_Palette.Grey; } } if (button == "Y" && setcolor == GH_Palette.Black) { if (yColor == GH_Palette.Black) { yColor = GH_Palette.Grey; } else { yColor = GH_Palette.Black; xColor = GH_Palette.Grey; VonMisesColor = GH_Palette.Grey; rxColor = GH_Palette.Grey; ryColor = GH_Palette.Grey; } } if (button == "VonMises" && setcolor == GH_Palette.Black) { if (VonMisesColor == GH_Palette.Black) { VonMisesColor = GH_Palette.Grey; } else { VonMisesColor = GH_Palette.Black; xColor = GH_Palette.Grey; yColor = GH_Palette.Grey; rxColor = GH_Palette.Grey; ryColor = GH_Palette.Grey; } } if (button == "RX" && setcolor == GH_Palette.Black) { if (rxColor == GH_Palette.Black) { rxColor = GH_Palette.Grey; } else { xColor = GH_Palette.Grey; yColor = GH_Palette.Grey; VonMisesColor = GH_Palette.Grey; rxColor = GH_Palette.Black; ryColor = GH_Palette.Grey; } } if (button == "RY" && setcolor == GH_Palette.Black) { if (ryColor == GH_Palette.Black) { ryColor = GH_Palette.Grey; } else { xColor = GH_Palette.Grey; yColor = GH_Palette.Grey; VonMisesColor = GH_Palette.Grey; rxColor = GH_Palette.Grey; ryColor = GH_Palette.Black; } } }
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(); }
protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel) { // Render the parameter capsule and any additional text on top of it. if (channel == GH_CanvasChannel.Objects) { // Define the default palette. GH_Palette palette = GH_Palette.White; // Adjust palette based on the Owner's worst case messaging level. switch (Owner.RuntimeMessageLevel) { case GH_RuntimeMessageLevel.Warning: palette = GH_Palette.Warning; break; case GH_RuntimeMessageLevel.Error: palette = GH_Palette.Error; break; } // Create a new Capsule without text or icon. GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, palette); // Render the capsule using the current Selection, Locked and Hidden states. // Integer parameters are always hidden since they cannot be drawn in the viewport. capsule.Render(graphics, Selected, Owner.Locked, true); // Always dispose of a GH_Capsule when you're done with it. capsule.Dispose(); capsule = null; // Now it's time to draw the text on top of the capsule. // First we'll draw the Owner NickName using a standard font and a black brush. // We'll also align the NickName in the center of the Bounds. StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; format.Trimming = StringTrimming.EllipsisCharacter; // Our entire capsule is 60 pixels high, and we'll draw // three lines of text, each 20 pixels high. RectangleF textRectangle = Bounds; textRectangle.Height = 20; textRectangle.Y += 5; // Draw the NickName in a Standard Grasshopper font. graphics.DrawString("About FemDesign API", GH_FontServer.Large, Brushes.Black, textRectangle, format); // Now we need to draw the median and mean information. // Adjust the formatting and the layout rectangle. format.Alignment = StringAlignment.Near; textRectangle.Inflate(-5, 0); //API version number IEnumerable <AssemblyName> assembly = Assembly.GetExecutingAssembly().GetReferencedAssemblies().Where(x => x.Name.Contains("FemDesign.Core")); string assemblyVersion = assembly.First().Version?.ToString(); Version ver = Version.Parse(assemblyVersion); string major = ver.Major.ToString(); string minor = ver.Minor.ToString(); string patch = ver.Build.ToString(); Pen pen = new Pen(Brushes.Black, Convert.ToSingle(0.5)); PointF pt1 = new PointF(textRectangle.X, textRectangle.Y + 20); PointF pt2 = new PointF(textRectangle.X + textRectangle.Width, textRectangle.Y + 20); graphics.DrawLine(pen, pt1, pt2); textRectangle.Y += 25; graphics.DrawString(String.Format("Version: " + major + "." + minor + "." + patch), GH_FontServer.StandardItalic, Brushes.Black, textRectangle, format); textRectangle.Y += 20; graphics.DrawString(String.Format("Useful links:"), GH_FontServer.StandardItalic, Brushes.Black, textRectangle, format); textRectangle.Y += 15; link1 = textRectangle; Font linkFont = new Font(GH_FontServer.StandardItalic, FontStyle.Underline); graphics.DrawString(String.Format("https://strusoft.freshdesk.com/", 5), linkFont, Brushes.Blue, textRectangle, format); textRectangle.Y += 15; link2 = textRectangle; graphics.DrawString(String.Format("https://wiki.fem-design.strusoft.com/"), linkFont, Brushes.Blue, textRectangle, format); textRectangle.Y += 15; link3 = textRectangle; graphics.DrawString(String.Format("https://github.com/strusoft/femdesign-api"), linkFont, Brushes.Blue, textRectangle, format); textRectangle.Y += 25; textRectangle.Height = Convert.ToSingle(textRectangle.Width * 0.227); Image image = FemDesign.Properties.Resources.fdlogo; graphics.DrawImage(image, textRectangle); // Always dispose of any GDI+ object that implement IDisposable. format.Dispose(); } }
public static GH_PaletteStyle GetPaletteStype(IButton button, out GH_Palette palette) { return(GetPaletteStype(button.Owner, button.Enable, button.RenderSet.normalPalette, out palette)); }
public static GH_PaletteStyle GetPaletteStype(ControllableComponent Owner, bool enable, GH_Palette normal, out GH_Palette palette) { palette = Owner.RuntimeMessages(GH_RuntimeMessageLevel.Error).Count > 0 ? GH_Palette.Error : Owner.RuntimeMessages(GH_RuntimeMessageLevel.Warning).Count > 0 ? GH_Palette.Warning : normal; return(GH_CapsuleRenderEngine.GetImpliedStyle(palette, Owner.Attributes.Selected, Owner.Locked || !enable, Owner.Hidden)); }
public static void RenderButtonText_Obsolete(Graphics graphics, GH_Component Owner, RectangleF bound, bool on, string text, Color onColor, Color offColor, int cornerRadius = 6, GH_Palette normalPalette = GH_Palette.Normal) { RenderButtonText_Obsolete(graphics, Owner, bound, on, text, onColor, offColor, GH_FontServer.Standard, cornerRadius, normalPalette); }
protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel) { // Render all the wires that connect the Owner to all its Sources. if (channel == GH_CanvasChannel.Wires) { RenderIncomingWires(canvas.Painter, Owner.Sources, Owner.WireDisplay); return; } // Render the parameter capsule and any additional text on top of it. if (channel == GH_CanvasChannel.Objects) { // Define the default palette. GH_Palette palette = GH_Palette.Normal; // Adjust palette based on the Owner's worst case messaging level. switch (Owner.RuntimeMessageLevel) { case GH_RuntimeMessageLevel.Warning: palette = GH_Palette.Warning; break; case GH_RuntimeMessageLevel.Error: palette = GH_Palette.Error; break; } // Create a new Capsule without text or icon. GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, palette); // Render the capsule using the current Selection, Locked and Hidden states. // Integer parameters are always hidden since they cannot be drawn in the viewport. capsule.Render(graphics, Selected, Owner.Locked, true); // Always dispose of a GH_Capsule when you're done with it. capsule.Dispose(); capsule = null; // Now it's time to draw the text on top of the capsule. // First we'll draw the Owner NickName using a standard font and a black brush. // We'll also align the NickName in the center of the Bounds. StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; format.Trimming = StringTrimming.EllipsisCharacter; // Our entire capsule is 60 pixels high, and we'll draw // three lines of text, each 20 pixels high. RectangleF textRectangle = Bounds; textRectangle.Height = 20; // Draw the NickName in a Standard Grasshopper font. graphics.DrawString(Owner.NickName, GH_FontServer.Standard, Brushes.Black, textRectangle, format); // Now we need to draw the median and mean information. // Adjust the formatting and the layout rectangle. format.Alignment = StringAlignment.Near; textRectangle.Inflate(-5, 0); textRectangle.Y += 20; graphics.DrawString(String.Format("Median: {0}", Owner.MedianValue), GH_FontServer.StandardItalic, Brushes.Black, textRectangle, format); textRectangle.Y += 20; graphics.DrawString(String.Format("Mean: {0:0.00}", Owner.MeanValue), GH_FontServer.StandardItalic, Brushes.Black, textRectangle, format); // Always dispose of any GDI+ object that implement IDisposable. format.Dispose(); } }
//protected override void Layout() //{ // // Compute the width of the NickName of the owner (plus some extra padding), // // then make sure we have at least 80 pixels. // int width = GH_FontServer.StringWidth(Owner.NickName, GH_FontServer.Standard); // width = Math.Max(width + 10, 80); // // The height of our object is always 60 pixels // int height = 60; // // Assign the width and height to the Bounds property. // // Also, make sure the Bounds are anchored to the Pivot // Bounds = new RectangleF(Pivot, new SizeF(width, height)); // int paramNameWidth = GH_FontServer.StringWidth(Owner.Params.Input[0].NickName, GH_FontServer.Standard) + 8; // var componentBox = new RectangleF(new PointF(Pivot.X + paramNameWidth, Pivot.Y), new SizeF(width - paramNameWidth, height)); // LayoutInputParams(Owner, componentBox); // LayoutOutputParams(Owner, componentBox); //} protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel) { // Render the component capsule and any additional text on top of it. if (channel == GH_CanvasChannel.Objects) { // Define the default palette. GH_Palette palette = GH_Palette.Blue; Color color = Color.LightCoral; //Color color = Color.MediumSpringGreen; //Color color = Color.DeepPink; bool usePalette = false; if (Selected) { usePalette = true; } // Adjust color based on the Owner's worst case messaging level. switch (Owner.RuntimeMessageLevel) { case GH_RuntimeMessageLevel.Warning: palette = GH_Palette.Warning; usePalette = true; break; case GH_RuntimeMessageLevel.Error: palette = GH_Palette.Error; usePalette = true; break; } // Create a new Capsule without text or icon. GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, palette); foreach (IGH_Param p in Owner.Params.Input) { capsule.AddInputGrip(p.Attributes.InputGrip.Y); } foreach (IGH_Param p in Owner.Params.Output) { capsule.AddOutputGrip(p.Attributes.OutputGrip.Y); } if (usePalette) { capsule.Render(graphics, Selected, Owner.Locked, true); } else { capsule.Render(graphics, color); } var icon = Owner.Icon_24x24; var point = new PointF( m_innerBounds.X, m_innerBounds.Y + m_innerBounds.Height / 2 - icon.Height / 2 ); graphics.DrawImage(icon, point); var modifierIcon = Grasshopper.GUI.GH_StandardIcons.FlattenIcon_24x24; // Always dispose of a GH_Capsule when you're done with it. capsule.Dispose(); capsule = null; // Now it's time to draw the text on top of the capsule. // First we'll draw the Owner NickName using a standard font and a black brush. // We'll also align the NickName in the center of the Bounds. StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; format.Trimming = StringTrimming.EllipsisCharacter; //Our entire capsule is 60 pixels high, and we'll draw // three lines of text, each 20 pixels high. RectangleF textRectangle = Bounds; textRectangle.Height = 20; format.Alignment = StringAlignment.Far; foreach (IGH_Param p in Owner.Params.Input) { textRectangle = p.Attributes.Bounds; graphics.DrawString(p.NickName, GH_FontServer.Standard, Brushes.Black, textRectangle, format); } format.Alignment = StringAlignment.Near; foreach (IGH_Param p in Owner.Params.Output) { textRectangle = p.Attributes.Bounds; graphics.DrawString(p.NickName, GH_FontServer.Standard, Brushes.Black, textRectangle, format); } // Always dispose of any GDI+ object that implement IDisposable. format.Dispose(); ////we should render this component's parameters after rendering the component //foreach (IGH_Param p in Owner.Params.Input) // p.Attributes.RenderToCanvas(canvas, channel); } else { base.Render(canvas, graphics, channel); } }