From fdb05718608565282b71ef3005f37b41ab7150e6 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 10 Apr 2024 20:45:16 +0200 Subject: [PATCH] xml docs and cleanup --- MLEM.Ui/Elements/Paragraph.cs | 4 ++-- MLEM.Ui/Style/UiStyle.cs | 9 +++++++++ MLEM/Font/GenericFont.cs | 30 ++++++++++++++++++++++++++++++ MLEM/Formatting/Token.cs | 19 +++++++++++++++---- MLEM/Formatting/TokenizedString.cs | 1 + Sandbox/GameImpl.cs | 4 ++-- 6 files changed, 59 insertions(+), 8 deletions(-) diff --git a/MLEM.Ui/Elements/Paragraph.cs b/MLEM.Ui/Elements/Paragraph.cs index 80a3245..3550bde 100644 --- a/MLEM.Ui/Elements/Paragraph.cs +++ b/MLEM.Ui/Elements/Paragraph.cs @@ -141,12 +141,12 @@ namespace MLEM.Ui.Elements { } /// /// The inclusive index in this paragraph's to start drawing at. - /// This value is passed to . + /// This value is passed to . /// public int? DrawStartIndex; /// /// The exclusive index in this paragraph's to stop drawing at. - /// This value is passed to . + /// This value is passed to . /// public int? DrawEndIndex; diff --git a/MLEM.Ui/Style/UiStyle.cs b/MLEM.Ui/Style/UiStyle.cs index 9fad332..e9f2cc5 100644 --- a/MLEM.Ui/Style/UiStyle.cs +++ b/MLEM.Ui/Style/UiStyle.cs @@ -166,8 +166,17 @@ namespace MLEM.Ui.Style { /// The offset of the element's top center coordinate from the bottom center of the element snapped to when is true. /// public Vector2 TooltipAutoNavOffset = new Vector2(0, 8); + /// + /// The auto-nav anchor that is used or tooltips by default. + /// public Anchor TooltipAutoNavAnchor = Anchor.BottomCenter; + /// + /// The mouse anchor that is used for tooltips by default. + /// public Anchor TooltipMouseAnchor = Anchor.BottomRight; + /// + /// Whether tooltips should use auto-nav rendering behavior for tooltips even when using a mouse by default. + /// public bool TooltipUseAutoNavBehaviorForMouse; /// /// The color that the text of a should have diff --git a/MLEM/Font/GenericFont.cs b/MLEM/Font/GenericFont.cs index 711fc40..fe96299 100644 --- a/MLEM/Font/GenericFont.cs +++ b/MLEM/Font/GenericFont.cs @@ -176,6 +176,16 @@ namespace MLEM.Font { return GenericFont.SplitStringSeparate(Enumerable.Repeat(new DecoratedCodePointSource(new CodePointSource(text), this, 0), 1), width, scale).First(); } + /// + /// Calculates a transformation matrix for drawing a string with the given data. + /// + /// The position to draw at. + /// The rotation to draw with. + /// The origin to subtract from the position. + /// The scale to draw with. + /// The flipping to draw with. + /// The size of the string, which is only used when is not . + /// A transformation matrix. public Matrix CalculateStringTransform(Vector2 position, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, Vector2 flipSize) { var (flipX, flipY) = (0F, 0F); var flippedV = (effects & SpriteEffects.FlipVertically) != 0; @@ -210,6 +220,13 @@ namespace MLEM.Font { return trans; } + /// + /// Moves the passed based on the given flipping data. + /// + /// The position to move. + /// The flipping to move based on. + /// The size of the object to move, which is only used when is not . + /// The moved position. public Vector2 MoveFlipped(Vector2 charPos, SpriteEffects effects, Vector2 charSize) { if ((effects & SpriteEffects.FlipHorizontally) != 0) charPos.X += charSize.X; @@ -218,6 +235,19 @@ namespace MLEM.Font { return charPos; } + /// + /// Transforms the position of a single character to draw. + /// In general, it is efficient to calculate the transformation matrix once at the start (using ) and to then apply flipping data for each character individually (using ). + /// + /// The position that the string is drawn at. + /// The offset from the that the current character is drawn at. + /// The rotation to draw with. + /// The origin to subtract from the position. + /// The scale to draw with. + /// The flipping to draw with. + /// The size of the string, which is only used when is not . + /// The size of the current character, which is only used when is not . + /// The transformed final draw position. public Vector2 TransformSingleCharacter(Vector2 stringPos, Vector2 charPosOffset, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, Vector2 stringSize, Vector2 charSize) { return Vector2.Transform(this.MoveFlipped(charPosOffset, effects, charSize), this.CalculateStringTransform(stringPos, rotation, origin, scale, effects, stringSize)); } diff --git a/MLEM/Formatting/Token.cs b/MLEM/Formatting/Token.cs index ccca36d..75830d4 100644 --- a/MLEM/Formatting/Token.cs +++ b/MLEM/Formatting/Token.cs @@ -104,11 +104,16 @@ namespace MLEM.Formatting { /// /// The time /// The sprite batch to use - /// The position to draw the token at + /// The position the string is drawn at. + /// The offset from the that the current character is drawn at. /// The font to use to draw /// The color to draw with - /// The scale to draw at + /// The scale to draw with. + /// The rotation to draw with. + /// The origin to subtract from the position. /// The depth to draw at + /// The flipping to draw with. + /// The size of the string. public void DrawSelf(GameTime time, SpriteBatch batch, Vector2 stringPos, Vector2 charPosOffset, GenericFont font, Color color, Vector2 scale, float rotation, Vector2 origin, float depth, SpriteEffects effects, Vector2 stringSize) { foreach (var code in this.AppliedCodes) code.DrawSelf(time, batch, this, stringPos, charPosOffset, font, color, scale, rotation, origin, depth, effects, stringSize); @@ -122,11 +127,17 @@ namespace MLEM.Formatting { /// The code point of the character to draw /// The string representation of the character to draw /// The index within this token that the character is at - /// The position to draw the token at + /// The position the string is drawn at. + /// The offset from the that the current character is drawn at. /// The font to use to draw /// The color to draw with - /// The scale to draw at + /// The scale to draw with. + /// The rotation to draw with. + /// The origin to subtract from the position. /// The depth to draw at + /// The flipping to draw with. + /// The size of the string. + /// The size of the current character. public void DrawCharacter(GameTime time, SpriteBatch batch, int codePoint, string character, int indexInToken, Vector2 stringPos, Vector2 charPosOffset, GenericFont font, Color color, Vector2 scale, float rotation, Vector2 origin, float depth, SpriteEffects effects, Vector2 stringSize, Vector2 charSize) { foreach (var code in this.AppliedCodes) { if (code.DrawCharacter(time, batch, codePoint, character, this, indexInToken, stringPos, ref charPosOffset, font, ref color, ref scale, ref rotation, ref origin, depth, effects, stringSize, charSize)) diff --git a/MLEM/Formatting/TokenizedString.cs b/MLEM/Formatting/TokenizedString.cs index 2729060..e600676 100644 --- a/MLEM/Formatting/TokenizedString.cs +++ b/MLEM/Formatting/TokenizedString.cs @@ -180,6 +180,7 @@ namespace MLEM.Formatting { return null; } + /// public void Draw(GameTime time, SpriteBatch batch, Vector2 pos, GenericFont font, Color color, float scale, float depth, float rotation = 0, Vector2 origin = default, SpriteEffects effects = SpriteEffects.None, int? startIndex = null, int? endIndex = null) { this.Draw(time, batch, pos, font, color, new Vector2(scale), depth, rotation, origin, effects, startIndex, endIndex); } diff --git a/Sandbox/GameImpl.cs b/Sandbox/GameImpl.cs index 6bd56d5..070b216 100644 --- a/Sandbox/GameImpl.cs +++ b/Sandbox/GameImpl.cs @@ -271,7 +271,7 @@ public class GameImpl : MlemGame { var formatted = formatter.Tokenize(genericFont, testString); this.OnDraw += (_, time) => { - if (MlemGame.Input.IsKeyPressed(Keys.I)) { + if (MlemGame.Input.IsPressed(Keys.I)) { index++; if (index == 1) { scale = 2; @@ -289,7 +289,7 @@ public class GameImpl : MlemGame { } this.SpriteBatch.Begin(); - if (MlemGame.Input.IsKeyDown(Keys.LeftShift)) { + if (MlemGame.Input.IsDown(Keys.LeftShift)) { this.SpriteBatch.DrawString(regularFont, testString, pos, Color.Red, rotation, origin, scale, effects, 0); } else { formatted.Draw(time, this.SpriteBatch, pos, genericFont, Color.Green, scale, 0, rotation, origin, effects);