@checksub_team/peaks_timeline 1.4.35 → 1.4.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/mode-layer.js CHANGED
@@ -1,391 +1,391 @@
1
- /**
2
- * @file
3
- *
4
- * Defines the {@link ModeLayer} class.
5
- *
6
- * @module mode-layer
7
- */
8
-
9
- define([
10
- './utils',
11
- './source-group',
12
- 'konva'
13
- ], function(Utils, SourceGroup, Konva) {
14
- 'use strict';
15
-
16
- var TIME_X_OFFSET = 20;
17
- var TIME_Y_OFFSET = 10;
18
-
19
- /**
20
- * Creates a Konva.Layer that displays additionnal information for alternative modes.
21
- *
22
- * @class
23
- * @alias ModeLayer
24
- *
25
- * @param {Peaks} peaks
26
- * @param {WaveformOverview|WaveformZoomView} view
27
- * @param {String} initialMode
28
- */
29
-
30
- function ModeLayer(peaks, view, stage, initialMode) {
31
- this._peaks = peaks;
32
- this._view = view;
33
- this._stage = stage;
34
-
35
- this._layer = new Konva.Layer({
36
- listening: this._mode !== 'default'
37
- });
38
-
39
- this._prepareDefaultMode();
40
-
41
- this._onMouseClickInDefaultMode = this._onMouseClickInDefaultMode.bind(this);
42
- this._onKeyboardDelete = this._onKeyboardDelete.bind(this);
43
-
44
- this._prepareCutMode();
45
-
46
- this._onMouseEnterInCutMode = this._onMouseEnterInCutMode.bind(this);
47
- this._onMouseMoveInCutMode = this._onMouseMoveInCutMode.bind(this);
48
- this._onMouseLeaveInCutMode = this._onMouseLeaveInCutMode.bind(this);
49
- this._onMouseClickInCutMode = this._onMouseClickInCutMode.bind(this);
50
-
51
- this.setMode(initialMode);
52
- }
53
-
54
- /**
55
- * Adds the layer to the given {Konva.Stage}.
56
- *
57
- * @param {Konva.Stage} stage
58
- */
59
-
60
- ModeLayer.prototype.addToStage = function(stage) {
61
- stage.add(this._layer);
62
- };
63
-
64
- ModeLayer.prototype.selectElement = function(element, notify) {
65
- this.deselectElement(notify);
66
- if (element) {
67
- this._selectedElement = element;
68
- this._selectedElement.setSelected(true);
69
- if (notify) {
70
- if (element instanceof SourceGroup) {
71
- this._peaks.emit('source.selected', this._selectedElement.getSource());
72
- }
73
- else {
74
- this._peaks.emit('segment.selected', this._selectedElement.getSegment());
75
- }
76
- }
77
- }
78
- };
79
-
80
- ModeLayer.prototype.deselectElement = function(notify) {
81
- if (this._selectedElement) {
82
- this._selectedElement.setSelected(false);
83
- if (notify) {
84
- if (this._selectedElement instanceof SourceGroup) {
85
- this._peaks.emit('source.deselected', this._selectedElement.getSource());
86
- }
87
- else {
88
- this._peaks.emit('segment.deselected', this._selectedElement.getSegment());
89
- }
90
- }
91
- this._selectedElement = null;
92
- }
93
- };
94
-
95
- ModeLayer.prototype._prepareDefaultMode = function() {
96
- this._selectedElement = null;
97
- };
98
-
99
- ModeLayer.prototype._prepareCutMode = function() {
100
- this._cutGroup = new Konva.Group({
101
- width: this._view.getWidth(),
102
- height: this._view.getHeight(),
103
- visible: false,
104
- listening: false
105
- });
106
-
107
- this._cursorTime = new Konva.Group({
108
- listening: false
109
- });
110
-
111
- this._timeLabel = new Konva.Text({
112
- x: 4,
113
- y: 2,
114
- text: '00:00:00',
115
- fontSize: 11,
116
- fontFamily: 'Open Sans',
117
- fill: '#999b9d',
118
- align: 'center',
119
- listening: false
120
- });
121
-
122
- this._timeBackground = new Konva.Rect({
123
- width: this._timeLabel.width() + 8,
124
- height: this._timeLabel.height() + 4,
125
- cornerRadius: 3,
126
- fill: '#37373c',
127
- strokeWidth: 0,
128
- listening: false
129
- });
130
-
131
- this._cursorTime.add(this._timeBackground);
132
- this._cursorTime.add(this._timeLabel);
133
-
134
- this._cuttingLine = new Konva.Line({
135
- points: [0, 0, 0, 10],
136
- stroke: 'red',
137
- strokeWidth: 1,
138
- opacity: 0.8,
139
- listening: false,
140
- visible: false
141
- });
142
-
143
- this._cutGroup.add(this._cursorTime);
144
- this._cutGroup.add(this._cuttingLine);
145
-
146
- this._layer.add(this._cutGroup);
147
- };
148
-
149
- ModeLayer.prototype._onMouseClickInDefaultMode = function() {
150
- var hoveredElement = this._view.getHoveredElement();
151
-
152
- if (hoveredElement) {
153
- this.selectElement(hoveredElement, true);
154
- }
155
- else {
156
- this.deselectElement(true);
157
- }
158
- };
159
-
160
- ModeLayer.prototype._onKeyboardDelete = function() {
161
- if (this._selectedElement) {
162
- var selectedElement = this._selectedElement;
163
-
164
- this.deselectElement(true);
165
-
166
- if (selectedElement instanceof SourceGroup) {
167
- this._peaks.destroySource(selectedElement.getSource().id);
168
- }
169
- else {
170
- if (selectedElement.getSegment().allowDeletion) {
171
- this._peaks.destroySegment(selectedElement.getSegment().id);
172
- }
173
- }
174
- }
175
- };
176
-
177
- ModeLayer.prototype._onMouseEnterInCutMode = function() {
178
- this._cutGroup.visible(true);
179
-
180
- this._layer.draw();
181
- };
182
-
183
- ModeLayer.prototype._updateCursorTime = function(mousePosition) {
184
- var hoveredElement = this._view.getHoveredElement();
185
-
186
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
187
- this._timeLabel.text(
188
- Utils.formatTime(
189
- this._view.pixelsToTime(mousePosition.x + this._view.getFrameOffset()),
190
- false
191
- )
192
- );
193
-
194
- this._timeBackground.width(this._timeLabel.width() + 8);
195
-
196
- this._cursorTime.x(mousePosition.x + TIME_X_OFFSET);
197
-
198
- if (mousePosition.y > this._view.getHeight()
199
- - this._timeBackground.height() - TIME_Y_OFFSET) {
200
- this._cursorTime.y(mousePosition.y - TIME_Y_OFFSET);
201
- }
202
- else {
203
- this._cursorTime.y(mousePosition.y + TIME_Y_OFFSET);
204
- }
205
-
206
- this._cursorTime.visible(true);
207
- }
208
- else {
209
- this._cursorTime.visible(false);
210
- }
211
- };
212
-
213
- ModeLayer.prototype._updateCuttingLine = function(mousePosition) {
214
- var hoveredElement = this._view.getHoveredElement();
215
-
216
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
217
- var minSize = this._view.timeToPixels(hoveredElement.getSource().minSize);
218
-
219
- if (hoveredElement.getWidth() >= 2 * minSize) {
220
- var height = hoveredElement.getCurrentHeight();
221
- var y = hoveredElement.getY();
222
-
223
- if (mousePosition.x < hoveredElement.x() + minSize) {
224
- this._cuttingLine.points([
225
- hoveredElement.x() + minSize,
226
- y,
227
- hoveredElement.x() + minSize,
228
- y + height
229
- ]);
230
- }
231
- else if (mousePosition.x
232
- > hoveredElement.x() + hoveredElement.getWidth() - minSize) {
233
- this._cuttingLine.points([
234
- hoveredElement.x() + hoveredElement.getWidth() - minSize,
235
- y,
236
- hoveredElement.x() + hoveredElement.getWidth() - minSize,
237
- y + height
238
- ]);
239
- }
240
- else {
241
- this._cuttingLine.points([mousePosition.x, y, mousePosition.x, y + height]);
242
- }
243
- this._cuttingLine.visible(true);
244
- }
245
- else {
246
- this._view.setCursor('not-allowed');
247
- }
248
- }
249
- else {
250
- this._cuttingLine.visible(false);
251
-
252
- if (this._view.getCursor('not-allowed')) {
253
- this._view.setCursor('default');
254
- }
255
- }
256
- };
257
-
258
- ModeLayer.prototype._onMouseMoveInCutMode = function() {
259
- var mousePosition = this._stage.getPointerPosition();
260
-
261
- mousePosition.x = this._view.timeToPixels(this._view.pixelsToTime(mousePosition.x));
262
-
263
- this._updateCursorTime(mousePosition);
264
- this._updateCuttingLine(mousePosition);
265
-
266
- this._layer.draw();
267
- };
268
-
269
- ModeLayer.prototype._onMouseLeaveInCutMode = function() {
270
- this._cutGroup.visible(false);
271
-
272
- this._layer.draw();
273
- };
274
-
275
- ModeLayer.prototype._onMouseClickInCutMode = function() {
276
- var mousePosition = this._stage.getPointerPosition();
277
-
278
- mousePosition.x = this._view.timeToPixels(this._view.pixelsToTime(mousePosition.x));
279
-
280
- var hoveredElement = this._view.getHoveredElement();
281
-
282
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
283
- var minSize = this._view.timeToPixels(hoveredElement.getSource().minSize);
284
-
285
- if (hoveredElement.getWidth() >= 2 * minSize) {
286
- var cuttingPixel;
287
-
288
- if (mousePosition.x < hoveredElement.x() + minSize) {
289
- cuttingPixel = hoveredElement.x() + minSize;
290
- }
291
- else if (mousePosition.x
292
- > hoveredElement.x() + hoveredElement.getWidth() - minSize) {
293
- cuttingPixel = hoveredElement.x()
294
- + hoveredElement.getWidth() - minSize;
295
- }
296
- else {
297
- cuttingPixel = mousePosition.x;
298
- }
299
-
300
- // Relative cuttingPixel
301
- cuttingPixel -= hoveredElement.x();
302
-
303
- this._cuttingLine.visible(false);
304
-
305
- this._peaks.emit(
306
- 'source.cut',
307
- hoveredElement.getSource(),
308
- this._view.pixelsToTime(cuttingPixel)
309
- );
310
- }
311
- }
312
- };
313
-
314
- ModeLayer.prototype.setMode = function(mode) {
315
- if (this._mode === mode) {
316
- return;
317
- }
318
- var hoveredElement = this._view.getHoveredElement();
319
-
320
- // Clean current mode
321
- switch (this._mode) {
322
- case 'cut':
323
- this._stage.off('mouseover', this._onMouseEnterInCutMode);
324
- this._stage.off('mousemove', this._onMouseMoveInCutMode);
325
- this._stage.off('mouseleave', this._onMouseLeaveInCutMode);
326
- this._stage.off('click', this._onMouseClickInCutMode);
327
- this._cutGroup.visible(false);
328
-
329
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
330
- hoveredElement.toggleDragging(hoveredElement.getSource().draggable);
331
- hoveredElement.toggleResizing(hoveredElement.getSource().resizable);
332
- }
333
-
334
- this._view.toggleMainCursor(false);
335
- break;
336
- case 'default':
337
- this._stage.off('click', this._onMouseClickInDefaultMode);
338
- this._peaks.off('keyboard.delete', this._onKeyboardDelete);
339
- break;
340
- }
341
-
342
- this.deselectElement(true);
343
-
344
- // Set new mode
345
- switch (mode) {
346
- case 'cut':
347
- this._stage.on('mouseover', this._onMouseEnterInCutMode);
348
- this._stage.on('mousemove', this._onMouseMoveInCutMode);
349
- this._stage.on('mouseleave', this._onMouseLeaveInCutMode);
350
- this._stage.on('click', this._onMouseClickInCutMode);
351
-
352
- var mousePosition = this._stage.getPointerPosition();
353
-
354
- if (mousePosition) {
355
- mousePosition.x = this._view.timeToPixels(this._view.pixelsToTime(mousePosition.x));
356
-
357
- if (mousePosition.x > 0 && mousePosition.x < this._view.getWidth()
358
- && mousePosition.y > 0 && mousePosition.y < this._view.getHeight()) {
359
- this._cutGroup.visible(true);
360
-
361
- this._updateCursorTime(mousePosition);
362
- this._updateCuttingLine(mousePosition);
363
- }
364
- }
365
-
366
- if (hoveredElement && hoveredElement instanceof SourceGroup) {
367
- hoveredElement.toggleDragging(false);
368
- hoveredElement.toggleResizing(false);
369
- }
370
-
371
- this._view.toggleMainCursor(true, 'default');
372
- break;
373
- case 'default':
374
- this._stage.on('click', this._onMouseClickInDefaultMode);
375
- this._peaks.on('keyboard.delete', this._onKeyboardDelete);
376
- break;
377
- default:
378
- return;
379
- }
380
-
381
- this._mode = mode;
382
- this._layer.draw();
383
- this._view.drawSourcesLayer();
384
- };
385
-
386
- ModeLayer.prototype.getCurrentMode = function() {
387
- return this._mode;
388
- };
389
-
390
- return ModeLayer;
391
- });
1
+ /**
2
+ * @file
3
+ *
4
+ * Defines the {@link ModeLayer} class.
5
+ *
6
+ * @module mode-layer
7
+ */
8
+
9
+ define([
10
+ './utils',
11
+ './source-group',
12
+ 'konva'
13
+ ], function(Utils, SourceGroup, Konva) {
14
+ 'use strict';
15
+
16
+ var TIME_X_OFFSET = 20;
17
+ var TIME_Y_OFFSET = 10;
18
+
19
+ /**
20
+ * Creates a Konva.Layer that displays additionnal information for alternative modes.
21
+ *
22
+ * @class
23
+ * @alias ModeLayer
24
+ *
25
+ * @param {Peaks} peaks
26
+ * @param {WaveformOverview|WaveformZoomView} view
27
+ * @param {String} initialMode
28
+ */
29
+
30
+ function ModeLayer(peaks, view, stage, initialMode) {
31
+ this._peaks = peaks;
32
+ this._view = view;
33
+ this._stage = stage;
34
+
35
+ this._layer = new Konva.Layer({
36
+ listening: this._mode !== 'default'
37
+ });
38
+
39
+ this._prepareDefaultMode();
40
+
41
+ this._onMouseClickInDefaultMode = this._onMouseClickInDefaultMode.bind(this);
42
+ this._onKeyboardDelete = this._onKeyboardDelete.bind(this);
43
+
44
+ this._prepareCutMode();
45
+
46
+ this._onMouseEnterInCutMode = this._onMouseEnterInCutMode.bind(this);
47
+ this._onMouseMoveInCutMode = this._onMouseMoveInCutMode.bind(this);
48
+ this._onMouseLeaveInCutMode = this._onMouseLeaveInCutMode.bind(this);
49
+ this._onMouseClickInCutMode = this._onMouseClickInCutMode.bind(this);
50
+
51
+ this.setMode(initialMode);
52
+ }
53
+
54
+ /**
55
+ * Adds the layer to the given {Konva.Stage}.
56
+ *
57
+ * @param {Konva.Stage} stage
58
+ */
59
+
60
+ ModeLayer.prototype.addToStage = function(stage) {
61
+ stage.add(this._layer);
62
+ };
63
+
64
+ ModeLayer.prototype.selectElement = function(element, notify) {
65
+ this.deselectElement(notify);
66
+ if (element) {
67
+ this._selectedElement = element;
68
+ this._selectedElement.setSelected(true);
69
+ if (notify) {
70
+ if (element instanceof SourceGroup) {
71
+ this._peaks.emit('source.selected', this._selectedElement.getSource());
72
+ }
73
+ else {
74
+ this._peaks.emit('segment.selected', this._selectedElement.getSegment());
75
+ }
76
+ }
77
+ }
78
+ };
79
+
80
+ ModeLayer.prototype.deselectElement = function(notify) {
81
+ if (this._selectedElement) {
82
+ this._selectedElement.setSelected(false);
83
+ if (notify) {
84
+ if (this._selectedElement instanceof SourceGroup) {
85
+ this._peaks.emit('source.deselected', this._selectedElement.getSource());
86
+ }
87
+ else {
88
+ this._peaks.emit('segment.deselected', this._selectedElement.getSegment());
89
+ }
90
+ }
91
+ this._selectedElement = null;
92
+ }
93
+ };
94
+
95
+ ModeLayer.prototype._prepareDefaultMode = function() {
96
+ this._selectedElement = null;
97
+ };
98
+
99
+ ModeLayer.prototype._prepareCutMode = function() {
100
+ this._cutGroup = new Konva.Group({
101
+ width: this._view.getWidth(),
102
+ height: this._view.getHeight(),
103
+ visible: false,
104
+ listening: false
105
+ });
106
+
107
+ this._cursorTime = new Konva.Group({
108
+ listening: false
109
+ });
110
+
111
+ this._timeLabel = new Konva.Text({
112
+ x: 4,
113
+ y: 2,
114
+ text: '00:00:00',
115
+ fontSize: 11,
116
+ fontFamily: 'Open Sans',
117
+ fill: '#999b9d',
118
+ align: 'center',
119
+ listening: false
120
+ });
121
+
122
+ this._timeBackground = new Konva.Rect({
123
+ width: this._timeLabel.width() + 8,
124
+ height: this._timeLabel.height() + 4,
125
+ cornerRadius: 3,
126
+ fill: '#37373c',
127
+ strokeWidth: 0,
128
+ listening: false
129
+ });
130
+
131
+ this._cursorTime.add(this._timeBackground);
132
+ this._cursorTime.add(this._timeLabel);
133
+
134
+ this._cuttingLine = new Konva.Line({
135
+ points: [0, 0, 0, 10],
136
+ stroke: 'red',
137
+ strokeWidth: 1,
138
+ opacity: 0.8,
139
+ listening: false,
140
+ visible: false
141
+ });
142
+
143
+ this._cutGroup.add(this._cursorTime);
144
+ this._cutGroup.add(this._cuttingLine);
145
+
146
+ this._layer.add(this._cutGroup);
147
+ };
148
+
149
+ ModeLayer.prototype._onMouseClickInDefaultMode = function() {
150
+ var hoveredElement = this._view.getHoveredElement();
151
+
152
+ if (hoveredElement) {
153
+ this.selectElement(hoveredElement, true);
154
+ }
155
+ else {
156
+ this.deselectElement(true);
157
+ }
158
+ };
159
+
160
+ ModeLayer.prototype._onKeyboardDelete = function() {
161
+ if (this._selectedElement) {
162
+ var selectedElement = this._selectedElement;
163
+
164
+ this.deselectElement(true);
165
+
166
+ if (selectedElement instanceof SourceGroup) {
167
+ this._peaks.destroySource(selectedElement.getSource().id);
168
+ }
169
+ else {
170
+ if (selectedElement.getSegment().allowDeletion) {
171
+ this._peaks.destroySegment(selectedElement.getSegment().id);
172
+ }
173
+ }
174
+ }
175
+ };
176
+
177
+ ModeLayer.prototype._onMouseEnterInCutMode = function() {
178
+ this._cutGroup.visible(true);
179
+
180
+ this._layer.draw();
181
+ };
182
+
183
+ ModeLayer.prototype._updateCursorTime = function(mousePosition) {
184
+ var hoveredElement = this._view.getHoveredElement();
185
+
186
+ if (hoveredElement && hoveredElement instanceof SourceGroup) {
187
+ this._timeLabel.text(
188
+ Utils.formatTime(
189
+ this._view.pixelsToTime(mousePosition.x + this._view.getFrameOffset()),
190
+ false
191
+ )
192
+ );
193
+
194
+ this._timeBackground.width(this._timeLabel.width() + 8);
195
+
196
+ this._cursorTime.x(mousePosition.x + TIME_X_OFFSET);
197
+
198
+ if (mousePosition.y > this._view.getHeight()
199
+ - this._timeBackground.height() - TIME_Y_OFFSET) {
200
+ this._cursorTime.y(mousePosition.y - TIME_Y_OFFSET);
201
+ }
202
+ else {
203
+ this._cursorTime.y(mousePosition.y + TIME_Y_OFFSET);
204
+ }
205
+
206
+ this._cursorTime.visible(true);
207
+ }
208
+ else {
209
+ this._cursorTime.visible(false);
210
+ }
211
+ };
212
+
213
+ ModeLayer.prototype._updateCuttingLine = function(mousePosition) {
214
+ var hoveredElement = this._view.getHoveredElement();
215
+
216
+ if (hoveredElement && hoveredElement instanceof SourceGroup) {
217
+ var minSize = this._view.timeToPixels(hoveredElement.getSource().minSize);
218
+
219
+ if (hoveredElement.getWidth() >= 2 * minSize) {
220
+ var height = hoveredElement.getCurrentHeight();
221
+ var y = hoveredElement.getY();
222
+
223
+ if (mousePosition.x < hoveredElement.x() + minSize) {
224
+ this._cuttingLine.points([
225
+ hoveredElement.x() + minSize,
226
+ y,
227
+ hoveredElement.x() + minSize,
228
+ y + height
229
+ ]);
230
+ }
231
+ else if (mousePosition.x
232
+ > hoveredElement.x() + hoveredElement.getWidth() - minSize) {
233
+ this._cuttingLine.points([
234
+ hoveredElement.x() + hoveredElement.getWidth() - minSize,
235
+ y,
236
+ hoveredElement.x() + hoveredElement.getWidth() - minSize,
237
+ y + height
238
+ ]);
239
+ }
240
+ else {
241
+ this._cuttingLine.points([mousePosition.x, y, mousePosition.x, y + height]);
242
+ }
243
+ this._cuttingLine.visible(true);
244
+ }
245
+ else {
246
+ this._view.setCursor('not-allowed');
247
+ }
248
+ }
249
+ else {
250
+ this._cuttingLine.visible(false);
251
+
252
+ if (this._view.getCursor('not-allowed')) {
253
+ this._view.setCursor('default');
254
+ }
255
+ }
256
+ };
257
+
258
+ ModeLayer.prototype._onMouseMoveInCutMode = function() {
259
+ var mousePosition = this._stage.getPointerPosition();
260
+
261
+ mousePosition.x = this._view.timeToPixels(this._view.pixelsToTime(mousePosition.x));
262
+
263
+ this._updateCursorTime(mousePosition);
264
+ this._updateCuttingLine(mousePosition);
265
+
266
+ this._layer.draw();
267
+ };
268
+
269
+ ModeLayer.prototype._onMouseLeaveInCutMode = function() {
270
+ this._cutGroup.visible(false);
271
+
272
+ this._layer.draw();
273
+ };
274
+
275
+ ModeLayer.prototype._onMouseClickInCutMode = function() {
276
+ var mousePosition = this._stage.getPointerPosition();
277
+
278
+ mousePosition.x = this._view.timeToPixels(this._view.pixelsToTime(mousePosition.x));
279
+
280
+ var hoveredElement = this._view.getHoveredElement();
281
+
282
+ if (hoveredElement && hoveredElement instanceof SourceGroup) {
283
+ var minSize = this._view.timeToPixels(hoveredElement.getSource().minSize);
284
+
285
+ if (hoveredElement.getWidth() >= 2 * minSize) {
286
+ var cuttingPixel;
287
+
288
+ if (mousePosition.x < hoveredElement.x() + minSize) {
289
+ cuttingPixel = hoveredElement.x() + minSize;
290
+ }
291
+ else if (mousePosition.x
292
+ > hoveredElement.x() + hoveredElement.getWidth() - minSize) {
293
+ cuttingPixel = hoveredElement.x()
294
+ + hoveredElement.getWidth() - minSize;
295
+ }
296
+ else {
297
+ cuttingPixel = mousePosition.x;
298
+ }
299
+
300
+ // Relative cuttingPixel
301
+ cuttingPixel -= hoveredElement.x();
302
+
303
+ this._cuttingLine.visible(false);
304
+
305
+ this._peaks.emit(
306
+ 'source.cut',
307
+ hoveredElement.getSource(),
308
+ this._view.pixelsToTime(cuttingPixel)
309
+ );
310
+ }
311
+ }
312
+ };
313
+
314
+ ModeLayer.prototype.setMode = function(mode) {
315
+ if (this._mode === mode) {
316
+ return;
317
+ }
318
+ var hoveredElement = this._view.getHoveredElement();
319
+
320
+ // Clean current mode
321
+ switch (this._mode) {
322
+ case 'cut':
323
+ this._stage.off('mouseover', this._onMouseEnterInCutMode);
324
+ this._stage.off('mousemove', this._onMouseMoveInCutMode);
325
+ this._stage.off('mouseleave', this._onMouseLeaveInCutMode);
326
+ this._stage.off('click', this._onMouseClickInCutMode);
327
+ this._cutGroup.visible(false);
328
+
329
+ if (hoveredElement && hoveredElement instanceof SourceGroup) {
330
+ hoveredElement.toggleDragging(hoveredElement.getSource().draggable);
331
+ hoveredElement.toggleResizing(hoveredElement.getSource().resizable);
332
+ }
333
+
334
+ this._view.toggleMainCursor(false);
335
+ break;
336
+ case 'default':
337
+ this._stage.off('click', this._onMouseClickInDefaultMode);
338
+ this._peaks.off('keyboard.delete', this._onKeyboardDelete);
339
+ break;
340
+ }
341
+
342
+ this.deselectElement(true);
343
+
344
+ // Set new mode
345
+ switch (mode) {
346
+ case 'cut':
347
+ this._stage.on('mouseover', this._onMouseEnterInCutMode);
348
+ this._stage.on('mousemove', this._onMouseMoveInCutMode);
349
+ this._stage.on('mouseleave', this._onMouseLeaveInCutMode);
350
+ this._stage.on('click', this._onMouseClickInCutMode);
351
+
352
+ var mousePosition = this._stage.getPointerPosition();
353
+
354
+ if (mousePosition) {
355
+ mousePosition.x = this._view.timeToPixels(this._view.pixelsToTime(mousePosition.x));
356
+
357
+ if (mousePosition.x > 0 && mousePosition.x < this._view.getWidth()
358
+ && mousePosition.y > 0 && mousePosition.y < this._view.getHeight()) {
359
+ this._cutGroup.visible(true);
360
+
361
+ this._updateCursorTime(mousePosition);
362
+ this._updateCuttingLine(mousePosition);
363
+ }
364
+ }
365
+
366
+ if (hoveredElement && hoveredElement instanceof SourceGroup) {
367
+ hoveredElement.toggleDragging(false);
368
+ hoveredElement.toggleResizing(false);
369
+ }
370
+
371
+ this._view.toggleMainCursor(true, 'default');
372
+ break;
373
+ case 'default':
374
+ this._stage.on('click', this._onMouseClickInDefaultMode);
375
+ this._peaks.on('keyboard.delete', this._onKeyboardDelete);
376
+ break;
377
+ default:
378
+ return;
379
+ }
380
+
381
+ this._mode = mode;
382
+ this._layer.draw();
383
+ this._view.drawSourcesLayer();
384
+ };
385
+
386
+ ModeLayer.prototype.getCurrentMode = function() {
387
+ return this._mode;
388
+ };
389
+
390
+ return ModeLayer;
391
+ });