-
Notifications
You must be signed in to change notification settings - Fork 6
/
TranshandDesign.jsx
69 lines (61 loc) · 1.77 KB
/
TranshandDesign.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React from 'react'
import fixCursorStyle from './fixCursorStyle'
export default class TranshandDesign extends React.Component {
render() {
var {rotateFingerDist, originRadius, stroke, getHitEvents,
coordinator, cursor, points, pOrigin, transformTypes} = this.props,
p = points.map(point => coordinator.localToGlobal(point)),
po = coordinator.localToGlobal(pOrigin),
or = originRadius
var boxHitPoints =
`${p[0].x} ,${p[0].y} ` +
`${p[1].x} ,${p[1].y} ` +
`${p[2].x} ,${p[2].y} ` +
`${p[3].x} ,${p[3].y}`
function renderOrigin() {
if (transformTypes.indexOf('origin') !== -1) {
return [
<line key='h' x1={po.x - or} y1={po.y} x2={po.x + or} y2={po.y} {...stroke}/>,
<line key='v' x1={po.x} y1={po.y - or} x2={po.x} y2={po.y + or} {...stroke}/>
]
}
else {
return null
}
}
return <g>
<polygon
fill='none'
{...stroke}
points = {boxHitPoints}>
</polygon>
{renderOrigin()}
<polygon ref='boxHit'
fill="black" opacity="0"
stroke="black"
strokeLinejoin='round'
strokeLocation='outside'
strokeWidth={rotateFingerDist}
points = {boxHitPoints}
style={{
cursor,
pointerEvents: 'auto',
}}
{...getHitEvents()}/>
<circle ref='originHit'
fill="black" opacity="0"
cx = {po.x}
cy = {po.y}
r = {originRadius}
style={{
cursor,
pointerEvents: 'auto',
}}
{...getHitEvents()}/>
</g>
}
componentDidUpdate() {
fixCursorStyle(this.refs.boxHit, this.props.cursor)//HACK
fixCursorStyle(this.refs.originHit, this.props.cursor)//HACK
}
}