Commit d1dc86b8 authored by Tobias Liese's avatar Tobias Liese

fixed drag and drop

parent 9665435b
Pipeline #93160 failed with stages
in 29 seconds
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
......@@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
......
class Field {
private canvas: HTMLCanvasElement = document.getElementsByTagName('canvas')[0];
private context = this.canvas.getContext("2d");
readonly states: State[] = new Array<State>()
private states: State[] = new Array<State>()
readonly xOrigin: number = this.canvas.getBoundingClientRect().left
readonly yOrigin: number = this.canvas.getBoundingClientRect().top
constructor() {
this.rePaint()
document.getElementById("removeState")
.addEventListener("mousedown", (e: Event) => {
.addEventListener("mousedown", () => {
this.removeState(selected)
}
);
let btn = document.getElementById("createState");
btn.addEventListener("mousedown", (e: Event) => {
this.addState(100, 1000, "q1")
btn.addEventListener("mousedown", () => {
this.addState(100, 300, "q1")
});
}
......@@ -26,9 +26,10 @@ class Field {
}
removeState(i: number) {
this.clearState(this.getStateByIndex(i))
// @todo fix this delete leaves undefined we don't want anything
delete this.states[i]
console.log(this.states)
this.states.splice(i, 1)
this.rePaint()
selected = null
}
......@@ -37,13 +38,12 @@ class Field {
}
updateState(i: number, x, y, name) {
this.clearState(this.states[i])
this.states[i].x = x
this.states[i].y = y
if (name != null) {
this.states[i].name = name
}
this.drawState(this.states[i])
this.rePaint()
}
rePaint() {
......@@ -71,15 +71,6 @@ class Field {
)
}
private clearState(state: State) {
this.context.fillStyle = "black"
this.context.arc(
state.x,
state.y,
state.radius + 1, 0, 2 * Math.PI)
this.context.fill()
}
getStateIndex(x: number, y: number): number {
let i: number = 0;
while (i < this.states.length) {
......@@ -121,7 +112,7 @@ onmousemove = (event: MouseEvent) => {
} else if (contextMenu == null) {
selected = field.getStateIndex(event.clientX - field.xOrigin, event.clientY - field.yOrigin)
if (selected != null) {
document.body.style.cursor = "move"
document.body.style.cursor = "grab"
} else {
document.body.style.cursor = "default"
}
......@@ -137,6 +128,7 @@ onmousedown = (event: MouseEvent) => {
}
if (selected != null) {
dragMode = true
document.body.style.cursor = "grabbing"
}
}
}
......
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