1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
import * as React from "react";
import {observable, action} from "mobx";
import {observer} from "mobx-react";
import "./TimelineOverview.scss";
interface TimelineOverviewProps{
scale: number;
totalLength: number;
visibleLength:number;
visibleStart:number;
currentBarX:number;
changeCurrentBarX: (pixel:number) => void;
movePanX: (pixel:number) => any;
}
@observer
export class TimelineOverview extends React.Component<TimelineOverviewProps>{
@observable private _visibleRef = React.createRef<HTMLDivElement>();
@observable private _scrubberRef = React.createRef<HTMLDivElement>();
private readonly DEFAULT_HEIGHT = 50;
private readonly DEFAULT_WIDTH = 300;
@action
onPointerDown = (e:React.PointerEvent) => {
e.stopPropagation();
e.preventDefault();
document.removeEventListener("pointermove", this.onPanX);
document.removeEventListener("pointerup", this.onPointerUp);
document.addEventListener("pointermove", this.onPanX);
document.addEventListener("pointerup", this.onPointerUp);
}
@action
onPanX = (e: PointerEvent) => {
e.stopPropagation();
e.preventDefault();
let movX = (this.props.visibleStart / this.props.totalLength)* (this.DEFAULT_WIDTH * this.props.scale) + e.movementX;
this.props.movePanX((movX / (this.DEFAULT_WIDTH * this.props.scale)) * this.props.totalLength);
}
@action
onPointerUp = (e: PointerEvent) => {
e.stopPropagation();
e.preventDefault();
document.removeEventListener("pointermove", this.onPanX);
document.removeEventListener("pointerup", this.onPointerUp);
}
@action
onScrubberDown = ( e:React.PointerEvent) => {
e.preventDefault();
e.stopPropagation();
document.removeEventListener("pointermove", this.onScrubberMove);
document.removeEventListener("pointerup", this.onScrubberUp);
document.addEventListener("pointermove", this.onScrubberMove);
document.addEventListener("pointerup", this.onScrubberUp);
}
@action
onScrubberMove = (e: PointerEvent) => {
e.preventDefault();
e.stopPropagation();
let scrubberRef = this._scrubberRef.current!;
let left = scrubberRef.getBoundingClientRect().left;
let offsetX = Math.round(e.clientX - left);
this.props.changeCurrentBarX(((offsetX / (this.DEFAULT_WIDTH * this.props.scale)) * this.props.totalLength) + this.props.currentBarX);
}
@action
onScrubberUp = (e:PointerEvent) => {
e.preventDefault();
e.stopPropagation();
document.removeEventListener("pointermove", this.onScrubberMove);
document.removeEventListener("pointerup", this.onScrubberUp);
}
render(){
return(
<div key="timeline-overview-container" className="timeline-overview-container" style={{height: `${this.DEFAULT_HEIGHT * this.props.scale * 0.8}px` ,width:`${this.DEFAULT_WIDTH * this.props.scale}`}}>
<div ref={this._visibleRef} key="timeline-overview-visible" className="timeline-overview-visible" style={{marginLeft:`${(this.props.visibleStart / this.props.totalLength)* this.DEFAULT_WIDTH * this.props.scale}px`, width:`${(this.props.visibleLength / this.props.totalLength) * this.DEFAULT_WIDTH * this.props.scale}px`}} onPointerDown={this.onPointerDown}></div>
<div ref={this._scrubberRef} key="timeline-overview-scrubber-container" className="timeline-overview-scrubber-container" style={{marginLeft:`${(this.props.currentBarX / this.props.totalLength) * this.DEFAULT_WIDTH * this.props.scale}px`, marginTop: `${-this.DEFAULT_HEIGHT * this.props.scale * 0.8}px`}} onPointerDown={this.onScrubberDown}>
<div key="timeline-overview-scrubber-head" className="timeline-overview-scrubber-head" style={{}}></div>
</div>
</div>
);
}
}
|