Skip to content

Commit 0cbec25

Browse files
committed
little-handle: add angle/radius properties instead of x/y
1 parent 1755420 commit 0cbec25

11 files changed

+279
-101
lines changed

app/build/mojs-curve-editor.js

Lines changed: 152 additions & 65 deletions
Large diffs are not rendered by default.

app/build/mojs-curve-editor.min.js

Lines changed: 5 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/css/blocks/code-panel.postcss.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
border-radius: calc( 6 * $PX ) calc( 6 * $PX ) 0 0;
99
background: rgba( 61, 27, 60, 1 );
1010
z-index: 1;
11+
display: none;
1112

1213
&__input-wrap {
1314
margin: calc( 4 * $PX ) calc( 5 * $PX ) calc( 5 * $PX );
@@ -24,7 +25,6 @@
2425
font-size: 9px;
2526
font-family: Arial, Helvetica, sans-serif;
2627
letter-spacing: 0.45px;
27-
line-height: 21px;
2828
font-weight: 100;
2929
padding: 0 0.3em 0 0.8em;
3030
border: none;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"code-panel":"_code-panel_1tvha_3","code-panel__input-wrap":"_code-panel__input-wrap_1tvha_1","code-panel__input-field":"_code-panel__input-field_1tvha_1"}
1+
{"code-panel":"_code-panel_1furt_3","code-panel__input-wrap":"_code-panel__input-wrap_1furt_1","code-panel__input-field":"_code-panel__input-field_1furt_1"}

app/css/blocks/point.postcss.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ $size: 10;
3838

3939
&:hover,
4040
&.is-selected {
41-
border-color: #8C6D8B;
41+
/*border-color: #8C6D8B;*/
42+
border-color: $c-orange;
4243
}
4344

4445
&.is-selected {

app/css/blocks/point.postcss.css.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"point":"_point_at09i_5","is-selected":"_is-selected_at09i_40","is-hide-handles":"_is-hide-handles_at09i_50"}
1+
{"point":"_point_3a5h7_5","is-selected":"_is-selected_3a5h7_40","is-hide-handles":"_is-hide-handles_3a5h7_51"}

app/js/helpers/make-point.babel.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ const fallback = ( value, fallback ) => {
33
return ( value != null ) ? value : fallback;
44
}
55

6+
7+
const makeHandlePoint = (o={}) => {
8+
return {
9+
index: fallback( o.index, 0 ),
10+
// coordinates
11+
angle: fallback( o.angle, -45 ),
12+
radius: fallback( o.radius, 25 ),
13+
// temporary coordinates (when user moves the point) -
14+
// should not be in history
15+
tempAngle: fallback( o.tempAngle, 0 ),
16+
tempRadius: fallback( o.tempRadius, 0 ),
17+
// state
18+
isTouched: fallback( o.isTouched, false ),
19+
isSelected: fallback( o.isSelected, false ),
20+
};
21+
}
22+
623
const makePositionPoint = (o={}) => {
724
return {
825
// coordinates
@@ -30,8 +47,8 @@ const makePoint = (o = {}) => {
3047
// add position attributes to self
3148
...makePositionPoint(o),
3249
// add curve handles
33-
handle1: makePositionPoint(o.handle1 || { x: -25, y: -25 }),
34-
handle2: makePositionPoint(o.handle2 || { x: 25, y: -25 })
50+
handle1: makeHandlePoint(o.handle1 || { index: 1 }),
51+
handle2: makeHandlePoint(o.handle2 || { index: 2 })
3552
};
3653
}
3754

app/js/reducers/points-reducer.babel.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,29 @@ const pointsReducer = (state = INITIAL_STATE, action) => {
9898

9999
return newState;
100100
}
101-
101+
102102
case 'POINT_DESELECT_ALL': {
103103
return deslectAll( state );
104104
}
105+
106+
107+
// HANDLES
108+
case 'HANDLE_TRANSLATE': {
109+
const {data} = action;
110+
// create new state and copy the new point into it
111+
const newState = [...state];
112+
const newPoint = { ...newState[data.parentIndex] };
113+
newState[data.parentIndex] = newPoint;
114+
// create handle and copy it into the new point
115+
const handleName = `handle${data.index}`;
116+
const newHandle = { ...newPoint[handleName] };
117+
newPoint[ handleName ] = newHandle;
118+
// finally add angle and radius
119+
newHandle.angle = data.angle;
120+
newHandle.radius = data.radius;
121+
122+
return newState;
123+
}
105124
}
106125
return state;
107126
}

