Commit 8439cc2d authored by Tobias Liese's avatar Tobias Liese

fixed state size problems

parent 442528e8
Pipeline #93846 failed with stages
in 34 seconds
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
// Classes:
class Field {
private canvas: HTMLCanvasElement = document.getElementsByTagName('canvas')[0];
private context = this.canvas.getContext("2d");
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
......@@ -22,12 +22,13 @@ class Field {
transitionMode = true
document.body.style.cursor = "crosshair"
});
}
addState(x: number, y: number, name: string) {
this.context.font = "40px Dancing Script"
let textSize: TextMetrics = field.context.measureText(name)
this.states.push(new State(x, y, name, textSize.width * 0.8, textSize.actualBoundingBoxDescent))
let textSize: TextMetrics = this.context.measureText(name)
this.states.push(new State(x, y, name, textSize.width * 0.9, textSize.actualBoundingBoxDescent))
this.drawState(this.states[this.states.length - 1])
states.textContent = states.innerText.replace(/{.*}/gm, "{" + this.states.toString() + "}")
}
......@@ -52,6 +53,10 @@ class Field {
this.rePaint()
}
drawLineTo(x: number, y: number) {
// this.context.arcTo(this.getStateByIndex(selected).x)
}
rePaint() {
this.canvas.height = 1000
this.canvas.width = document.getElementsByClassName("menu").item(0).clientWidth
......@@ -61,16 +66,16 @@ class Field {
}
private drawState(state: State) {
this.context.font = "40px Dancing Script"
this.context.fillStyle = "#212121"
this.context.textAlign = "center"
this.context.beginPath()
this.context.arc(
state.x,
state.y,
state.radius, 0, 2 * Math.PI)
state.radius, 0, 2 * Math.PI,)
this.context.fill()
this.context.fillStyle = "white"
this.context.font = "40px Dancing Script"
this.context.textAlign = "center"
this.context.fillText(
state.name,
state.x, state.y + state.height,
......@@ -175,14 +180,15 @@ window.addEventListener("contextmenu", e => {
return false
});
// linear code:
let states = document.getElementById("states");
let contextMenu
let dragMode: boolean = false
let transitionMode: boolean = false
let menuVisible: boolean = false
const field: Field = new Field();
let states = document.getElementById("states");
let contextMenu
let selected: number
let dragMode: boolean = false
let transitionMode: boolean = false
// let webSocket = new WebSocket(
// 'ws://' + window.location.host + "/websocket");
......
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