previewAreaComponent.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import * as React from "react";
  2. import { GlobalState } from '../../globalState';
  3. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
  4. import { faPlay, faStop, faPalette } from '@fortawesome/free-solid-svg-icons';
  5. import { Color3, Color4 } from 'babylonjs/Maths/math.color';
  6. import { DataStorage } from '../../dataStorage';
  7. interface IPreviewAreaComponent {
  8. globalState: GlobalState;
  9. width: number;
  10. }
  11. export class PreviewAreaComponent extends React.Component<IPreviewAreaComponent> {
  12. changeAnimation() {
  13. this.props.globalState.rotatePreview = !this.props.globalState.rotatePreview;
  14. this.props.globalState.onAnimationCommandActivated.notifyObservers();
  15. this.forceUpdate();
  16. }
  17. changeBackground(value: string) {
  18. const newColor = Color3.FromHexString(value);
  19. DataStorage.StoreNumber("BackgroundColorR", newColor.r);
  20. DataStorage.StoreNumber("BackgroundColorG", newColor.g);
  21. DataStorage.StoreNumber("BackgroundColorB", newColor.b);
  22. this.props.globalState.backgroundColor = Color4.FromColor3(newColor, 1.0);
  23. this.props.globalState.onPreviewBackgroundChanged.notifyObservers();
  24. }
  25. render() {
  26. return (
  27. <>
  28. <div id="preview" style={{height: this.props.width + "px"}}>
  29. <canvas id="preview-canvas"/>
  30. </div>
  31. <div id="preview-config-bar">
  32. <div onClick={() => this.changeAnimation()} className={"button"}>
  33. <FontAwesomeIcon icon={this.props.globalState.rotatePreview ? faStop : faPlay} />
  34. </div>
  35. <div className={"button align"}>
  36. <label htmlFor="color-picker" id="color-picker-label">
  37. <FontAwesomeIcon icon={faPalette} />
  38. </label>
  39. <input ref="color-picker" id="color-picker" type="color" onChange={evt => this.changeBackground(evt.target.value)} />
  40. </div>
  41. </div>
  42. </>
  43. );
  44. }
  45. }