app/js/reducers/resize-reducer.babel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
const INITIAL_STATE = {
3-
translate: { x: 150, y: 150 },
3+
translate: { x: 150, y: 100 },
44
top: 0,
55
temp_top: 0,
66

app/js/tags/little-handle.tag

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,85 @@
11

2+
3+
24
<little-handle class={ this.CLASSES['little-handle'] } style={this.getStyle()}>
35

46
<script type="babel">
57
this.CLASSES = require('../../css/blocks/little-handle.postcss.css.json');
68
require('../../css/blocks/little-handle');
9+
import store from '../store';
10+
store.subscribe(() => {
11+
this.update();
12+
});
13+
14+
const angleToPoint = (angle, radius) => {
15+
return mojs.h.getRadialPoint({ angle, radius, center: { x: 0, y: 0 } })
16+
}
17+
18+
const anglePointToAngle = (x, y) => {
19+
let radius = Math.sqrt( x*x + y*y ),
20+
angle = Math.atan( y/x ) * (180/Math.PI) - 90;
21+
if ( x > 0 ) { angle = angle - 180 };
22+
23+
return { radius, angle };
24+
}
725

826
this.getStyle = () => {
9-
// const {resize} = store.getState(),
10-
// x = clamp(this.point.x + this.point.tempX, 0, 100),
11-
// cleanX = x * resize.scalerX;
12-
13-
// let y = this.point.y + this.point.tempY;
14-
const x = this.x + this.tempX,
15-
y = this.y + this.tempY;
16-
17-
const translate = `transform: translate(${x}px, ${y}px)`;
27+
const point = angleToPoint( this.angle, this.radius );
28+
29+
const translate = `transform: translate(${point.x}px, ${point.y}px) rotate(${this.angle}deg)`;
1830
return `${mojs.h.prefix.css}${translate}; ${translate}`;
1931
}
2032

33+
import Hammer from 'hammerjs';
34+
import propagating from 'propagating-hammerjs';
35+
this.on('mount', () => {
36+
var hammertime = propagating(new Hammer(this.root))
37+
.on('pan', (e) => {
38+
const point = angleToPoint( this.angle, this.radius ),
39+
newX = point.x + e.deltaX,
40+
newY = point.y + e.deltaY;
41+
42+
store.dispatch({
43+
type: 'HANDLE_TRANSLATE',
44+
data: {
45+
index: this.index,
46+
parentIndex: this.opts.parentIndex,
47+
...anglePointToAngle( newX, newY )
48+
}
49+
});
50+
51+
e.stopPropagation();
52+
})
53+
.on('panend', (e) => {
54+
// // reset temporary deltas
55+
// store.dispatch({ type: 'POINT_TRANSLATE', data: { x: 0, y: 0, index: this._index } });
56+
// // fire translate end and save it to the store
57+
// store.dispatch({
58+
// type: 'POINT_TRANSLATE_END',
59+
// data: {
60+
// x: this.point.x + getTempX(e),
61+
// y: getY(e),
62+
// index: this._index
63+
// },
64+
// isRecord: true
65+
// });
66+
67+
e.stopPropagation();
68+
})
69+
// .on('tap', (e) => {
70+
// store.dispatch({
71+
// type: 'POINT_SELECT',
72+
// data: {
73+
// index: this._index,
74+
// type: this.point.type,
75+
// isDeselect: !e.srcEvent.shiftKey
76+
// }
77+
78+
// });
79+
// e.stopPropagation();
80+
// });
81+
});
82+
2183
</script>
2284

2385
</little-handle>

0 commit comments

Comments
 (0)