Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add playback scaling #65

Merged
merged 1 commit into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 55 additions & 10 deletions pkg/session_recording/player.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,22 @@
this.fastForwardToEnd = this.fastForwardToEnd.bind(this);
this.skipFrame = this.skipFrame.bind(this);
this.handleKeyDown = this.handleKeyDown.bind(this);
this.sync = this.sync.bind(this);

this.state = {
cols: 80,
rows: 25,
title: _("Player"),
term: null,
paused: true,
cols: 80,
rows: 25,
title: _("Player"),
term: null,
paused: true,
/* Speed exponent */
speedExp: 0,
speedExp: 0,
containerWidth: 630,
scale: 1
};

this.containerHeight = 290;

/* Auto-loading buffer of recording's packets */
this.buf = new PacketBuffer(this.props.matchList);

Expand Down Expand Up @@ -543,6 +548,9 @@
}

componentDidMount() {
if (this.refs.wrapper.offsetWidth) {
this.setState({containerWidth: this.refs.wrapper.offsetWidth});
}
/* Open the terminal */
this.state.term.open(this.refs.term);
/* Reset playback */
Expand Down Expand Up @@ -591,6 +599,18 @@
this.setState({ title: _("Player") + ": " + title });
}

_transform(width, height) {
var relation = Math.min(
this.state.containerWidth / this.state.term.element.offsetWidth,
this.containerHeight / this.state.term.element.offsetHeight
);
this.setState({
scale: relation,
cols: width,
rows: height
});
}

/* Synchronize playback */
sync() {
let locDelay;
Expand Down Expand Up @@ -619,7 +639,7 @@
}

/* Skip packets we don't output */
if (!pkt.is_io || !pkt.is_output) {
if (pkt.is_io && !pkt.is_output) {
continue;
}

Expand Down Expand Up @@ -669,7 +689,12 @@
}

/* Output the packet */
this.state.term.write(this.pkt.io);
if (this.pkt.is_io) {
this.state.term.write(this.pkt.io);
} else {
this.state.term.resize(this.pkt.width, this.pkt.height);
this._transform(this.pkt.width, this.pkt.height);
}

/* We no longer have a packet */
this.pkt = null;
Expand Down Expand Up @@ -758,14 +783,34 @@
speedStr = "";
}

const style = {
"transform": "scale(" + this.state.scale + ") translate(-50%, -50%)",
"transform-origin": "top left",
"display": "inline-block",
"margin": "0 auto",
"position": "absolute",
"top": "50%",
"left": "50%",
};

const scrollwrap = {
"min-width": "630px",
"height": this.containerHeight + "px",
"background-color": "#f5f5f5",
"overflow": "hidden",
"position": "relative",
};

// ensure react never reuses this div by keying it with the terminal widget
return (
<div className="panel panel-default">
<div ref="wrapper" className="panel panel-default">
<div className="panel-heading">
<span>{this.state.title}</span>
</div>
<div className="panel-body">
<div ref="term" className="console-ct" key={this.state.term} />
<div style={scrollwrap}>
<div ref="term" className="console-ct" key={this.state.term} style={style} />
</div>
</div>
<div className="panel-footer">
<button title="Play/Pause - Hotkey: p" type="button" ref="playbtn"
Expand Down
10 changes: 10 additions & 0 deletions pkg/session_recording/recordings.css
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,13 @@ table.listing-ct > thead th:last-child, tr.listing-ct-item td:last-child {
.valid {
background-color: #ffffff;
}

.player-wrap {
min-width: 672px;
height: auto;
overflow: hidden;
}

.player-wrap .panel-body, .player-wrap .console-ct > .terminal {
padding: 0;
}
8 changes: 1 addition & 7 deletions pkg/session_recording/recordings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,6 @@
ref="player"
matchList={this.props.recording.matchList} />);

let style = {
width: '672.97px',
height: 'auto',
overflow: 'hidden',
};

return (
<div className="container-fluid">
<div className="row">
Expand Down Expand Up @@ -313,7 +307,7 @@
</div>
</div>
</div>
<div className="col-md-6" style={style}>
<div className="col-md-6 player-wrap">
{player}
</div>
</div>
Expand Down