Select Git revision
MouseHandler.js
Andrew Cohen authored
MouseHandler.js 10.28 KiB
/*****************************************************************************/
//
// Copyright 2015 Andrew Cohen
//
// This file is part of CloneView - the tool for displaying stem cell lineaging in a webpage.
//
// CloneView is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// CloneView is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with CloneView in file "gnu gpl v3.txt". If not, see
// <http://www.gnu.org/licenses/>.
//
/*****************************************************************************/
// Handles all mouse related events/tasks
// Handler for mouse click event
window.onmousedown = function (e) {
var sidebar = document.getElementById('sidebar');
if(e.ctrlKey){
var whichScaling = true;
var testCase = window.innerWidth/window.innerHeight;
var testCondition = gImageObj.width/gImageObj.height;
if(testCase < testCondition) {
whichScaling = true;
}else{
whichScaling = false;
}
if(whichScaling) {
var hullsScaling = gScale * (window.innerWidth / gImageObj.width);
}else{
var hullsScaling = gScale * (window.innerHeight / gImageObj.height);
}
var hitANode = false;
for (var i = 0; i < gLeverDataHulls.Time[gImageTime - 1].Hulls.length; i++) {
var nodeID = parseInt(gLeverDataHulls.Time[gImageTime-1].Hulls[i].TrackID);
var pointList=gLeverDataHulls.Time[gImageTime-1].Hulls[i].Points;
var arrayX = [];
var arrayY = [];
for (var j = 1; j < pointList.length; j++) {
arrayX.push((-ImgClippingX + pointList[j][0]) * hullsScaling);
arrayY.push((-ImgClippingY + pointList[j][1]) * hullsScaling);
}
if(pnpoly(arrayX.length, arrayX, arrayY, e.layerX, e.layerY)){
hitANode = true;
LightTheTree(nodeID);
}
}
if(hitANode == false){
notRun = true;
drawMiniLineageTree();
if(gLineageWindow != undefined){
gLineageWindow.drawLineageTree();
}
}
return;
}
//Check for click on miniTimeLine
if ((e.target).id == "miniTimeLine") {
mousedrag = false;
sideBarDown(e);
}
// Checking for a click on the sidebar
if(e.x == undefined){ // Firefox condition
if (e.clientX + 15 > (window.innerWidth - sidebar.clientWidth)) {
sideBarDown(e);
gDragX = e.x + (gRedBoxWidth / 2);
gDragY = e.y + (gRedBoxHeight / 2);
mousedrag = false;
return;
}
}else { // Chrome and IE
if (e.x + 15 > (window.innerWidth - sidebar.clientWidth)) {
sideBarDown(e);
gDragX = e.x + (gRedBoxWidth / 2);
gDragY = e.y + (gRedBoxHeight / 2);
mousedrag = false;
return;
}
}
// Handles as a normal click and drag else
if(e.x == undefined){ // Firefox condition
gDragX = e.layerX;
gDragY = e.layerY;
}else{ // Chrome and IE
gDragX = e.x;
gDragY = e.y;
}
mousedrag = true;
} //onmousedown
// Handles the mouseup event
window.onmouseup = function (e) {
// Handles minimap up
if(miniMapmousedrag){
miniMapmousedrag = false;
gDragX = 0;
gDragY = 0;
}
// Handles miniLineage up
if(miniLineagemousedrag){
miniLineagemousedrag = false;
}
// Normal up handled
mousedrag = false;
gDragX = 0;
gDragY = 0;
} //onmouseup
// Handles a click/drag on the sidebar
function sideBarDown(e){
if(e.srcElement == undefined){// Firefox condition
// Minimap click/drag
if ((e.target).id == "miniMap") {
if(e.offsetY == undefined){
var y = e.layerY;
}else{
var y = e.offsetY;
}
if(e.offsetX == undefined){
var x = e.layerX;
}else{
var x = e.offsetX;
}
ImgClippingX = ((x) - (gRedBoxWidth / 2)) * 6;
ImgClippingY = ((y) - (gRedBoxHeight / 2)) * 6;
miniMapmousedrag = true;
reDraw();
return false;
// miniLineage click/drag
} else if ((e.target).id == "miniTimeLine") {
var miniTimeLine = document.getElementById("miniTimeLine");
miniLineagemousedrag = true;
if(e.offsetY == undefined){
var y = e.layerY;
}else{
var y = e.offsetY;
}
gImageTime = Math.round(gMaxHeight * (y / miniTimeLine.height)) - 70;
if(Math.round((gMaxHeight * (y / miniTimeLine.height)) - 50) > 0) {
gImageTime = Math.round(gMaxHeight * (y / miniTimeLine.height)) - 50;
}else{
gImageTime = 1;
}
if(gImageTime > gNFRAMES){
gImageTime = gNFRAMES;
}
drawMiniLineage(gImageTime);
UpdateTime();
}
}else {// Chrome and IE
// Minimap click/drag
if ((e.target).id == "miniMap") {
ImgClippingX = (e.offsetX - (gRedBoxWidth / 2)) * 6;
ImgClippingY = (e.offsetY - (gRedBoxHeight / 2)) * 6;
miniMapmousedrag = true;
if(!gAnimationFlag){
reDraw();
}
return false;
// miniLineage click/drag
} else if ((e.target).id == "miniTimeLine") {
var miniTimeLine = document.getElementById("miniTimeLine");
miniLineagemousedrag = true;
if(e.offsetY == undefined){
var y = e.layerY;
}else{
var y = e.offsetY;
}
if(Math.round((gMaxHeight * (y / miniTimeLine.height)) - 50) > 0) {
gImageTime = Math.round(gMaxHeight * (y / miniTimeLine.height)) - 50;
}else{
gImageTime = 1;
}
if(gImageTime > gNFRAMES){
gImageTime = gNFRAMES;
}
drawMiniLineage(gImageTime);
UpdateTime();
}
}
} //sideBarDown
// Handles the mousemove event on the entire window
function drag(e) {
// Hover over href links of the other clones in the movie
if((e.target).localName == 'a'){
var name = ((e.target).innerHTML)
var split = name.split(" ");
if(split.length == 2){
for (var i = 0; i < (gLeverData.Lineage).length; i++) {
if(((gLeverData.Lineage[i]).Tree[0]).TrackID == split[0]){
var LineageIndex = i;
}
}
CloneX2 = (gLeverData.Lineage[LineageIndex]).CloneBoundingBox[0];
CloneY2 = (gLeverData.Lineage[LineageIndex]).CloneBoundingBox[1];
CloneSizeX2 = parseInt((gLeverData.Lineage[LineageIndex]).CloneBoundingBox[2])-parseInt((gLeverData.Lineage[LineageIndex]).CloneBoundingBox[0]);
CloneSizeY2 = parseInt((gLeverData.Lineage[LineageIndex]).CloneBoundingBox[3])-parseInt((gLeverData.Lineage[LineageIndex]).CloneBoundingBox[1]);
clone2 = true;
if(secondCloneDraw == false){
reDraw();
secondCloneDraw = true;
}
}
}else{
if(secondCloneDraw){
clone2 = false;
reDraw();
secondCloneDraw = false;
}
}
// Prevent drag when fully zoomed out
if(gScale == 1){
return false;
}
// Handles drag on the image
if (mousedrag && miniLineagemousedrag == false) {
var canvas = document.getElementById("imageCanvas");
var context = canvas.getContext("2d");
if(e.x == undefined){// Firefox condition
var sx = gDragX - e.layerX;
var sy = gDragY - e.layerY;
gDragX = e.layerX;
gDragY = e.layerY;
ImgClippingX = (gMouseSen * sx) + ImgClippingX;
ImgClippingY = (gMouseSen * sy) + ImgClippingY;
}else {// Chrome and IE
sx = gDragX - e.x;
sy = gDragY - e.y;
gDragX = e.x;
gDragY = e.y;
ImgClippingX = (gMouseSen * sx) + ImgClippingX;
ImgClippingY = (gMouseSen * sy) + ImgClippingY;
}
if(!gAnimationFlag) {
reDraw();
}
}
// Handles miniMap click/drag
if (miniMapmousedrag ) {
sideBarDown(e);
}
// Handles miniLineage click/drag
if(miniLineagemousedrag){
sideBarDown(e);
}
// Button click handles
var cloneToolTip=document.getElementById("infoToolTip");
if((e.target).id == "hoverInfo"){
cloneToolTip.style.display="inline";
}
else{
cloneToolTip.style.display="none";
}
var controlsToolTip=document.getElementById("controlsToolTip");
if((e.target).id == "hoverControls"){
controlsToolTip.style.display="inline";
}
else{
controlsToolTip.style.display="none";
}
return false;
} //drag
// Handles the scroll wheel as a zoom
// This doesn't handle the Firefox wheel event
function scroll(e){
var sidebar = document.getElementById('sidebar');
// Checking for scroll on sidebar first
if(e.clientX > (window.innerWidth - sidebar.clientWidth)){
return false;
}
// Forward is zoomIn and backward is zoomOut
if(e.wheelDelta < 0){
zoomOut(1.4);
}else{
zoomIn(1.4);
}
} //scroll
// Handles the Firefox Scroll event
function firefoxScroll(e){
var sidebar = document.getElementById('sidebar');
// Checking for scroll on sidebar first
if(e.clientX > (window.innerWidth - sidebar.clientWidth)){
return false;
}
// Forward is zoomIn and backward is zoomOut
if(e.detail < 0){
zoomIn(1.4);
}else{
zoomOut(1.4);
}
} //firefoxScroll