/// <summary> /// Draws the text board in screen space with an offset given in pixels. /// </summary> public void Draw(Vector2 origin) { Vector2 halfSize = _size * .5f * Scale; BoundingBox2 box = new BoundingBox2(origin - halfSize, origin + halfSize); Draw(box, CroppedBox.defaultMask, HudMain.PixelToWorldRef); }
public bool Intersects(BoundingBox2 boundingBox) { Vec2 clampedLocation; if (center.x > boundingBox.max.x) { clampedLocation.x = boundingBox.max.x; } else if (center.x < boundingBox.min.x) { clampedLocation.x = boundingBox.min.x; } else { clampedLocation.x = center.x; } if (center.y > boundingBox.max.y) { clampedLocation.y = boundingBox.max.y; } else if (center.y < boundingBox.min.y) { clampedLocation.y = boundingBox.min.y; } else { clampedLocation.y = center.y; } return(clampedLocation.DistanceSquared(center) <= (radius * radius)); }
public override bool HitTest(Vector2 position) { if (IsVisible && Texture != null) { Vector2 localPosition = Vector2.Transform(position, Matrix.Invert(WorldTransform)); Vector2 textureCoordinate = localPosition + Origin; BoundingBox2 textureBox = new BoundingBox2(Vector2.Zero, new Vector2(Texture.Width, Texture.Height)); Rectangle r = textureBox.Intersection(new BoundingBox2(Rectangle)).ToRectangle(); int x = (int)textureCoordinate.X; int y = (int)textureCoordinate.Y; // TODO: Optimize this! if (x >= 0 && y >= 0 && x < r.Width && y < r.Height) { int[] data = new int[r.Width * r.Height]; Texture.GetData(0, r, data, 0, data.Length); if (data[x + y * r.Width] != 0) { return(true); } } } return(false); }
public QuadBoard(MyStringId textureID, BoundingBox2 matFit, Color color, float skewRatio = 0f) { this.textureID = textureID; this.texCoords = matFit; bbColor = GetQuadBoardColor(color); this.skewRatio = skewRatio; }
public SpriteBuilder(IMyTextSurface surface) { Surface = surface; Color = surface.ScriptForegroundColor; BGColor = surface.ScriptBackgroundColor; Box = new BoundingBox2(Cursor, Cursor); }
public SpriteBuilder(IMyTextSurface surface, Vector2 pos, float scale = 1.0f, float frame = 0) : this(surface) { Cursor = pos; Box = new BoundingBox2(Cursor, Cursor); Scale = scale; FrameCount = frame; }
public QuadBoard(MyStringId textureID, BoundingBox2 matFit, Vector4 bbColor, float skewRatio = 0f) { this.textureID = textureID; this.texCoords = matFit; this.bbColor = bbColor; this.skewRatio = skewRatio; }
public QuadBoard(MyStringId textureID, BoundingBox2 matFit, Vector4 bbColor, float skewRatio = 0f) { materialData.textureID = textureID; materialData.texBounds = matFit; materialData.bbColor = bbColor; this.skewRatio = skewRatio; }
public QuadBoard(MyStringId textureID, BoundingBox2 matFit, Color color, float skewRatio = 0f) { materialData.textureID = textureID; materialData.texBounds = matFit; materialData.bbColor = BillBoardUtils.GetBillBoardBoardColor(color); this.skewRatio = skewRatio; }
public void DrawRectangle(BoundingBox2 boundingBox, Vector2 cornerRadius, PrimitiveBrush brush, Matrix transformMatrix) { int startIndex = _vertexCount; DrawRectangle(boundingBox, cornerRadius, brush); ApplyTransformMatrix(startIndex, _vertexCount, transformMatrix); }
/// <summary> /// Returns the bounds of the thumb /// </summary> /// <param name="parentTopLeft">The parents top left position</param> /// <returns>The bounds for this thumb on the given parent</returns> public BoundingBox2 GetBounds(Vector2 parentTopLeft) { Vector2 size = MyGuiConstants.TEXTURE_SLIDER_THUMB_DEFAULT.SizeGui; BoundingBox2 bounds = new BoundingBox2(parentTopLeft + CurrentPosition - size / 2, parentTopLeft + CurrentPosition + size / 2); return(bounds); }
/// <summary> /// Used to check whether the cursor is moused over the element and whether its being /// obstructed by another element. /// </summary> protected override void InputDepth() { State &= ~HudElementStates.IsMouseInBounds; if (HudMain.InputMode != HudInputMode.NoInput && (HudSpace?.IsFacingCamera ?? false)) { Vector3 cursorPos = HudSpace.CursorPos; Vector2 halfSize = Vector2.Max(cachedSize, new Vector2(minMouseBounds)) * .5f; BoundingBox2 box = new BoundingBox2(cachedPosition - halfSize, cachedPosition + halfSize); bool mouseInBounds; if (maskingBox == null) { mouseInBounds = box.Contains(new Vector2(cursorPos.X, cursorPos.Y)) == ContainmentType.Contains; } else { mouseInBounds = box.Intersect(maskingBox.Value).Contains(new Vector2(cursorPos.X, cursorPos.Y)) == ContainmentType.Contains; } if (mouseInBounds) { State |= HudElementStates.IsMouseInBounds; HudMain.Cursor.TryCaptureHudSpace(cursorPos.Z, HudSpace.GetHudSpaceFunc); } } }
public void EmptyBox(BoxStyle style) { Vector2 size = style.Size * Scale; BoundingBox2 box = new BoundingBox2(Cursor, Cursor + size); MoveCursor(box.Width); MergeBox(box); }
public void GetBounds(ref BoundingBox2 texcoordRange, int face, out float min, out float max) { BoundingBox query = new BoundingBox(new Vector3(texcoordRange.Min, 0f), new Vector3(texcoordRange.Max, 0f)); this.m_heightmap.Faces[face].GetBounds(ref query); min = query.Min.Z; max = query.Max.Z; }
/// <summary> /// Draws the text board in world space on the XY plane of the matrix, facing in the +Z /// direction. /// </summary> public void Draw(Vector2 offset, ref MatrixD matrix) { Vector2 halfSize = _size * .5f * Scale; BoundingBox2 box = new BoundingBox2(offset - halfSize, offset + halfSize); matRef[0] = matrix; Draw(box, CroppedBox.defaultMask, matRef); }
public static BoundingBox2 GetBounds(INode node) { BoundingBox2 bounds = node.GetWorldBounds(); for (int i = 0; i < node.Children.Count; i++) { bounds = bounds.Union(GetBounds(node.Children[i])); } return(bounds); }
public SpriteBuilder(SpriteBuilder sb, Vector2 pos) { Surface = sb.Surface; FontId = sb.FontId; FontScale = sb.FontScale; Color = sb.Color; BGColor = sb.BGColor; Cursor = pos; Box = new BoundingBox2(Cursor, Cursor); Scale = sb.Scale; FrameCount = sb.FrameCount; }
static JsonData SerializeRect(BoundingBox2 r) { var ret = CreateObj(); ret["top"] = r.Top; ret["left"] = r.Left; ret["bottom"] = r.Bottom; ret["right"] = r.Right; return(ret); }
public void SpriteBox(BoxStyle style, string spriteId) { BoundingBox2 box = new BoundingBox2(Cursor, Cursor + style.Size * Scale); if (Sprites != null) { Sprites.Add(new MySprite(SpriteType.TEXTURE, spriteId, box.Center, style.InnerSize * Scale, Color)); } MoveCursor(box.Width); MergeBox(box); }
// ---- public BoundingBox2 AppendBlockIcon(SpriteBuilder maker, BoxStyle style, IMonitorBlock monitorBlock, MonitorInfo info) { BoundingBox2 box = new BoundingBox2(Cursor, Cursor); SpriteBuilder sb = new SpriteBuilder(maker); InfoItem item; if (info.TryGetValue("block", out item)) { CommonInfo commonInfo = item as CommonInfo; string icon = ""; if (commonInfo.IsBeingHacked) { if ((FrameCount % 1.0f) < 0.5f) { icon = SpriteId.Danger; } else { icon = SpriteId.Cross; } } else if (!commonInfo.IsFunctional) { icon = SpriteId.Cross; } //else if (!info.BlockInfo.IsEnabled) // icon = SpriteId.Construction; else if (!commonInfo.IsWorking) { icon = SpriteId.Danger; } if (icon != "") { sb.SpriteBox(style, icon); //box = maker.SpriteBox(Sprites, style, icon); } else { SpriteDataBuilder sdb; if (IconRes.TryGetValue(commonInfo.Icon, out sdb)) { sb.SpriteDataBox(style, sdb); } //box = maker.SpriteDataBox(Sprites, style, sdb); } } Cursor.X += sb.Box.Width; //Cursor.X += box.Width; Sprites.AddRange(sb.Sprites); return(sb.Box); }
private void UpdateToolTip(bool boundTooltip, float scale) { toolTip.Visible = IsToolTipRegistered; if (GetToolTipFunc != null) { ToolTipMembers data = GetToolTipFunc(); if (data.Item1 != null) { toolTip.Visible = true; toolTip.Format = ToolTip.DefaultText; toolTip.TextBoard.SetText(data.Item1); if (data.Item2 != null) { toolTip.Color = data.Item2.Value; } else { toolTip.Color = ToolTip.DefaultBG; } } GetToolTipFunc = null; /* Position tooltip s.t. its placed below and to the right of the cursor while also bounding * the position to keep it from going off screen. */ Vector2 halfTooltipSize = toolTip.Size * .5f, cursorPos = new Vector2(CursorPos.X, CursorPos.Y), toolTipPos = cursorPos + new Vector2(24f, -24f); toolTipPos.X += halfTooltipSize.X; toolTipPos.Y -= halfTooltipSize.Y; BoundingBox2 toolBox = new BoundingBox2(toolTipPos - halfTooltipSize, toolTipPos + halfTooltipSize); if (boundTooltip) { Vector2 halfScreenSize = new Vector2(ScreenWidth, ScreenHeight) * .5f / scale; BoundingBox2 screenBox = new BoundingBox2(-halfScreenSize, halfScreenSize), offsetBox = new BoundingBox2(cursorPos - halfScreenSize, cursorPos + halfScreenSize); offsetBox = offsetBox.Intersect(screenBox); toolBox = toolBox.Intersect(offsetBox); } toolTipPos -= cursorPos; Vector2 delta = (toolBox.Center - cursorPos) - toolTipPos; toolTip.Offset = toolTipPos + 2f * delta; } }
public void TextBox(BoxStyle style, string text) { if (style.SizeRule == SizeRule.Auto) { style = new BoxStyle(style) { Size = CalcStringSize(text, FontId, FontScale) }; } Vector2 size = style.Size * Scale; TextAlignment align = style.Align; MySprite sprite; BoundingBox2 box = new BoundingBox2(Cursor, Cursor + size); Vector2 innerSize = style.InnerSize * Scale; float textScale; if (size.Y != 0) { textScale = innerSize.Y / size.Y; } else { textScale = 0; } Vector2 textPos = new Vector2(box.Center.X, box.Center.Y - innerSize.Y / 2.0f); if (align == TextAlignment.LEFT) { textPos.X -= innerSize.X / 2.0f; } else if (align == TextAlignment.RIGHT) { textPos.X += innerSize.X / 2.0f; } if (Sprites != null) { //sprite = MySprite.CreateSprite(SpriteId.SquareSimple, box.Center, box.Size); //sprite.Color = BGColor; //Sprites.Add(sprite); sprite = MySprite.CreateText(text, FontId, Color, textScale * FontScale * Scale, align); sprite.Position = textPos; Sprites.Add(sprite); } MoveCursor(box.Width); MergeBox(box); }
public void SpriteDataBox(BoxStyle style, SpriteDataBuilder data) { Vector2 size = style.Size * Scale; BoundingBox2 box = new BoundingBox2(Cursor, Cursor + size); if (Sprites != null) { data.BuildSprites(Sprites, box.Center, style.InnerSize * Scale, FrameCount, Color, BGColor); } MoveCursor(box.Width); MergeBox(box); }
protected override void Draw() { Vector2 halfSize = (cachedSize - cachedPadding) * .5f; BoundingBox2 box = new BoundingBox2(cachedPosition - halfSize, cachedPosition + halfSize); if (maskingBox != null) { _textBoard.Draw(box, maskingBox.Value, HudSpace.PlaneToWorldRef); } else { _textBoard.Draw(box, CroppedBox.defaultMask, HudSpace.PlaneToWorldRef); } }
public Glyph(Material atlas, Vector2 size, Vector2 origin, float aw, float lsb) { advanceWidth = aw; leftSideBearing = lsb; matFrame = new MaterialFrame() { Material = new Material(atlas.TextureID, atlas.size, origin, size), Alignment = MaterialAlignment.FitHorizontal, }; Vector2 bbSize = matFrame.Material.size; texCoords = matFrame.GetMaterialAlignment(bbSize.X / bbSize.Y); MatFrame = matFrame; }
public BoundingBox2 AppendTestSprite(TestBlock monitorBlock) { BoundingBox2 box = new BoundingBox2(Cursor, Cursor); //SpriteMaker m = new SpriteMaker(Surface, Cursor, Scale, FrameCount) //{ // Color = Color, // BGColor = BGColor, //}; //MonitorOption opt; //BoxStyle style; //string type = ""; Cursor.Y += box.Height; return(box); }
public BoundingBox2 GetWorldBounds() { GetBounds().GetCorners(_corners); for (int i = 0; i < 4; i++) { _corners[i] = Vector2.Transform(_corners[i], WorldTransform); } BoundingBox2 bounds = new BoundingBox2(_corners[0], _corners[0]); for (int i = 1; i < 4; i++) { bounds.Extend(_corners[i]); } return(bounds); }
public void PushScissorRectangle(Rectangle rectangle) { if (_transformMatrix != Matrix.Identity) { BoundingBox2 b = new BoundingBox2(rectangle); b.Min = Vector2.Transform(b.Min, _transformMatrix); b.Max = Vector2.Transform(b.Max, _transformMatrix); rectangle = b.ToRectangle(); } Viewport v = _spriteBatch.GraphicsDevice.Viewport; rectangle.X += v.X; rectangle.Y += v.Y; _scissorRectangleBuffer[_scissorRectangleCount] = _spriteBatch.GraphicsDevice.ScissorRectangle; _scissorRectangleCount++; _spriteBatch.GraphicsDevice.ScissorRectangle = rectangle; }
protected override void Draw() { if (ShowCaret) { bool isCharVisible = text.Count == 0 || text[0].Count == 0; CaretIndex = ClampIndex(CaretIndex); // If line visible if ((text.Count > 0 && text[0].Count > 0) && (CaretIndex.X >= text.VisibleLineRange.X && CaretIndex.X <= text.VisibleLineRange.Y)) { // Damned special cases Vector2I index = Vector2I.Max(CaretIndex, Vector2I.Zero); // Calculate visibilty on line IRichChar ch = text[index]; Vector2 size = ch.Size, pos = ch.Offset + text.TextOffset; BoundingBox2 textBounds = BoundingBox2.CreateFromHalfExtent(Vector2.Zero, .5f * text.Size), charBounds = BoundingBox2.CreateFromHalfExtent(pos, .5f * Vector2.Max(size, new Vector2(8f))); if (textBounds.Contains(charBounds) != ContainmentType.Disjoint) { isCharVisible = true; } } if (blink & isCharVisible) { UpdateOffset(); base.Draw(); } if (blinkTimer.ElapsedMilliseconds > 500) { blink = !blink; blinkTimer.Restart(); } } }
/// <summary> /// Update selection and highlight based on user input /// </summary> protected virtual void UpdateSelectionInput(Vector2 cursorPos) { HighlightIndex = MathHelper.Clamp(HighlightIndex, 0, Entries.Count - 1); // If using arrow keys to scroll, adjust the scrollbox's start/end indices if (KeyboardScroll) { // If using arrow keys to scroll, then the focus should follow the highlight FocusIndex = HighlightIndex; } else // Otherwise, focus index should follow the selection { FocusIndex = SelectionIndex; } // Keyboard input if (HasFocus) { if (SharedBinds.UpArrow.IsNewPressed || SharedBinds.UpArrow.IsPressedAndHeld) { HighlightIndex--; KeyboardScroll = true; lastCursorPos = cursorPos; } else if (SharedBinds.DownArrow.IsNewPressed || SharedBinds.DownArrow.IsPressedAndHeld) { HighlightIndex++; KeyboardScroll = true; lastCursorPos = cursorPos; } } else { KeyboardScroll = false; lastCursorPos = new Vector2(float.MinValue); } bool listMousedOver = false; // Mouse input if (IsMousedOver) { // If the user moves the cursor after using arrow keys for selection then moves the // mouse, disable arrow selection if ((cursorPos - lastCursorPos).LengthSquared() > 4f) { KeyboardScroll = false; } if (!KeyboardScroll) { Vector2 cursorOffset = cursorPos - ListPos; BoundingBox2 listBounds = new BoundingBox2(-ListSize * .5f, ListSize * .5f); // If the list is moused over, then calculate highlight index based on cursor position. if (listBounds.Contains(cursorOffset) == ContainmentType.Contains) { int newIndex = ListRange.X; for (int i = ListRange.X; i <= ListRange.Y; i++) { if (Entries[i].Enabled) { TElement element = Entries[i].Element; Vector2 halfSize = element.Size * .5f, offset = element.Offset; BoundingBox2 bb = new BoundingBox2(offset - halfSize, offset + halfSize); if (bb.Contains(cursorOffset) == ContainmentType.Contains) { break; } } newIndex++; } if (newIndex >= 0 && newIndex < Entries.Count) { HighlightIndex = newIndex; listMousedOver = true; } } } } if ((listMousedOver && SharedBinds.LeftButton.IsNewPressed) || (HasFocus && SharedBinds.Space.IsNewPressed)) { SelectionIndex = HighlightIndex; SelectionChanged?.Invoke(this, EventArgs.Empty); KeyboardScroll = false; } HighlightIndex = MathHelper.Clamp(HighlightIndex, 0, Entries.Count - 1); }
public void DrawRectangle(BoundingBox2 boundingBox, Vector2 cornerRadius, PrimitiveBrush brush) { int startIndex = _vertexCount; float bi = -1; Vector2 half = (boundingBox.Max - boundingBox.Min) * 0.5f; if (brush.BorderThickness == 0) { brush.BorderAlignment = BorderAlignment.Inner; brush.BorderThickness = Math.Min(half.X, half.Y); brush.BorderColor = brush.FillColor; bi = 1; } _borderColor = brush.BorderColor; _fillColor = brush.FillColor; bi *= brush.BorderThickness * _edgeSoftness; if (cornerRadius.X < 0) cornerRadius.X = 0; if (cornerRadius.Y < 0) cornerRadius.Y = 0; if (cornerRadius.X > half.X) cornerRadius.X = half.X; if (cornerRadius.Y > half.Y) cornerRadius.Y = half.Y; boundingBox.Min += cornerRadius; boundingBox.Max -= cornerRadius; boundingBox.GetCorners(_corners); // Setting the inner and outer border radius based on BorderAlignment. Vector2 innerRadius = cornerRadius; Vector2 outerRadius = cornerRadius; if (brush.BorderAlignment == BorderAlignment.Inner) { innerRadius -= new Vector2(brush.BorderThickness); } else if (brush.BorderAlignment == BorderAlignment.Outer) { outerRadius += new Vector2(brush.BorderThickness); } else { innerRadius -= new Vector2(brush.BorderThickness * 0.5f); outerRadius += new Vector2(brush.BorderThickness * 0.5f); } if (innerRadius.X < 0 && cornerRadius.X > half.X) innerRadius.X = 0; if (innerRadius.Y < 0 && cornerRadius.Y > half.Y) innerRadius.Y = 0; //int lod = (int)outerRadius; //int lod = (int)(2 * MathHelper.Pi * (cornerRadius.X + cornerRadius.Y) / 16); int lod = 16; if (Math.Min(cornerRadius.X, cornerRadius.Y) == 0) { BoundingBox2 innerBox = new BoundingBox2(boundingBox.Min - innerRadius, boundingBox.Max + innerRadius); BoundingBox2 outerBox = new BoundingBox2(boundingBox.Min - outerRadius, boundingBox.Max + outerRadius); _edge = bi; innerBox.GetCorners(_corners); PushVerticesForRectangle(_corners); _edge = 0; outerBox.GetCorners(_corners); PushVerticesForRectangle(_corners); if (_fillColor.A > 0) PushIndicesForRectangle(startIndex + 3, startIndex + 0, startIndex + 2, startIndex + 1); PushIndicesForStrip(startIndex, startIndex + 4, 4, true); } else if (Math.Min(innerRadius.X, innerRadius.Y) <= 0) { //_borderColor = Color.GreenYellow; _edge = bi; // Center rectangle. PushVerticesForRectangle(_corners); if (_fillColor.A > 0) PushIndicesForRectangle(startIndex + 3, startIndex, startIndex + 2, startIndex + 1); _edge = 0; // Create border. PushVerticesAndIndicesForBorder(startIndex, _corners, outerRadius, lod, true); // Reposition inner corner. _vertexBuffer[startIndex + 0].Position.X -= innerRadius.X; _vertexBuffer[startIndex + 0].Position.Y -= innerRadius.Y; _vertexBuffer[startIndex + 1].Position.X += innerRadius.X; _vertexBuffer[startIndex + 1].Position.Y -= innerRadius.Y; _vertexBuffer[startIndex + 2].Position.X += innerRadius.X; _vertexBuffer[startIndex + 2].Position.Y += innerRadius.Y; _vertexBuffer[startIndex + 3].Position.X -= innerRadius.X; _vertexBuffer[startIndex + 3].Position.Y += innerRadius.Y; } // If the inner radius is greater than zero, we need to create a inner and outer border. else if (Math.Min(innerRadius.X, innerRadius.Y) > 0) { //_borderColor = Color.Orange; _edge = bi; // Center rectangle. if (_fillColor.A > 0) { PushVerticesForRectangle(_corners); PushIndicesForRectangle(startIndex + 3, startIndex, startIndex + 2, startIndex + 1); } int innerStartIndex = _vertexCount; // Create inner border. PushVerticesAndIndicesForBorder(startIndex, _corners, innerRadius, lod, _fillColor.A > 0); _edge = 0; int outerStartIndex = _vertexCount; // Create outer border. PushVerticesForCircle(_corners[0], outerRadius, -MathHelper.Pi, -MathHelper.PiOver2, lod); PushVerticesForCircle(_corners[1], outerRadius, -MathHelper.PiOver2, 0, lod); PushVerticesForCircle(_corners[2], outerRadius, 0, MathHelper.PiOver2, lod); PushVerticesForCircle(_corners[3], outerRadius, MathHelper.PiOver2, MathHelper.Pi, lod); PushIndicesForStrip(innerStartIndex, outerStartIndex, lod * 4 + 4, true); } }
public BoxConstraint(Verlet target, BoundingBox2 bounds) { Target = target; Bounds = bounds; }
public override bool HitTest(Vector2 position) { if (IsVisible && Texture != null) { Vector2 localPosition = Vector2.Transform(position, Matrix.Invert(WorldTransform)); Vector2 textureCoordinate = localPosition + Origin; BoundingBox2 textureBox = new BoundingBox2(Vector2.Zero, new Vector2(Texture.Width, Texture.Height)); Rectangle r = textureBox.Intersection(new BoundingBox2(Rectangle)).ToRectangle(); int x = (int)textureCoordinate.X; int y = (int)textureCoordinate.Y; // TODO: Optimize this! if (x >= 0 && y >= 0 && x < r.Width && y < r.Height) { int[] data = new int[r.Width * r.Height]; Texture.GetData(0, r, data, 0, data.Length); if (data[x + y * r.Width] != 0) return true; } } return false; }