Skip to content

Commit

Permalink
feat: subtitles scale
Browse files Browse the repository at this point in the history
closes #78
  • Loading branch information
abdallahmehiz committed Sep 13, 2024
1 parent 4482f22 commit 1b6af37
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SubtitlesPreferences(preferenceStore: PreferenceStore) {
val fontsFolder = preferenceStore.getString("sub_fonts_folder")
val font = preferenceStore.getString("sub_font", "Sans Serif")
val fontSize = preferenceStore.getInt("sub_font_size", 55)
val subScale = preferenceStore.getFloat("sub_scale", 1f)
val borderSize = preferenceStore.getInt("sub_border_size", 3)
val bold = preferenceStore.getBoolean("sub_bold")
val italic = preferenceStore.getBoolean("sub_italic")
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/live/mehiz/mpvkt/ui/player/MPVView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,6 @@ class MPVView(context: Context, attributes: AttributeSet) : BaseMPVView(context,
MPVLib.setOptionString("sub-border-style", subtitlesPreferences.borderStyle.get().value)
MPVLib.setOptionString("sub-shadow-offset", subtitlesPreferences.shadowOffset.get().toString())
MPVLib.setOptionString("sub-pos", subtitlesPreferences.subPos.get().toString())
MPVLib.setOptionString("sub-scale", subtitlesPreferences.subScale.get().toString())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,11 @@ fun GestureHandler(modifier: Modifier = Modifier) {
if (position >= duration && dragAmount > 0) return@detectHorizontalDragGestures
calculateNewHorizontalGestureValue(startingPosition, startingX, change.position.x, 0.15f).let {
viewModel.gestureSeekAmount.update { _ ->
Pair(startingPosition, (it - startingPosition)
.coerceIn(0 - startingPosition, (duration - startingPosition).toInt()))
Pair(
startingPosition,
(it - startingPosition)
.coerceIn(0 - startingPosition, (duration - startingPosition).toInt())
)
}
viewModel.seekTo(it, preciseSeeking)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.widthIn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AlignVerticalCenter
import androidx.compose.material.icons.filled.EditOff
import androidx.compose.material.icons.filled.FormatSize
import androidx.compose.material.icons.filled.Tune
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
Expand All @@ -27,6 +28,7 @@ import live.mehiz.mpvkt.preferences.SubtitlesPreferences
import live.mehiz.mpvkt.preferences.preference.deleteAndGet
import live.mehiz.mpvkt.presentation.components.ExpandableCard
import live.mehiz.mpvkt.presentation.components.SliderItem
import live.mehiz.mpvkt.ui.player.controls.components.sheets.toFixed
import live.mehiz.mpvkt.ui.theme.spacing
import me.zhanghai.compose.preference.ProvidePreferenceLocals
import me.zhanghai.compose.preference.SwitchPreference
Expand Down Expand Up @@ -62,9 +64,29 @@ fun SubtitlesMiscellaneousCard(modifier: Modifier = Modifier) {
},
{ Text(stringResource(R.string.player_sheets_sub_override_ass)) },
)
var subScale by remember {
mutableStateOf(MPVLib.getPropertyDouble("sub-scale").toFloat())
}
var subPos by remember {
mutableStateOf(MPVLib.getPropertyInt("sub-pos"))
}
SliderItem(
label = stringResource(R.string.player_sheets_sub_scale),
value = subScale,
valueText = subScale.toFixed(2).toString(),
onChange = {
subScale = it
preferences.subScale.set(it)
MPVLib.setPropertyDouble("sub-scale", it.toDouble())
},
max = 5f,
icon = {
Icon(
Icons.Default.FormatSize,
null,
)
},
)
SliderItem(
label = stringResource(R.string.player_sheets_sub_position),
value = subPos,
Expand All @@ -80,20 +102,24 @@ fun SubtitlesMiscellaneousCard(modifier: Modifier = Modifier) {
Icons.Default.AlignVerticalCenter,
null,
)
}
},
)
Row(
modifier = Modifier
.fillMaxWidth()
.padding(end = MaterialTheme.spacing.medium, bottom = MaterialTheme.spacing.medium),
horizontalArrangement = Arrangement.End
horizontalArrangement = Arrangement.End,
) {
TextButton(
onClick = {
preferences.subPos.deleteAndGet().let {
subPos = it
MPVLib.setPropertyInt("sub-pos", it)
}
preferences.subScale.deleteAndGet().let {
subScale = it
MPVLib.setPropertyDouble("sub-scale", it.toDouble())
}
preferences.overrideAssSubs.deleteAndGet().let { overrideAssSubs = it }
MPVLib.setPropertyString("sub-ass-override", "scale") // mpv's default is 'scale'
},
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<string name="player_sheets_sub_color_blue">Blue</string>
<string name="player_sheets_sub_color_alpha">Alpha</string>
<string name="player_sheets_sub_override_ass">Override ASS/SSA subtitles</string>
<string name="player_sheets_sub_scale">Scale</string>
<string name="player_sheets_sub_position">Position</string>
<string name="player_sheets_sub_typography_card_title">Typography</string>
<string name="player_sheets_sub_typography_font">Font</string>
Expand Down

0 comments on commit 1b6af37

Please sign in to comment.