2017-02-07 08:10:50 +08:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
|
2017-02-24 08:11:27 +08:00
|
|
|
export default class PresentationOverlay extends React.Component {
|
2017-02-07 08:10:50 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
//last sent coordinates
|
|
|
|
offsetX: 0,
|
|
|
|
offsetY: 0,
|
|
|
|
|
2017-04-28 06:18:53 +08:00
|
|
|
//last updated coordinates
|
2017-02-07 08:10:50 +08:00
|
|
|
lastOffsetX: 0,
|
|
|
|
lastOffsetY: 0,
|
|
|
|
|
|
|
|
//id of the setInterval()
|
|
|
|
intervalId: 0,
|
|
|
|
};
|
|
|
|
this.mouseMoveHandler = this.mouseMoveHandler.bind(this);
|
|
|
|
this.checkCursor = this.checkCursor.bind(this);
|
|
|
|
this.mouseEnterHandler = this.mouseEnterHandler.bind(this);
|
|
|
|
this.mouseOutHandler = this.mouseOutHandler.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
mouseMoveHandler(event) {
|
2017-05-09 04:29:54 +08:00
|
|
|
//for the case where you change settings in one of the lists (which are displayed on the slide)
|
|
|
|
//the mouse starts pointing to the slide right away and mouseEnter doesn't fire
|
|
|
|
//so we call it manually here
|
|
|
|
if(!this.state.intervalId) {
|
|
|
|
this.mouseEnterHandler();
|
|
|
|
}
|
|
|
|
|
2017-02-07 08:10:50 +08:00
|
|
|
this.setState({
|
|
|
|
lastOffsetX: event.nativeEvent.offsetX,
|
|
|
|
lastOffsetY: event.nativeEvent.offsetY,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
checkCursor() {
|
|
|
|
if (this.state.offsetX != this.state.lastOffsetX
|
|
|
|
&& this.state.offsetY != this.state.lastOffsetY) {
|
|
|
|
|
|
|
|
let xPercent = this.state.lastOffsetX / this.props.vbwidth;
|
|
|
|
let yPercent = this.state.lastOffsetY / this.props.vbheight;
|
2017-02-08 03:05:59 +08:00
|
|
|
this.props.updateCursor({ xPercent: xPercent, yPercent: yPercent });
|
2017-02-07 08:10:50 +08:00
|
|
|
this.setState({
|
|
|
|
offsetX: this.state.lastOffsetX,
|
|
|
|
offsetY: this.state.lastOffsetY,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mouseEnterHandler(event) {
|
|
|
|
let intervalId = setInterval(this.checkCursor, 100);
|
|
|
|
this.setState({ intervalId: intervalId });
|
|
|
|
}
|
|
|
|
|
|
|
|
mouseOutHandler(event) {
|
|
|
|
clearInterval(this.state.intervalId);
|
2017-05-09 04:29:54 +08:00
|
|
|
this.setState({ intervalId: 0 });
|
2017-02-07 08:10:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<foreignObject
|
|
|
|
clipPath="url(#viewBox)"
|
|
|
|
x={this.props.x}
|
|
|
|
y={this.props.y}
|
|
|
|
width={this.props.vbwidth}
|
|
|
|
height={this.props.vbheight}
|
|
|
|
>
|
|
|
|
{ this.props.isUserPresenter ?
|
|
|
|
<div
|
|
|
|
onMouseOut={this.mouseOutHandler}
|
|
|
|
onMouseEnter={this.mouseEnterHandler}
|
|
|
|
onMouseMove={this.mouseMoveHandler}
|
|
|
|
style={{ width: '100%', height: '100%' }}
|
2017-02-24 08:11:27 +08:00
|
|
|
>
|
2017-03-01 02:35:56 +08:00
|
|
|
{this.props.children}
|
2017-02-24 08:11:27 +08:00
|
|
|
</div>
|
2017-02-07 08:10:50 +08:00
|
|
|
: null }
|
|
|
|
</foreignObject>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|