// deck.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors
/* global window,document */
import React, {Component} from 'react';
import {render} from 'react-dom';
import DeckGL, {OrthographicView} from 'deck.gl';
import {isWebGL2} from '@luma.gl/core';
import ControlPanel from './components/control-panel';
import AsciiLayer from './ascii-layer/ascii-layer';
class Root extends Component {
constructor(props) {
super(props);
this.state = {
width: 500,
height: 500,
settings: {
fontFamily: 'Monaco',
isPlaying: true,
sizeScale: 1,
videoSource: 0
},
timestamp: Date.now(),
webgl2Supported: true,
videoLoading: true
};
this._onResize = this._onResize.bind(this);
this._onUpdate = this._onUpdate.bind(this);
this._onLoad = this._onLoad.bind(this);
this._onInitialize = this._onInitialize.bind(this);
this._updateSettings = this._updateSettings.bind(this);
}
componentDidMount() {
this._onResize();
window.addEventListener('resize', this._onResize);
this._timer = window.requestAnimationFrame(this._onUpdate);
}
componentWillUnmount() {
window.removeEventListener('resize', this._onResize);
window.cancelAnimationFrame(this._timer);
}
_onResize() {
this.setState({
width: window.innerWidth,
height: window.innerHeight
});
}
_onUpdate() {
if (this.state.settings.isPlaying) {
this.setState({
timestamp: Date.now()
});
}
this._timer = window.requestAnimationFrame(this._onUpdate);
}
_onLoad(video) {
if (video) {
video.crossOrigin = 'anonymouse';
}
this._video = video;
}
_onInitialize(gl) {
this.setState({
webgl2Supported: isWebGL2(gl)
});
}
_updateSettings(settings) {
this.setState({
settings: {...this.state.settings, ...settings}
});
}
_renderDeckGLOverlay({width, height, video}) {
const {timestamp, settings} = this.state;
return (