cursorRenderer.tsx 1.1 KB

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