Newer
Older
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import * as React from 'react'
import { App } from '../app';
import { MarkerAction } from 'mol-geo/geometry/marker-data';
David Sehnal
committed
import { labelFirst } from 'mol-canvas3d/label';
interface ViewportProps {
app: App
}
interface ViewportState {
noWebGl: boolean
pickingInfo: string
taskInfo: string
}
export class Viewport extends React.Component<ViewportProps, ViewportState> {
private container: HTMLDivElement | null = null;
private canvas: HTMLCanvasElement | null = null;
state: ViewportState = {
noWebGl: false,
pickingInfo: '',
taskInfo: ''
};
handleResize() {
this.props.app.viewer.handleResize()
}
componentDidMount() {
if (!this.canvas || !this.container || !this.props.app.initViewer(this.canvas, this.container)) {
this.setState({ noWebGl: true });
}
this.handleResize()
const viewer = this.props.app.viewer
viewer.input.resize.subscribe(() => this.handleResize())
viewer.input.move.subscribe(({x, y, inside, buttons}) => {
if (!inside || buttons) return
const p = viewer.identify(x, y)
if (p) {
const loci = viewer.getLoci(p)
if (!areLociEqual(loci, prevLoci)) {
viewer.mark(prevLoci, MarkerAction.RemoveHighlight)
viewer.mark(loci, MarkerAction.Highlight)
prevLoci = loci
const pickingInfo = `${label}`
this.setState({ pickingInfo })
this.props.app.taskCountChanged.subscribe(({ count, info }) => {
this.setState({ taskInfo: count > 0 ? info : '' })
})
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
}
componentWillUnmount() {
if (super.componentWillUnmount) super.componentWillUnmount();
// TODO viewer cleanup
}
renderMissing() {
return <div>
<div>
<p><b>WebGL does not seem to be available.</b></p>
<p>This can be caused by an outdated browser, graphics card driver issue, or bad weather. Sometimes, just restarting the browser helps.</p>
<p>For a list of supported browsers, refer to <a href='http://caniuse.com/#feat=webgl' target='_blank'>http://caniuse.com/#feat=webgl</a>.</p>
</div>
</div>
}
render() {
if (this.state.noWebGl) return this.renderMissing();
return <div style={{ backgroundColor: 'rgb(0, 0, 0)', width: '100%', height: '100%'}}>
<div ref={elm => this.container = elm} style={{width: '100%', height: '100%'}}>
<canvas ref={elm => this.canvas = elm}></canvas>
</div>
<div
style={{
position: 'absolute',
top: 10,
left: 10,
padding: 10,
color: 'lightgrey',
background: 'rgba(0, 0, 0, 0.2)'
}}
>
{ this.state.taskInfo ?
<div
style={{
position: 'absolute',
top: 10,
right: 10,
padding: 10,
color: 'lightgrey',
background: 'rgba(0, 0, 0, 0.2)'
}}
>
{this.state.taskInfo}
</div>
: '' }