3 using Microsoft.Xna.Framework;
4 using Microsoft.Xna.Framework.Graphics;
8 internal partial class CircuitBoxNode
10 public RectangleF DrawRect;
11 private RectangleF TopDrawRect;
13 protected void UpdateDrawRects()
15 var drawRect =
new RectangleF(Position - Size / 2f, Size);
16 drawRect.Y = -drawRect.Y;
17 drawRect.Y -= drawRect.Height;
20 TopDrawRect =
new RectangleF(drawRect.X, drawRect.Y - (CircuitBoxSizes.NodeHeaderHeight - 1), drawRect.Width, CircuitBoxSizes.NodeHeaderHeight);
23 public void OnUICreated()
25 Size = CalculateSize(Connectors);
29 public virtual void OnResized(RectangleF drawRect) { }
31 public void DrawBackground(SpriteBatch spriteBatch, RectangleF drawRect, RectangleF topDrawRect, Color color)
33 CircuitBox.NodeFrameSprite?.Draw(spriteBatch, drawRect, color);
34 CircuitBox.NodeTopSprite?.Draw(spriteBatch, topDrawRect, color);
37 public void Draw(SpriteBatch spriteBatch, Vector2 drawPos, Color color)
39 RectangleF drawRect = OverrideRectLocation(DrawRect, drawPos, Position),
40 topDrawRect = OverrideRectLocation(TopDrawRect, drawPos, Position);
42 DrawBackground(spriteBatch, drawRect, topDrawRect, color);
43 DrawHeader(spriteBatch, topDrawRect, color);
44 DrawBody(spriteBatch, drawRect, color);
46 DrawConnectors(spriteBatch, drawPos);
49 public void DrawHUD(SpriteBatch spriteBatch, Camera camera)
51 foreach (var c
in Connectors)
53 c.DrawHUD(spriteBatch, camera);
57 public virtual void DrawHeader(SpriteBatch spriteBatch, RectangleF rect, Color color) { }
58 public virtual void DrawBody(SpriteBatch spriteBatch, RectangleF rect, Color color) { }
60 public void DrawConnectors(SpriteBatch spriteBatch, Vector2 drawPos)
62 var color = Color.White * Opacity;
63 foreach (var c
in Connectors)
65 c.Draw(spriteBatch, drawPos, Position, color);
69 public void DrawSelection(SpriteBatch spriteBatch, Color color)
71 int pad = GUI.IntScale(8);
75 rect.Y -= rect.Height;
77 rect.Inflate(pad, pad);
79 GUI.DrawFilledRectangle(spriteBatch, rect, color * Opacity);
85 public static RectangleF OverrideRectLocation(RectangleF rect, Vector2 overridePos, Vector2 originalPos)
87 rect.Location -=
new Vector2(originalPos.X, -originalPos.Y);
88 rect.Location +=
new Vector2(overridePos.X, -overridePos.Y);