2021-08-06 01:51:58 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
2021-08-07 06:05:54 +00:00
|
|
|
<t-card class="overflow-x-scroll h-full">
|
|
|
|
<div :style="`height: ${blocksWidthHeight.h}px;width: ${blocksWidthHeight.w}px;`">
|
|
|
|
<canvas
|
|
|
|
:ref="canvasName"
|
|
|
|
:id="canvasName"
|
|
|
|
class="previewcanvas"
|
|
|
|
:width="blocksWidthHeight.w"
|
|
|
|
:height="blocksWidthHeight.h"
|
2021-12-21 09:03:40 +00:00
|
|
|
@mouseup.right="openContextMenu"
|
|
|
|
@contextmenu.prevent
|
2021-08-07 06:05:54 +00:00
|
|
|
/>
|
2021-08-15 01:20:58 +00:00
|
|
|
</div>
|
2021-12-21 09:03:40 +00:00
|
|
|
|
|
|
|
<context-menu :ref="`block-menu-${hash}`" class="z-50" >
|
2021-12-26 01:41:24 +00:00
|
|
|
<ul>
|
|
|
|
<li @click="canvasToPng()" class="ab-context-menu-item">
|
|
|
|
Save as PNG
|
|
|
|
</li>
|
|
|
|
<li @click="startExport('clipboard')" class="ab-context-menu-item">
|
|
|
|
Export Brush to mIRC Clipboard
|
|
|
|
</li>
|
|
|
|
<li @click="startExport('file')" class="ab-context-menu-item">
|
|
|
|
Export Brush to mIRC File
|
|
|
|
</li>
|
|
|
|
<li @click="saveToLibrary()" class="ab-context-menu-item">
|
|
|
|
Save to Library
|
|
|
|
</li>
|
|
|
|
</ul>
|
2021-12-21 09:03:40 +00:00
|
|
|
</context-menu>
|
2021-08-06 04:00:21 +00:00
|
|
|
</t-card>
|
2021-08-06 01:51:58 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-08-07 06:05:54 +00:00
|
|
|
|
2021-08-06 01:51:58 +00:00
|
|
|
<script>
|
2021-12-26 01:41:24 +00:00
|
|
|
import { mircColours99, blockWidth, blockHeight, cyrb53, getBlocksWidth, filterNullBlocks,
|
|
|
|
canvasToPng,
|
|
|
|
exportMirc,
|
|
|
|
downloadFile } from "../../ascii";
|
2021-12-21 09:03:40 +00:00
|
|
|
import ContextMenu from "./ContextMenu.vue";
|
2021-08-06 01:51:58 +00:00
|
|
|
export default {
|
|
|
|
name: "BrushCanvas",
|
2021-08-14 06:41:42 +00:00
|
|
|
created() {
|
|
|
|
window.addEventListener('load', () => {
|
|
|
|
// Fixes the font on load issue
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
})
|
|
|
|
},
|
2021-08-06 01:51:58 +00:00
|
|
|
mounted() {
|
2021-08-14 06:41:42 +00:00
|
|
|
this.ctx = this.$refs[this.canvasName].getContext("2d");
|
2021-08-06 01:51:58 +00:00
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
blocks: {
|
|
|
|
type: [Array, Boolean],
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
2021-12-21 09:03:40 +00:00
|
|
|
components: {
|
|
|
|
ContextMenu,
|
|
|
|
},
|
2021-08-06 01:51:58 +00:00
|
|
|
data: () => ({
|
|
|
|
ctx: null,
|
|
|
|
redraw: true,
|
|
|
|
}),
|
|
|
|
computed: {
|
2021-08-14 06:41:42 +00:00
|
|
|
blockWidth() {
|
|
|
|
return blockWidth * this.blockSizeMultiplier;
|
|
|
|
},
|
|
|
|
blockHeight() {
|
|
|
|
return blockHeight * this.blockSizeMultiplier;
|
|
|
|
},
|
|
|
|
blockSizeMultiplier() {
|
|
|
|
return this.$store.getters.blockSizeMultiplier
|
|
|
|
},
|
2021-08-06 01:51:58 +00:00
|
|
|
currentAscii() {
|
|
|
|
return this.$store.getters.currentAscii;
|
|
|
|
},
|
|
|
|
toolbarState() {
|
|
|
|
return this.$store.getters.toolbarState;
|
|
|
|
},
|
|
|
|
isTargettingBg() {
|
|
|
|
return this.$store.getters.isTargettingBg;
|
|
|
|
},
|
|
|
|
isTargettingFg() {
|
|
|
|
return this.$store.getters.isTargettingFg;
|
|
|
|
},
|
|
|
|
isTargettingChar() {
|
|
|
|
return this.$store.getters.isTargettingChar;
|
|
|
|
},
|
|
|
|
currentFg() {
|
|
|
|
return this.$store.getters.currentFg;
|
|
|
|
},
|
|
|
|
currentBg() {
|
|
|
|
return this.$store.getters.currentBg;
|
|
|
|
},
|
|
|
|
currentChar() {
|
|
|
|
return this.$store.getters.currentChar;
|
|
|
|
},
|
|
|
|
brushSizeHeight() {
|
|
|
|
return this.$store.getters.brushSizeHeight;
|
|
|
|
},
|
|
|
|
brushSizeWidth() {
|
|
|
|
return this.$store.getters.brushSizeWidth;
|
|
|
|
},
|
|
|
|
brushSizeType() {
|
|
|
|
return this.$store.getters.brushSizeType;
|
|
|
|
},
|
|
|
|
options() {
|
|
|
|
return this.$store.getters.options;
|
|
|
|
},
|
2021-12-21 09:03:40 +00:00
|
|
|
hash() {
|
|
|
|
return cyrb53(JSON.stringify(this.getBlocks));
|
|
|
|
},
|
2021-08-06 01:51:58 +00:00
|
|
|
canvasName() {
|
2021-12-21 09:03:40 +00:00
|
|
|
return `${this.hash}-brush-canvas`;
|
2021-08-06 01:51:58 +00:00
|
|
|
},
|
|
|
|
getBlocks() {
|
|
|
|
return this.blocks === false
|
|
|
|
? this.$store.getters.brushBlocks
|
|
|
|
: this.blocks;
|
|
|
|
},
|
|
|
|
isMainCanvas() {
|
|
|
|
return this.blocks === false;
|
|
|
|
},
|
2021-08-06 04:00:21 +00:00
|
|
|
blocksWidthHeight() {
|
|
|
|
return {
|
2021-08-14 06:41:42 +00:00
|
|
|
w: getBlocksWidth(this.getBlocks) * this.blockWidth,
|
|
|
|
h: this.getBlocks.length * this.blockHeight
|
2021-08-07 22:36:00 +00:00
|
|
|
}
|
2021-08-06 04:00:21 +00:00
|
|
|
},
|
2021-08-06 01:51:58 +00:00
|
|
|
mircColours() {
|
|
|
|
return mircColours99;
|
|
|
|
},
|
2021-08-07 23:45:37 +00:00
|
|
|
canvasRef() {
|
|
|
|
return this.$refs[this.canvasName];
|
2021-12-26 01:41:24 +00:00
|
|
|
},
|
2021-08-06 01:51:58 +00:00
|
|
|
},
|
|
|
|
watch: {
|
2021-08-14 06:41:42 +00:00
|
|
|
blockSizeMultiplier() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
2021-08-06 01:51:58 +00:00
|
|
|
getBlocks() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
2021-08-06 04:00:21 +00:00
|
|
|
blocks() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
2021-08-06 01:51:58 +00:00
|
|
|
currentAscii() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
|
|
|
brushSizeHeight() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
|
|
|
brushSizeWidth() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
|
|
|
isTargettingBg() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
|
|
|
isTargettingFg() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
|
|
|
isTargettingChar() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
|
|
|
currentFg() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
|
|
|
currentBg() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
|
|
|
currentChar() {
|
|
|
|
this.delayRedrawCanvas();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2021-12-26 01:41:24 +00:00
|
|
|
startExport(type) {
|
|
|
|
let ascii = exportMirc(this.getBlocks);
|
|
|
|
console.log(ascii);
|
|
|
|
switch (type) {
|
|
|
|
case "clipboard":
|
|
|
|
this.$copyText(ascii.output.join("")).then(
|
|
|
|
(e) => {
|
|
|
|
this.$toasted.show("Copied mIRC brush to clipboard!", {
|
|
|
|
type: "success",
|
|
|
|
});
|
|
|
|
},
|
|
|
|
(e) => {
|
|
|
|
this.$toasted.show("Error when copying mIRC to clipboard!", {
|
|
|
|
type: "error",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
this.$refs[`block-menu-${this.hash}`].close();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case "file":
|
|
|
|
downloadFile(ascii.output.join(""), ascii.filename, "text/plain");
|
|
|
|
this.$refs[`block-menu-${this.hash}`].close();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
saveToLibrary() {
|
|
|
|
this.$store.commit("pushBrushLibrary", this.getBlocks);
|
|
|
|
this.$toasted.show(`Saved brush to Library`, {
|
|
|
|
type: "success",
|
|
|
|
});
|
|
|
|
this.$refs[`block-menu-${this.hash}`].close();
|
|
|
|
},
|
|
|
|
canvasToPng() {
|
|
|
|
canvasToPng(this.canvasRef, `brush-${this.hash}.png`)
|
|
|
|
this.$refs[`block-menu-${this.hash}`].close();
|
|
|
|
},
|
2021-08-07 02:41:47 +00:00
|
|
|
getBlocksWidth(blocks) {
|
|
|
|
return getBlocksWidth(blocks)
|
|
|
|
},
|
|
|
|
filterNullBlocks(blocks) {
|
|
|
|
return filterNullBlocks(blocks)
|
|
|
|
},
|
2021-12-21 09:03:40 +00:00
|
|
|
openContextMenu(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
// These are the correct X and Y when inside the floating panel
|
|
|
|
this.$refs[`block-menu-${this.hash}`].open({
|
|
|
|
pageX: e.layerX,
|
|
|
|
pageY: e.layerY,
|
|
|
|
});
|
|
|
|
},
|
2021-08-06 01:51:58 +00:00
|
|
|
drawPreview() {
|
2021-08-07 23:45:37 +00:00
|
|
|
this.ctx.clearRect(0, 0, this.canvasRef.width, this.canvasRef.height);
|
2021-08-06 01:51:58 +00:00
|
|
|
this.ctx.fillStyle = this.mircColours[1];
|
|
|
|
|
|
|
|
// hack font for ascii shout outs 2 beenz
|
|
|
|
this.ctx.font = "13px Hack";
|
|
|
|
|
|
|
|
let y = 0;
|
|
|
|
let x = 0;
|
|
|
|
|
|
|
|
// Get middle block
|
|
|
|
if (this.getBlocks) {
|
2021-08-07 02:41:47 +00:00
|
|
|
let blocksWidth = this.getBlocksWidth(this.getBlocks)
|
2021-08-06 01:51:58 +00:00
|
|
|
for (y = 0; y < this.getBlocks.length; y++) {
|
2021-08-07 02:41:47 +00:00
|
|
|
for (x = 0; x < blocksWidth; x++) {
|
2021-08-06 01:51:58 +00:00
|
|
|
if (this.getBlocks[y] && this.getBlocks[y][x]) {
|
|
|
|
const curBlock = this.getBlocks[y][x];
|
|
|
|
|
2021-12-17 10:09:59 +00:00
|
|
|
if (curBlock.bg !== undefined) {
|
2021-08-06 05:12:37 +00:00
|
|
|
this.ctx.fillStyle = this.mircColours[curBlock.bg];
|
2021-08-06 01:51:58 +00:00
|
|
|
|
|
|
|
this.ctx.fillRect(
|
2021-08-14 06:41:42 +00:00
|
|
|
x * this.blockWidth,
|
|
|
|
y * this.blockHeight,
|
|
|
|
this.blockWidth,
|
|
|
|
this.blockHeight
|
2021-08-06 01:51:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-17 10:09:59 +00:00
|
|
|
if (curBlock.fg !== undefined) {
|
2021-08-06 05:12:37 +00:00
|
|
|
this.ctx.fillStyle = this.mircColours[curBlock.fg];
|
2021-08-06 01:51:58 +00:00
|
|
|
}
|
|
|
|
|
2021-12-17 10:09:59 +00:00
|
|
|
if (curBlock.char !== undefined) {
|
2021-08-06 05:12:37 +00:00
|
|
|
this.ctx.fillStyle = this.mircColours[curBlock.fg];
|
2021-08-06 01:51:58 +00:00
|
|
|
this.ctx.fillText(
|
2021-08-06 05:12:37 +00:00
|
|
|
curBlock.char,
|
2021-08-14 06:41:42 +00:00
|
|
|
x * this.blockWidth,
|
|
|
|
y * this.blockHeight + this.blockHeight - 3
|
2021-08-06 01:51:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
delayRedrawCanvas() {
|
|
|
|
if (this.redraw) {
|
|
|
|
this.redraw = false;
|
2021-10-02 03:48:39 +00:00
|
|
|
var _this = this;
|
|
|
|
setTimeout(function(){
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
_this.drawPreview();
|
|
|
|
_this.redraw = true;
|
|
|
|
});
|
|
|
|
}, 1000/this.options.fps)
|
2021-08-06 01:51:58 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|