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'; |
Hector Dearman | 667982b | 2018-09-20 17:02:51 +0100 | [diff] [blame] | 16 | import {globals} from './globals'; |
Deepanjan Roy | 56fa86b | 2018-08-02 10:25:56 -0400 | [diff] [blame] | 17 | |
Deepanjan Roy | 424485b | 2018-07-26 08:37:35 -0400 | [diff] [blame] | 18 | /** |
Deepanjan Roy | 56fa86b | 2018-08-02 10:25:56 -0400 | [diff] [blame] | 19 | * This interface forces track implementations to have some static properties. |
| 20 | * Typescript does not have abstract static members, which is why this needs to |
| 21 | * be in a seperate interface. |
Deepanjan Roy | 424485b | 2018-07-26 08:37:35 -0400 | [diff] [blame] | 22 | */ |
| 23 | export interface TrackCreator { |
Hector Dearman | c62a5e3 | 2018-07-27 12:54:44 +0100 | [diff] [blame] | 24 | // Store the kind explicitly as a string as opposed to using class.kind in |
Deepanjan Roy | 424485b | 2018-07-26 08:37:35 -0400 | [diff] [blame] | 25 | // case we ever minify our code. |
Hector Dearman | c62a5e3 | 2018-07-27 12:54:44 +0100 | [diff] [blame] | 26 | readonly kind: string; |
Deepanjan Roy | 75b46a9 | 2018-07-24 09:11:29 -0400 | [diff] [blame] | 27 | |
Deepanjan Roy | 56fa86b | 2018-08-02 10:25:56 -0400 | [diff] [blame] | 28 | // We need the |create| method because the stored value in the registry is an |
| 29 | // abstract class, and we cannot call 'new' on an abstract class. |
Deepanjan Roy | 424485b | 2018-07-26 08:37:35 -0400 | [diff] [blame] | 30 | create(TrackState: TrackState): Track; |
| 31 | } |
Michail Schwab | beb3452 | 2018-07-20 08:15:17 -0400 | [diff] [blame] | 32 | |
Deepanjan Roy | 424485b | 2018-07-26 08:37:35 -0400 | [diff] [blame] | 33 | /** |
| 34 | * The abstract class that needs to be implemented by all tracks. |
| 35 | */ |
Hector Dearman | 667982b | 2018-09-20 17:02:51 +0100 | [diff] [blame] | 36 | export abstract class Track<Config = {}, Data = {}> { |
Deepanjan Roy | 424485b | 2018-07-26 08:37:35 -0400 | [diff] [blame] | 37 | constructor(protected trackState: TrackState) {} |
Deepanjan Roy | 9d95a25 | 2018-08-09 10:10:19 -0400 | [diff] [blame] | 38 | abstract renderCanvas(ctx: CanvasRenderingContext2D): void; |
Hector Dearman | 87aec0f | 2018-09-19 13:46:15 +0100 | [diff] [blame] | 39 | |
| 40 | get config(): Config { |
| 41 | return this.trackState.config as Config; |
| 42 | } |
| 43 | |
Deepanjan Roy | 32ad0d7 | 2018-10-18 14:50:16 -0400 | [diff] [blame^] | 44 | data(): Data|undefined { |
Hector Dearman | 667982b | 2018-09-20 17:02:51 +0100 | [diff] [blame] | 45 | return globals.trackDataStore.get(this.trackState.id) as Data; |
| 46 | } |
| 47 | |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 48 | getHeight(): number { |
Hector Dearman | edbe097 | 2018-08-31 13:02:58 +0100 | [diff] [blame] | 49 | return 40; |
Primiano Tucci | f30cd9c | 2018-08-13 01:53:26 +0200 | [diff] [blame] | 50 | } |
Hector Dearman | 87aec0f | 2018-09-19 13:46:15 +0100 | [diff] [blame] | 51 | |
Michail Schwab | 8d6c98c | 2018-08-08 12:42:26 -0400 | [diff] [blame] | 52 | onMouseMove(_position: {x: number, y: number}) {} |
Hector Dearman | 87aec0f | 2018-09-19 13:46:15 +0100 | [diff] [blame] | 53 | |
Michail Schwab | 8d6c98c | 2018-08-08 12:42:26 -0400 | [diff] [blame] | 54 | onMouseOut() {} |
Deepanjan Roy | 424485b | 2018-07-26 08:37:35 -0400 | [diff] [blame] | 55 | } |