Skip to content

Commit

Permalink
Should be gap index.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Aug 16, 2024
1 parent 1aa4435 commit 1980d31
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface IPreviewLyricPositionProvider

int GetCharIndicatorByPosition(float position);

RectangleF GetRectByCharIndicator(int charIndex);
RectangleF GetRectByCharIndicator(int gapIndex);

RectangleF? GetRubyTagByPosition(RubyTag rubyTag);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public RectangleF GetRectByCharIndex(int charIndex)
public int GetCharIndicatorByPosition(float position)
=> previewKaraokeSpriteText.GetCharIndicatorByPosition(position - LyricPosition.X);

public RectangleF GetRectByCharIndicator(int charIndex)
=> previewKaraokeSpriteText.GetRectByCharIndicator(charIndex).Offset(LyricPosition);
public RectangleF GetRectByCharIndicator(int gapIndex)
=> previewKaraokeSpriteText.GetRectByCharIndicator(gapIndex).Offset(LyricPosition);

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,27 @@ float getTriggerPositionByTimeIndex(int charIndex)
}
}

public RectangleF GetRectByCharIndicator(int charIndex)
public RectangleF GetRectByCharIndicator(int gapIndex)
{
if (charIndex < 0 || charIndex > Text.Length)
throw new ArgumentOutOfRangeException(nameof(charIndex));
if (gapIndex < 0 || gapIndex > Text.Length)
throw new ArgumentOutOfRangeException(nameof(gapIndex));

const float min_spacing_width = 1;

if (charIndex == 0)
if (gapIndex == 0)
{
var referenceRectangle = spriteText.GetCharacterDrawRectangle(charIndex);
var referenceRectangle = spriteText.GetCharacterDrawRectangle(gapIndex);
return new RectangleF(referenceRectangle.X - min_spacing_width, referenceRectangle.Y, min_spacing_width, referenceRectangle.Height);
}

if (charIndex == Text.Length)
if (gapIndex == Text.Length)
{
var referenceRectangle = spriteText.GetCharacterDrawRectangle(charIndex - 1);
var referenceRectangle = spriteText.GetCharacterDrawRectangle(gapIndex - 1);
return new RectangleF(referenceRectangle.Right, referenceRectangle.Top, min_spacing_width, referenceRectangle.Height);
}

var leftRectangle = spriteText.GetCharacterDrawRectangle(charIndex - 1);
var rightRectangle = spriteText.GetCharacterDrawRectangle(charIndex);
var leftRectangle = spriteText.GetCharacterDrawRectangle(gapIndex - 1);
var rightRectangle = spriteText.GetCharacterDrawRectangle(gapIndex);
return new RectangleF(leftRectangle.Right, leftRectangle.Top, rightRectangle.X - leftRectangle.Right, leftRectangle.Y);
}

Expand Down

0 comments on commit 1980d31

Please sign in to comment.