[WIP] Add preview of collision mask polygons

This commit is contained in:
Florian Rival
2018-03-30 22:01:21 +02:00
parent 54d7d284c8
commit 4ccbc1b958
2 changed files with 30 additions and 15 deletions

View File

@@ -1,40 +1,54 @@
// @flow // @flow
import React from 'react'; import React from 'react';
import { mapVector } from '../../../../Utils/MapFor'; import { mapVector } from '../../../../Utils/MapFor';
import Measure from 'react-measure';
const styles = { const styles = {
container: { container: {
position: 'relative', position: 'relative',
}, },
svg: {
width: '100%',
height: '100%',
},
}; };
type Props = {| type Props = {|
polygons: gdVectorPolygon2d, polygons: gdVectorPolygon2d,
imageWidth: number,
imageHeight: number,
|}; |};
export default class CollisionMasksPreview extends React.Component< export default class CollisionMasksPreview extends React.Component<
Props, Props,
void void
> { > {
render() { render() {
const { polygons } = this.props; const { polygons } = this.props;
return ( return (
<div style={styles.container}> <svg
<svg> width={this.props.imageWidth}
{mapVector(polygons, polygon => { height={this.props.imageHeight}
const vertices = polygon.getVertices(); style={styles.svg}
return mapVector(vertices, vertex => ( >
<circle {mapVector(polygons, (polygon, i) => {
cx={vertex.get_x()} const vertices = polygon.getVertices();
cy={vertex.get_y()} return (
r="3" <polygon
fill="blue" fill="rgba(255,0,0,0.2)"
/> stroke="rgba(255,0,0,0.5)"
)); strokeWidth={1}
})} fileRule="evenodd"
</svg> points={mapVector(
</div> vertices,
(vertex, j) => `${vertex.get_x()},${vertex.get_y()}`
).join(' ')}
/>
);
})}
</svg>
); );
} }
} }

View File

@@ -22,6 +22,7 @@ export default class SetupGridDialog extends Component {
const actions = [ const actions = [
<FlatButton <FlatButton
label="Cancel" label="Cancel"
primary={false}
onClick={this.props.onCancel} onClick={this.props.onCancel}
/>, />,
<FlatButton <FlatButton