diff --git a/gallium-live/src/BPMSelector.js b/gallium-live/src/BPMSelector.js index ad447ca..96ca0a7 100644 --- a/gallium-live/src/BPMSelector.js +++ b/gallium-live/src/BPMSelector.js @@ -81,10 +81,10 @@ const Input = styled.input` font-family: monospace; cursor: pointer; outline: none; - color: #252525; + color: white; &:active, &:hover { - box-shadow: 0 0 0 1px #252525; + box-shadow: 0 0 0 1px white; } margin-left: 10px; `; diff --git a/gallium-live/src/Editor.js b/gallium-live/src/Editor.js index 5e532ca..67b76c6 100644 --- a/gallium-live/src/Editor.js +++ b/gallium-live/src/Editor.js @@ -15,6 +15,7 @@ import * as Playback from "./playback"; import * as AppActions from "./app_actions"; import { BPMSelector } from "./BPMSelector"; import { ToggleInvert } from "./ToggleInvert"; +import * as Shader from "./shader"; type OwnProps = {}; @@ -44,7 +45,9 @@ export class _Editor extends React.Component< }; } - textarea: ?HTMLTextAreaElement; + textarea: HTMLTextAreaElement; + + textCanvas: HTMLCanvasElement; componentDidMount() { this.props.dispatch(AppActions.initialize()); @@ -57,10 +60,14 @@ export class _Editor extends React.Component< } onChange = (e: *) => { + const text = e.target.value; this.setState({ - text: e.target.value + text }); - this.updateABT(e.target.value); + this.updateABT(text); + if (this.textCanvas) { + this.drawText(text); + } }; updateABT(text: string) { @@ -112,14 +119,43 @@ export class _Editor extends React.Component< } }; - onTextareaRefLoad = (ref: HTMLTextAreaElement) => { - this.textarea = ref; - if (!this.textarea) { + registerContent = (ref: HTMLElement) => { + if (!ref) { + return; + } + const canvas: HTMLCanvasElement = (ref.children[0]: any); + const textCanvas: HTMLCanvasElement = (ref.children[1]: any); + + (textCanvas.width = Math.max(window.innerHeight, window.innerWidth)), + (textCanvas.height = textCanvas.width); + + this.textCanvas = textCanvas; + this.drawText(this.state.text); + Shader.registerWebGL({ canvas, textCanvas }); + }; + + registerTextarea = (ref: HTMLTextAreaElement) => { + if (!ref) { return; } - this.textarea.focus(); + ref.focus(); + this.textarea = ref; }; + drawText(text: string) { + const ctx = this.textCanvas.getContext("2d"); + ctx.clearRect(0, 0, this.textCanvas.width, this.textCanvas.height); + ctx.font = "16px mono"; + ctx.fillStyle = "white"; + const lineHeight = ctx.measureText("M").width * 1.8; + const lines = text.split("\n"); + let y = 0; + for (const line of lines) { + ctx.fillText(line, 0, y); + y += lineHeight; + } + } + render() { const barStyle = this.state.error ? "dotted" : "solid"; return ( @@ -127,35 +163,37 @@ export class _Editor extends React.Component< isInitialized={this.state.isInitialized} style={{ filter: this.props.invert ? "invert()" : "" }} > - - - gallium.live - - - source - - - + + +