Skip to content

Commit 641e345

Browse files
committed
curve-editor: add reset shortcut
1 parent 064fafc commit 641e345

File tree

9 files changed

+313
-241
lines changed

9 files changed

+313
-241
lines changed

app/build/mojs-curve-editor.js

Lines changed: 271 additions & 219 deletions
Large diffs are not rendered by default.

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

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

app/index.html

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,15 @@
3636

3737
var scaleCurve = new window.MojsCurveEditor({ name: 'curve_scale', isSaveState: true });
3838

39-
var curveEditor11 = new window.MojsCurveEditor({ name: 'curve111', isSaveState: true });
40-
4139
var curveEditor = new window.MojsCurveEditor({ name: 'curve1', isSaveState: true });
4240

43-
// var html = new mojs.Html({
44-
// el: '#js-el',
45-
// y: { [-200] : -200, curve: curveEditor.getEasing() },
46-
// scaleX: { 2:2, curve: scaleCurve.getEasing() }
47-
// });
41+
var html = new mojs.Html({
42+
el: '#js-el',
43+
y: { [-200] : -200, curve: curveEditor.getEasing() },
44+
scaleX: { 2:2, curve: scaleCurve.getEasing() }
45+
});
4846

49-
// new MojsPlayer({ add: html });
47+
new MojsPlayer({ add: html });
5048
// scaleX/scaleY : M0, 0 C0.6729540169506724, -28.101525445522107 13.041331697335014, -94.89847455447803 40, -95 C74.3872397312364, -94.81581115980767 71.04133169733501, 0.10152544552201628 100, 0
5149
// originY : M0, 0 C4.324651237095854, -97.09389091882751 -12.269098738159038, -100.52241754574061 40, -100 C69.70027963716932, -99.70315257828365 75, -100 75, -100 C75, -100 77.18670774544789, -105.94552943119928 80, 0 C93.51535255761112, -0.007114543223372127 100, 0 100, 0
5250
// var curveEditor = new window.MojsCurveEditor({ name: 'curve1', isSaveState: true });

app/js/actions/points.babel.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import C from '../constants';
2+
3+
export function reset (store) {
4+
store.dispatch({ type: 'POINTS_REMOVE' });
5+
store.dispatch({ type: 'POINT_ADD', data: { point: {x: 0, y: C.CURVE_SIZE, isLockedX: true}, index: 0 } });
6+
store.dispatch({ type: 'POINT_ADD', data: { point: {x: 100, y: 0, isLockedX: true}, index: 1 } });
7+
}

app/js/app.babel.jsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import C from './constants';
66
import hash from './helpers/hash';
77
import fallbackTo from './helpers/fallback-to';
88
import defer from './helpers/defer';
9+
import {reset} from './actions/points';
910
import addPointerDown from './helpers/add-pointer-down';
1011

1112
/*
@@ -42,7 +43,7 @@ class API {
4243
}
4344

4445
_vars () {
45-
this.revision = '1.2.1';
46+
this.revision = '1.3.0';
4647
this.store = initStore();
4748

4849
this._easings = [];
@@ -84,11 +85,7 @@ class API {
8485
_tryToRestore () {
8586
const stored = localStorage.getItem(this._localStorage);
8687
if ( stored ) { this.store.dispatch({ type: 'SET_STATE', data: JSON.parse(stored) });}
87-
else {
88-
this.store.dispatch({ type: 'POINT_ADD', data: { point: {x: 0, y: C.CURVE_SIZE, isLockedX: true}, index: 0 } });
89-
this.store.dispatch({ type: 'POINT_ADD', data: { point: {x: 100, y: 0, isLockedX: true}, index: 1 } });
90-
// this.store.dispatch({ type: 'POINT_SELECT', data: { index: 0, type: 'straight' } });
91-
}
88+
else { reset(this.store); }
9289
}
9390

9491
_subscribe () {
@@ -136,10 +133,10 @@ class API {
136133
_updateParent( easing ) {
137134
const parent = easing._parent;
138135

139-
// console.log(parent.timeline.callbacksContext);
140-
141136
if ( parent && parent.setProgress ) {
142137
this._triggerParent( parent );
138+
} else if (parent._o.callbacksContext) {
139+
this._triggerParent( parent._o.callbacksContext.timeline );
143140
} else if ( parent.timeline ) {
144141
this._triggerParent( parent.timeline )
145142
} else if ( parent.tween ) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ const pointsReducer = (state = INITIAL_STATE, action) => {
160160
return state;
161161
}
162162

163+
case 'POINTS_REMOVE': {
164+
return {...state, points: []};
165+
}
166+
163167
// case 'EDITOR_RESIZE': {
164168
// const {data} = action,
165169
// points = [...state.points],

app/js/tags/curve-editor.babel.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import CodePanel from './code-panel';
99
import Icons from './icons';
1010
import mod from '../helpers/resize-mod';
1111
import addPointerDown from '../helpers/add-pointer-down';
12+
import {reset} from '../actions/points';
1213
require('../../css/blocks/curve-editor');
1314

1415
class CurveEditor extends Component {
@@ -59,6 +60,8 @@ class CurveEditor extends Component {
5960
}
6061

6162
componentDidMount () {
63+
this._resetCounter = 0;
64+
6265
const {store} = this.context,
6366
el = this.base.querySelector('#js-left-panel'),
6467
mc = propagating(new Hammer.Manager(el));
@@ -90,6 +93,7 @@ class CurveEditor extends Component {
9093

9194
_onKeyUp (e) {
9295
const {store} = this.context;
96+
console.log( e.which );
9397
if ( !e.altKey ) { return; }
9498
switch (e.which) {
9599
// z
@@ -98,9 +102,18 @@ class CurveEditor extends Component {
98102
case 88: { return store.dispatch(ActionCreators.redo()); }
99103
// d
100104
case 68: { return store.dispatch({ type: 'POINT_DELETE' }); }
105+
// \
106+
case 220: { return e.shiftKey && this._tryToReset(store); }
101107
}
102108
}
103109

110+
_tryToReset (store) {
111+
if (++this._resetCounter > 2) { reset(store); }
112+
113+
clearTimeout(this._tm);
114+
this._tm = setTimeout(() => { this._resetCounter = 0; }, 300);
115+
}
116+
104117
}
105118

106119

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mojs-curve-editor",
3-
"version": "1.2.1",
3+
"version": "1.3.0",
44
"description": "mojs GUI for editing easing/property curves",
55
"keywords": [
66
"mojs",

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ After you are happy with the curve you need to change the `sample`(`mojsCurve.ge
108108
- `alt + z` - `undo` curve action
109109
- `alt + x` - `rendo` curve action
110110
- `alt + d` - `delete` selected point(s)
111+
- [3 times] `alt + \` - `reset` curve
111112

112113
## Development
113114

0 commit comments

Comments
 (0)