Skip to content

Commit

Permalink
Merge pull request #892 from JamesAPetts/feature/freehandAndBrushTouch
Browse files Browse the repository at this point in the history
Feature/freehand and brush touch
  • Loading branch information
JamesAPetts authored Mar 21, 2019
2 parents e4ce8d4 + 1e6b9b1 commit 9ec78f4
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 54 deletions.
3 changes: 0 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,6 @@
});
});

console.log(cornerstone.getEnabledElement(elements[0]).uuid);
console.log(cornerstoneTools.store);

// Iterate over all tool-category links
const toolCategoryLinks = document.querySelectorAll(
'ul.tool-category-list a'
Expand Down
1 change: 1 addition & 0 deletions src/eventDispatchers/shared/customCallbackHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function(handlerType, customFunction, evt) {

// Tool is active, and specific callback is active
tools = getActiveToolsForElement(element, tools, handlerType);

// Tool has expected callback custom function
tools = tools.filter(tool => typeof tool[customFunction] === 'function');

Expand Down
4 changes: 4 additions & 0 deletions src/eventDispatchers/touchEventHandlers/touchStart.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export default function(evt) {
}
}

if (state.isMultiPartToolActive) {
return;
}

const annotationTools = getToolsWithDataForElement(
element,
activeAndPassiveTools
Expand Down
69 changes: 57 additions & 12 deletions src/tools/FreehandSculpterMouseTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class FreehandSculpterMouseTool extends BaseTool {
const defaultConfig = {
name: 'FreehandSculpterMouse',
referencedToolName: 'FreehandMouse',
supportedInteractionTypes: ['Mouse'],
supportedInteractionTypes: ['Mouse', 'Touch', 'DoubleTap'],
mixins: ['activeOrDisabledBinaryTool'],
configuration: getDefaultFreehandSculpterMouseToolConfiguration(),
};
Expand All @@ -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,27 +87,34 @@ 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) {
this._initialiseSculpting(evt);

return true;
}

/**
* Event handler for MOUSE_DOWN.
*
* @param {Object} evt - The event.
* @returns {boolean}
*/
preMouseDownCallback(evt) {
const eventData = evt.detail;
const config = this.configuration;

if (config.currentTool === null) {
this._selectFreehandTool(eventData);
if (!this.options.mouseButtonMask.includes(evt.detail.buttons)) {
return;
}

this._initialiseSculpting(eventData);

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

return true;
}
Expand Down Expand Up @@ -149,6 +157,23 @@ 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._deselectAllTools(evt);
this._recentTouchEnd = true;
}

_activeEnd(evt) {
const eventData = evt.detail;
const element = eventData.element;
const config = this.configuration;
Expand Down Expand Up @@ -185,6 +210,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 @@ -337,9 +364,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 @@ -351,6 +383,8 @@ export default class FreehandSculpterMouseTool extends BaseTool {

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

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

/**
Expand Down Expand Up @@ -786,6 +820,10 @@ 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.activeTouchEndCallback);
element.addEventListener(EVENTS.TOUCH_TAP, this.activeTouchEndCallback);
element.addEventListener(EVENTS.TOUCH_DRAG, this.activeMouseDragCallback);

external.cornerstone.updateImage(element);
}

Expand All @@ -805,6 +843,13 @@ export default class FreehandSculpterMouseTool extends BaseTool {
this.activeMouseDragCallback
);

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

external.cornerstone.updateImage(element);
}

Expand Down
Loading

0 comments on commit 9ec78f4

Please sign in to comment.