bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/whiteboard/shapes/rectangle/component.jsx

67 lines
1.6 KiB
React
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
2016-06-10 02:58:41 +08:00
import ShapeHelpers from '../helpers.js';
export default class RectangleDrawComponent extends React.Component {
constructor(props) {
super(props);
}
2016-06-10 02:58:41 +08:00
getCoordinates() {
2017-06-03 03:25:02 +08:00
// x1 and y1 are the coordinates of the top left corner of the shape
// x2 and y2 are the coordinates of the bottom right corner of the shape
2016-06-10 02:58:41 +08:00
let x1 = this.props.shape.points[0];
let y1 = this.props.shape.points[1];
let x2 = this.props.shape.points[2];
let y2 = this.props.shape.points[3];
2017-06-03 03:25:02 +08:00
// Presenter pulled rectangle to the left
2016-06-10 02:58:41 +08:00
if (x2 < x1) {
x1 = this.props.shape.points[2];
x2 = this.props.shape.points[0];
}
2017-06-03 03:25:02 +08:00
// Presenter pulled Rectangle to the top
2016-06-10 02:58:41 +08:00
if (y2 < y1) {
y1 = this.props.shape.points[3];
y2 = this.props.shape.points[1];
}
2017-06-03 03:25:02 +08:00
const x = x1 / 100 * this.props.slideWidth;
const y = y1 / 100 * this.props.slideHeight;
const width = (x2 - x1) / 100 * this.props.slideWidth;
const height = (y2 - y1) / 100 * this.props.slideHeight;
2016-06-10 02:58:41 +08:00
return {
2017-06-03 03:25:02 +08:00
x,
y,
width,
height,
};
2016-06-10 02:58:41 +08:00
}
2016-06-10 02:58:41 +08:00
render() {
2017-06-03 03:25:02 +08:00
const results = this.getCoordinates();
2016-06-10 02:58:41 +08:00
return (
<rect
2016-06-10 02:58:41 +08:00
x={results.x}
y={results.y}
width={results.width}
height={results.height}
rx="1"
ry="1"
fill="none"
stroke={ShapeHelpers.formatColor(this.props.shape.color)}
strokeWidth={this.props.shape.thickness}
style={this.props.style}
2017-06-03 03:25:02 +08:00
/>
);
}
}
2016-06-10 02:58:41 +08:00
RectangleDrawComponent.defaultProps = {
style: {
WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)',
},
};