• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2019 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import {TPTime} from '../common/time';
16import {TRACK_SHELL_WIDTH} from './css_constants';
17import {TimeScale} from './time_scale';
18
19export function drawVerticalLineAtTime(
20    ctx: CanvasRenderingContext2D,
21    timeScale: TimeScale,
22    time: TPTime,
23    height: number,
24    color: string,
25    lineWidth = 2) {
26  const xPos = TRACK_SHELL_WIDTH + Math.floor(timeScale.tpTimeToPx(time));
27  drawVerticalLine(ctx, xPos, height, color, lineWidth);
28}
29
30function drawVerticalLine(ctx: CanvasRenderingContext2D,
31                          xPos: number,
32                          height: number,
33                          color: string,
34                          lineWidth = 2) {
35    ctx.beginPath();
36    ctx.strokeStyle = color;
37    const prevLineWidth = ctx.lineWidth;
38    ctx.lineWidth = lineWidth;
39    ctx.moveTo(xPos, 0);
40    ctx.lineTo(xPos, height);
41    ctx.stroke();
42    ctx.closePath();
43    ctx.lineWidth = prevLineWidth;
44}
45
46