molstar
Version:
A comprehensive macromolecular library.
78 lines • 6.41 kB
JavaScript
import { __assign, __extends } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { PluginCommands } from '../mol-plugin/commands';
import { PluginConfig } from '../mol-plugin/config';
import { PluginUIComponent } from './base';
import { ControlGroup, IconButton } from './controls/common';
import { AutorenewSvg, BuildOutlinedSvg, CameraOutlinedSvg, CloseSvg, FullscreenSvg, TuneSvg } from './controls/icons';
import { ToggleSelectionModeButton } from './structure/selection';
import { ViewportCanvas } from './viewport/canvas';
import { DownloadScreenshotControls } from './viewport/screenshot';
import { SimpleSettingsControl } from './viewport/simple-settings';
var ViewportControls = /** @class */ (function (_super) {
__extends(ViewportControls, _super);
function ViewportControls() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.allCollapsedState = {
isSettingsExpanded: false,
isScreenshotExpanded: false
};
_this.state = __assign({}, _this.allCollapsedState);
_this.resetCamera = function () {
PluginCommands.Camera.Reset(_this.plugin, {});
};
_this.toggleSettingsExpanded = _this.toggle('isSettingsExpanded');
_this.toggleScreenshotExpanded = _this.toggle('isScreenshotExpanded');
_this.toggleControls = function () {
PluginCommands.Layout.Update(_this.plugin, { state: { showControls: !_this.plugin.layout.state.showControls } });
};
_this.toggleExpanded = function () {
PluginCommands.Layout.Update(_this.plugin, { state: { isExpanded: !_this.plugin.layout.state.isExpanded } });
};
_this.setSettings = function (p) {
var _a;
PluginCommands.Canvas3D.SetSettings(_this.plugin, { settings: (_a = {}, _a[p.name] = p.value, _a) });
};
_this.setLayout = function (p) {
var _a;
PluginCommands.Layout.Update(_this.plugin, { state: (_a = {}, _a[p.name] = p.value, _a) });
};
_this.screenshot = function () {
var _a;
(_a = _this.plugin.helpers.viewportScreenshot) === null || _a === void 0 ? void 0 : _a.download();
};
_this.onMouseMove = function (e) {
// ignore mouse moves when no button is held
if (e.buttons === 0)
e.stopPropagation();
};
return _this;
}
ViewportControls.prototype.toggle = function (panel) {
var _this = this;
return function (e) {
var _a;
_this.setState(__assign(__assign({}, _this.allCollapsedState), (_a = {}, _a[panel] = !_this.state[panel], _a)));
e === null || e === void 0 ? void 0 : e.currentTarget.blur();
};
};
ViewportControls.prototype.componentDidMount = function () {
var _this = this;
this.subscribe(this.plugin.events.canvas3d.settingsUpdated, function () { return _this.forceUpdate(); });
this.subscribe(this.plugin.layout.events.updated, function () { return _this.forceUpdate(); });
};
ViewportControls.prototype.icon = function (icon, onClick, title, isOn) {
if (isOn === void 0) { isOn = true; }
return _jsx(IconButton, { svg: icon, toggleState: isOn, onClick: onClick, title: title, style: { background: 'transparent' } }, void 0);
};
ViewportControls.prototype.render = function () {
return _jsxs("div", __assign({ className: 'msp-viewport-controls', onMouseMove: this.onMouseMove }, { children: [_jsxs("div", __assign({ className: 'msp-viewport-controls-buttons' }, { children: [_jsxs("div", { children: [_jsx("div", { className: 'msp-semi-transparent-background' }, void 0), this.icon(AutorenewSvg, this.resetCamera, 'Reset Camera')] }, void 0), _jsxs("div", { children: [_jsx("div", { className: 'msp-semi-transparent-background' }, void 0), this.icon(CameraOutlinedSvg, this.toggleScreenshotExpanded, 'Screenshot / State Snapshot', this.state.isScreenshotExpanded)] }, void 0), _jsxs("div", { children: [_jsx("div", { className: 'msp-semi-transparent-background' }, void 0), this.plugin.config.get(PluginConfig.Viewport.ShowControls) && this.icon(BuildOutlinedSvg, this.toggleControls, 'Toggle Controls Panel', this.plugin.layout.state.showControls), this.plugin.config.get(PluginConfig.Viewport.ShowExpand) && this.icon(FullscreenSvg, this.toggleExpanded, 'Toggle Expanded Viewport', this.plugin.layout.state.isExpanded), this.plugin.config.get(PluginConfig.Viewport.ShowSettings) && this.icon(TuneSvg, this.toggleSettingsExpanded, 'Settings / Controls Info', this.state.isSettingsExpanded)] }, void 0), this.plugin.config.get(PluginConfig.Viewport.ShowSelectionMode) && _jsxs("div", { children: [_jsx("div", { className: 'msp-semi-transparent-background' }, void 0), _jsx(ToggleSelectionModeButton, {}, void 0)] }, void 0)] }), void 0), this.state.isScreenshotExpanded && _jsx("div", __assign({ className: 'msp-viewport-controls-panel' }, { children: _jsx(ControlGroup, __assign({ header: 'Screenshot / State', title: 'Click to close.', initialExpanded: true, hideExpander: true, hideOffset: true, onHeaderClick: this.toggleScreenshotExpanded, topRightIcon: CloseSvg, noTopMargin: true, childrenClassName: 'msp-viewport-controls-panel-controls' }, { children: _jsx(DownloadScreenshotControls, { close: this.toggleScreenshotExpanded }, void 0) }), void 0) }), void 0), this.state.isSettingsExpanded && _jsx("div", __assign({ className: 'msp-viewport-controls-panel' }, { children: _jsx(ControlGroup, __assign({ header: 'Settings / Controls Info', title: 'Click to close.', initialExpanded: true, hideExpander: true, hideOffset: true, onHeaderClick: this.toggleSettingsExpanded, topRightIcon: CloseSvg, noTopMargin: true, childrenClassName: 'msp-viewport-controls-panel-controls' }, { children: _jsx(SimpleSettingsControl, {}, void 0) }), void 0) }), void 0)] }), void 0);
};
return ViewportControls;
}(PluginUIComponent));
export { ViewportControls };
export var Logo = function () {
return _jsx("a", { className: 'msp-logo', href: 'https://molstar.org', target: '_blank' }, void 0);
};
export var Viewport = function () { return _jsx(ViewportCanvas, { logo: Logo }, void 0); };
//# sourceMappingURL=viewport.js.map