function eventsRegistration() { // rotate rect 180 degrees, in absolute coordinates - around (cX, cY) function rotate(rect, cX, cY) { var tmp = {}; tmp.left = Math.round(2*cX - rect.right); tmp.top = Math.round(2*cY - rect.bottom); rect.right = Math.round(2*cX - rect.left); rect.bottom = Math.round(2*cY - rect.top); rect.left = tmp.left; rect.top = tmp.top; } // distance is computed intentionally as a sum of distances along axes X and Y function neDist(pt1, pt2) { return Math.abs(pt1.X-pt2.X) + Math.abs(pt1.Y-pt2.Y); } // direction of diagonal function diagonal(pt1, pt2) { var sign = (pt1.X-pt2.X)*(pt1.Y-pt2.Y); return (sign>0 ? "down" : (sign<0 ? "up" : null)); } function resetInlay() { $('#inlay').offset({ left: 0, top: 0 }); $('#inlay').width(0); $('#inlay').height(0); } function getXY(e) { return (browser()==="MSIE" ? { X: e.offsetX, Y:e.offsetY } : { X: e.layerX, Y:e.layerY }); } function primary(bn) { return (browser()==="MSIE" && getInternetExplorerVersion()<9.0) ? bn===1 : bn===0; } function secondary(bn) { return (bn === 2); } function bnAction(bn) { return primary(bn) ? 'primary' : (secondary(bn) ? 'secondary' : null); } function inside(e) { return e.target.id==="overlay"; } function bnAllowed(e) { return primary(e.button) || (secondary(e.button) && (image.mouseMode==="motion" || image.mouseMode==="privacy")); } function bnEnhanced(e) { if((image.mouseMode==="motion" || image.mouseMode==="privacy") && (e.ctrlKey || e.shiftKey)) { return e.shiftKey ? "over" : "under"; } else { return null; } } function executePTZnBacklight(selImg, dist, how) { if ((image.mouseMode==="ptz" || image.mouseMode==="ptzback") && dist>10) { // PTZ image.left.set('value', selImg.left); image.top.set('value', selImg.top); image.right.set('value', selImg.right); image.bottom.set('value', selImg.bottom); applyVideo(); if (image.mouseMode==="ptzback") { image.left.onSet(); image.top.onSet(); image.right.onSet(); image.bottom.onSet(); } } if ((image.mouseMode==="backlight" || image.mouseMode==="ptzback") && dist>10 && selImg.width>=128 && selImg.height>=128) { // exposure window (backlight reference) /*if (how === 'default') { // TODO 1: make dependent on the camera resolution // var mrg = 32; var mrg = Math.min(160, selImg.width/4, selImg.height/4); selImg.left += mrg; selImg.top += mrg; selImg.width -= 2*mrg; selImg.height -= 2*mrg; } */ // remember value of 'exposure' and restore it after finishing with expwnd... //var prevExp = (how==='default' ? "on" : getCameraParam('exposure')); if (how==='default') setCameraParam('exposure', 'on'); else { setCameraParam('exposure', 'off'); setCameraParam('expwndleft', selImg.left); setCameraParam('expwndtop', selImg.top); setCameraParam('expwndwidth', selImg.width); setCameraParam('expwndheight', selImg.height); } } } function executePrivacy(selImg, dist, how, overunder, updown) { var pcell = 32, rect, onoff; function setBlock(rect, onoff) { // TODO 1: Math.round() is not tested on AV10005 setCameraParam('pmaskleft', rect.left); setCameraParam('pmasktop', rect.top); setCameraParam('pmaskright', rect.right); setCameraParam('pmaskbottom', rect.bottom); setCameraParam('pmaskblock', onoff); } // TODO 1: do not check with camera, after Privacy is set to update immediately if (getCameraParam("pmask") !== "on") { alert('To change privacy mask, check Enable Privacy Mask checkbox.') } if (how === 'default') { rect = { left : Math.ceil(selImg.left/pcell) - 1, top : Math.ceil(selImg.top/pcell) - 1, right : Math.ceil(selImg.right/pcell) - 1, bottom : Math.ceil(selImg.bottom/pcell) - 1 }; setBlock(rect, "off"); } else if (overunder!==null && updown!==null) { onoff = (how==='primary'?"on":"off"); rect = { left : Math.ceil(selImg.left/pcell) - 1, top : Math.ceil(selImg.top/pcell) - 1, right : Math.ceil(selImg.right/pcell) - 1, bottom : Math.ceil(selImg.bottom/pcell) - 1 }; var tangent = Math.abs((rect.right-rect.left)/(Math.max(rect.bottom-rect.top, 1))), r = {}, Y0 = (overunder==='under' ? rect.top : rect.bottom), Y1 = Y0, Y2 = (overunder==='under' ? rect.bottom : rect.top), dy = (overunder==='under' ? 1 : -1), currHeight = 0, //X0 = ((updown==='down' && overunder==='under') || (updown==='up' && overunder==='over') ? rect.left : rect.right), dx = ((updown==='down' && overunder==='under') || (updown==='up' && overunder==='over') ? 1 : -1), X1, currWidth; while (Y1+currHeight !== Y2) { currWidth = Math.round(tangent*Math.abs(Y1+currHeight-Y0)); if (currWidth===Math.round(tangent*Math.abs(Y1+currHeight+1-Y0))) { // continue increasing height of the block currHeight += dy; } else { // cannot increase height of the block anymore X1 = (dx>0 ? rect.left : rect.right + dx*currWidth); r = { left : X1, top : Y1, right : X1 + currWidth, bottom : Y1 + currHeight }; setBlock(r, onoff); Y1 += currHeight+dy; currHeight = 0; } } /* for (h=rect.top; h' + currHeight); */