mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-12-24 17:29:23 +01:00
xml docs and cleanup
This commit is contained in:
parent
76eb5d0679
commit
fdb0571860
6 changed files with 59 additions and 8 deletions
|
@ -141,12 +141,12 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
/// <summary>
|
||||
/// The inclusive index in this paragraph's <see cref="Text"/> to start drawing at.
|
||||
/// This value is passed to <see cref="TokenizedString.Draw"/>.
|
||||
/// This value is passed to <see cref="TokenizedString.Draw(Microsoft.Xna.Framework.GameTime,Microsoft.Xna.Framework.Graphics.SpriteBatch,Microsoft.Xna.Framework.Vector2,MLEM.Font.GenericFont,Microsoft.Xna.Framework.Color,Vector2,float,float,Microsoft.Xna.Framework.Vector2,Microsoft.Xna.Framework.Graphics.SpriteEffects,System.Nullable{int},System.Nullable{int})"/>.
|
||||
/// </summary>
|
||||
public int? DrawStartIndex;
|
||||
/// <summary>
|
||||
/// The exclusive index in this paragraph's <see cref="Text"/> to stop drawing at.
|
||||
/// This value is passed to <see cref="TokenizedString.Draw"/>.
|
||||
/// This value is passed to <see cref="TokenizedString.Draw(Microsoft.Xna.Framework.GameTime,Microsoft.Xna.Framework.Graphics.SpriteBatch,Microsoft.Xna.Framework.Vector2,MLEM.Font.GenericFont,Microsoft.Xna.Framework.Color,Vector2,float,float,Microsoft.Xna.Framework.Vector2,Microsoft.Xna.Framework.Graphics.SpriteEffects,System.Nullable{int},System.Nullable{int})"/>.
|
||||
/// </summary>
|
||||
public int? DrawEndIndex;
|
||||
|
||||
|
|
|
@ -166,8 +166,17 @@ namespace MLEM.Ui.Style {
|
|||
/// The offset of the <see cref="Tooltip"/> element's top center coordinate from the bottom center of the element snapped to when <see cref="Tooltip.DisplayInAutoNavMode"/> is true.
|
||||
/// </summary>
|
||||
public Vector2 TooltipAutoNavOffset = new Vector2(0, 8);
|
||||
/// <summary>
|
||||
/// The auto-nav anchor that is used or tooltips by default.
|
||||
/// </summary>
|
||||
public Anchor TooltipAutoNavAnchor = Anchor.BottomCenter;
|
||||
/// <summary>
|
||||
/// The mouse anchor that is used for tooltips by default.
|
||||
/// </summary>
|
||||
public Anchor TooltipMouseAnchor = Anchor.BottomRight;
|
||||
/// <summary>
|
||||
/// Whether tooltips should use auto-nav rendering behavior for tooltips even when using a mouse by default.
|
||||
/// </summary>
|
||||
public bool TooltipUseAutoNavBehaviorForMouse;
|
||||
/// <summary>
|
||||
/// The color that the text of a <see cref="Tooltip"/> should have
|
||||
|
|
|
@ -176,6 +176,16 @@ namespace MLEM.Font {
|
|||
return GenericFont.SplitStringSeparate(Enumerable.Repeat(new DecoratedCodePointSource(new CodePointSource(text), this, 0), 1), width, scale).First();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates a transformation matrix for drawing a string with the given data.
|
||||
/// </summary>
|
||||
/// <param name="position">The position to draw at.</param>
|
||||
/// <param name="rotation">The rotation to draw with.</param>
|
||||
/// <param name="origin">The origin to subtract from the position.</param>
|
||||
/// <param name="scale">The scale to draw with.</param>
|
||||
/// <param name="effects">The flipping to draw with.</param>
|
||||
/// <param name="flipSize">The size of the string, which is only used when <paramref name="effects"/> is not <see cref="SpriteEffects.None"/>.</param>
|
||||
/// <returns>A transformation matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the passed <paramref name="charPos"/> based on the given flipping data.
|
||||
/// </summary>
|
||||
/// <param name="charPos">The position to move.</param>
|
||||
/// <param name="effects">The flipping to move based on.</param>
|
||||
/// <param name="charSize">The size of the object to move, which is only used when <paramref name="effects"/> is not <see cref="SpriteEffects.None"/>.</param>
|
||||
/// <returns>The moved position.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the position of a single character to draw.
|
||||
/// In general, it is efficient to calculate the transformation matrix once at the start (using <see cref="CalculateStringTransform"/>) and to then apply flipping data for each character individually (using <see cref="MoveFlipped"/>).
|
||||
/// </summary>
|
||||
/// <param name="stringPos">The position that the string is drawn at.</param>
|
||||
/// <param name="charPosOffset">The offset from the <paramref name="stringPos"/> that the current character is drawn at.</param>
|
||||
/// <param name="rotation">The rotation to draw with.</param>
|
||||
/// <param name="origin">The origin to subtract from the position.</param>
|
||||
/// <param name="scale">The scale to draw with.</param>
|
||||
/// <param name="effects">The flipping to draw with.</param>
|
||||
/// <param name="stringSize">The size of the string, which is only used when <paramref name="effects"/> is not <see cref="SpriteEffects.None"/>.</param>
|
||||
/// <param name="charSize">The size of the current character, which is only used when <paramref name="effects"/> is not <see cref="SpriteEffects.None"/>.</param>
|
||||
/// <returns>The transformed final draw position.</returns>
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -104,11 +104,16 @@ namespace MLEM.Formatting {
|
|||
/// </summary>
|
||||
/// <param name="time">The time</param>
|
||||
/// <param name="batch">The sprite batch to use</param>
|
||||
/// <param name="pos">The position to draw the token at</param>
|
||||
/// <param name="stringPos">The position the string is drawn at.</param>
|
||||
/// <param name="charPosOffset">The offset from the <paramref name="stringPos"/> that the current character is drawn at.</param>
|
||||
/// <param name="font">The font to use to draw</param>
|
||||
/// <param name="color">The color to draw with</param>
|
||||
/// <param name="scale">The scale to draw at</param>
|
||||
/// <param name="scale">The scale to draw with.</param>
|
||||
/// <param name="rotation">The rotation to draw with.</param>
|
||||
/// <param name="origin">The origin to subtract from the position.</param>
|
||||
/// <param name="depth">The depth to draw at</param>
|
||||
/// <param name="effects">The flipping to draw with.</param>
|
||||
/// <param name="stringSize">The size of the string.</param>
|
||||
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 {
|
|||
/// <param name="codePoint">The code point of the character to draw</param>
|
||||
/// <param name="character">The string representation of the character to draw</param>
|
||||
/// <param name="indexInToken">The index within this token that the character is at</param>
|
||||
/// <param name="pos">The position to draw the token at</param>
|
||||
/// <param name="stringPos">The position the string is drawn at.</param>
|
||||
/// <param name="charPosOffset">The offset from the <paramref name="stringPos"/> that the current character is drawn at.</param>
|
||||
/// <param name="font">The font to use to draw</param>
|
||||
/// <param name="color">The color to draw with</param>
|
||||
/// <param name="scale">The scale to draw at</param>
|
||||
/// <param name="scale">The scale to draw with.</param>
|
||||
/// <param name="rotation">The rotation to draw with.</param>
|
||||
/// <param name="origin">The origin to subtract from the position.</param>
|
||||
/// <param name="depth">The depth to draw at</param>
|
||||
/// <param name="effects">The flipping to draw with.</param>
|
||||
/// <param name="stringSize">The size of the string.</param>
|
||||
/// <param name="charSize">The size of the current character.</param>
|
||||
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))
|
||||
|
|
|
@ -180,6 +180,7 @@ namespace MLEM.Formatting {
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GenericFont.DrawString(SpriteBatch,string,Vector2,Color,float,Vector2,float,SpriteEffects,float)"/>
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue