Skip to content

Commit

Permalink
i want a raise. wip lyric stuff i cant be bothered to complete rn
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Nov 11, 2024
1 parent d2ea42c commit 52a24c5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ class MyGradientSpan(val gradientWidth: Float, color: Int, highlightColor: Int)
val ourProgress = if (lineOffsets[o + 4] == -1) 1f - ourProgressLtr else ourProgressLtr
shader.setLocalMatrix(matrix.apply {
reset()
//val overhangToRemove = max(0f, min(((lineOffsets[o + 1] + gradientWidth) * ourProgress) - lineOffsets[o + 1], gradientWidth - 1))
val overhangToRemove = gradientWidth - 1f
postScale((1f / gradientWidth) * (gradientWidth - overhangToRemove), 1f)
if (lineOffsets[o + 4] == -1) postRotate(180f, gradientWidth / 2f, 1f)
postTranslate(preOffsetFromLeft + (lineOffsets[o + 1] + gradientWidth * 2) * ourProgress
- gradientWidth * 2f, 0f)
postTranslate(preOffsetFromLeft + lineOffsets[o + 1] * ourProgress, 0f)
postTranslate(gradientWidth * (ourProgress - 1f), 0f)
})
tp.shader = shader
lineCount++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ class NewLyricsView(context: Context, attrs: AttributeSet) : View(context, attrs
spForRender!!.forEachIndexed { i, it ->
var spanEnd = -1
var spanStartGradient = -1
var realGradientStart = -1
var realGradientEnd = -1
var wordIdx: Int? = null
var gradientProgress = Float.NEGATIVE_INFINITY
val firstTs = lines?.get(i)?.lyric?.start ?: ULong.MIN_VALUE
Expand Down Expand Up @@ -305,8 +307,24 @@ class NewLyricsView(context: Context, attrs: AttributeSet) : View(context, attrs
firstTs.toFloat() - timeOffsetForUse), gradientEndTime - 1f)
gradientProgress = lerpInv(gradientStartTime, gradientEndTime,
posForRender.toFloat())
if (gradientProgress >= 0f && gradientProgress <= 1f)
spanStartGradient = word.charRange.first // TODO be greedy and eat as much as the line as can be eaten (is in same text direction). to fix japanese text moving bug
if (gradientProgress >= 0f && gradientProgress <= 1f) {
spanStartGradient = word.charRange.first
// be greedy and eat as much as the line as can be eaten (text that is
// same line + is in same text direction). improves font rendering for
// japanese if font rendering renders whole text in one pass
val wordStartLine = it.layout.getLineForOffset(word.charRange.first)
val wordEndLine = it.layout.getLineForOffset(word.charRange.endInclusive)
val firstCharOnStartLine = it.layout.getLineStart(wordStartLine)
val lastCharOnEndLineExcl = it.layout.getLineEnd(wordEndLine)
realGradientStart = lines[i].lyric.words?.lastOrNull {
it.charRange.first >= firstCharOnStartLine && it.charRange.last <
word.charRange.first && it.isRtl != word.isRtl }?.charRange
?.last?.plus(1) ?: firstCharOnStartLine
realGradientEnd = lines[i].lyric.words?.firstOrNull {
it.charRange.first > word.charRange.last && it.charRange.last <
lastCharOnEndLineExcl && it.isRtl != word.isRtl }?.charRange
?.first ?: lastCharOnEndLineExcl
}
}
} else {
spanEnd = it.text.length
Expand All @@ -322,7 +340,7 @@ class NewLyricsView(context: Context, attrs: AttributeSet) : View(context, attrs
}
if (gradientProgress >= -.1f && gradientProgress <= 1f)
animating = true
val spanEndWithoutGradient = if (spanStartGradient == -1) spanEnd else spanStartGradient
val spanEndWithoutGradient = if (realGradientStart == -1) spanEnd else realGradientStart
val inColorAnim = (scaleInProgress >= 0f && scaleInProgress <= 1f && gradientProgress ==
Float.NEGATIVE_INFINITY) || (scaleOutProgress >= 0f && scaleOutProgress <= 1f)
var colorSpan = it.text.getSpans<MyForegroundColorSpan>().firstOrNull()
Expand Down Expand Up @@ -404,7 +422,7 @@ class NewLyricsView(context: Context, attrs: AttributeSet) : View(context, attrs
else -> makeGradientSpan()
}
}
it.text.setSpan(gradientSpan, spanStartGradient, spanEnd,
it.text.setSpan(gradientSpan, realGradientStart, realGradientEnd,
Spanned.SPAN_INCLUSIVE_INCLUSIVE)
}
}
Expand Down

0 comments on commit 52a24c5

Please sign in to comment.