Skip to content

Improve UX with creating new shape by shortkey #941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 37 additions & 28 deletions cvat/apps/engine/static/engine/js/shapeCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class ShapeCreatorModel extends Listener {
this._shapeCollection.update();
}

switchCreateMode(forceClose) {
switchCreateMode(forceClose, usingShortkey) {
this._usingShortkey = usingShortkey;
// if parameter force (bool) setup to true, current result will not save
if (!forceClose) {
this._createMode = !this._createMode && window.cvat.mode == null;
Expand Down Expand Up @@ -146,15 +147,15 @@ class ShapeCreatorController {
let shortkeys = window.cvat.config.shortkeys;

let switchDrawHandler = Logger.shortkeyLogDecorator(function() {
this.switchCreateMode(false);
this.switchCreateMode(false, true);
}.bind(this));

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

switchCreateMode(force) {
this._model.switchCreateMode(force);
switchCreateMode(force, usingShortkey) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about default value? This method is called with a single arguments in many places

this._model.switchCreateMode(force, usingShortkey);
}

setDefaultShapeType(type) {
Expand Down Expand Up @@ -261,6 +262,23 @@ class ShapeCreatorView {
this._polyShapeSizeInput.on('keydown', function(e) {
e.stopPropagation();
});

this._playerFrame.on('mousemove.shapeCreatorAIM', (e) => {
if (!['polygon', 'polyline', 'points'].includes(this._type)) {
this._aimCoord = window.cvat.translate.point.clientToCanvas(this._frameContent.node, e.clientX, e.clientY);
if (this._aim) {
this._aim.x.attr({
y1: this._aimCoord.y,
y2: this._aimCoord.y,
});

this._aim.y.attr({
x1: this._aimCoord.x,
x2: this._aimCoord.x,
});
}
}
});
}


Expand Down Expand Up @@ -324,7 +342,6 @@ class ShapeCreatorView {
}
});


this._frameContent.on('mousemove.shapeCreator', (e) => {
if (e.shiftKey && ['polygon', 'polyline'].includes(this._type)) {
if (lastPoint.x === null || lastPoint.y === null) {
Expand Down Expand Up @@ -388,8 +405,7 @@ class ShapeCreatorView {
}.bind(this));
}


_create() {
_create(usingShortkey) {
let sizeUI = null;
switch(this._type) {
case 'box':
Expand Down Expand Up @@ -425,7 +441,7 @@ class ShapeCreatorView {
this._controller.finish(box, this._type);
}

this._controller.switchCreateMode(true);
this._controller.switchCreateMode(true, usingShortkey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always false is suitable here, I assume.
And you do not need an additional argument :)

}.bind(this)).on('drawupdate', (e) => {
sizeUI = drawBoxSize.call(sizeUI, this._frameContent, this._frameText, e.target.getBBox());
}).on('drawcancel', () => {
Expand Down Expand Up @@ -517,34 +533,27 @@ class ShapeCreatorView {
this._mode = model.defaultMode;

if (!['polygon', 'polyline', 'points'].includes(this._type)) {
if (!model._usingShortkey) {
this._aimCoord = {
x: 0,
y: 0
};
}
this._drawAim();
this._playerFrame.on('mousemove.shapeCreatorAIM', (e) => {
this._aimCoord = window.cvat.translate.point.clientToCanvas(this._frameContent.node, e.clientX, e.clientY);
if (this._aim) {
this._aim.x.attr({
y1: this._aimCoord.y,
y2: this._aimCoord.y,
});

this._aim.y.attr({
x1: this._aimCoord.x,
x2: this._aimCoord.x,
});
}
});
}

this._createButton.text("Stop Creation");
document.oncontextmenu = () => false;
this._create();
this._create(model._usingShortkey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, write a getter for the field

if (!model._usingShortkey) {
this._aimCoord = {
x: 0,
y: 0
};
}
}
else {
this._playerFrame.off('mousemove.shapeCreatorAIM');
this._removeAim();
this._aimCoord = {
x: 0,
y: 0
};
this._cancel = true;
this._createButton.text("Create Shape");
document.oncontextmenu = null;
Expand Down