Commit 041aff3f authored by Tobias Liese's avatar Tobias Liese

Added scroll logic

parent 1ee81cfe
Pipeline #94172 failed with stages
in 16 minutes and 1 second
......@@ -3,8 +3,8 @@ class Field {
private canvas: HTMLCanvasElement = <HTMLCanvasElement>document.getElementById("canvas")
private context: CanvasRenderingContext2D = this.canvas.getContext("2d")
private states: State[] = new Array<State>()
readonly xOrigin: number = this.canvas.getBoundingClientRect().left
readonly yOrigin: number = this.canvas.getBoundingClientRect().top
readonly xOrigin: number
readonly yOrigin: number
constructor() {
this.rePaint()
......@@ -13,7 +13,9 @@ class Field {
}
);
document.getElementById("createState").addEventListener("mousedown", (event: MouseEvent) => {
this.addState(event.clientX - this.xOrigin, event.clientY - this.yOrigin, "q1")
let x = event.clientX - field.xOrigin + +window.pageXOffset.valueOf()
let y = event.clientY - field.yOrigin + window.pageYOffset.valueOf()
this.addState(x, y, "q1")
});
document.getElementById("addTransition").addEventListener("mousedown", () => {
transitionMode = true
......@@ -23,6 +25,8 @@ class Field {
let elm = this.getStateByIndex(lastSelected)
this.updateState(lastSelected, elm.x, elm.y, editName.value)
}
this.xOrigin = this.canvas.getBoundingClientRect().left
this.yOrigin = this.canvas.getBoundingClientRect().top
}
addState(x: number, y: number, name: string) {
......@@ -123,8 +127,8 @@ class State {
// listener:
onmousemove = (event: MouseEvent) => {
let x = event.clientX - field.xOrigin
let y = event.clientY - field.yOrigin
let x = event.clientX - field.xOrigin + +window.pageXOffset.valueOf()
let y = event.clientY - field.yOrigin + window.pageYOffset.valueOf()
if (dragMode) {
field.updateState(selected, x, y, null)
} else if (menuVisible) {
......@@ -188,8 +192,10 @@ window.addEventListener("contextmenu", e => {
} else {
contextMenu = document.getElementById("field-menu");
}
contextMenu.style.left = e.clientX + "px"
contextMenu.style.top = e.clientY + "px"
let x = e.clientX + +window.pageXOffset.valueOf()
let y = e.clientY + window.pageYOffset.valueOf()
contextMenu.style.left = x + "px"
contextMenu.style.top = y + "px"
contextMenu.className = "show";
menuVisible = true
return false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment