ic labels

This commit is contained in:
Matei Adriel 2019-07-31 20:03:27 +03:00
parent 12db01963f
commit fec7d7cc91
4 changed files with 24 additions and 3 deletions

View file

@ -3,9 +3,6 @@ import FluidCanvas from './FluidCanvas'
import loop from 'mainloop.js' import loop from 'mainloop.js'
import { renderSimulation } from '../../simulationRenderer/helpers/renderSimulation' import { renderSimulation } from '../../simulationRenderer/helpers/renderSimulation'
import { getRendererSafely } from '../../logic-gates/helpers/getRendererSafely' import { getRendererSafely } from '../../logic-gates/helpers/getRendererSafely'
import { Subscription } from 'rxjs'
import { rendererSubject } from '../subjects/rendererSubject'
import { filter } from 'rxjs/operators'
class Canvas extends Component { class Canvas extends Component {
private canvasRef: RefObject<HTMLCanvasElement> = createRef() private canvasRef: RefObject<HTMLCanvasElement> = createRef()
@ -24,6 +21,11 @@ class Canvas extends Component {
public componentDidMount() { public componentDidMount() {
if (this.canvasRef.current) { if (this.canvasRef.current) {
this.renderingContext = this.canvasRef.current.getContext('2d') this.renderingContext = this.canvasRef.current.getContext('2d')
if (this.renderingContext) {
this.renderingContext.textAlign = 'center'
}
getRendererSafely().updateWheelListener(this.canvasRef) getRendererSafely().updateWheelListener(this.canvasRef)
} }

View file

@ -0,0 +1,5 @@
export const textSettings = {
font: '30px Roboto',
offset: 30,
fill: `rgba(256,256,256,0.75)`
}

View file

@ -7,6 +7,7 @@ import { roundImage } from '../../../common/canvas/helpers/drawRoundedImage'
import { ImageStore } from '../stores/imageStore' import { ImageStore } from '../stores/imageStore'
import { gatesInSelection } from './gatesInSelection' import { gatesInSelection } from './gatesInSelection'
import { idIsSelected } from './idIsSelected' import { idIsSelected } from './idIsSelected'
import { textSettings } from '../data/textSettings'
export const renderGate = ( export const renderGate = (
ctx: CanvasRenderingContext2D, ctx: CanvasRenderingContext2D,
@ -58,5 +59,15 @@ export const renderGate = (
} }
ctx.stroke() ctx.stroke()
if (gate.template.tags.includes('integrated')) {
ctx.fillStyle = textSettings.fill
ctx.fillText(
gate.template.metadata.name,
relativeTransform.center[0],
relativeTransform.maxY + textSettings.offset
)
}
ctx.restore() ctx.restore()
} }

View file

@ -6,6 +6,7 @@ import { renderClickedPins } from './renderClickedPins'
import { renderWires } from './renderWires' import { renderWires } from './renderWires'
import { renderSelectedArea } from './renderSelectedArea' import { renderSelectedArea } from './renderSelectedArea'
import { currentContext } from '../subjects' import { currentContext } from '../subjects'
import { textSettings } from '../data/textSettings'
export const renderSimulation = ( export const renderSimulation = (
ctx: CanvasRenderingContext2D, ctx: CanvasRenderingContext2D,
@ -27,6 +28,8 @@ export const renderSimulation = (
renderWires(ctx, renderer, wire) renderWires(ctx, renderer, wire)
} }
ctx.font = textSettings.font
ctx.textAlign = 'center'
for (const gate of renderer.simulation.gates) { for (const gate of renderer.simulation.gates) {
renderGate(ctx, renderer, gate) renderGate(ctx, renderer, gate)
} }