cursorRenderer.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {mat3, vec2} from 'gl-matrix';
  2. import {FlamegraphTheme} from '../flamegraph/flamegraphTheme';
  3. import {getContext, Rect} from '../gl/utils';
  4. class CursorRenderer {
  5. canvas: HTMLCanvasElement;
  6. context: CanvasRenderingContext2D;
  7. theme: FlamegraphTheme;
  8. constructor(canvas: HTMLCanvasElement, theme: FlamegraphTheme) {
  9. this.canvas = canvas;
  10. this.theme = theme;
  11. this.context = getContext(canvas, '2d');
  12. }
  13. draw(
  14. configSpaceCursor: vec2,
  15. physicalSpace: Rect,
  16. configViewToPhysicalSpace: mat3
  17. ): void {
  18. const physicalSpaceCursor = vec2.transformMat3(
  19. vec2.create(),
  20. configSpaceCursor,
  21. configViewToPhysicalSpace
  22. );
  23. this.context.beginPath();
  24. this.context.moveTo(physicalSpaceCursor[0], 0);
  25. this.context.lineTo(physicalSpaceCursor[0], physicalSpace.height);
  26. this.context.moveTo(0, physicalSpaceCursor[1]);
  27. this.context.lineTo(physicalSpace.width, physicalSpaceCursor[1]);
  28. this.context.strokeStyle = this.theme.COLORS.CURSOR_CROSSHAIR;
  29. this.context.stroke();
  30. }
  31. }
  32. export {CursorRenderer};