Skip to content

Commit 37c46e3

Browse files
mmarkelovbsekachev
authored andcommitted
Improve UX with creating new shape by shortkey (#941)
1 parent 0f5cf20 commit 37c46e3

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

cvat/apps/engine/static/engine/js/shapeCreator.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ class ShapeCreatorModel extends Listener {
7979
this._shapeCollection.update();
8080
}
8181

82-
switchCreateMode(forceClose) {
82+
switchCreateMode(forceClose, usingShortkey) {
83+
this._usingShortkey = usingShortkey;
8384
// if parameter force (bool) setup to true, current result will not save
8485
if (!forceClose) {
8586
this._createMode = !this._createMode && window.cvat.mode == null;
@@ -113,6 +114,10 @@ class ShapeCreatorModel extends Listener {
113114
return this._createMode;
114115
}
115116

117+
get usingShortkey() {
118+
return this._usingShortkey;
119+
}
120+
116121
get defaultType() {
117122
return this._defaultType;
118123
}
@@ -146,15 +151,15 @@ class ShapeCreatorController {
146151
let shortkeys = window.cvat.config.shortkeys;
147152

148153
let switchDrawHandler = Logger.shortkeyLogDecorator(function() {
149-
this.switchCreateMode(false);
154+
this.switchCreateMode(false, true);
150155
}.bind(this));
151156

152157
Mousetrap.bind(shortkeys["switch_draw_mode"].value, switchDrawHandler.bind(this), 'keydown');
153158
}
154159
}
155160

156-
switchCreateMode(force) {
157-
this._model.switchCreateMode(force);
161+
switchCreateMode(force, usingShortkey = false) {
162+
this._model.switchCreateMode(force, usingShortkey);
158163
}
159164

160165
setDefaultShapeType(type) {
@@ -261,6 +266,23 @@ class ShapeCreatorView {
261266
this._polyShapeSizeInput.on('keydown', function(e) {
262267
e.stopPropagation();
263268
});
269+
270+
this._playerFrame.on('mousemove.shapeCreatorAIM', (e) => {
271+
if (!['polygon', 'polyline', 'points'].includes(this._type)) {
272+
this._aimCoord = window.cvat.translate.point.clientToCanvas(this._frameContent.node, e.clientX, e.clientY);
273+
if (this._aim) {
274+
this._aim.x.attr({
275+
y1: this._aimCoord.y,
276+
y2: this._aimCoord.y,
277+
});
278+
279+
this._aim.y.attr({
280+
x1: this._aimCoord.x,
281+
x2: this._aimCoord.x,
282+
});
283+
}
284+
}
285+
});
264286
}
265287

266288

@@ -324,7 +346,6 @@ class ShapeCreatorView {
324346
}
325347
});
326348

327-
328349
this._frameContent.on('mousemove.shapeCreator', (e) => {
329350
if (e.shiftKey && ['polygon', 'polyline'].includes(this._type)) {
330351
if (lastPoint.x === null || lastPoint.y === null) {
@@ -388,7 +409,6 @@ class ShapeCreatorView {
388409
}.bind(this));
389410
}
390411

391-
392412
_create() {
393413
let sizeUI = null;
394414
switch(this._type) {
@@ -517,34 +537,21 @@ class ShapeCreatorView {
517537
this._mode = model.defaultMode;
518538

519539
if (!['polygon', 'polyline', 'points'].includes(this._type)) {
540+
if (!model.usingShortkey) {
541+
this._aimCoord = {
542+
x: 0,
543+
y: 0
544+
};
545+
}
520546
this._drawAim();
521-
this._playerFrame.on('mousemove.shapeCreatorAIM', (e) => {
522-
this._aimCoord = window.cvat.translate.point.clientToCanvas(this._frameContent.node, e.clientX, e.clientY);
523-
if (this._aim) {
524-
this._aim.x.attr({
525-
y1: this._aimCoord.y,
526-
y2: this._aimCoord.y,
527-
});
528-
529-
this._aim.y.attr({
530-
x1: this._aimCoord.x,
531-
x2: this._aimCoord.x,
532-
});
533-
}
534-
});
535547
}
536548

537549
this._createButton.text("Stop Creation");
538550
document.oncontextmenu = () => false;
539551
this._create();
540552
}
541553
else {
542-
this._playerFrame.off('mousemove.shapeCreatorAIM');
543554
this._removeAim();
544-
this._aimCoord = {
545-
x: 0,
546-
y: 0
547-
};
548555
this._cancel = true;
549556
this._createButton.text("Create Shape");
550557
document.oncontextmenu = null;

0 commit comments

Comments
 (0)