Skip to content

Commit 8f27ed7

Browse files
authored
Merge pull request #372 from jfboeve/feature/SubtitlePlugin
Feature/subtitle plugin
2 parents f4e587f + cc634f3 commit 8f27ed7

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

src/Subtitles/SubtitleComponent.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Lightning from '../Lightning'
2222
export default class SubtitleComponent extends Lightning.Component {
2323
static _template() {
2424
return {
25-
visibility: false,
25+
visible: false,
2626
rect: true,
2727
color: 0x90000000,
2828
shader: { type: Lightning.shaders.RoundedRectangle, radius: 5 },
@@ -66,25 +66,43 @@ export default class SubtitleComponent extends Lightning.Component {
6666
}
6767

6868
show() {
69-
this.visibility = true
69+
this.visible = true
7070
}
7171

7272
hide() {
73-
this.visibilty = false
73+
this.visible = false
7474
}
7575

7676
position() {
7777
this.x = this._calculateX(this.xPos)
7878
this.y = this._calculateY(this.yPos)
7979
}
8080

81+
set viewportW(v) {
82+
this._viewportW = v
83+
this.x = this._calculateX(this.xPos)
84+
}
85+
86+
get viewportW() {
87+
return this._viewportW || this.application.finalW
88+
}
89+
90+
set viewportH(v) {
91+
this._viewportH = v
92+
this.y = this._calculateY(this.yPos)
93+
}
94+
95+
get viewportH() {
96+
return this._viewportH || this.application.finalH
97+
}
98+
8199
_calculateX(x) {
82100
if (x === 'center') {
83-
x = (this.application.finalW - this.finalW) / 2
101+
x = (this.viewportW - this.finalW) / 2
84102
} else if (x === 'left') {
85103
x = 60
86104
} else if (x === 'right') {
87-
x = this.application.finalW - this.finalW - 60
105+
x = this.viewportW - this.finalW - 60
88106
}
89107
return x
90108
}
@@ -100,11 +118,11 @@ export default class SubtitleComponent extends Lightning.Component {
100118

101119
_calculateY(y) {
102120
if (y === 'center') {
103-
return (this.application.finalH - this.finalH) / 2
121+
return (this.viewportH - this.finalH) / 2
104122
} else if (y === 'top') {
105123
return 60
106124
} else if (y === 'bottom') {
107-
return this.application.finalH - this.finalH - 60
125+
return this.viewportH - this.finalH - 60
108126
}
109127
return y
110128
}
@@ -162,9 +180,7 @@ export default class SubtitleComponent extends Lightning.Component {
162180

163181
this.tag('Text').text.wordWrapWidth = breakpoint
164182
this.tag('Text').text = v
165-
setTimeout(() => {
166-
this.setSmooth('alpha', 1, { duration: 0.2 })
167-
}, 100)
183+
this.alpha = 1
168184
}
169185
}
170186

src/Subtitles/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const getOrCreateSubtitlesComponent = () => {
3030
AppInstance.stage.c({
3131
ref: 'Subtitles',
3232
type: SubtitleComponent,
33+
forceZIndexContext: true,
3334
zIndex: 2,
3435
})
3536
))
@@ -75,6 +76,11 @@ export default {
7576
const subtitles = getOrCreateSubtitlesComponent()
7677
subtitles.textAlignVertical = v
7778
},
79+
viewport(w, h) {
80+
const subtitles = getOrCreateSubtitlesComponent()
81+
subtitles.viewportW = w
82+
subtitles.viewportH = h
83+
},
7884
position(x, y) {
7985
const subtitles = getOrCreateSubtitlesComponent()
8086
subtitles.xPos = x

0 commit comments

Comments
 (0)