/** * Tool module. * @module tool */ var dwv = dwv || {}; /** * Namespace for tool functions. * @class tool * @namespace dwv * @static */ dwv.tool = dwv.tool || {}; /** * Scroll class. * @class Scroll * @namespace dwv.tool * @constructor * @param {Object} app The associated application. */ dwv.tool.Scroll = function(app) { /** * Closure to self: to be used by event handlers. * @property self * @private * @type WindowLevel */ var self = this; /** * Interaction start flag. * @property started * @type Boolean */ this.started = false; /** * Handle mouse down event. * @method mousedown * @param {Object} event The mouse down event. */ this.mousedown = function(event){ self.started = true; // first position self.x0 = event._x; self.y0 = event._y; }; /** * Handle mouse move event. * @method mousemove * @param {Object} event The mouse move event. */ this.mousemove = function(event){ if (!self.started) { return; } // difference to last position var diffY = event._y - self.y0; // do not trigger for small moves if( Math.abs(diffY) < 15 ) { return; } // update GUI if( diffY > 0 ) { app.getView().incrementSliceNb(); } else { app.getView().decrementSliceNb(); } // reset origin point self.x0 = event._x; self.y0 = event._y; }; /** * Handle mouse up event. * @method mouseup * @param {Object} event The mouse up event. */ this.mouseup = function(/*event*/){ if (self.started) { // stop recording self.started = false; } }; /** * Handle mouse out event. * @method mouseout * @param {Object} event The mouse out event. */ this.mouseout = function(event){ self.mouseup(event); }; /** * Handle touch start event. * @method touchstart * @param {Object} event The touch start event. */ this.touchstart = function(event){ self.mousedown(event); }; /** * Handle touch move event. * @method touchmove * @param {Object} event The touch move event. */ this.touchmove = function(event){ self.mousemove(event); }; /** * Handle touch end event. * @method touchend * @param {Object} event The touch end event. */ this.touchend = function(event){ self.mouseup(event); }; /** * Handle key down event. * @method keydown * @param {Object} event The key down event. */ this.keydown = function(event){ app.onKeydown(event); }; /** * Enable the tool. * @method enable * @param {Boolean} bool The flag to enable or not. */ this.display = function(bool){ dwv.gui.displayScrollHtml(bool); }; }; // Scroll class /** * Help for this tool. * @method getHelp * @returns {Object} The help content. */ dwv.tool.Scroll.prototype.getHelp = function() { return { 'title': "Scroll", 'brief': "The scroll tool allows to scroll through slices.", 'mouse': { 'mouse_drag': "A single vertical mouse drag changes the current slice.", }, 'touch': { 'touch_drag': "A single vertical touch drag changes the current slice.", } }; }; /** * Initialise the tool. * @method init */ dwv.tool.Scroll.prototype.init = function() { // nothing to do. };