Hector Dearman | 3d26fdb | 2018-07-09 13:54:06 +0100 | [diff] [blame] | 1 | // Copyright (C) 2018 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. |
Micha Schwab | 01b3568 | 2018-06-28 13:56:49 +0100 | [diff] [blame] | 14 | |
Deepanjan Roy | 75b46a9 | 2018-07-24 09:11:29 -0400 | [diff] [blame] | 15 | import {TrackState} from '../common/state'; |
| 16 | |
Deepanjan Roy | 424485b | 2018-07-26 08:37:35 -0400 | [diff] [blame] | 17 | import {TimeScale} from './time_scale'; |
Michail Schwab | bbdd983 | 2018-07-12 12:02:53 -0400 | [diff] [blame] | 18 | import {VirtualCanvasContext} from './virtual_canvas_context'; |
Micha Schwab | 01b3568 | 2018-06-28 13:56:49 +0100 | [diff] [blame] | 19 | |
Deepanjan Roy | 424485b | 2018-07-26 08:37:35 -0400 | [diff] [blame] | 20 | /** |
| 21 | * This interface forces track implementations to have two static properties: |
| 22 | * type and a create function. |
| 23 | * |
| 24 | * Typescript does not have abstract static members, which is why this needs to |
| 25 | * be in a seperate interface. We need the |create| method because the stored |
| 26 | * value in the registry is an abstract class, and we cannot call 'new' |
| 27 | * on an abstract class. |
| 28 | */ |
| 29 | export interface TrackCreator { |
| 30 | // Store the type explicitly as a string as opposed to using class.name in |
| 31 | // case we ever minify our code. |
| 32 | readonly type: string; |
Deepanjan Roy | 75b46a9 | 2018-07-24 09:11:29 -0400 | [diff] [blame] | 33 | |
Deepanjan Roy | 424485b | 2018-07-26 08:37:35 -0400 | [diff] [blame] | 34 | create(TrackState: TrackState): Track; |
| 35 | } |
Michail Schwab | beb3452 | 2018-07-20 08:15:17 -0400 | [diff] [blame] | 36 | |
Deepanjan Roy | 424485b | 2018-07-26 08:37:35 -0400 | [diff] [blame] | 37 | /** |
| 38 | * The abstract class that needs to be implemented by all tracks. |
| 39 | */ |
| 40 | export abstract class Track { |
| 41 | constructor(protected trackState: TrackState) {} |
| 42 | abstract renderCanvas( |
Michail Schwab | 405002c | 2018-07-26 13:19:10 -0400 | [diff] [blame] | 43 | vCtx: VirtualCanvasContext, width: number, timeScale: TimeScale, |
| 44 | visibleWindowMs: {start: number, end: number}): void; |
Deepanjan Roy | 424485b | 2018-07-26 08:37:35 -0400 | [diff] [blame] | 45 | } |