blob: bd21f3908df64f099cade12bc8092141e1abd80d [file] [log] [blame]
Hector Dearman3d26fdb2018-07-09 13:54:06 +01001// 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 Schwab01b35682018-06-28 13:56:49 +010014
Deepanjan Roy75b46a92018-07-24 09:11:29 -040015import {TrackState} from '../common/state';
Hector Dearman667982b2018-09-20 17:02:51 +010016import {globals} from './globals';
Deepanjan Roy56fa86b2018-08-02 10:25:56 -040017
Deepanjan Roy424485b2018-07-26 08:37:35 -040018/**
Deepanjan Roy56fa86b2018-08-02 10:25:56 -040019 * 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 Roy424485b2018-07-26 08:37:35 -040022 */
23export interface TrackCreator {
Hector Dearmanc62a5e32018-07-27 12:54:44 +010024 // Store the kind explicitly as a string as opposed to using class.kind in
Deepanjan Roy424485b2018-07-26 08:37:35 -040025 // case we ever minify our code.
Hector Dearmanc62a5e32018-07-27 12:54:44 +010026 readonly kind: string;
Deepanjan Roy75b46a92018-07-24 09:11:29 -040027
Deepanjan Roy56fa86b2018-08-02 10:25:56 -040028 // 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 Roy424485b2018-07-26 08:37:35 -040030 create(TrackState: TrackState): Track;
31}
Michail Schwabbeb34522018-07-20 08:15:17 -040032
Deepanjan Roy424485b2018-07-26 08:37:35 -040033/**
34 * The abstract class that needs to be implemented by all tracks.
35 */
Hector Dearman667982b2018-09-20 17:02:51 +010036export abstract class Track<Config = {}, Data = {}> {
Deepanjan Roy424485b2018-07-26 08:37:35 -040037 constructor(protected trackState: TrackState) {}
Deepanjan Roy9d95a252018-08-09 10:10:19 -040038 abstract renderCanvas(ctx: CanvasRenderingContext2D): void;
Hector Dearman87aec0f2018-09-19 13:46:15 +010039
40 get config(): Config {
41 return this.trackState.config as Config;
42 }
43
Deepanjan Roy32ad0d72018-10-18 14:50:16 -040044 data(): Data|undefined {
Hector Dearman667982b2018-09-20 17:02:51 +010045 return globals.trackDataStore.get(this.trackState.id) as Data;
46 }
47
Primiano Tuccif30cd9c2018-08-13 01:53:26 +020048 getHeight(): number {
Hector Dearmanedbe0972018-08-31 13:02:58 +010049 return 40;
Primiano Tuccif30cd9c2018-08-13 01:53:26 +020050 }
Hector Dearman87aec0f2018-09-19 13:46:15 +010051
Michail Schwab8d6c98c2018-08-08 12:42:26 -040052 onMouseMove(_position: {x: number, y: number}) {}
Hector Dearman87aec0f2018-09-19 13:46:15 +010053
Michail Schwab8d6c98c2018-08-08 12:42:26 -040054 onMouseOut() {}
Deepanjan Roy424485b2018-07-26 08:37:35 -040055}