slitscan/src/components/Player.vue

66 lines
1.3 KiB
Vue

<template>
<div id="player">
<div id="player-canvas-container">
<canvas ref="canvas" id="player-canvas" :height="height" :width="width"></canvas>
</div>
<button @click="playPause">{{buttonLabel}}</button>
</div>
</template>
<script>
export default {
name: 'player',
props: {
width: String,
height: String
},
data: function () {
return {
image: null,
buttonLabel: 'PLAY',
playing: false
}
},
mounted: function () {
this.$bus.$on('imageLoaded', (image) => {
this.image = image
})
this.clear('red')
},
watch: {
width: function () {
setTimeout(() => {
this.clear('red')
}, 0)
},
height: function () {
setTimeout(() => {
this.clear('red')
}, 0)
}
},
methods: {
playPause: function () {
this.playing = !this.playing
if (this.playing) {
this.buttonLabel = 'STOP'
} else {
this.buttonLabel = 'PLAY'
}
},
clear: function (style) {
let ctx = this.$refs.canvas.getContext('2d')
ctx.fillStyle = style
ctx.fillRect(0, 0, parseInt(this.width), parseInt(this.height))
},
$render: function () {
}
}
}
</script>
<style scoped>
</style>