Skip to content

Commit

Permalink
cleanup virtual touchpad code.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmiscool authored and mmiscool committed Aug 24, 2023
1 parent 5ac1a0c commit 378353e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 64 deletions.
29 changes: 1 addition & 28 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,7 @@

<script src="./static/index.bundle.js"></script>

<script>
// check for common mobile user agents
if (
navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/BlackBerry/i) ||
navigator.userAgent.match(/Windows Phone/i)
) {
// the user is using a mobile device, so redirect to the mobile version of the website
try {
//detect iframe parent and see if it is the mobile mouse
//if frame is loaded in mouse page do nothing otherwise redirect to mouse page
if ( window.location.pathname == window.parent.location.pathname ) {
//test if parent is mobile mouse emulator page and redirect if not
if (!window.parent.location.pathname.includes("/mouse.html")){
window.location = "./mouse.html" + window.location.search;
}
}
} catch { }
}



</script>

<script src="./mouse/checkIfMobile.js"></script>

</body>

Expand Down
2 changes: 1 addition & 1 deletion web/mouse.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
</style>

<body>
<iframe id="jsketcher" title="JSketcher" scrolling="no"></iframe>
<iframe id="pointerTarget" scrolling="no"></iframe>

<div id="holderHolder">
<div id="FakeMouseHolder">
Expand Down
22 changes: 22 additions & 0 deletions web/mouse/checkIfMobile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// check for common mobile user agents
if (
navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/BlackBerry/i) ||
navigator.userAgent.match(/Windows Phone/i)
) {
// the user is using a mobile device, so redirect to the mobile version of the website
try {
//detect iframe parent and see if it is the mobile mouse
//if frame is loaded in mouse page do nothing otherwise redirect to mouse page
if ( window.location.pathname == window.parent.location.pathname ) {
//test if parent is mobile mouse emulator page and redirect if not
if (!window.parent.location.pathname.includes("/mouse.html")){
window.location = "./mouse.html" + window.location.search;
}
}
} catch { }
}
28 changes: 15 additions & 13 deletions web/mouse/mouseController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
pointerImage =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeAQMAAAAB/jzhAAAABlBMVEX/AAAAAABBoxIDAAAAAnRSTlP/AOW3MEoAAABISURBVHicPc6xCQAgDETRhBQpM0JGyWjBTR3BAQTlW9g8uOK4kz5nS0FCgIOBgjwaChICHAwU5NFQkBDgYKA//hroYHdyY/W+8QFAUbYNynAAAAAASUVORK5CYII=";

