Skip to content

Commit

Permalink
Merge branch 'cursor_handling' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
bhousel committed Oct 21, 2023
2 parents 2718baf + d5bec9b commit 6b72f66
Show file tree
Hide file tree
Showing 23 changed files with 177 additions and 181 deletions.
135 changes: 0 additions & 135 deletions css/55_cursors.css

This file was deleted.

Binary file removed dist/img/cursor-draw-connect-line2x.png
Binary file not shown.
Binary file removed dist/img/cursor-draw-connect-vertex2x.png
Binary file not shown.
Binary file removed dist/img/cursor-draw2x.png
Binary file not shown.
Binary file removed dist/img/cursor-grab2x.png
Binary file not shown.
Binary file removed dist/img/cursor-grabbing2x.png
Binary file not shown.
Binary file removed dist/img/cursor-pointing2x.png
Binary file not shown.
Binary file removed dist/img/cursor-select-acting2x.png
Binary file not shown.
Binary file removed dist/img/cursor-select-add2x.png
Binary file not shown.
Binary file removed dist/img/cursor-select-area2x.png
Binary file not shown.
Binary file removed dist/img/cursor-select-line2x.png
Binary file not shown.
Binary file removed dist/img/cursor-select-mapillary2x.png
Binary file not shown.
Binary file removed dist/img/cursor-select-point2x.png
Binary file not shown.
Binary file removed dist/img/cursor-select-split2x.png
Binary file not shown.
Binary file removed dist/img/cursor-select-vertex2x.png
Binary file not shown.
13 changes: 8 additions & 5 deletions modules/behaviors/MapInteractionBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ export class MapInteractionBehavior extends AbstractBehavior {

this.lastDown = down;
this.gesture = null;
eventManager.setCursor('grabbing');
const mode = this.context.mode.id;
if (mode === 'draw-area' || mode === 'draw-line') {
eventManager.setCursor('crosshair');
} else eventManager.setCursor('grabbing');
}


Expand Down Expand Up @@ -241,7 +244,10 @@ export class MapInteractionBehavior extends AbstractBehavior {
this.gesture = null;

const eventManager = this.context.systems.map.renderer.events;
eventManager.setCursor('inherit');
const mode = this.context.mode.id;
if (mode === 'draw-area' || mode === 'draw-line') {
eventManager.setCursor('crosshair');
} else eventManager.setCursor('grab');
}


Expand All @@ -255,9 +261,6 @@ export class MapInteractionBehavior extends AbstractBehavior {
// After pointercancel, there should be no more `pointermove` or `pointerup` events.
this.lastDown = null;
this.gesture = null;

const eventManager = this.context.systems.map.renderer.events;
eventManager.setCursor('inherit');
}


Expand Down
9 changes: 9 additions & 0 deletions modules/behaviors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ export const behaviors = {
available: new Map() // Map (id -> Behavior constructor)
};

export const cursors = {
connectLineCursor: 'url(/img/cursor-draw-connect-line.png) 9 9, crosshair',
connectVertexCursor: 'url(/img/cursor-draw-connect-vertex.png) 9 9, crosshair',
lineCursor:'url(/img/cursor-select-line.png), auto',
vertexCursor: 'url(/img/cursor-select-vertex.png), auto',
pointCursor:'url(/img/cursor-select-point.png), auto',
areaCursor:'url(/img/cursor-select-area.png), auto',
};

