test load picture on canvas
This commit is contained in:
parent
c4db938d8e
commit
8972335198
@ -38,8 +38,10 @@
|
|||||||
getDraw1d: "draw1d",
|
getDraw1d: "draw1d",
|
||||||
getDraw2d: "draw2d",
|
getDraw2d: "draw2d",
|
||||||
getDraw2dLast: "draw2dLast",
|
getDraw2dLast: "draw2dLast",
|
||||||
|
getDraw2dPicture: "draw2dpicture",
|
||||||
boardWidth: "boardWidth",
|
boardWidth: "boardWidth",
|
||||||
boardHeight: "boardHeight",
|
boardHeight: "boardHeight",
|
||||||
|
picture: "picture",
|
||||||
}),
|
}),
|
||||||
...mapWritableState(globalStore, {
|
...mapWritableState(globalStore, {
|
||||||
lastBoard: "lastBoard",
|
lastBoard: "lastBoard",
|
||||||
@ -62,6 +64,9 @@
|
|||||||
getDraw2dLast(value) {
|
getDraw2dLast(value) {
|
||||||
if (value == true) this.draw2dLast();
|
if (value == true) this.draw2dLast();
|
||||||
},
|
},
|
||||||
|
getDraw2dPicture(value) {
|
||||||
|
if (value == true) this.draw2dPicture();
|
||||||
|
},
|
||||||
getReset(value) {
|
getReset(value) {
|
||||||
if (value == true) this.reset();
|
if (value == true) this.reset();
|
||||||
},
|
},
|
||||||
@ -137,9 +142,22 @@
|
|||||||
this.draw2d(board);
|
this.draw2d(board);
|
||||||
},
|
},
|
||||||
// draw 2d automaton from the last known generated board
|
// draw 2d automaton from the last known generated board
|
||||||
async draw2dLast() {
|
draw2dLast() {
|
||||||
if (this.lastBoard != undefined) this.draw2d(this.lastBoard);
|
if (this.lastBoard != undefined) this.draw2d(this.lastBoard);
|
||||||
},
|
},
|
||||||
|
// draw 2d automaton from an uploaded picture
|
||||||
|
draw2dPicture(e) {
|
||||||
|
this.picture.width = this.canvas.width;
|
||||||
|
this.picture.height = this.canvas.height;
|
||||||
|
this.ctx.drawImage(
|
||||||
|
this.picture,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
this.canvas.width,
|
||||||
|
this.canvas.height
|
||||||
|
);
|
||||||
|
this.toggleStop();
|
||||||
|
},
|
||||||
// stop drawing routines and clear the canvas
|
// stop drawing routines and clear the canvas
|
||||||
reset() {
|
reset() {
|
||||||
this.toggleStop();
|
this.toggleStop();
|
||||||
|
@ -15,14 +15,14 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<label>Start from picture</label><br />
|
<label>Start from picture</label><br />
|
||||||
<input type="file" @change="previewFile" />
|
<input type="file" @change="preparePicture" />
|
||||||
<input type="button" value="start" @click="toggleDraw2dLast()" />
|
<input type="button" value="start" @click="toggle2dDrawFromPicture()" />
|
||||||
</div>
|
</div>
|
||||||
</MenuRow>
|
</MenuRow>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapActions } from "pinia";
|
import { mapActions, mapWritableState } from "pinia";
|
||||||
import MenuRow from "./MenuRow.vue";
|
import MenuRow from "./MenuRow.vue";
|
||||||
import { globalStore } from "../stores/index.js";
|
import { globalStore } from "../stores/index.js";
|
||||||
|
|
||||||
@ -31,10 +31,38 @@
|
|||||||
components: {
|
components: {
|
||||||
MenuRow,
|
MenuRow,
|
||||||
},
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
uploadedFile: "",
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...mapWritableState(globalStore, ["picture"]),
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(globalStore, ["toggleDraw2dLast", "toggleDraw2d"]),
|
...mapActions(globalStore, [
|
||||||
previewFile(event) {
|
"toggleDraw2dLast",
|
||||||
console.log(event.target.files);
|
"toggleDraw2d",
|
||||||
|
"toggle2dDrawFromPicture",
|
||||||
|
]),
|
||||||
|
preparePicture(event) {
|
||||||
|
const files = event.target.files;
|
||||||
|
this.picture = new Image();
|
||||||
|
this.picture.width = this.canvasWidth;
|
||||||
|
if (FileReader && files && files.length) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
|
||||||
|
reader.onload = () => {
|
||||||
|
this.picture.src = reader.result;
|
||||||
|
this.toggle2dDrawFromPicture();
|
||||||
|
};
|
||||||
|
|
||||||
|
reader.onerror = () => {
|
||||||
|
console.log(reader.error);
|
||||||
|
};
|
||||||
|
|
||||||
|
reader.readAsDataURL(files[0]);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<MenuRow row-title="Elementary Automaton">
|
<MenuRow row-title="Elementary Automaton">
|
||||||
<form>
|
<form>
|
||||||
|
<div class="form-field">
|
||||||
|
<input
|
||||||
|
type="button"
|
||||||
|
name="start"
|
||||||
|
value="start"
|
||||||
|
@click="toggleDraw1d()"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<label>
|
<label>
|
||||||
Initial state presets
|
Initial state presets
|
||||||
@ -62,9 +70,6 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div class="form-field">
|
|
||||||
<input type="button" name="start" value="start" @click="toggleDraw1d()" />
|
|
||||||
</div>
|
|
||||||
</MenuRow>
|
</MenuRow>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -3,7 +3,11 @@
|
|||||||
<h2 :id="rowTitle" @click="$emit('update-active', rowTitle)">
|
<h2 :id="rowTitle" @click="$emit('update-active', rowTitle)">
|
||||||
{{ rowTitle }}
|
{{ rowTitle }}
|
||||||
</h2>
|
</h2>
|
||||||
<div v-if="isActive" class="menu-row-content">
|
<div
|
||||||
|
v-if="isActive"
|
||||||
|
class="menu-row-content"
|
||||||
|
@mouseleave="$emit('update-active', '')"
|
||||||
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -32,8 +32,10 @@ export const globalStore = defineStore("globalStore", {
|
|||||||
draw1d: false,
|
draw1d: false,
|
||||||
draw2d: false,
|
draw2d: false,
|
||||||
draw2dLast: false,
|
draw2dLast: false,
|
||||||
|
draw2dpicture: false,
|
||||||
reset: false,
|
reset: false,
|
||||||
canDraw: true,
|
canDraw: true,
|
||||||
|
picture: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@ -58,6 +60,12 @@ export const globalStore = defineStore("globalStore", {
|
|||||||
this.canDraw = true;
|
this.canDraw = true;
|
||||||
this.draw2dLast = true;
|
this.draw2dLast = true;
|
||||||
},
|
},
|
||||||
|
toggle2dDrawFromPicture() {
|
||||||
|
console.log("toggleDraw2dFromPicture");
|
||||||
|
this.toggleStop();
|
||||||
|
this.canDraw = true;
|
||||||
|
this.draw2dpicture = true;
|
||||||
|
},
|
||||||
toggleReset() {
|
toggleReset() {
|
||||||
this.toggleStop();
|
this.toggleStop();
|
||||||
this.reset = true;
|
this.reset = true;
|
||||||
@ -66,6 +74,7 @@ export const globalStore = defineStore("globalStore", {
|
|||||||
this.draw1d = false;
|
this.draw1d = false;
|
||||||
this.draw2d = false;
|
this.draw2d = false;
|
||||||
this.draw2dLast = false;
|
this.draw2dLast = false;
|
||||||
|
this.draw2dpicture = false;
|
||||||
this.canDraw = false;
|
this.canDraw = false;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user