document.body.innerHTML += `
<svg id="cursor" xmlns="http://www.w3.org/2000/svg" viewBox="-10003 -10003 20010 20010">
<path d="M 0 0 L 0 10000 Z M 0 0 L 0 -10000 M 0 0 L -10000 0 M 0 0 L 10000 0 M 25 0 A 1 1 0 0 0 -25 0 A 1 1 0 0 0 25 0" stroke="black" stroke-width="3" fill="none"/>
Expand Down Expand Up @@ -31,17 +28,17 @@ var lastTouchY = 0;

var speed = 0.6;

const pointerTarget = document.getElementById("jsketcher").contentWindow;
const pointerTarget = document.getElementById("pointerTarget");

function sendNewEvent(eventType) {
let obj = JSON.parse(JSON.stringify(mouseObject));
obj.eventType = eventType;
//console.log("sending this", obj);
pointerTarget.postMessage(obj);
return pointerTarget.contentWindow.postMessage(obj);
}

document.getElementById("touchpadArea").addEventListener("touchstart", function (event) {
//document.body.requestFullscreen();
console.log(event.touches);
if (window.innerHeight !== screen.height) document.body.requestFullscreen();

if (event.touches.length == 1){
lastTouchX = event.touches[0].clientX;
Expand All @@ -67,7 +64,11 @@ document.getElementById("touchpadArea").addEventListener("touchend", function (e
}
});

document.getElementById("touchpadArea").addEventListener("click", function (event) {
document.getElementById("touchpadArea").addEventListener("click", async function (event) {
// //alert(await sendNewEvent("whatUnderTouchLocation"));
// let bla = await sendNewEvent("whatUnderTouchLocation");
// console.log(bla)

document.getElementById("leftMouseButton").click();
});

Expand Down Expand Up @@ -250,17 +251,18 @@ document.getElementById("ScrollWheel").addEventListener("touchmove", async funct
});

window.addEventListener("message", function (event) {
console.log("Message received from the child: " + event.data); // Message received from child
//console.log("Message received from the child: " + event.data); // Message received from child
if (event.data == "showTouchpad") toggleMousepad("show");
});

var iframe = document.getElementById("jsketcher");

iframe.onload = function () {

pointerTarget.onload = function () {
const elem = document.createElement(`script`);
elem.src = "./mouse/virtualMousePointer.js";
elem.type="module";

iframe.contentDocument.body.appendChild(elem);
pointerTarget.contentDocument.body.appendChild(elem);

console.log(window.location);
};
Expand All @@ -269,7 +271,7 @@ document.body.onload = function () {
try {
document.getElementById("mouseSpeed").value = localStorage.mouseSpeed;
} catch {}
iframe.src = "./" + window.location.search;
pointerTarget.src = "./" + window.location.search;
//console.log("dats the window locations", window.location.search);
};

Expand Down
12 changes: 0 additions & 12 deletions web/mouse/virtualMousePointer.css

This file was deleted.

34 changes: 24 additions & 10 deletions web/mouse/virtualMousePointer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//Allways keep page at propper position,
// prevents page scrolling acidentally due to html elements going out of view.
mouseDebugger = false;
let mouseDebugger = false;

uiElementsToggle = {
let uiElementsToggle = {
toggleUItabs: "none",
toggleUIoverlay: "none",
toggleUItoolbar: "none",
Expand All @@ -26,9 +26,9 @@ function setDisplayValueByClassName(clssOfItem, newDsiplayValue) {
} catch {}
}

mouseOverList = [];
var mouseOverList = [];

theToolbar = document.getElementsByClassName("x-Toolbar disable-selection condensed x-Toolbar-flat")[0];
let theToolbar = document.getElementsByClassName("x-Toolbar disable-selection condensed x-Toolbar-flat")[0];
theToolbar.style.display = "none";
theToolbar.style.position = "fixed";
theToolbar.style.left = "30px";
Expand Down Expand Up @@ -56,20 +56,29 @@ var lastThingToDo = {
};
var shiftKey = false;

scaleFactor = 2;
let scaleFactor = 2;
let absoluteX = 0;
let absoluteY = 0;
let deltaY;
let eventType;;

window.addEventListener(
"message",
(event) => {
const thingToDo = event.data;
if (typeof thingToDo !== "object") return;

// if (thingToDo == "whatUnderTouchLocation"){
// return "here is my message";
// }

absoluteX = thingToDo.absoluteX ? thingToDo.absoluteX : "";
absoluteY = thingToDo.absoluteY ? thingToDo.absoluteY : "";

if (mouseDebugger) console.log(absoluteX, absoluteY);

deltaY = thingToDo.deltaY ? thingToDo.deltaY : "";
eventType = thingToDo.eventType ? thingToDo.eventType : "";
eventType = thingToDo.eventType ? thingToDo.eventType : "";

if (eventType == "toggleUItabs") {
uiElementsToggle.toggleUItabs = uiElementsToggle.toggleUItabs == "none" ? "" : "none";
Expand Down Expand Up @@ -154,10 +163,15 @@ window.addEventListener(


lastThingToDo = thingToDo;
stoplooping = "";


//let stoplooping = "";

const itemsUnderMouse = document.elementsFromPoint(absoluteX, absoluteY);

stoplooping = doTheProperEvents(itemsUnderMouse[0]);
doTheProperEvents(itemsUnderMouse[0]);

// stoplooping = doTheProperEvents(itemsUnderMouse[0]);
// if (itemsUnderMouse[0].nodeName == "CANVAS" && stoplooping !== "stop") {
// itemsUnderMouse.forEach( (item, key) => {
// if (key !== 0) stoplooping = doTheProperEvents(item);
Expand Down Expand Up @@ -191,7 +205,7 @@ window.addEventListener(
]);
});

//__CAD_APP.pickControlService.pickListMode = false;
__CAD_APP.pickControlService.pickListMode = false;
},
true
);
Expand Down Expand Up @@ -263,7 +277,7 @@ window.addEventListener(
}

function exicuteEvents(TargetElement, eventTypes, eventToSend = {}) {
eventTemplate = JSON.parse(JSON.stringify(eventToSend));
const eventTemplate = JSON.parse(JSON.stringify(eventToSend));
eventTypes.forEach( (enenvtToFire, key) => {
eventTemplate.type = enenvtToFire;
exicuteEvent(TargetElement, eventTemplate);
Expand Down

0 comments on commit 378353e

Please sign in to comment.