Adds cursor xy tracking

This commit is contained in:
Lajellu 2016-07-15 13:45:54 -07:00
parent e679288d8a
commit 1acdc0a13b
3 changed files with 84 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import React, { PropTypes } from 'react';
import WhiteboardShapeModel from './shape-factory/component.jsx';
import Cursor from './cursor/component.jsx';
import { createContainer } from 'meteor/react-meteor-data';
import Slide from './slide/component.jsx';
import styles from './styles.scss';
@ -62,6 +63,15 @@ export default class Whiteboard extends React.Component {
/>
)
: null }
<Cursor
viewBoxWidth={viewBoxWidth}
viewBoxHeight={viewBoxHeight}
viewBoxX={x}
viewBoxY={y}
widthRatio={slideObj.width_ratio}
cursorX={this.props.cursor[0].x}
cursorY={this.props.cursor[0].y}
/>
</g>
</svg>
</ReactCSSTransitionGroup>

View File

@ -0,0 +1,67 @@
import React, { Component, PropTypes } from 'react';
import WhiteboardService from '/imports/ui/components/whiteboard/service.js';
const propTypes = {
//Defines the cursor x position
cx: PropTypes.number,
//Defines the cursor y position
cy: PropTypes.number,
/**
* Defines the cursor fill colour
* @defaultValue 'red'
*/
fill: PropTypes.string,
/**
* Defines the cursor radius
* @defaultValue 5
*/
radius: PropTypes.number,
};
const defaultProps = {
fill: 'red',
radius: 5,
};
export default class Cursor extends Component {
constructor(props) {
super(props);
}
render() {
const {
viewBoxWidth,
viewBoxHeight,
viewBoxX,
viewBoxY,
widthRatio,
cursorX,
cursorY,
fill,
radius,
} = this.props;
//Adjust the x,y cursor position according to zoom
let cx = (cursorX * viewBoxWidth) + viewBoxX;
let cy = (cursorY * viewBoxHeight) + viewBoxY;
//Adjust the radius of the cursor according to zoom
let finalRadius = radius * widthRatio / 100;
return (
<circle
cx={cx}
cy={cy}
r={finalRadius}
fill={fill}
/>
);
}
}
Cursor.propTypes = propTypes;
Cursor.defaultProps = defaultProps;

View File

@ -1,10 +1,12 @@
import Presentations from '/imports/api/presentations';
import Shapes from '/imports/api/shapes';
import Slides from '/imports/api/slides';
import Cursor from '/imports/api/cursor';
let getWhiteboardData = () => {
let currentSlide;
let shapes;
let cursor;
let currentPresentation = Presentations.findOne({
'presentation.current': true,
});
@ -20,11 +22,16 @@ let getWhiteboardData = () => {
shapes = Shapes.find({
whiteboardId: currentSlide.slide.id,
}).fetch();
cursor = Cursor.find({
meetingId: currentSlide.meetingId,
}).fetch();
}
return {
currentSlide: currentSlide,
shapes: shapes,
cursor: cursor,
};
};