/// <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); } } }
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; } }
/// <summary> /// Draws the text board in world space on the XY plane of the matrix, facing in the +Z /// direction. /// </summary> public void Draw(BoundingBox2 box, BoundingBox2 mask, MatrixD[] matrix) { ContainmentType containment; mask.Contains(ref box, out containment); if (containment != ContainmentType.Disjoint) { if (offsetsAreStale) { UpdateOffsets(); } else if (lineRangeIsStale || (endLine == -1 && lines.Count > 0)) { UpdateLineRange(); } if (AutoResize) { _textOffset = Vector2.Zero; } if (updateEvent && (eventTimer.ElapsedTicks / TimeSpan.TicksPerMillisecond) > 500) { TextChanged?.Invoke(); eventTimer.Restart(); updateEvent = false; } BoundingBox2 textMask = box.Intersect(mask); Vector2 offset = box.Center + _textOffset * Scale; IReadOnlyList <Line> lineList = lines.PooledLines; CroppedBox bb = default(CroppedBox); bb.mask = textMask; // Draw glyphs for (int ln = startLine; ln <= endLine && ln < lines.Count; ln++) { Line line = lineList[ln]; for (int ch = 0; ch < line.Count; ch++) { GlyphLocData locData = line.LocData[ch]; Vector2 halfSize = locData.bbSize * Scale * .5f, pos = offset + locData.bbOffset * Scale; bb.bounds = new BoundingBox2(pos - halfSize, pos + halfSize); bb.mask.Value.Contains(ref bb.bounds, out containment); if (containment == ContainmentType.Contains) { line.GlyphBoards[ch].Draw(ref bb, ref matrix[0]); } else if (containment != ContainmentType.Disjoint) { line.GlyphBoards[ch].DrawCroppedTex(ref bb, ref matrix[0]); } } } QuadBoard underlineBoard = QuadBoard.Default; // Draw underlines for (int n = 0; n < underlines.Count; n++) { Vector2 halfSize = underlines[n].size * Scale * .5f, pos = offset + underlines[n].offset * Scale; bb.bounds = new BoundingBox2(pos - halfSize, pos + halfSize); bb.mask.Value.Contains(ref bb.bounds, out containment); underlineBoard.bbColor = underlines[n].color; if (containment == ContainmentType.Contains) { underlineBoard.Draw(ref bb, ref matrix[0]); } else if (containment != ContainmentType.Disjoint) { underlineBoard.DrawCropped(ref bb, ref matrix[0]); } } } }