diff --git a/LICENSE b/LICENSE index ee4c1c3..ad81dfa 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2011 Cristiano Belloni, http://bitterspring.net/ +Copyright (c) 2013 Cristiano Belloni, http://bitterspring.net/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/amd.js b/amd.js index 966a63b..acab75b 100644 --- a/amd.js +++ b/amd.js @@ -9,3 +9,5 @@ else { console.log ("KievII: setting window.K2 (no AMD)"); window.kievII = window.K2 = K2; } + +})(); \ No newline at end of file diff --git a/common.js b/common.js index 75837d2..fff5f5c 100644 --- a/common.js +++ b/common.js @@ -1,3 +1,5 @@ +(function () { + /* The K2 element! */ var K2 = {}; diff --git a/dist/kievII.js b/dist/kievII.js index 3766af3..850513e 100644 --- a/dist/kievII.js +++ b/dist/kievII.js @@ -1,3 +1,5 @@ +(function () { + /* The K2 element! */ var K2 = {}; @@ -536,19 +538,19 @@ K2.UI = function(engine, parameters) { if (isEventSupported('touchstart')) { this.domElement.addEventListener('touchstart', this.onMouseEvent(), true); - console.log ("touchstart supported"); + 0; } else { this.domElement.addEventListener('mousedown', this.onMouseEvent(), true); - console.log ("no touchstart, supporting mousedown"); + 0; } if (isEventSupported('touchend')) { this.domElement.addEventListener('touchend', this.onMouseEvent(), true); - console.log ("touchend supported"); + 0; } else { this.domElement.addEventListener('mouseup', this.onMouseEvent(), true); - console.log ("no touchend, supporting mouseup"); + 0; } // TODO see if it's not superseded by ondrag this.domElement.addEventListener('mousemove', this.onMouseEvent(), true); @@ -1148,26 +1150,26 @@ K2.Area.prototype.tap = K2.Area.prototype.dragstart = function(x, y) { if ((x > left_min_prox) && x < (left_max_prox) && this.dragBorders.left === true) { // We're next to the left side this.leftSide = true; - console.log ("Left side click detected"); + 0; } if ((x > right_min_prox) && x < (right_max_prox) && this.dragBorders.right === true) { // We're next to the right side this.rightSide = true; - console.log ("Right side click detected"); + 0; } if ((y > bottom_min_prox) && y < (bottom_max_prox) && this.dragBorders.bottom === true) { // We're next to the bottom side this.bottomSide = true; - console.log ("Bottom side click detected"); + 0; } if ((y > top_min_prox) && y < (top_max_prox) && this.dragBorders.top === true) { // We're next to the top side this.topSide = true; - console.log ("Top side click detected"); + 0; } if (this.isInArea (x,y)) { - console.log ("clicked inside!"); + 0; this.inside = true; this.startPoint = [x,y]; } @@ -2162,7 +2164,7 @@ K2.Bar.prototype.dragstart = function(curr_x, curr_y) { K2.Bar.prototype.setValue = function(slot, value) { - console.log('Setting ' + slot + ' to ' + value); + 0; if (slot == 'barPos') { if (value[0] <= this.width) { @@ -2499,11 +2501,11 @@ K2.ClickBar.prototype.getready = function(args) { K2.ClickBar.prototype.isInROI = function(x, y) { - console.log ('y = ', y, "roitop = ", this.ROITop); + 0; if ((x >= this.ROILeft) && (y >= this.ROITop - this.landingHeight)) { - console.log ("1st"); + 0; if ((x <= (this.ROILeft + this.ROIWidth)) && (y <= (this.ROITop + this.ROIHeight + this.landingHeight))) { - console.log ("In ROI!"); + 0; return true; } } @@ -2514,9 +2516,9 @@ K2.ClickBar.prototype.isInROI = function(x, y) { K2.ClickBar.prototype.calculateValue = function (x,y) { var clickedHeigth = y - this.yOrigin; - console.log ("heigth on click is ", clickedHeigth, " pixels"); + 0; var clickedValue = 1 - (clickedHeigth / this.height); - console.log ("for a value of ", clickedValue, " (", clickedHeigth, " / ", this.height, ")"); + 0; if (clickedValue > this.maxValue) { clickedValue = this.maxValue; @@ -2682,14 +2684,14 @@ K2.Gauge.prototype.calculateAngle = function (x,y) { var centerX = this.xOrigin + this.width / 2; var centerY = this.yOrigin + this.height / 2; - console.log ("Point is: ", x, y, "Center is: ", centerX, centerY); + 0; var radtan = Math.atan2 (x - centerX, y - centerY); - console.log('radiant atan ', radtan); + 0; var degreetan = radtan * (180 / Math.PI); degreetan = 180 - degreetan; - console.log('degree atan ', degreetan); + 0; var range_val = K2.MathUtils.linearRange(0, 360, 0, 1, Math.floor(degreetan)); return range_val; @@ -2699,11 +2701,11 @@ K2.Gauge.prototype.calculateAngle = function (x,y) { K2.Gauge.prototype.tap = K2.Gauge.prototype.mousedown = K2.Gauge.prototype.touchstart = function(x, y) { var dist = K2.MathUtils.distance(x, y, this.xOrigin + this.width / 2, this.yOrigin + this.height / 2); - console.log("dist is, ", dist, " radius is ", this.radius, " thickness is ", this.thickness); + 0; if ((dist > this.radius - this.thickness / 2) && (dist < this.radius + this.thickness / 2)) { - console.log("down / tapped Inside the dial"); + 0; this.triggered = true; var range_val = this.calculateAngle (x,y); @@ -2720,7 +2722,7 @@ K2.Gauge.prototype.tap = K2.Gauge.prototype.mousedown = K2.Gauge.prototype.touch K2.Gauge.prototype.drag = K2.Gauge.prototype.mousemove = function (x, y) { if (this.triggered) { - console.log ("triggered mousemove"); + 0; var range_val = this.calculateAngle (x,y); //this.prevValue = this.values.gaugevalue; var ret = {'slot' : 'gaugevalue', 'value' : range_val}; @@ -3028,18 +3030,18 @@ K2.Knob.prototype.calculateAngle = function (x,y) { var centerX = this.xOrigin + this.width / 2; var centerY = this.yOrigin + this.height / 2; - console.log ("Point is: ", x, y, "Center is: ", centerX, centerY); + 0; var radtan = Math.atan2 (x - centerX, y - centerY); - console.log('radiant atan ', radtan); + 0; // normalize arctan if (radtan < 0) { radtan += (2 * Math.PI); } - console.log ('radiant atan, normalized, is ', radtan); + 0; var degreetan = radtan * (180 / Math.PI); - console.log('degree atan is', degreetan); + 0; // now we have a value from 0 to 360, where 0 is the lowest // intersection with the circumference. degree increases anticlockwise @@ -3060,7 +3062,7 @@ K2.Knob.prototype.calculateAngle = function (x,y) { } var range_val = K2.MathUtils.linearRange(0, 360, 0, 1, Math.floor(degreetan)); - console.log ('value is', range_val); + 0; return range_val; }; @@ -3345,16 +3347,16 @@ K2.RotKnob.prototype.getRangedAmount = function (angle) { var endAngOffset = this.stopAngValue - this.initAngValue; var startAngOffset = this.startAngValue - this.initAngValue; - console.log ("start -> end", startAngOffset, endAngOffset); + 0; if ((angle > this.initAngValue) && (startAngOffset < 0)) { - console.log ("Angle now is", angle); + 0; angle = -(360 - angle); } var rangedAng = K2.MathUtils.linearRange(startAngOffset, endAngOffset, 0, 1, angle); - console.log ("knob value", rangedAng); + 0; if (rangedAng < 0) { rangedAng = 0; @@ -3383,10 +3385,10 @@ K2.RotKnob.prototype.calculateAngle = function (x,y) { var centerX = this.xOrigin + this.width / 2; var centerY = this.yOrigin + this.height / 2; - console.log ("Point is: ", x, y, "Center is: ", centerX, centerY); + 0; var radtan = Math.atan2 (x - centerX, y - centerY); - console.log('radiant atan ', radtan); + 0; var degreetan = radtan * (180 / Math.PI); degreetan = 180 - degreetan; @@ -3399,7 +3401,7 @@ K2.RotKnob.prototype.calculateAngle = function (x,y) { } var degreeMod = (degreetan - this.initAngValue) % 360; - console.log('degreetan -> offset', degreetan, degreeOffset, degreeMod); + 0; var range_val = this.getRangedAmount (Math.floor(degreeOffset)); @@ -3520,7 +3522,7 @@ K2.RotKnob.prototype.setValue = function(slot, value) { stepped_new_value = value; } - console.log('Value is: ', stepped_new_value); + 0; // Now, we call the superclass K2.RotKnob.superclass.setValue.call(this, slot, stepped_new_value); @@ -3842,7 +3844,7 @@ K2.Wavebox.prototype.release = K2.Wavebox.prototype.mouseup = function(curr_x, c } else { - console.error('orientation invalid, this will probably break something'); + 0; } // Click on button is completed, the button is no more triggered. @@ -3860,7 +3862,7 @@ K2.Wavebox.prototype.release = K2.Wavebox.prototype.mouseup = function(curr_x, c K2.Wavebox.prototype.setValue = function(slot, value) { - console.log('Setting ' + slot + ' to ' + value); + 0; // Won't call the parent: this element has a custom way to set values. @@ -3915,11 +3917,11 @@ K2.Wavebox.prototype.setValue = function(slot, value) { if (slot == 'yPos') { if (value <= this.height) { - console.log('Setting yPos to ' + value); + 0; this.values.yPos = value; } else { - console.log('NOT setting yPos to ' + value + ' because height is ' + this.height); + 0; } } }; @@ -3956,7 +3958,7 @@ K2.Wavebox.prototype.refresh_CANVAS2D = function(engine) { binFunction = this.calculateBinNone; } else { - console.log('Error: no binMethod!'); + 0; } var i = 0; @@ -4201,7 +4203,7 @@ var CurveEditor = function(parameters) { this.callback = function() { var that = this; return function(slot, value, element) { - console.log("Element: ", element, ". onValueSet callback: slot is ", slot, " and value is ", value, " while that is ", that); + 0; // Call the optional callback if (typeof that.externalCallback === 'function') { @@ -4264,7 +4266,7 @@ var CurveEditor = function(parameters) { that.status.curveArray.splice(that.status.selected + 1, 0, newCurveArgs.ID); } - console.log("Reorganizing elements"); + 0; that.reorganizeElements(); that.ui.refresh(); }; @@ -4282,7 +4284,7 @@ var CurveEditor = function(parameters) { }; this.addCurve = function(curveType, grade, first_point, last_point) { - console.log("Adding a curve"); + 0; var lastElementID; // Get a deep copy of the template object @@ -4336,7 +4338,7 @@ var CurveEditor = function(parameters) { if ((lastPoint[0] === this.lastCalculatedPoint[0]) && (lastPoint[1] === this.lastCalculatedPoint[1])) { // Set the curve to paint only its first handle - console.log("Remove something before adding stuff"); + 0; // Undo the previous paintTerminalPoints inference this.ui.setProp(lastElementID, 'paintTerminalPoints', 'all'); return; @@ -4377,7 +4379,7 @@ var CurveEditor = function(parameters) { var prevID; if (this.status.selected !== null) { - console.log("Deleting selected curve " + this.status.selected); + 0; //arr = arr.filter(function(){return true}); @@ -4422,7 +4424,7 @@ var CurveEditor = function(parameters) { var i; if (this.status.selected !== null) { - console.log("Transforming selected curve " + this.status.selected); + 0; var bezierN = grade; @@ -4433,11 +4435,11 @@ var CurveEditor = function(parameters) { if (curveNow === curveType) { if (curveType !== 'bezier') { - console.log("Identical type, doing nothing"); + 0; return; } else { if (bezierN === curveGrade) { - console.log("Identical type and grade, doing nothing"); + 0; return; } } @@ -4562,7 +4564,7 @@ var AreaEditor = function(parameters) { this.callback = function() { var that = this; return function(slot, value, element) { - console.log("Element: ", element, ". onValueSet callback: slot is ", slot, " and value is ", value, " while that is ", that); + 0; // Call the optional callback if (typeof that.externalCallback === 'function') { @@ -4631,7 +4633,7 @@ var AreaEditor = function(parameters) { }; this.addArea = function(width, height) { - console.log("Adding an area"); + 0; var lastElement; // Get a deep copy of the template object @@ -4758,11 +4760,11 @@ var BarSelect = function (parameters) { this.callback = function() { var that = this; return function(slot, value, element) { - console.log("Element: ", element, ". onValueSet callback: slot is ", slot, " and value is ", value, " while that is ", that); + 0; var width; if (slot === 'dragStart') { - console.log ('Storing dragStart value ', value); + 0; that.dragStart = value; if (that.areaElement === null) { @@ -5292,7 +5294,7 @@ K2.OSC.Decoder.prototype.decode = function (msg) { } } catch (e) { - console.log("can't decode incoming message: " + e.message); + 0; } }; @@ -5338,13 +5340,13 @@ K2.OSCHandler = function (proxyServer, udpServers) { this.socket = io.connect('http://' + this.proxyServer.host + ':' + this.proxyServer.port); } catch (e) { - console.error ("io.connect failed. No proxy server?"); + 0; return; } this.socket.on('admin', function (data) { // TODO check the version and the ID - console.log("Received an admin message: ", data); + 0; // Let's assume everything is OK this.proxyOK = true; @@ -5360,7 +5362,7 @@ K2.OSCHandler = function (proxyServer, udpServers) { // OSC is received from the server // Transform it in an array var oscArray = Array.prototype.slice.call(data.osc, 0); - console.log ("received osc from the server: " + oscArray); + 0; // Send it to the local clients this.sendLocalMessage (oscArray); @@ -5368,7 +5370,7 @@ K2.OSCHandler = function (proxyServer, udpServers) { this.socket.on ('disconnect', function (data) { - console.log ("socket disconnected"); + 0; this.proxyConnected = false; this.proxyOK = false; @@ -5376,7 +5378,7 @@ K2.OSCHandler = function (proxyServer, udpServers) { this.socket.on ('connect', function (data) { - console.log ("socket connected"); + 0; this.proxyConnected = true; }.bind(this)); @@ -5395,7 +5397,7 @@ K2.OSCHandler.prototype.unregisterClient = function (clientID) { K2.OSCHandler.prototype.sendLocalMessage = function (oscMessage, clientID) { // Try to decode it var received = this.OSCDecoder.decode (oscMessage); - console.log ("decoded OSC = " + received); + 0; // Send it to the callbacks, except for the clientID one for (var client in this.localClients) { @@ -5655,794 +5657,15 @@ K2.CanvasUtils.drawRotate = function (ctx, args /*{image, x, y, rot}*/) { ctx.restore(); }; if (typeof window.define === "function" && window.define.amd) { - console.log ("AMD detected, setting define"); + 0; window.define("kievII", [], function() { - console.log ("KievII: returning K2 object inside the define (AMD detected)"); + 0; return K2; }); } else { - console.log ("KievII: setting window.K2 (no AMD)"); + 0; window.kievII = window.K2 = K2; } -/* - * Hammer.JS - * version 0.6.3 - * author: Eight Media - * https://github.com/EightMedia/hammer.js - * Licensed under the MIT license. - */ -function Hammer(element, options, undefined) -{ - var self = this; - - var defaults = { - // prevent the default event or not... might be buggy when false - prevent_default : false, - css_hacks : true, - - swipe : true, - swipe_time : 200, // ms - swipe_min_distance : 20, // pixels - - drag : true, - drag_vertical : true, - drag_horizontal : true, - // minimum distance before the drag event starts - drag_min_distance : 20, // pixels - - // pinch zoom and rotation - transform : true, - scale_treshold : 0.1, - rotation_treshold : 15, // degrees - - tap : true, - tap_double : true, - tap_max_interval : 300, - tap_max_distance : 10, - tap_double_distance: 20, - - hold : true, - hold_timeout : 500 - }; - options = mergeObject(defaults, options); - - // some css hacks - (function() { - if(!options.css_hacks) { - return false; - } - - var vendors = ['webkit','moz','ms','o','']; - var css_props = { - "userSelect": "none", - "touchCallout": "none", - "userDrag": "none", - "tapHighlightColor": "rgba(0,0,0,0)" - }; - - var prop = ''; - for(var i = 0; i < vendors.length; i++) { - for(var p in css_props) { - prop = p; - if(vendors[i]) { - prop = vendors[i] + prop.substring(0, 1).toUpperCase() + prop.substring(1); - } - element.style[ prop ] = css_props[p]; - } - } - })(); - - // holds the distance that has been moved - var _distance = 0; - - // holds the exact angle that has been moved - var _angle = 0; - - // holds the direction that has been moved - var _direction = 0; - - // holds position movement for sliding - var _pos = { }; - - // how many fingers are on the screen - var _fingers = 0; - - var _first = false; - - var _gesture = null; - var _prev_gesture = null; - - var _touch_start_time = null; - var _prev_tap_pos = {x: 0, y: 0}; - var _prev_tap_end_time = null; - - var _hold_timer = null; - - var _offset = {}; - - // keep track of the mouse status - var _mousedown = false; - - var _event_start; - var _event_move; - var _event_end; - - var _has_touch = ('ontouchstart' in window); - - - /** - * option setter/getter - * @param string key - * @param mixed value - * @return mixed value - */ - this.option = function(key, val) { - if(val != undefined) { - options[key] = val; - } - - return options[key]; - }; - - - /** - * angle to direction define - * @param float angle - * @return string direction - */ - this.getDirectionFromAngle = function( angle ) { - var directions = { - down: angle >= 45 && angle < 135, //90 - left: angle >= 135 || angle <= -135, //180 - up: angle < -45 && angle > -135, //270 - right: angle >= -45 && angle <= 45 //0 - }; - - var direction, key; - for(key in directions){ - if(directions[key]){ - direction = key; - break; - } - } - return direction; - }; - - - /** - * destroy events - * @return void - */ - this.destroy = function() { - if(_has_touch) { - removeEvent(element, "touchstart touchmove touchend touchcancel", handleEvents); - } - // for non-touch - else { - removeEvent(element, "mouseup mousedown mousemove", handleEvents); - removeEvent(element, "mouseout", handleMouseOut); - } - }; - - - /** - * count the number of fingers in the event - * when no fingers are detected, one finger is returned (mouse pointer) - * @param event - * @return int fingers - */ - function countFingers( event ) - { - // there is a bug on android (until v4?) that touches is always 1, - // so no multitouch is supported, e.g. no, zoom and rotation... - return event.touches ? event.touches.length : 1; - } - - - /** - * get the x and y positions from the event object - * @param event - * @return array [{ x: int, y: int }] - */ - function getXYfromEvent( event ) - { - event = event || window.event; - - // no touches, use the event pageX and pageY - if(!_has_touch) { - var doc = document, - body = doc.body; - - return [{ - x: event.pageX || event.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && doc.clientLeft || 0 ), - y: event.pageY || event.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && doc.clientTop || 0 ) - }]; - } - // multitouch, return array with positions - else { - var pos = [], src; - for(var t=0, len=event.touches.length; t touch_time) && (_distance > options.swipe_min_distance)) { - // calculate the angle - _angle = getAngle(_pos.start[0], _pos.move[0]); - _direction = self.getDirectionFromAngle(_angle); - - _gesture = 'swipe'; - - var position = { x: _pos.move[0].x - _offset.left, - y: _pos.move[0].y - _offset.top }; - - var event_obj = { - originalEvent : event, - position : position, - direction : _direction, - distance : _distance, - distanceX : _distance_x, - distanceY : _distance_y, - angle : _angle - }; - - // normal slide event - triggerEvent("swipe", event_obj); - } - }, - - - // drag gesture - // fired on mousemove - drag : function(event) - { - // get the distance we moved - var _distance_x = _pos.move[0].x - _pos.start[0].x; - var _distance_y = _pos.move[0].y - _pos.start[0].y; - _distance = Math.sqrt(_distance_x * _distance_x + _distance_y * _distance_y); - - // drag - // minimal movement required - if(options.drag && (_distance > options.drag_min_distance) || _gesture == 'drag') { - // calculate the angle - _angle = getAngle(_pos.start[0], _pos.move[0]); - _direction = self.getDirectionFromAngle(_angle); - - // check the movement and stop if we go in the wrong direction - var is_vertical = (_direction == 'up' || _direction == 'down'); - if(((is_vertical && !options.drag_vertical) || (!is_vertical && !options.drag_horizontal)) - && (_distance > options.drag_min_distance)) { - return; - } - - _gesture = 'drag'; - - var position = { x: _pos.move[0].x - _offset.left, - y: _pos.move[0].y - _offset.top }; - - var event_obj = { - originalEvent : event, - position : position, - direction : _direction, - distance : _distance, - distanceX : _distance_x, - distanceY : _distance_y, - angle : _angle - }; - - // on the first time trigger the start event - if(_first) { - triggerEvent("dragstart", event_obj); - - _first = false; - } - - // normal slide event - triggerEvent("drag", event_obj); - - cancelEvent(event); - } - }, - - - // transform gesture - // fired on touchmove - transform : function(event) - { - if(options.transform) { - if(countFingers(event) != 2) { - return false; - } - - var rotation = calculateRotation(_pos.start, _pos.move); - var scale = calculateScale(_pos.start, _pos.move); - - if(_gesture != 'drag' && - (_gesture == 'transform' || Math.abs(1-scale) > options.scale_treshold || Math.abs(rotation) > options.rotation_treshold)) { - _gesture = 'transform'; - - _pos.center = { x: ((_pos.move[0].x + _pos.move[1].x) / 2) - _offset.left, - y: ((_pos.move[0].y + _pos.move[1].y) / 2) - _offset.top }; - - if(_first) - _pos.startCenter = _pos.center; - - var _distance_x = _pos.center.x - _pos.startCenter.x; - var _distance_y = _pos.center.y - _pos.startCenter.y; - _distance = Math.sqrt(_distance_x*_distance_x + _distance_y*_distance_y); - - var event_obj = { - originalEvent : event, - position : _pos.center, - scale : scale, - rotation : rotation, - distance : _distance, - distanceX : _distance_x, - distanceY : _distance_y, - }; - - // on the first time trigger the start event - if(_first) { - triggerEvent("transformstart", event_obj); - _first = false; - } - - triggerEvent("transform", event_obj); - - cancelEvent(event); - - return true; - } - } - - return false; - }, - - - // tap and double tap gesture - // fired on touchend - tap : function(event) - { - // compare the kind of gesture by time - var now = new Date().getTime(); - var touch_time = now - _touch_start_time; - - // dont fire when hold is fired - if(options.hold && !(options.hold && options.hold_timeout > touch_time)) { - return; - } - - // when previous event was tap and the tap was max_interval ms ago - var is_double_tap = (function(){ - if (_prev_tap_pos && - options.tap_double && - _prev_gesture == 'tap' && - (_touch_start_time - _prev_tap_end_time) < options.tap_max_interval) - { - var x_distance = Math.abs(_prev_tap_pos[0].x - _pos.start[0].x); - var y_distance = Math.abs(_prev_tap_pos[0].y - _pos.start[0].y); - return (_prev_tap_pos && _pos.start && Math.max(x_distance, y_distance) < options.tap_double_distance); - } - return false; - })(); - - if(is_double_tap) { - _gesture = 'double_tap'; - _prev_tap_end_time = null; - - triggerEvent("doubletap", { - originalEvent : event, - position : _pos.start - }); - cancelEvent(event); - } - - // single tap is single touch - else { - var x_distance = (_pos.move) ? Math.abs(_pos.move[0].x - _pos.start[0].x) : 0; - var y_distance = (_pos.move) ? Math.abs(_pos.move[0].y - _pos.start[0].y) : 0; - _distance = Math.max(x_distance, y_distance); - - if(_distance < options.tap_max_distance) { - _gesture = 'tap'; - _prev_tap_end_time = now; - _prev_tap_pos = _pos.start; - - if(options.tap) { - triggerEvent("tap", { - originalEvent : event, - position : _pos.start - }); - cancelEvent(event); - } - } - } - - } - - }; - - - function handleEvents(event) - { - switch(event.type) - { - case 'mousedown': - case 'touchstart': - _pos.start = getXYfromEvent(event); - _touch_start_time = new Date().getTime(); - _fingers = countFingers(event); - _first = true; - _event_start = event; - - // borrowed from jquery offset https://github.com/jquery/jquery/blob/master/src/offset.js - var box = element.getBoundingClientRect(); - var clientTop = element.clientTop || document.body.clientTop || 0; - var clientLeft = element.clientLeft || document.body.clientLeft || 0; - var scrollTop = window.pageYOffset || element.scrollTop || document.body.scrollTop; - var scrollLeft = window.pageXOffset || element.scrollLeft || document.body.scrollLeft; - - _offset = { - top: box.top + scrollTop - clientTop, - left: box.left + scrollLeft - clientLeft - }; - - _mousedown = true; - - // hold gesture - gestures.hold(event); - - if(options.prevent_default) { - cancelEvent(event); - } - break; - - case 'mousemove': - case 'touchmove': - if(!_mousedown) { - return false; - } - _event_move = event; - _pos.move = getXYfromEvent(event); - - if(!gestures.transform(event)) { - gestures.drag(event); - } - break; - - case 'mouseup': - case 'mouseout': - case 'touchcancel': - case 'touchend': - if(!_mousedown || (_gesture != 'transform' && event.touches && event.touches.length > 0)) { - return false; - } - - _mousedown = false; - _event_end = event; - - - // swipe gesture - gestures.swipe(event); - - - // drag gesture - // dragstart is triggered, so dragend is possible - if(_gesture == 'drag') { - triggerEvent("dragend", { - originalEvent : event, - direction : _direction, - distance : _distance, - angle : _angle - }); - } - - // transform - // transformstart is triggered, so transformed is possible - else if(_gesture == 'transform') { - triggerEvent("transformend", { - originalEvent : event, - position : _pos.center, - scale : calculateScale(_pos.start, _pos.move), - rotation : calculateRotation(_pos.start, _pos.move), - distance : _distance, - distanceX : _distance_x, - distanceY : _distance_y - }); - } - else { - gestures.tap(_event_start); - } - - _prev_gesture = _gesture; - - // trigger release event. - // "release" by default doesn't return the co-ords where your - // finger was released. "position" will return "the last touched co-ords" - triggerEvent("release", { - originalEvent : event, - gesture : _gesture, - position : _pos.move || _pos.start - }); - - // reset vars - reset(); - break; - } - } - - - function handleMouseOut(event) { - if(!isInsideHammer(element, event.relatedTarget)) { - handleEvents(event); - } - } - - - // bind events for touch devices - // except for windows phone 7.5, it doesnt support touch events..! - if(_has_touch) { - addEvent(element, "touchstart touchmove touchend touchcancel", handleEvents); - } - // for non-touch - else { - addEvent(element, "mouseup mousedown mousemove", handleEvents); - addEvent(element, "mouseout", handleMouseOut); - } - - - /** - * find if element is (inside) given parent element - * @param object element - * @param object parent - * @return bool inside - */ - function isInsideHammer(parent, child) { - // get related target for IE - if(!child && window.event && window.event.toElement){ - child = window.event.toElement; - } - - if(parent === child){ - return true; - } - - // loop over parentNodes of child until we find hammer element - if(child){ - var node = child.parentNode; - while(node !== null){ - if(node === parent){ - return true; - }; - node = node.parentNode; - } - } - return false; - } - - - /** - * merge 2 objects into a new object - * @param object obj1 - * @param object obj2 - * @return object merged object - */ - function mergeObject(obj1, obj2) { - var output = {}; - - if(!obj2) { - return obj1; - } - - for (var prop in obj1) { - if (prop in obj2) { - output[prop] = obj2[prop]; - } else { - output[prop] = obj1[prop]; - } - } - return output; - } - - - /** - * check if object is a function - * @param object obj - * @return bool is function - */ - function isFunction( obj ){ - return Object.prototype.toString.call( obj ) == "[object Function]"; - } - - - /** - * attach event - * @param node element - * @param string types - * @param object callback - */ - function addEvent(element, types, callback) { - types = types.split(" "); - for(var t= 0,len=types.length; t0?n[t]=e(t):e(t))}var n={},r=t;return i}()}function fact_lookup(e){if(00)return!1;y=!1,E=n,_.swipe(n),c=="drag"?A("dragend",{"originalEvent":n,"direction":u,"distance":s,"angle":o}):c=="transform"?A("transformend",{"originalEvent":n,"position":a.center,"scale":k(a.start,a.move),"rotation":L(a.start,a.move),"distance":s,"distanceX":_distance_x,"distanceY":_distance_y}):_.tap(b),h=c,A("release",{"originalEvent":n,"gesture":c,"position":a.move||a.start}),M()}}function P(t){H(e,t.relatedTarget)||D(t)}function H(e,t){!t&&window.event&&window.event.toElement&&(t=window.event.toElement);if(e===t)return!0;if(t){var n=t.parentNode;while(n!==null){if(n===e)return!0;n=n.parentNode}}return!1}function B(e,t){var n={};if(!t)return e;for(var r in e)r in t?n[r]=t[r]:n[r]=e[r];return n}function j(e){return Object.prototype.toString.call(e)=="[object Function]"}function F(e,t,n){t=t.split(" ");for(var r=0,i=t.length;r=45&&e<135,"left":e>=135||e<=-135,"up":e<-45&&e>-135,"right":e>=-45&&e<=45},n,r;for(r in t)if(t[r]){n=r;break}return n},this.destroy=function(){S?I(e,"touchstart touchmove touchend touchcancel",D):(I(e,"mouseup mousedown mousemove",D),I(e,"mouseout",P))};var _={"hold":function(e){t.hold&&(c="hold",clearTimeout(m),m=setTimeout(function(){c=="hold"&&A("hold",{"originalEvent":e,"position":a.start})},t.hold_timeout))},"swipe":function(e){if(!a.move||c==="transform")return;var n=a.move[0].x-a.start[0].x,i=a.move[0].y-a.start[0].y;s=Math.sqrt(n*n+i*i);var f=(new Date).getTime(),l=f-p;if(t.swipe&&t.swipe_time>l&&s>t.swipe_min_distance){o=N(a.start[0],a.move[0]),u=r.getDirectionFromAngle(o),c="swipe";var h={"x":a.move[0].x-g.left,"y":a.move[0].y-g.top},d={"originalEvent":e,"position":h,"direction":u,"distance":s,"distanceX":n,"distanceY":i,"angle":o};A("swipe",d)}},"drag":function(e){var n=a.move[0].x-a.start[0].x,i=a.move[0].y-a.start[0].y;s=Math.sqrt(n*n+i*i);if(t.drag&&s>t.drag_min_distance||c=="drag"){o=N(a.start[0],a.move[0]),u=r.getDirectionFromAngle(o);var f=u=="up"||u=="down";if((f&&!t.drag_vertical||!f&&!t.drag_horizontal)&&s>t.drag_min_distance)return;c="drag";var h={"x":a.move[0].x-g.left,"y":a.move[0].y-g.top},p={"originalEvent":e,"position":h,"direction":u,"distance":s,"distanceX":n,"distanceY":i,"angle":o};l&&(A("dragstart",p),l=!1),A("drag",p),O(e)}},"transform":function(e){if(t.transform){if(x(e)!=2)return!1;var n=L(a.start,a.move),r=k(a.start,a.move);if(c!="drag"&&(c=="transform"||Math.abs(1-r)>t.scale_treshold||Math.abs(n)>t.rotation_treshold)){c="transform",a.center={"x":(a.move[0].x+a.move[1].x)/2-g.left,"y":(a.move[0].y+a.move[1].y)/2-g.top},l&&(a.startCenter=a.center);var i=a.center.x-a.startCenter.x,o=a.center.y-a.startCenter.y;s=Math.sqrt(i*i+o*o);var u={"originalEvent":e,"position":a.center,"scale":r,"rotation":n,"distance":s,"distanceX":i,"distanceY":o};return l&&(A("transformstart",u),l=!1),A("transform",u),O(e),!0}}return!1},"tap":function(e){var n=(new Date).getTime(),r=n-p;if(t.hold&&!(t.hold&&t.hold_timeout>r))return;var i=function(){if(d&&t.tap_double&&h=="tap"&&p-v=this.zMin;r-=1)if(typeof this.zArray[r]!="undefined")for(var i=this.zArray[r].length-1;i>=0;i-=1)if(this.zArray[r][i].getListening()&&typeof this.zArray[r][i][n]=="function"){var s=this.zArray[r][i][n](e,t);if(typeof s!="undefined"){if(s instanceof Array)for(var o=0;oi)this.zMin=i;if(typeof this.zMax=="undefined"||this.zMaxt)this.zMin=t;if(typeof this.zMax=="undefined"||this.zMaxo)throw new Error("Recursion exceeded");if(t[p].element===u&&t[p].slot===f)return}}this.elements[u].element.setValue(f,a),typeof this.elements[u].element.onValueSet=="function"&&l!==!1&&this.elements[u].element.onValueSet(f,this.elements[u].element.values[f],u),t.push({"element":u,"slot":f});if(typeof this.connections[u]!="undefined"&&typeof this.connections[u][f]!="undefined")for(s in this.connections[u][f])if(this.connections[u][f].hasOwnProperty(s)){n=this.connections[u][f][s],r=n.recvElement,i=n.recvSlot;if(typeof n.callback=="function"){var d={"sender":u,"sendSlot":f,"recv":r,"recvSlot":i,"ui":this};h=n.callback(a,d)}var v;n.cascade===!1?v=!1:v=!0,this.setValue({"elementID":r,"slot":i,"value":h,"history":t,"fireCallback":v})}},this.hideElement=function(e){var t;if(typeof this.elements[e]=="undefined")throw new Error("Element "+e+" not present.");t=this.elements[e].element.getVisible(),t===!0&&(this.elements[e].element.setVisible(!1),this.elements[e].element.setListening(!1))},this.unhideElement=function(e){var t;if(typeof this.elements[e]=="undefined")throw new Error("Element "+e+" not present.");t=this.elements[e].element.getVisible(),t===!1&&(this.elements[e].element.setVisible(!0),this.elements[e].element.setListening(!0))},this.setHidden=function(e,t){this.setVisible(e,!t)},this.setVisible=function(e,t){var n;if(typeof this.elements[e]=="undefined")throw new Error("Element "+e+" not present.");n=this.elements[e].element.getVisible(),n!==t&&(this.elements[e].element.setVisible(t),this.elements[e].element.setListening(t))},this.setListening=function(e,t){var n;if(typeof this.elements[e]=="undefined")throw new Error("Element "+e+" not present.");n=this.elements[e].element.getListening(),n!==t&&this.elements[e].element.setListening(t)},this.refreshZ=function(e){for(var t=e,n=this.zArray.length;t0?e>this.values.xOffset&&ethis.values.xOffset+this.values.width&&(n=!0),this.values.height>0?t>this.values.yOffset&&tthis.values.height+this.values.yOffset&&(r=!0),n&&r?!0:!1},K2.Area.prototype.tap=K2.Area.prototype.dragstart=function(e,t){var n=this.values.xOffset-this.proximity,r=this.values.xOffset+this.proximity,i=this.values.xOffset+this.values.width-this.proximity,s=this.values.xOffset+this.values.width+this.proximity,o=this.values.height+this.values.yOffset+this.proximity,u=this.values.height+this.values.yOffset-this.proximity,a=this.values.yOffset+this.proximity,f=this.values.yOffset-this.proximity;e>n&&ei&&eu&&tf&&t0)return n;if(this.inside&&this.move!=="none"){var u=e-this.startPoint[0],a=t-this.startPoint[1];this.startPoint=[e,t];if(this.move==="all")return[{"slot":"xOffset","value":this.values.xOffset+u},{"slot":"yOffset","value":this.values.yOffset+a}];if(this.move==="x")return{"slot":"xOffset","value":this.values.xOffset+u};if(this.move==="y")return{"slot":"yOffset","value":this.values.yOffset+a}}},K2.Area.prototype.release=K2.Area.prototype.dragend=K2.Area.prototype.mouseup=function(e,t){var n;return this.leftSide=this.rightSide=this.bottomSide=this.topSide=!1,this.inside&&this.isInArea(e,t)&&(n={"slot":"selected","value":[e,t]}),this.inside=!1,n},K2.Area.prototype.hold=function(e,t){if(this.isInArea(e,t)){var n={"slot":"held","value":[e,t]};return n}},K2.Area.prototype.doubletap=function(e,t){if(this.isInArea(e,t))return{"slot":"doubletap","value":[e,t]}},K2.Area.prototype.setValue=function(e,t){K2.Area.superclass.setValue.call(this,e,t)},K2.Area.prototype.refresh_CANVAS2D=function(e){if(this.isVisible===!0){e.context.fillStyle=this.color,e.context.strokeStyle=this.borderColor,e.context.lineWidth=this.thickness;var t=Math.floor(this.thickness/2);e.context.fillRect(this.xOrigin+this.values.xOffset+t,this.values.yOffset+t,this.values.width-t*2,this.values.height-t*2),this.thickness>0&&e.context.strokeRect(this.xOrigin+this.values.xOffset,this.values.yOffset,this.values.width,this.values.height)}},K2.Area.prototype.getXCoord=function(){return this.values.xOrigin},K2.Area.prototype.getYCoord=function(){return this.values.yOrigin},K2.Area.prototype.getWidth=function(){return this.values.width},K2.Area.prototype.getHeight=function(){return this.values.height},K2.Area.prototype.setHeight=function(e){this.values.height=e,typeof this.ROIHeight=="undefined"&&(this.ROIHeight=e)},K2.Area.prototype.setWidth=function(e){this.values.width=e,typeof this.ROIWidth=="undefined"&&(this.ROIWidth=e)},K2.Curve=function(e){arguments.length&&this.getready(e)},K2.extend(K2.Curve,K2.UIElement),K2.Curve.prototype.getready=function(e){K2.Curve.superclass.getready.call(this,e),this.values={"points":[],"selected":[],"held":[],"doubletap_c":[],"doubletap_h":[]},this.defaultSlot="points",this.setWidth(e.width),this.setHeight(e.height),this.curveType=e.curveType||"bezier",this.thickness=e.thickness||2,this.curveColor=e.curveColor||"black",this.helperColor=e.helperColor||"#CCCCCC",this.handleColor=e.handleColor||"red",this.curveLabels=typeof e.curveLabels=="boolean"?e.curveLabels:!1,this.terminalPointStyle=e.terminalPointStyle||"rect",this.paintTerminalPoints=e.paintTerminalPoints||"all",this.midPointStyle=e.midPointStyle||"circle",this.terminalPointSize=e.terminalPointSize||16,this.midPointSize=e.midPointSize||8,this.terminalPointColor=e.terminalPointColor||this.handleColor,this.midPointColor=e.midPointColor||this.handleColor,this.terminalPointFill=e.terminalPointFill||null,this.midPointFill=e.midPointFill||null,this.xMonotone=e.xMonotone||!1,this.handleSize=e.handleSize||this.terminalPointSize>this.midPointSize?this.terminalPointSize:this.midPointSize,this.handleClicked=null,this.supportPoints=[],this.selectStart=!1,this.whereHappened=[];switch(e.curveType){case"bezier":if(e.points.length%2!==0||e.points.length<4)throw"Incorrect number of points "+e.points.length;break;case"halfcosine":case"smooth":case"linear":if(e.points.length!==4)throw"Incorrect number of points "+e.points.length;break;default:throw"Unknown curve type "+e.curveType}var t=[];for(var n=0;nthis.supportPoints[i][0]-this.thickness&&ethis.supportPoints[i][1]-this.thickness&&tn[r][0]-this.handleSize&&en[r][1]-this.handleSize&&tthis.ROILeft&&t>this.ROITop&&ee[e.length-1][0]&&(e[0][0]>this.values.points[0][0]?e[0][0]=e[e.length-1][0]:e[e.length-1][0]=e[0][0])},K2.Curve.prototype.drag=function(e,t){var n={},r;return this.handleClicked!==null?(r=K2.GenericUtils.clone(this.values.points),this.isInROI(e,t)?(this.triggered=!1,r[this.handleClicked][0]=e,r[this.handleClicked][1]=t):(r[this.handleClicked][0]=e,r[this.handleClicked][1]=t,e>this.ROILeft+this.ROIWidth&&(r[this.handleClicked][0]=this.ROILeft+this.ROIWidth),ethis.ROITop+this.ROIHeight&&(r[this.handleClicked][1]=this.ROITop+this.ROIHeight),tthis.ROILeft&&t>this.ROITop&&ethis.ROILeft&&ethis.ROITop&&ethis.width&&(n[0]=this.width),n[0]<0&&(n[0]=0)}else if(this.orientation===1){if(!this.isInROIY(e))return;n=[r[0],t-this.yOrigin],n[1]>this.height&&(n[1]=this.height),n[1]<0&&(n[1]=0)}return n},K2.Bar.prototype.mousedown=K2.Bar.prototype.touchstart=function(e,t){if(!this.isInROI(e,t))return;this.started=!0;var n=this.commonDrag(e,t);if(typeof n!="undefined")return ret={"slot":"barPos","value":n},ret},K2.Bar.prototype.drag=function(e,t){if(!this.started)return;var n=this.commonDrag(e,t);if(typeof n!="undefined")return ret={"slot":"barPos","value":n},ret},K2.Bar.prototype.dragend=K2.Bar.prototype.swipe=function(e,t){if(!this.started)return;this.started=!1;var n=this.commonDrag(e,t);if(typeof n!="undefined")return ret=[{"slot":"barPos","value":n},{"slot":"dragEnd","value":[e-this.xOrigin,t-this.yOrigin]}],ret},K2.Bar.prototype.dragstart=function(e,t){if(this.isInROI(e,t))return ret={"slot":"dragStart","value":[e-this.xOrigin,t-this.yOrigin]},ret},K2.Bar.prototype.setValue=function(e,t){console.log("Setting "+e+" to "+t),e=="barPos"?(t[0]<=this.width&&(this.values.barPos[0]=t[0]),t[1]<=this.height&&(this.values.barPos[1]=t[1])):this.values[e]=t},K2.Bar.prototype.refresh_CANVAS2D=function(e){if(this.isVisible===!0){var t=e.context;t.lineWidth=this.thickness,t.strokeStyle=this.barColor,t.beginPath();if(this.orientation===0){var n=this.xOrigin+this.values.barPos[0];t.moveTo(n,this.yOrigin+this.height),t.lineTo(n,this.yOrigin)}else this.orientation===1&&(t.moveTo(this.xOrigin+this.width,this.yOrigin+this.values.barPos[1]),t.lineTo(this.xOrigin,this.yOrigin+this.values.barPos[1]));t.stroke(),t.closePath()}},K2.Button=function(e){arguments.length&&this.getready(e)},K2.extend(K2.Button,K2.UIElement),K2.Button.prototype.getready=function(e){if(e===undefined)throw new Error("Error: args is undefined!");K2.Button.superclass.getready.call(this,e),this.values={"buttonvalue":0},this.defaultSlot="buttonvalue",this.triggered=!1,this.mode=e.mode||"persistent",this.imagesArray=e.imagesArray;if(this.imagesArray.length<1)throw new Error("Invalid images array length, "+this.imagesArray.length);this.nButtons=this.imagesArray.length;for(var t=0;t=this.ROILeft&&t>=this.ROITop&&e<=this.ROILeft+this.ROIWidth&&t<=this.ROITop+this.ROIHeight?!0:!1},K2.Button.prototype.mousedown=K2.Button.prototype.touchstart=function(e,t){if(this.isInROI(e,t)){this.triggered=!0;if(this.mode==="persistent")return undefined;if(this.mode==="immediate")return to_set=(this.values.buttonvalue+1)%this.nButtons,ret={"slot":"buttonvalue","value":to_set},ret}},K2.Button.prototype.mouseup=K2.Button.prototype.touchend=function(e,t){var n=0,r={};if(this.mode==="persistent"){if(this.triggered&&this.isInROI(e,t))return n=(this.values.buttonvalue+1)%this.nButtons,r={"slot":"buttonvalue","value":n},this.triggered=!1,r}else if(this.mode==="immediate"&&this.triggered)return n=(this.values.buttonvalue-1)%this.nButtons,r={"slot":"buttonvalue","value":n},this.triggered=!1,r;return undefined},K2.Button.prototype.mouseout=function(e,t){if(this.mode==="immediate")return this.mouseup(e,t)},K2.Button.prototype.setValue=function(e,t){if(t<0||t>this.nButtons)return;K2.Button.superclass.setValue.call(this,e,t)},K2.Button.prototype.refresh_CANVAS2D=function(e){this.isVisible===!0&&e.context.drawImage(this.imagesArray[this.values.buttonvalue],this.xOrigin,this.yOrigin)},K2.Button.prototype.setStatesNumber=function(e){this.nButtons=e},K2.Button.prototype.getStatesNumber=function(){return this.nButtons},K2.Background=function(e){arguments.length&&this.getready(e)},K2.extend(K2.Background,K2.UIElement),K2.Background.prototype.getready=function(e){if(typeof e=="undefined")throw new Error("Error: args is undefined!");K2.Background.superclass.getready.call(this,e),this.values={"selected":[],"held":[],"doubletap":[],"tap":[]},this.defaultSlot="selected",this.image=e.image,this.setWidth(this.image.width),this.setHeight(this.image.height)},K2.Background.prototype.GetImage=function(){return this.image},K2.Background.prototype.isInROI=function(e,t){if(e>this.ROILeft&&t>this.ROITop)return ethis.maxValue&&(r=this.maxValue),rthis.radius-this.thickness/2&&n=this.ROILeft&&t>=this.ROITop&&e<=this.ROILeft+this.ROIWidth&&t<=this.ROITop+this.ROIHeight?!0:!1},K2.Grid.prototype.mousedown=function(e,t){return this.isInROI(e,t)&&(this.triggered=!0),undefined},K2.Grid.prototype.mouseup=function(e,t){return this.triggered&&this.isInROI(e,t)?(this.triggered=!1,{"slot":"selected","value":[e,t]}):undefined},K2.Grid.prototype.setValue=function(e,t){K2.Grid.superclass.setValue.call(this,e,t)},K2.Grid.prototype.refresh_CANVAS2D=function(e){if(this.isVisible===!0){var t=e.context,n=Math.floor(this.height/this.rows),r=Math.floor(this.width/this.columns);t.fillStyle=this.bgColor,t.fillRect(this.xOrigin,this.yOrigin,this.width,this.height),t.beginPath(),t.lineWidth=this.lineWidth;for(var i=this.xOrigin+0;it&&(t=this.imagesArray[r].width),this.imagesArray[r].height>n&&(n=this.imagesArray[r].height)}this.setWidth(t),this.setHeight(n)},K2.Knob.prototype.getImageNum=function(){if(this.values.knobvalue<0||this.values.knobvalue>1)return undefined;var e=Math.round(this.values.knobvalue*(this.imageNum-1));return e},K2.Knob.prototype.getImage=function(){var e=this.getImageNum();return this.imagesArray[e]},K2.Knob.prototype.calculateAngle=function(e,t){var n=this.xOrigin+this.width/2,r=this.yOrigin+this.height/2;console.log("Point is: ",e,t,"Center is: ",n,r);var i=Math.atan2(e-n,t-r);console.log("radiant atan ",i),i<0&&(i+=2*Math.PI),console.log("radiant atan, normalized, is ",i);var s=i*(180/Math.PI);console.log("degree atan is",s),s=360-s,typeof this.bottomAngularOffset!="undefined"&&(s=K2.MathUtils.linearRange(0,360,-this.bottomAngularOffset,360+this.bottomAngularOffset,s),s<0&&(s=0),s>360&&(s=360));var o=K2.MathUtils.linearRange(0,360,0,1,Math.floor(s));return console.log("value is",o),o},K2.Knob.prototype.isInROI=function(e,t){return e>this.ROILeft&&t>this.ROITop&&e1&&(s=1),s<0&&(s=0),n={"slot":"knobvalue","value":s},n}}else if(this.knobMethod==="atan"&&this.start_x!==undefined&&this.start_y!==undefined){var o=this.calculateAngle(e,t);return n={"slot":"knobvalue","value":o},n}return undefined},K2.Knob.prototype.setValue=function(e,t){var n=t;if(n<0||n>1)return;K2.Knob.superclass.setValue.call(this,e,t)},K2.Knob.prototype.refresh_CANVAS2D=function(e){if(this.isVisible===!0)if(this.imagesArray.length>1){var t=this.getImageNum();e.context.drawImage(this.imagesArray[t],this.xOrigin,this.yOrigin)}else if(this.imagesArray.length==1){var n=0,r=this.height*this.getImageNum();e.context.drawImage(this.imagesArray[0],n,r,this.width,this.height,this.xOrigin,this.yOrigin,this.width,this.height)}},K2.Label=function(e){arguments.length&&this.getready(e)},K2.extend(K2.Label,K2.UIElement),K2.Label.prototype.getready=function(e){K2.Label.superclass.getready.call(this,e),this.values={"labelvalue":""},this.defaultSlot="labelvalue",this.textColor=e.textColor||"black",this.setWidth(e.width),this.setHeight(e.height)},K2.Label.prototype.isInROI=function(e,t){return e>this.ROILeft&&t>this.ROITop&&e1)return undefined;var e=this.values.knobvalue*360,t=360-(e*(this.startAngValue-this.stopAngValue)/360+this.stopAngValue)%360,n=(360-this.initAngValue+t)%360,r=n*Math.PI/180;return r},K2.RotKnob.prototype.getRangedAmount=function(e){var t=this.stopAngValue-this.initAngValue,n=this.startAngValue-this.initAngValue;console.log("start -> end",n,t),e>this.initAngValue&&n<0&&(console.log("Angle now is",e),e=-(360-e));var r=K2.MathUtils.linearRange(n,t,0,1,e);return console.log("knob value",r),r<0&&(r=0),r>1&&(r=1),r},K2.RotKnob.prototype.isInROI=function(e,t){return e>this.ROILeft&&t>this.ROITop&&e offset",s,o,u);var a=this.getRangedAmount(Math.floor(o));return a},K2.RotKnob.prototype.dragstart=K2.RotKnob.prototype.mousedown=K2.RotKnob.prototype.touchstart=function(e,t){var n=this.isInROI(e,t);if(n){this.start_x=e,this.start_y=t;if(this.knobMethod==="atan"){var r=this.calculateAngle(e,t),i={"slot":"knobvalue","value":r};return i}}return undefined},K2.RotKnob.prototype.dragend=K2.RotKnob.prototype.mouseup=K2.RotKnob.prototype.touchend=function(e,t){return this.start_x=null,this.start_y=null,undefined},K2.RotKnob.prototype.drag=K2.RotKnob.prototype.mousemove=function(e,t){var n;if(this.knobMethod==="updown"){if(this.start_x!==null&&this.start_y!==null){var r=0,i,s;return r=t-this.start_y,i=this.values.realknobvalue,s=i-r/this.sensitivity*this.moveDirection,s>1&&(s=1),s<0&&(s=0),n={"slot":"knobvalue","value":s},n}}else if(this.knobMethod==="atan"&&this.isInROI(e,t)&&this.start_x!==null&&this.start_y!==null){var o=this.calculateAngle(e,t);return n={"slot":"knobvalue","value":o},n}return undefined},K2.RotKnob.prototype.setValue=function(e,t){var n;if(t<0||t>1)return;if(this.values[e]===undefined)throw new Error("Slot "+e+" not present or value undefined");if(t===this.values[e]||t===this.values["real"+e])return;this.values["real"+e]=t;if(this.angSteps!==undefined){var r=1/this.angSteps;n=Math.floor(t/r)*r;if(n===this.values[e])return}else n=t;console.log("Value is: ",n),K2.RotKnob.superclass.setValue.call(this,e,n)},K2.RotKnob.prototype.refresh_CANVAS2D=function(e){if(this.isVisible===!0){var t=this.getRotateAmount();K2.CanvasUtils.drawRotate(e.context,{"image":this.image,"x":this.xOrigin,"y":this.yOrigin,"rot":t})}},K2.Slider=function(e){arguments.length&&this.getready(e)},K2.extend(K2.Slider,K2.UIElement),K2.Slider.prototype.getready=function(e){if(typeof e=="undefined")throw"Slider error: args is undefined!";K2.Slider.superclass.getready.call(this,e),this.values={"slidervalue":0},this.defaultSlot="slidervalue",this.width=0,this.height=0,this.sliderImage=e.sliderImg,this.knobImage=e.knobImg,this.type=e.type,this.type!=="horizontal"&&this.type!=="vertical"&&(this.type="vertical"),this.calculateDimensions()},K2.Slider.prototype.getKnobPosition=function(){var e;if(this.values.slidervalue<0||this.values.slidervalue>1)return undefined;switch(this.type){case"horizontal":e=Math.round(this.values.slidervalue*this.width+this.zeroLimit);break;case"vertical":e=Math.round(this.values.slidervalue*this.height+this.zeroLimit);break;default:throw new Error("Error: Slider orientation is undefined!")}return e},K2.Slider.prototype.isInROI=function(e,t){switch(this.type){case"horizontal":if(e>this.getKnobPosition()&&t>this.ROITop&&ethis.getKnobPosition()&&e>this.ROILeft&&t1&&(n=1),n<0&&(n=0),r={"slot":"slidervalue","value":n},r}return undefined},K2.Slider.prototype.setValue=function(e,t){if(t<0||t>1)return;K2.Slider.superclass.setValue.call(this,e,t)},K2.Slider.prototype.refresh_CANVAS2D=function(e){if(this.isVisible===!0){e.context.drawImage(this.sliderImage,this.xOrigin,this.yOrigin);switch(this.type){case"horizontal":e.context.drawImage(this.knobImage,this.getKnobPosition(),this.yOrigin);break;case"vertical":e.context.drawImage(this.knobImage,this.xOrigin,this.getKnobPosition());break;default:throw new Error("Error: Slider orientation unknown: ",this.type)}}},K2.Slider.prototype.calculateDimensions=function(){this.kWidth=this.knobImage.width,this.kHeight=this.knobImage.height,this.setWidth(this.sliderImage.width),this.setHeight(this.sliderImage.height);switch(this.type){case"horizontal":this.totalStride=this.width+this.kWidth,this.additionalEndSpace=Math.round(this.kWidth/2),this.zeroLimit=this.xOrigin-this.additionalEndSpace,this.oneLimit=this.xOrigin+this.width+this.additionalEndSpace;break;case"vertical":this.totalStride=this.height+this.kHeight,this.additionalEndSpace=Math.round(this.kHeight/2),this.zeroLimit=this.yOrigin-this.additionalEndSpace,this.oneLimit=this.yOrigin+this.height+this.additionalEndSpace;break;default:throw new Error("Error: Slider orientation is undefined!")}},K2.Slider.prototype.setGraphicWrapper=function(e){K2.Slider.superclass.setGraphicWrapper.call(this,e),this.drawClass=e.initObject([{"objName":"drawImage","objParms":this.objParms}])},K2.Wavebox=function(e){arguments.length&&this.getready(e)},K2.extend(K2.Wavebox,K2.UIElement),K2.Wavebox.prototype.getready=function(e){K2.Wavebox.superclass.getready.call(this,e),this.values={"waveboxposition":0,"startsample":0,"endsample":null,"waveboxsignal":[],"xPos":0,"yPos":0},this.defaultSlot="waveboxposition",this.setWidth(e.width),this.setHeight(e.height),this.binMethod=e.binMethod||"minmax",this.orientation=e.orientation||0,this.waveColor=e.waveColor||"black"},K2.Wavebox.prototype.isInROI=function(e,t){return e>this.ROILeft&&t>this.ROITop&&ethis.values.waveboxsignal.length)throw new Error("Error: Trying to set ",e," bigger than signal length: ",t," > ",this.values.waveboxsignal.length)}if(e==="startsample"&&t>this.values.endsample)throw new Error("Error: Trying to set startsample > endsample: ",t," > ",this.values.endsample);if(e==="endsample"&&tn.endsample&&(s=n.endsample);var o=r[i],u=r[i];for(var a=1;au&&(u=r[i+a]);var f={"max":u,"min":o};return f},K2.Wavebox.prototype.calculateBinNone=function(e,t,n){var r=n.startsample+e*t,i=parseInt(t/2,10),s=n.waveboxsignal[r+i],o={"max":s,"min":-s};return o},K2.Wavebox.prototype.calculateBinAvg=function(e,t){var n=this.values.waveboxsignal,r=this.values.startsample+e*t,i=r+(e+1)*t;i>this.values.endsample&&(i=this.values.endsample);var s=n.subarray(r,i),o=0,u=s.length;for(var a=0;athis.width&&(a[0]=this.width),a[1]<0&&(a[1]=0);if(a[0]===this.lastCalculatedPoint[0]&&a[1]===this.lastCalculatedPoint[1]){console.log("Remove something before adding stuff"),this.ui.setProp(i,"paintTerminalPoints","all");return}}this.lastCalculatedPoint[0]=a[0],this.lastCalculatedPoint[1]=a[1];switch(e){case"linear":case"smooth":case"halfcosine":s.points=u.concat(a);break;case"bezier":var p=u.slice();for(var d=1;de)e+=i[l++%f],e>u&&(e=u),c?this.lineTo(e,0):this.moveTo(e,0),c=!c;this.restore()}),K2.OSC={},K2.OSC.Message=function(e){this.address=e,this.typetags="",this.args=[];for(var t=1;t"+e+"s",t,0,[this.value])}},K2.OSC.TInt=function(e){this.value=e},K2.OSC.TInt.prototype={"typetag":"i","decode":function(e){if(e.length<4)throw new ShortBuffer("int",e,4);return this.value=Struct.Unpack(">i",e.slice(0,4))[0],e.slice(4)},"encode":function(){var e=new Array(4);return Struct.PackTo(">i",e,0,[this.value])}},K2.OSC.TTime=function(e){this.value=e},K2.OSC.TTime.prototype={"typetag":"t","decode":function(e){if(e.length<8)throw new ShortBuffer("time",e,8);return this.value=Struct.Unpack(">LL",e.slice(0,8))[0],e.slice(8)},"encode":function(e,t){return Struct.PackTo(">LL",e,t,this.value)}},K2.OSC.TFloat=function(e){this.value=e},K2.OSC.TFloat.prototype={"typetag":"f","decode":function(e){if(e.length<4)throw new ShortBuffer("float",e,4);return this.value=Struct.Unpack(">f",e.slice(0,4))[0],e.slice(4)},"encode":function(){var e=new Array(4);return Struct.PackTo(">f",e,0,[this.value])}},K2.OSC.TBlob=function(e){this.value=e},K2.OSC.TBlob.prototype={"typetag":"b","decode":function(e){var t=Struct.Unpack(">i",e.slice(0,4))[0],n=parseInt(Math.ceil(t/4)*4,10)+4;return this.value=e.slice(4,t+4),e.slice(n)},"encode":function(e,t){var n=Math.ceil(this.value.length/4,10)*4;return Struct.PackTo(">i"+n+"s",e,t,[n,this.value])}},K2.OSC.TDouble=function(e){this.value=e},K2.OSC.TDouble.prototype={"typetag":"d","decode":function(e){if(e.length<8)throw new ShortBuffer("double",e,8);return this.value=Struct.Unpack(">d",e.slice(0,8))[0],e.slice(8)},"encode":function(e,t){return Struct.PackTo(">d",e,t,[this.value])}},K2.OSC.tagToConstructor={"i":function(){return new K2.OSC.TInt},"f":function(){return new K2.OSC.TFloat},"s":function(){return new K2.OSC.TString},"b":function(){return new K2.OSC.TBlob},"d":function(){return new K2.OSC.TDouble}},K2.OSC.decodeBundle=function(e){var t=[],n={"time":null,"args":[]},r=new K2.OSC.TTime;e=r.decode(e),n.time=r.value;while(e.length>0){var i=new K2.OSC.TInt;e=i.decode(e);var s=K2.OSC.decode(e.slice(0,i.value));n.args.push(s),e=e.slice(i.value)}return t.push(n),t},K2.OSC.decode=function(e){var t=[],n=new K2.OSC.TString;e=n.decode(e),t.push(n.value);if(n.value==="#bundle")return K2.OSC.decodeBundle(e);if(e.length>0){var r=new K2.OSC.TString;e=r.decode(e),r=r.value;if(r[0]!=",")throw"invalid type tag in incoming OSC message, must start with comma";for(var i=1;i0?n[t]=e(t):e(t))}var n={},r=t;return i}()}function l(e){if(0=this.zMin;r-=1)if(typeof this.zArray[r]!="undefined")for(var i=this.zArray[r].length-1;i>=0;i-=1)if(this.zArray[r][i].getListening()&&typeof this.zArray[r][i][n]=="function"){var s=this.zArray[r][i][n](e,t);if(typeof s!="undefined"){if(s instanceof Array)for(var o=0;oi)this.zMin=i;if(typeof this.zMax=="undefined"||this.zMaxt)this.zMin=t;if(typeof this.zMax=="undefined"||this.zMaxo)throw new Error("Recursion exceeded");if(t[p].element===u&&t[p].slot===f)return}}this.elements[u].element.setValue(f,a),typeof this.elements[u].element.onValueSet=="function"&&l!==!1&&this.elements[u].element.onValueSet(f,this.elements[u].element.values[f],u),t.push({"element":u,"slot":f});if(typeof this.connections[u]!="undefined"&&typeof this.connections[u][f]!="undefined")for(s in this.connections[u][f])if(this.connections[u][f].hasOwnProperty(s)){n=this.connections[u][f][s],r=n.recvElement,i=n.recvSlot;if(typeof n.callback=="function"){var d={"sender":u,"sendSlot":f,"recv":r,"recvSlot":i,"ui":this};h=n.callback(a,d)}var v;n.cascade===!1?v=!1:v=!0,this.setValue({"elementID":r,"slot":i,"value":h,"history":t,"fireCallback":v})}},this.hideElement=function(e){var t;if(typeof this.elements[e]=="undefined")throw new Error("Element "+e+" not present.");t=this.elements[e].element.getVisible(),t===!0&&(this.elements[e].element.setVisible(!1),this.elements[e].element.setListening(!1))},this.unhideElement=function(e){var t;if(typeof this.elements[e]=="undefined")throw new Error("Element "+e+" not present.");t=this.elements[e].element.getVisible(),t===!1&&(this.elements[e].element.setVisible(!0),this.elements[e].element.setListening(!0))},this.setHidden=function(e,t){this.setVisible(e,!t)},this.setVisible=function(e,t){var n;if(typeof this.elements[e]=="undefined")throw new Error("Element "+e+" not present.");n=this.elements[e].element.getVisible(),n!==t&&(this.elements[e].element.setVisible(t),this.elements[e].element.setListening(t))},this.setListening=function(e,t){var n;if(typeof this.elements[e]=="undefined")throw new Error("Element "+e+" not present.");n=this.elements[e].element.getListening(),n!==t&&this.elements[e].element.setListening(t)},this.refreshZ=function(e){for(var t=e,n=this.zArray.length;t0?e>this.values.xOffset&&ethis.values.xOffset+this.values.width&&(n=!0),this.values.height>0?t>this.values.yOffset&&tthis.values.height+this.values.yOffset&&(r=!0),n&&r?!0:!1},e.Area.prototype.tap=e.Area.prototype.dragstart=function(e,t){var n=this.values.xOffset-this.proximity,r=this.values.xOffset+this.proximity,i=this.values.xOffset+this.values.width-this.proximity,s=this.values.xOffset+this.values.width+this.proximity,o=this.values.height+this.values.yOffset+this.proximity,u=this.values.height+this.values.yOffset-this.proximity,a=this.values.yOffset+this.proximity,f=this.values.yOffset-this.proximity;e>n&&ei&&eu&&tf&&t0)return n;if(this.inside&&this.move!=="none"){var u=e-this.startPoint[0],a=t-this.startPoint[1];this.startPoint=[e,t];if(this.move==="all")return[{"slot":"xOffset","value":this.values.xOffset+u},{"slot":"yOffset","value":this.values.yOffset+a}];if(this.move==="x")return{"slot":"xOffset","value":this.values.xOffset+u};if(this.move==="y")return{"slot":"yOffset","value":this.values.yOffset+a}}},e.Area.prototype.release=e.Area.prototype.dragend=e.Area.prototype.mouseup=function(e,t){var n;return this.leftSide=this.rightSide=this.bottomSide=this.topSide=!1,this.inside&&this.isInArea(e,t)&&(n={"slot":"selected","value":[e,t]}),this.inside=!1,n},e.Area.prototype.hold=function(e,t){if(this.isInArea(e,t)){var n={"slot":"held","value":[e,t]};return n}},e.Area.prototype.doubletap=function(e,t){if(this.isInArea(e,t))return{"slot":"doubletap","value":[e,t]}},e.Area.prototype.setValue=function(t,n){e.Area.superclass.setValue.call(this,t,n)},e.Area.prototype.refresh_CANVAS2D=function(e){if(this.isVisible===!0){e.context.fillStyle=this.color,e.context.strokeStyle=this.borderColor,e.context.lineWidth=this.thickness;var t=Math.floor(this.thickness/2);e.context.fillRect(this.xOrigin+this.values.xOffset+t,this.values.yOffset+t,this.values.width-t*2,this.values.height-t*2),this.thickness>0&&e.context.strokeRect(this.xOrigin+this.values.xOffset,this.values.yOffset,this.values.width,this.values.height)}},e.Area.prototype.getXCoord=function(){return this.values.xOrigin},e.Area.prototype.getYCoord=function(){return this.values.yOrigin},e.Area.prototype.getWidth=function(){return this.values.width},e.Area.prototype.getHeight=function(){return this.values.height},e.Area.prototype.setHeight=function(e){this.values.height=e,typeof this.ROIHeight=="undefined"&&(this.ROIHeight=e)},e.Area.prototype.setWidth=function(e){this.values.width=e,typeof this.ROIWidth=="undefined"&&(this.ROIWidth=e)},e.Curve=function(e){arguments.length&&this.getready(e)},e.extend(e.Curve,e.UIElement),e.Curve.prototype.getready=function(t){e.Curve.superclass.getready.call(this,t),this.values={"points":[],"selected":[],"held":[],"doubletap_c":[],"doubletap_h":[]},this.defaultSlot="points",this.setWidth(t.width),this.setHeight(t.height),this.curveType=t.curveType||"bezier",this.thickness=t.thickness||2,this.curveColor=t.curveColor||"black",this.helperColor=t.helperColor||"#CCCCCC",this.handleColor=t.handleColor||"red",this.curveLabels=typeof t.curveLabels=="boolean"?t.curveLabels:!1,this.terminalPointStyle=t.terminalPointStyle||"rect",this.paintTerminalPoints=t.paintTerminalPoints||"all",this.midPointStyle=t.midPointStyle||"circle",this.terminalPointSize=t.terminalPointSize||16,this.midPointSize=t.midPointSize||8,this.terminalPointColor=t.terminalPointColor||this.handleColor,this.midPointColor=t.midPointColor||this.handleColor,this.terminalPointFill=t.terminalPointFill||null,this.midPointFill=t.midPointFill||null,this.xMonotone=t.xMonotone||!1,this.handleSize=t.handleSize||this.terminalPointSize>this.midPointSize?this.terminalPointSize:this.midPointSize,this.handleClicked=null,this.supportPoints=[],this.selectStart=!1,this.whereHappened=[];switch(t.curveType){case"bezier":if(t.points.length%2!==0||t.points.length<4)throw"Incorrect number of points "+t.points.length;break;case"halfcosine":case"smooth":case"linear":if(t.points.length!==4)throw"Incorrect number of points "+t.points.length;break;default:throw"Unknown curve type "+t.curveType}var n=[];for(var r=0;rthis.supportPoints[i][0]-this.thickness&&ethis.supportPoints[i][1]-this.thickness&&tn[r][0]-this.handleSize&&en[r][1]-this.handleSize&&tthis.ROILeft&&t>this.ROITop&&ee[e.length-1][0]&&(e[0][0]>this.values.points[0][0]?e[0][0]=e[e.length-1][0]:e[e.length-1][0]=e[0][0])},e.Curve.prototype.drag=function(t,n){var r={},i;return this.handleClicked!==null?(i=e.GenericUtils.clone(this.values.points),this.isInROI(t,n)?(this.triggered=!1,i[this.handleClicked][0]=t,i[this.handleClicked][1]=n):(i[this.handleClicked][0]=t,i[this.handleClicked][1]=n,t>this.ROILeft+this.ROIWidth&&(i[this.handleClicked][0]=this.ROILeft+this.ROIWidth),tthis.ROITop+this.ROIHeight&&(i[this.handleClicked][1]=this.ROITop+this.ROIHeight),nthis.ROILeft&&t>this.ROITop&&ethis.ROILeft&&ethis.ROITop&&ethis.width&&(n[0]=this.width),n[0]<0&&(n[0]=0)}else if(this.orientation===1){if(!this.isInROIY(e))return;n=[r[0],t-this.yOrigin],n[1]>this.height&&(n[1]=this.height),n[1]<0&&(n[1]=0)}return n},e.Bar.prototype.mousedown=e.Bar.prototype.touchstart=function(e,t){if(!this.isInROI(e,t))return;this.started=!0;var n=this.commonDrag(e,t);if(typeof n!="undefined")return ret={"slot":"barPos","value":n},ret},e.Bar.prototype.drag=function(e,t){if(!this.started)return;var n=this.commonDrag(e,t);if(typeof n!="undefined")return ret={"slot":"barPos","value":n},ret},e.Bar.prototype.dragend=e.Bar.prototype.swipe=function(e,t){if(!this.started)return;this.started=!1;var n=this.commonDrag(e,t);if(typeof n!="undefined")return ret=[{"slot":"barPos","value":n},{"slot":"dragEnd","value":[e-this.xOrigin,t-this.yOrigin]}],ret},e.Bar.prototype.dragstart=function(e,t){if(this.isInROI(e,t))return ret={"slot":"dragStart","value":[e-this.xOrigin,t-this.yOrigin]},ret},e.Bar.prototype.setValue=function(e,t){0,e=="barPos"?(t[0]<=this.width&&(this.values.barPos[0]=t[0]),t[1]<=this.height&&(this.values.barPos[1]=t[1])):this.values[e]=t},e.Bar.prototype.refresh_CANVAS2D=function(e){if(this.isVisible===!0){var t=e.context;t.lineWidth=this.thickness,t.strokeStyle=this.barColor,t.beginPath();if(this.orientation===0){var n=this.xOrigin+this.values.barPos[0];t.moveTo(n,this.yOrigin+this.height),t.lineTo(n,this.yOrigin)}else this.orientation===1&&(t.moveTo(this.xOrigin+this.width,this.yOrigin+this.values.barPos[1]),t.lineTo(this.xOrigin,this.yOrigin+this.values.barPos[1]));t.stroke(),t.closePath()}},e.Button=function(e){arguments.length&&this.getready(e)},e.extend(e.Button,e.UIElement),e.Button.prototype.getready=function(t){if(t===undefined)throw new Error("Error: args is undefined!");e.Button.superclass.getready.call(this,t),this.values={"buttonvalue":0},this.defaultSlot="buttonvalue",this.triggered=!1,this.mode=t.mode||"persistent",this.imagesArray=t.imagesArray;if(this.imagesArray.length<1)throw new Error("Invalid images array length, "+this.imagesArray.length);this.nButtons=this.imagesArray.length;for(var n=0;n=this.ROILeft&&t>=this.ROITop&&e<=this.ROILeft+this.ROIWidth&&t<=this.ROITop+this.ROIHeight?!0:!1},e.Button.prototype.mousedown=e.Button.prototype.touchstart=function(e,t){if(this.isInROI(e,t)){this.triggered=!0;if(this.mode==="persistent")return undefined;if(this.mode==="immediate")return to_set=(this.values.buttonvalue+1)%this.nButtons,ret={"slot":"buttonvalue","value":to_set},ret}},e.Button.prototype.mouseup=e.Button.prototype.touchend=function(e,t){var n=0,r={};if(this.mode==="persistent"){if(this.triggered&&this.isInROI(e,t))return n=(this.values.buttonvalue+1)%this.nButtons,r={"slot":"buttonvalue","value":n},this.triggered=!1,r}else if(this.mode==="immediate"&&this.triggered)return n=(this.values.buttonvalue-1)%this.nButtons,r={"slot":"buttonvalue","value":n},this.triggered=!1,r;return undefined},e.Button.prototype.mouseout=function(e,t){if(this.mode==="immediate")return this.mouseup(e,t)},e.Button.prototype.setValue=function(t,n){if(n<0||n>this.nButtons)return;e.Button.superclass.setValue.call(this,t,n)},e.Button.prototype.refresh_CANVAS2D=function(e){this.isVisible===!0&&e.context.drawImage(this.imagesArray[this.values.buttonvalue],this.xOrigin,this.yOrigin)},e.Button.prototype.setStatesNumber=function(e){this.nButtons=e},e.Button.prototype.getStatesNumber=function(){return this.nButtons},e.Background=function(e){arguments.length&&this.getready(e)},e.extend(e.Background,e.UIElement),e.Background.prototype.getready=function(t){if(typeof t=="undefined")throw new Error("Error: args is undefined!");e.Background.superclass.getready.call(this,t),this.values={"selected":[],"held":[],"doubletap":[],"tap":[]},this.defaultSlot="selected",this.image=t.image,this.setWidth(this.image.width),this.setHeight(this.image.height)},e.Background.prototype.GetImage=function(){return this.image},e.Background.prototype.isInROI=function(e,t){if(e>this.ROILeft&&t>this.ROITop)return e=this.ROILeft&&t>=this.ROITop-this.landingHeight){0;if(e<=this.ROILeft+this.ROIWidth&&t<=this.ROITop+this.ROIHeight+this.landingHeight)return 0,!0}return!1},e.ClickBar.prototype.calculateValue=function(e,t){var n=t-this.yOrigin;0;var r=1-n/this.height;return 0,r>this.maxValue&&(r=this.maxValue),rthis.radius-this.thickness/2&&r=this.ROILeft&&t>=this.ROITop&&e<=this.ROILeft+this.ROIWidth&&t<=this.ROITop+this.ROIHeight?!0:!1},e.Grid.prototype.mousedown=function(e,t){return this.isInROI(e,t)&&(this.triggered=!0),undefined},e.Grid.prototype.mouseup=function(e,t){return this.triggered&&this.isInROI(e,t)?(this.triggered=!1,{"slot":"selected","value":[e,t]}):undefined},e.Grid.prototype.setValue=function(t,n){e.Grid.superclass.setValue.call(this,t,n)},e.Grid.prototype.refresh_CANVAS2D=function(e){if(this.isVisible===!0){var t=e.context,n=Math.floor(this.height/this.rows),r=Math.floor(this.width/this.columns);t.fillStyle=this.bgColor,t.fillRect(this.xOrigin,this.yOrigin,this.width,this.height),t.beginPath(),t.lineWidth=this.lineWidth;for(var i=this.xOrigin+0;in&&(n=this.imagesArray[i].width),this.imagesArray[i].height>r&&(r=this.imagesArray[i].height)}this.setWidth(n),this.setHeight(r)},e.Knob.prototype.getImageNum=function(){if(this.values.knobvalue<0||this.values.knobvalue>1)return undefined;var e=Math.round(this.values.knobvalue*(this.imageNum-1));return e},e.Knob.prototype.getImage=function(){var e=this.getImageNum();return this.imagesArray[e]},e.Knob.prototype.calculateAngle=function(t,n){var r=this.xOrigin+this.width/2,i=this.yOrigin+this.height/2;0;var s=Math.atan2(t-r,n-i);0,s<0&&(s+=2*Math.PI),0;var o=s*(180/Math.PI);0,o=360-o,typeof this.bottomAngularOffset!="undefined"&&(o=e.MathUtils.linearRange(0,360,-this.bottomAngularOffset,360+this.bottomAngularOffset,o),o<0&&(o=0),o>360&&(o=360));var u=e.MathUtils.linearRange(0,360,0,1,Math.floor(o));return 0,u},e.Knob.prototype.isInROI=function(e,t){return e>this.ROILeft&&t>this.ROITop&&e1&&(s=1),s<0&&(s=0),n={"slot":"knobvalue","value":s},n}}else if(this.knobMethod==="atan"&&this.start_x!==undefined&&this.start_y!==undefined){var o=this.calculateAngle(e,t);return n={"slot":"knobvalue","value":o},n}return undefined},e.Knob.prototype.setValue=function(t,n){var r=n;if(r<0||r>1)return;e.Knob.superclass.setValue.call(this,t,n)},e.Knob.prototype.refresh_CANVAS2D=function(e){if(this.isVisible===!0)if(this.imagesArray.length>1){var t=this.getImageNum();e.context.drawImage(this.imagesArray[t],this.xOrigin,this.yOrigin)}else if(this.imagesArray.length==1){var n=0,r=this.height*this.getImageNum();e.context.drawImage(this.imagesArray[0],n,r,this.width,this.height,this.xOrigin,this.yOrigin,this.width,this.height)}},e.Label=function(e){arguments.length&&this.getready(e)},e.extend(e.Label,e.UIElement),e.Label.prototype.getready=function(t){e.Label.superclass.getready.call(this,t),this.values={"labelvalue":""},this.defaultSlot="labelvalue",this.textColor=t.textColor||"black",this.setWidth(t.width),this.setHeight(t.height)},e.Label.prototype.isInROI=function(e,t){return e>this.ROILeft&&t>this.ROITop&&e1)return undefined;var e=this.values.knobvalue*360,t=360-(e*(this.startAngValue-this.stopAngValue)/360+this.stopAngValue)%360,n=(360-this.initAngValue+t)%360,r=n*Math.PI/180;return r},e.RotKnob.prototype.getRangedAmount=function(t){var n=this.stopAngValue-this.initAngValue,r=this.startAngValue-this.initAngValue;0,t>this.initAngValue&&r<0&&(0,t=-(360-t));var i=e.MathUtils.linearRange(r,n,0,1,t);return 0,i<0&&(i=0),i>1&&(i=1),i},e.RotKnob.prototype.isInROI=function(e,t){return e>this.ROILeft&&t>this.ROITop&&e1&&(s=1),s<0&&(s=0),n={"slot":"knobvalue","value":s},n}}else if(this.knobMethod==="atan"&&this.isInROI(e,t)&&this.start_x!==null&&this.start_y!==null){var o=this.calculateAngle(e,t);return n={"slot":"knobvalue","value":o},n}return undefined},e.RotKnob.prototype.setValue=function(t,n){var r;if(n<0||n>1)return;if(this.values[t]===undefined)throw new Error("Slot "+t+" not present or value undefined");if(n===this.values[t]||n===this.values["real"+t])return;this.values["real"+t]=n;if(this.angSteps!==undefined){var i=1/this.angSteps;r=Math.floor(n/i)*i;if(r===this.values[t])return}else r=n;0,e.RotKnob.superclass.setValue.call(this,t,r)},e.RotKnob.prototype.refresh_CANVAS2D=function(t){if(this.isVisible===!0){var n=this.getRotateAmount();e.CanvasUtils.drawRotate(t.context,{"image":this.image,"x":this.xOrigin,"y":this.yOrigin,"rot":n})}},e.Slider=function(e){arguments.length&&this.getready(e)},e.extend(e.Slider,e.UIElement),e.Slider.prototype.getready=function(t){if(typeof t=="undefined")throw"Slider error: args is undefined!";e.Slider.superclass.getready.call(this,t),this.values={"slidervalue":0},this.defaultSlot="slidervalue",this.width=0,this.height=0,this.sliderImage=t.sliderImg,this.knobImage=t.knobImg,this.type=t.type,this.type!=="horizontal"&&this.type!=="vertical"&&(this.type="vertical"),this.calculateDimensions()},e.Slider.prototype.getKnobPosition=function(){var e;if(this.values.slidervalue<0||this.values.slidervalue>1)return undefined;switch(this.type){case"horizontal":e=Math.round(this.values.slidervalue*this.width+this.zeroLimit);break;case"vertical":e=Math.round(this.values.slidervalue*this.height+this.zeroLimit);break;default:throw new Error("Error: Slider orientation is undefined!")}return e},e.Slider.prototype.isInROI=function(e,t){switch(this.type){case"horizontal":if(e>this.getKnobPosition()&&t>this.ROITop&&ethis.getKnobPosition()&&e>this.ROILeft&&t1&&(n=1),n<0&&(n=0),r={"slot":"slidervalue","value":n},r}return undefined},e.Slider.prototype.setValue=function(t,n){if(n<0||n>1)return;e.Slider.superclass.setValue.call(this,t,n)},e.Slider.prototype.refresh_CANVAS2D=function(e){if(this.isVisible===!0){e.context.drawImage(this.sliderImage,this.xOrigin,this.yOrigin);switch(this.type){case"horizontal":e.context.drawImage(this.knobImage,this.getKnobPosition(),this.yOrigin);break;case"vertical":e.context.drawImage(this.knobImage,this.xOrigin,this.getKnobPosition());break;default:throw new Error("Error: Slider orientation unknown: ",this.type)}}},e.Slider.prototype.calculateDimensions=function(){this.kWidth=this.knobImage.width,this.kHeight=this.knobImage.height,this.setWidth(this.sliderImage.width),this.setHeight(this.sliderImage.height);switch(this.type){case"horizontal":this.totalStride=this.width+this.kWidth,this.additionalEndSpace=Math.round(this.kWidth/2),this.zeroLimit=this.xOrigin-this.additionalEndSpace,this.oneLimit=this.xOrigin+this.width+this.additionalEndSpace;break;case"vertical":this.totalStride=this.height+this.kHeight,this.additionalEndSpace=Math.round(this.kHeight/2),this.zeroLimit=this.yOrigin-this.additionalEndSpace,this.oneLimit=this.yOrigin+this.height+this.additionalEndSpace;break;default:throw new Error("Error: Slider orientation is undefined!")}},e.Slider.prototype.setGraphicWrapper=function(t){e.Slider.superclass.setGraphicWrapper.call(this,t),this.drawClass=t.initObject([{"objName":"drawImage","objParms":this.objParms}])},e.Wavebox=function(e){arguments.length&&this.getready(e)},e.extend(e.Wavebox,e.UIElement),e.Wavebox.prototype.getready=function(t){e.Wavebox.superclass.getready.call(this,t),this.values={"waveboxposition":0,"startsample":0,"endsample":null,"waveboxsignal":[],"xPos":0,"yPos":0},this.defaultSlot="waveboxposition",this.setWidth(t.width),this.setHeight(t.height),this.binMethod=t.binMethod||"minmax",this.orientation=t.orientation||0,this.waveColor=t.waveColor||"black"},e.Wavebox.prototype.isInROI=function(e,t){return e>this.ROILeft&&t>this.ROITop&&ethis.values.waveboxsignal.length)throw new Error("Error: Trying to set ",e," bigger than signal length: ",t," > ",this.values.waveboxsignal.length)}if(e==="startsample"&&t>this.values.endsample)throw new Error("Error: Trying to set startsample > endsample: ",t," > ",this.values.endsample);if(e==="endsample"&&tn.endsample&&(s=n.endsample);var o=r[i],u=r[i];for(var a=1;au&&(u=r[i+a]);var f={"max":u,"min":o};return f},e.Wavebox.prototype.calculateBinNone=function(e,t,n){var r=n.startsample+e*t,i=parseInt(t/2,10),s=n.waveboxsignal[r+i],o={"max":s,"min":-s};return o},e.Wavebox.prototype.calculateBinAvg=function(e,t){var n=this.values.waveboxsignal,r=this.values.startsample+e*t,i=r+(e+1)*t;i>this.values.endsample&&(i=this.values.endsample);var s=n.subarray(r,i),o=0,u=s.length;for(var a=0;athis.width&&(f[0]=this.width),f[1]<0&&(f[1]=0);if(f[0]===this.lastCalculatedPoint[0]&&f[1]===this.lastCalculatedPoint[1]){0,this.ui.setProp(s,"paintTerminalPoints","all");return}}this.lastCalculatedPoint[0]=f[0],this.lastCalculatedPoint[1]=f[1];switch(t){case"linear":case"smooth":case"halfcosine":o.points=a.concat(f);break;case"bezier":var d=a.slice();for(var v=1;ve)e+=i[l++%f],e>u&&(e=u),c?this.lineTo(e,0):this.moveTo(e,0),c=!c;this.restore()}),e.OSC={},e.OSC.Message=function(t){this.address=t,this.typetags="",this.args=[];for(var n=1;n"+e+"s",t,0,[this.value])}},e.OSC.TInt=function(e){this.value=e},e.OSC.TInt.prototype={"typetag":"i","decode":function(e){if(e.length<4)throw new ShortBuffer("int",e,4);return this.value=Struct.Unpack(">i",e.slice(0,4))[0],e.slice(4)},"encode":function(){var e=new Array(4);return Struct.PackTo(">i",e,0,[this.value])}},e.OSC.TTime=function(e){this.value=e},e.OSC.TTime.prototype={"typetag":"t","decode":function(e){if(e.length<8)throw new ShortBuffer("time",e,8);return this.value=Struct.Unpack(">LL",e.slice(0,8))[0],e.slice(8)},"encode":function(e,t){return Struct.PackTo(">LL",e,t,this.value)}},e.OSC.TFloat=function(e){this.value=e},e.OSC.TFloat.prototype={"typetag":"f","decode":function(e){if(e.length<4)throw new ShortBuffer("float",e,4);return this.value=Struct.Unpack(">f",e.slice(0,4))[0],e.slice(4)},"encode":function(){var e=new Array(4);return Struct.PackTo(">f",e,0,[this.value])}},e.OSC.TBlob=function(e){this.value=e},e.OSC.TBlob.prototype={"typetag":"b","decode":function(e){var t=Struct.Unpack(">i",e.slice(0,4))[0],n=parseInt(Math.ceil(t/4)*4,10)+4;return this.value=e.slice(4,t+4),e.slice(n)},"encode":function(e,t){var n=Math.ceil(this.value.length/4,10)*4;return Struct.PackTo(">i"+n+"s",e,t,[n,this.value])}},e.OSC.TDouble=function(e){this.value=e},e.OSC.TDouble.prototype={"typetag":"d","decode":function(e){if(e.length<8)throw new ShortBuffer("double",e,8);return this.value=Struct.Unpack(">d",e.slice(0,8))[0],e.slice(8)},"encode":function(e,t){return Struct.PackTo(">d",e,t,[this.value])}},e.OSC.tagToConstructor={"i":function(){return new e.OSC.TInt},"f":function(){return new e.OSC.TFloat},"s":function(){return new e.OSC.TString},"b":function(){return new e.OSC.TBlob},"d":function(){return new e.OSC.TDouble}},e.OSC.decodeBundle=function(t){var n=[],r={"time":null,"args":[]},i=new e.OSC.TTime;t=i.decode(t),r.time=i.value;while(t.length>0){var s=new e.OSC.TInt;t=s.decode(t);var o=e.OSC.decode(t.slice(0,s.value));r.args.push(o),t=t.slice(s.value)}return n.push(r),n},e.OSC.decode=function(t){var n=[],r=new e.OSC.TString;t=r.decode(t),n.push(r.value);if(r.value==="#bundle")return e.OSC.decodeBundle(t);if(t.length>0){var i=new e.OSC.TString;t=i.decode(t),i=i.value;if(i[0]!=",")throw"invalid type tag in incoming OSC message, must start with comma";for(var s=1;s=0.8.0" + } +} \ No newline at end of file