Browse Source

Merge pull request #993 from ssssobek/dev

Add blurred background option for subtitles
pull/973/head
chaos 1 year ago committed by GitHub
parent
commit
3d333dcb03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      src/assets/locales/en.json
  2. 1
      src/assets/locales/pl.json
  3. 8
      src/components/player/atoms/settings/CaptionSettingsView.tsx
  4. 4
      src/components/player/base/SubtitleView.tsx
  5. 10
      src/pages/parts/settings/CaptionsPart.tsx
  6. 8
      src/stores/subtitles/index.ts

1
src/assets/locales/en.json

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

1
src/assets/locales/pl.json

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

8
src/components/player/atoms/settings/CaptionSettingsView.tsx

@ -262,6 +262,14 @@ export function CaptionSettingsView({ id }: { id: string }) { @@ -262,6 +262,14 @@ export function CaptionSettingsView({ id }: { id: string }) {
value={styling.backgroundOpacity * 100}
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
label={t("settings.subtitles.textSizeLabel")}
max={200}

4
src/components/player/base/SubtitleView.tsx

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

10
src/pages/parts/settings/CaptionsPart.tsx

@ -92,6 +92,16 @@ export function CaptionsPart(props: { @@ -92,6 +92,16 @@ export function CaptionsPart(props: {
value={props.styling.backgroundOpacity * 100}
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
label={t("settings.subtitles.textSizeLabel")}
max={200}

8
src/stores/subtitles/index.ts

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

Loading…
Cancel
Save