Skip to content

Commit

Permalink
Hide hover cursor when in touch mode with freehand sculpter.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Petts committed Mar 20, 2019
1 parent e416e0d commit 4f1a6ac
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 49 deletions.
67 changes: 36 additions & 31 deletions src/tools/FreehandSculpterMouseTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class FreehandSculpterMouseTool extends BaseTool {

// Create bound functions for private event loop.
this.activeMouseUpCallback = this.activeMouseUpCallback.bind(this);
this.activeTouchEndCallback = this.activeTouchEndCallback.bind(this);
this.activeMouseDragCallback = this.activeMouseDragCallback.bind(this);
}

Expand Down Expand Up @@ -77,7 +78,7 @@ export default class FreehandSculpterMouseTool extends BaseTool {
this.configuration.mouseLocation.handles,
options
);
} else if (this.configuration.showCursorOnHover) {
} else if (this.configuration.showCursorOnHover && !this._recentTouchEnd) {
this._renderHoverCursor(evt);
}
}
Expand All @@ -86,29 +87,18 @@ export default class FreehandSculpterMouseTool extends BaseTool {
const eventData = evt.detail;

this._selectFreehandTool(eventData);

external.cornerstone.updateImage(eventData.element);
}

doubleTapCallback(evt) {
const eventData = evt.detail;

this._selectFreehandTool(eventData);

external.cornerstone.updateImage(eventData.element);
}

preTouchStartCallback(evt) {
const eventData = evt.detail;
const config = this.configuration;

if (config.currentTool === null) {
this._selectFreehandTool(eventData);
}

this._initialiseSculpting(eventData);

external.cornerstone.updateImage(eventData.element);
this._initialiseSculpting(evt);

return true;
}
Expand All @@ -120,21 +110,11 @@ export default class FreehandSculpterMouseTool extends BaseTool {
* @returns {boolean}
*/
preMouseDownCallback(evt) {
const eventData = evt.detail;

if (!this.options.mouseButtonMask.includes(eventData.buttons)) {
if (!this.options.mouseButtonMask.includes(evt.detail.buttons)) {
return;
}

const config = this.configuration;

if (config.currentTool === null) {
this._selectFreehandTool(eventData);
}

this._initialiseSculpting(eventData);

external.cornerstone.updateImage(eventData.element);
this._initialiseSculpting(evt);

return true;
}
Expand Down Expand Up @@ -177,6 +157,22 @@ export default class FreehandSculpterMouseTool extends BaseTool {
* @returns {void}
*/
activeMouseUpCallback(evt) {
this._activeEnd(evt);
}

/**
* Event handler for TOUCH_END during the active loop.
*
* @param {Object} evt - The event.
* @returns {void}
*/
activeTouchEndCallback(evt) {
this._activeEnd(evt);

this._recentTouchEnd = true;
}

_activeEnd(evt) {
const eventData = evt.detail;
const element = eventData.element;
const config = this.configuration;
Expand Down Expand Up @@ -213,6 +209,8 @@ export default class FreehandSculpterMouseTool extends BaseTool {
const toolState = getToolState(element, this.referencedToolName);
const data = toolState.data[this.configuration.currentTool];

this._recentTouchEnd = false;

let coords;

if (this.configuration.mouseUpRender) {
Expand Down Expand Up @@ -365,9 +363,14 @@ export default class FreehandSculpterMouseTool extends BaseTool {
* @param {Object} eventData - Data object associated with the event.
* @returns {void}
*/
_initialiseSculpting(eventData) {
const element = eventData.element;
_initialiseSculpting(evt) {
const eventData = evt.detail;
const config = this.configuration;
const element = eventData.element;

if (config.currentTool === null) {
this._selectFreehandTool(eventData);
}

this._active = true;

Expand All @@ -379,6 +382,8 @@ export default class FreehandSculpterMouseTool extends BaseTool {

this._activateFreehandTool(element, config.currentTool);
this._activateSculpt(element);

external.cornerstone.updateImage(eventData.element);
}

/**
Expand Down Expand Up @@ -814,8 +819,8 @@ export default class FreehandSculpterMouseTool extends BaseTool {
element.addEventListener(EVENTS.MOUSE_CLICK, this.activeMouseUpCallback);
element.addEventListener(EVENTS.MOUSE_DRAG, this.activeMouseDragCallback);

element.addEventListener(EVENTS.TOUCH_END, this.activeMouseUpCallback);
element.addEventListener(EVENTS.TOUCH_TAP, this.activeMouseUpCallback);
element.addEventListener(EVENTS.TOUCH_END, this.activeTouchEndCallback);
element.addEventListener(EVENTS.TOUCH_TAP, this.activeTouchEndCallback);
element.addEventListener(EVENTS.TOUCH_DRAG, this.activeMouseDragCallback);

external.cornerstone.updateImage(element);
Expand All @@ -837,8 +842,8 @@ export default class FreehandSculpterMouseTool extends BaseTool {
this.activeMouseDragCallback
);

element.removeEventListener(EVENTS.TOUCH_END, this.activeMouseUpCallback);
element.removeEventListener(EVENTS.TOUCH_TAP, this.activeMouseUpCallback);
element.removeEventListener(EVENTS.TOUCH_END, this.activeTouchEndCallback);
element.removeEventListener(EVENTS.TOUCH_TAP, this.activeTouchEndCallback);
element.removeEventListener(
EVENTS.TOUCH_DRAG,
this.activeMouseDragCallback
Expand Down
24 changes: 6 additions & 18 deletions src/tools/annotation/FreehandMouseTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,27 +632,11 @@ export default class FreehandMouseTool extends BaseAnnotationTool {
* @returns {undefined}
*/
_drawingMouseDragCallback(evt) {
const eventData = evt.detail;

if (!this.options.mouseButtonMask.includes(eventData.buttons)) {
if (!this.options.mouseButtonMask.includes(evt.detail.buttons)) {
return;
}

const toolState = getToolState(eventData.element, this.name);

const config = this.configuration;
const currentTool = config.currentTool;

const data = toolState.data[currentTool];

// Set the mouseLocation handle
this._getMouseLocation(eventData);
this._checkInvalidHandleLocation(data, eventData);
this._addPointPencilMode(eventData, data.handles.points);
this._dragging = true;

// Force onImageRendered
external.cornerstone.updateImage(eventData.element);
this._drawingDrag(evt);
}

/**
Expand All @@ -663,6 +647,10 @@ export default class FreehandMouseTool extends BaseAnnotationTool {
* @returns {undefined}
*/
_drawingTouchDragCallback(evt) {
this._drawingDrag(evt);
}

_drawingDrag(evt) {
const eventData = evt.detail;

const toolState = getToolState(eventData.element, this.name);
Expand Down

0 comments on commit 4f1a6ac

Please sign in to comment.