behaviors.available.set('drag', DragBehavior);
behaviors.available.set('draw', DrawBehavior);
behaviors.available.set('hover', HoverBehavior);
Expand Down
40 changes: 13 additions & 27 deletions modules/modes/AddPointMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export class AddPointMode extends AbstractMode {
this._active = true;
const context = this.context;

context.enableBehaviors(['hover', 'draw', 'map-interaction']);
const eventManager = context.systems.map.renderer.events;
eventManager.setCursor('crosshair');

context.enableBehaviors(['hover', 'draw', 'map-interaction']);
context.behaviors.draw
.on('click', this._click)
.on('cancel', this._cancel)
Expand All @@ -67,6 +69,9 @@ export class AddPointMode extends AbstractMode {

const context = this.context;

const eventManager = context.systems.map.renderer.events;
eventManager.setCursor('grab');

context.behaviors.draw
.off('click', this._click)
.off('cancel', this._cancel)
Expand Down Expand Up @@ -130,16 +135,10 @@ export class AddPointMode extends AbstractMode {
const l10n = context.systems.l10n;

const node = osmNode({ loc: loc, tags: this.defaultTags });
// this.nodeID = node.id;

editor.perform(actionAddEntity(node));
editor.commit({
annotation: l10n.t('operations.add.annotation.point'),
selectedIDs: [node.id]
});
context.enter('select-osm', {
selection: { osm: [node.id] },
newFeature: true
});
editor.commit({ annotation: l10n.t('operations.add.annotation.point'), selectedIDs: [node.id] });
context.enter('select-osm', { selection: { osm: [node.id] }, newFeature: true });
}


Expand All @@ -154,14 +153,8 @@ export class AddPointMode extends AbstractMode {

const node = osmNode({ tags: this.defaultTags });
editor.perform(actionAddMidpoint({ loc: loc, edge: edge }, node));
editor.commit({
annotation: l10n.t('operations.add.annotation.vertex'),
selectedIDs: [node.id]
});
context.enter('select-osm', {
selection: { osm: [node.id] },
newFeature: true
});
editor.commit({ annotation: l10n.t('operations.add.annotation.vertex'), selectedIDs: [node.id] });
context.enter('select-osm', { selection: { osm: [node.id] }, newFeature: true });
}


Expand All @@ -185,14 +178,8 @@ export class AddPointMode extends AbstractMode {
}

editor.perform(actionChangeTags(node.id, tags));
editor.commit({
annotation: l10n.t('operations.add.annotation.point'),
selectedIDs: [node.id]
});
context.enter('select-osm', {
selection: { osm: [node.id] },
newFeature: false
});
editor.commit({ annotation: l10n.t('operations.add.annotation.point'), selectedIDs: [node.id] });
context.enter('select-osm', { selection: { osm: [node.id] }, newFeature: false });
}


Expand All @@ -203,5 +190,4 @@ export class AddPointMode extends AbstractMode {
_cancel() {
this.context.enter('browse');
}

}
51 changes: 46 additions & 5 deletions modules/modes/BrowseMode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AbstractMode } from './AbstractMode';
import { operationPaste } from '../operations/paste';
import { cursors } from './index';

const DEBUG = false;

Expand All @@ -19,6 +20,9 @@ export class BrowseMode extends AbstractMode {
super(context);
this.context = context;
this.id = 'browse';

// Make sure the event handlers have `this` bound correctly
this._hover = this._hover.bind(this);
}


Expand All @@ -31,9 +35,14 @@ export class BrowseMode extends AbstractMode {
console.log('BrowseMode: entering'); // eslint-disable-line no-console
}

const context = this.context;
this._active = true;
this.operations = [ operationPaste(this.context) ];
this.context.enableBehaviors(['hover', 'select', 'drag', 'paste', 'lasso', 'map-interaction']);

this.operations = [ operationPaste(context) ];
context.enableBehaviors(['hover', 'select', 'drag', 'paste', 'lasso', 'map-interaction']);

context.behaviors.hover
.on('hoverchange', this._hover);

// Get focus on the body.
// I think this was done to remove focus from whatever
Expand All @@ -58,12 +67,44 @@ export class BrowseMode extends AbstractMode {
if (DEBUG) {
console.log('BrowseMode: exiting'); // eslint-disable-line no-console
}

this.context.behaviors.hover
.off('hoverchange', this._hover);
}


sidebar() {
console.error('error: do not call BrowseMode.sidebar anymore'); // eslint-disable-line no-console
/**
* _hover
* Changes the cursor styling based on what geometry is hovered
*/
_hover(eventData) {
const context = this.context;
const editor = context.systems.editor;
const graph = editor.staging.graph;
const eventManager = context.systems.map.renderer.events;

const target = eventData.target;
const datum = target?.data;
const entity = datum && graph.hasEntity(datum.id);
const geom = entity?.geometry(graph) ?? 'unknown';

switch (geom) {
case 'line':
eventManager.setCursor(cursors.lineCursor);
break;
case 'vertex':
eventManager.setCursor(cursors.vertexCursor);
break;
case 'point':
eventManager.setCursor(cursors.pointCursor);
break;
case 'area':
eventManager.setCursor(cursors.areaCursor);
break;
default:
eventManager.setCursor('grab');
break;
}
}

}

Loading

0 comments on commit 6b72f66

Please sign in to comment.