Merge pull request #993 from ssssobek/dev

Add blurred background option for subtitles
This commit is contained in:
chaos 2024-03-11 01:05:50 +02:00 committed by GitHub
commit 3d333dcb03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 32 additions and 0 deletions

View File

@ -533,6 +533,7 @@
}, },
"subtitles": { "subtitles": {
"backgroundLabel": "Background opacity", "backgroundLabel": "Background opacity",
"backgroundBlurLabel": "Background blur",
"colorLabel": "Color", "colorLabel": "Color",
"previewQuote": "I must not fear. Fear is the mind-killer.", "previewQuote": "I must not fear. Fear is the mind-killer.",
"textSizeLabel": "Text size", "textSizeLabel": "Text size",

View File

@ -525,6 +525,7 @@
}, },
"subtitles": { "subtitles": {
"backgroundLabel": "Krycie tła", "backgroundLabel": "Krycie tła",
"backgroundBlurLabel": "Rozmycie tła",
"colorLabel": "Kolor", "colorLabel": "Kolor",
"previewQuote": "Nie wolno mi się bać. Strach zabija myślenie.", "previewQuote": "Nie wolno mi się bać. Strach zabija myślenie.",
"textSizeLabel": "Rozmiar czcionki", "textSizeLabel": "Rozmiar czcionki",

View File

@ -262,6 +262,14 @@ export function CaptionSettingsView({ id }: { id: string }) {
value={styling.backgroundOpacity * 100} value={styling.backgroundOpacity * 100}
textTransformer={(s) => `${s}%`} textTransformer={(s) => `${s}%`}
/> />
<CaptionSetting
label={t("settings.subtitles.backgroundBlurLabel")}
max={100}
min={0}
onChange={(v) => updateStyling({ backgroundBlur: v / 100 })}
value={styling.backgroundBlur * 100}
textTransformer={(s) => `${s}%`}
/>
<CaptionSetting <CaptionSetting
label={t("settings.subtitles.textSizeLabel")} label={t("settings.subtitles.textSizeLabel")}
max={200} max={200}

View File

@ -55,6 +55,10 @@ export function CaptionCue({
color: styling.color, color: styling.color,
fontSize: `${(1.5 * styling.size).toFixed(2)}em`, fontSize: `${(1.5 * styling.size).toFixed(2)}em`,
backgroundColor: `rgba(0,0,0,${styling.backgroundOpacity.toFixed(2)})`, backgroundColor: `rgba(0,0,0,${styling.backgroundOpacity.toFixed(2)})`,
backdropFilter:
styling.backgroundBlur !== 0
? `blur(${Math.floor(styling.backgroundBlur * 64)}px)`
: "none",
}} }}
> >
<span <span

View File

@ -92,6 +92,16 @@ export function CaptionsPart(props: {
value={props.styling.backgroundOpacity * 100} value={props.styling.backgroundOpacity * 100}
textTransformer={(s) => `${s}%`} textTransformer={(s) => `${s}%`}
/> />
<CaptionSetting
label={t("settings.subtitles.backgroundBlurLabel")}
max={100}
min={0}
onChange={(v) =>
props.setStyling({ ...props.styling, backgroundBlur: v / 100 })
}
value={props.styling.backgroundBlur * 100}
textTransformer={(s) => `${s}%`}
/>
<CaptionSetting <CaptionSetting
label={t("settings.subtitles.textSizeLabel")} label={t("settings.subtitles.textSizeLabel")}
max={200} max={200}

View File

@ -17,6 +17,11 @@ export interface SubtitleStyling {
* background opacity, ranges between 0 and 1 * background opacity, ranges between 0 and 1
*/ */
backgroundOpacity: number; backgroundOpacity: number;
/**
* background blur, ranges between 0 and 1
*/
backgroundBlur: number;
} }
export interface SubtitleStore { export interface SubtitleStore {
@ -51,6 +56,7 @@ export const useSubtitleStore = create(
color: "#ffffff", color: "#ffffff",
backgroundOpacity: 0.5, backgroundOpacity: 0.5,
size: 1, size: 1,
backgroundBlur: 0.5,
}, },
resetSubtitleSpecificSettings() { resetSubtitleSpecificSettings() {
set((s) => { set((s) => {
@ -62,6 +68,8 @@ export const useSubtitleStore = create(
set((s) => { set((s) => {
if (newStyling.backgroundOpacity !== undefined) if (newStyling.backgroundOpacity !== undefined)
s.styling.backgroundOpacity = newStyling.backgroundOpacity; s.styling.backgroundOpacity = newStyling.backgroundOpacity;
if (newStyling.backgroundBlur !== undefined)
s.styling.backgroundBlur = newStyling.backgroundBlur;
if (newStyling.color !== undefined) if (newStyling.color !== undefined)
s.styling.color = newStyling.color.toLowerCase(); s.styling.color = newStyling.color.toLowerCase();
if (newStyling.size !== undefined) if (newStyling.size !== undefined)