/** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * Adapted from LiteMol * Copyright (c) 2016 - now David Sehnal, licensed under Apache 2.0, See LICENSE file for more info. * * @author Alexander Rose */ import * as React from 'react' import { ViewportController } from '../../controller/visualization/viewport' import { View } from '../view'; import { HelpBox, Toggle, Button } from '../controls/common' import { Slider } from '../controls/slider' import { ImageCanvas } from './image-canvas'; export class ViewportControls extends View { state = { showSceneOptions: false, showHelp: false }; private help() { return
Left button
One finger touch
} />
Right button
Pinch
} />
Middle button
Two finger touch
} />
Mouse wheel
Three finger touch
} /> } render() { let state = this.controller.latestState; let options: any; let layoutController = this.controller.context.layout; let layoutState = layoutController.latestState; if (this.state.showSceneOptions) { options =
this.controller.setState({ enableFog: v })} value={state.enableFog!} label='Fog' /> this.controller.setState({ cameraFOV: v }) } value={state.cameraFOV!} /> this.controller.setState({ cameraSpeed: v }) } value={state.cameraSpeed!} />
; } else if (this.state.showHelp) { options = this.help(); } let controlsShown = !layoutState.hideControls; return
this.setState({ showSceneOptions: false, showHelp: false })}>
{options}
; } } export const Logo = () =>
type ViewportState = { noWebGl: boolean, showLogo: boolean, aspectRatio: number, width: number height: number images: { [k: string]: ImageData } info: string } export class Viewport extends View { private container: HTMLDivElement | null = null; private canvas: HTMLCanvasElement | null = null; private defaultBg = { r: 1, g: 1, b: 1 } state: ViewportState = { noWebGl: false, showLogo: true, images: {}, aspectRatio: 1, width: 0, height: 0, info: '' }; handleResize() { if (this.container) { this.setState({ aspectRatio: this.container.clientWidth / this.container.clientHeight, width: this.container.clientWidth, height: this.container.clientHeight }) } } componentDidMount() { if (!this.canvas || !this.container || !this.controller.context.initStage(this.canvas, this.container)) { this.setState({ noWebGl: true }); } const viewer = this.controller.context.stage.viewer viewer.reprCount.subscribe(count => { this.setState({ showLogo: false // showLogo: count === 0 }) }) viewer.identified.subscribe(info => { this.setState({ info }) }) viewer.didDraw.subscribe(() => { // this.setState({ imageData: viewer.getImageData() }) this.setState({ images: { 'object': viewer.getImageData('pickObject'), 'instance': viewer.getImageData('pickInstance'), 'element': viewer.getImageData('pickElement') } }) }) viewer.input.resize.subscribe(() => this.handleResize()) this.handleResize() } componentWillUnmount() { super.componentWillUnmount(); this.controller.context.destroy(); } renderMissing() { return

WebGL does not seem to be available.

This can be caused by an outdated browser, graphics card driver issue, or bad weather. Sometimes, just restarting the browser helps.

For a list of supported browsers, refer to http://caniuse.com/#feat=webgl.

} render() { if (this.state.noWebGl) return this.renderMissing(); const color = this.controller.latestState.clearColor! || this.defaultBg; return
this.container = elm} className='molstar-viewport-container'> this.canvas = elm} className='molstar-viewport-canvas'>
{this.state.showLogo ? : void 0}
{this.state.info}
{Object.keys(this.state.images).map(k => { const imageData = this.state.images[k] return })}
; } }