mirror of
https://github.com/igorski/bitmappery.git
synced 2026-07-14 19:08:56 +02:00
Fixed bug in document resize. Application now starts without open document.
This commit is contained in:
@@ -57,10 +57,20 @@ export default {
|
||||
},
|
||||
activeDocument: {
|
||||
deep: true,
|
||||
handler( document ) {
|
||||
handler( document, oldValue = null ) {
|
||||
if ( !document?.layers ) {
|
||||
if ( zCanvas ) {
|
||||
zCanvas.dispose();
|
||||
zCanvas = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ( !zCanvas ) {
|
||||
this.createCanvas();
|
||||
this.$nextTick(() => {
|
||||
zCanvas.insertInPage( this.$refs.canvasContainer );
|
||||
});
|
||||
}
|
||||
const { name, width, height } = document;
|
||||
if ( name !== lastDocument ) {
|
||||
lastDocument = name;
|
||||
@@ -99,19 +109,18 @@ export default {
|
||||
runSpriteFn( sprite => sprite.setDraggable( isDraggable || sprite instanceof DrawableLayer ));
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
zCanvas = new canvas({
|
||||
width: 160,
|
||||
height: 90,
|
||||
animate: true,
|
||||
smoothing: true,
|
||||
backgroundColor: "#FFFFFF",
|
||||
stretchToFit: false,
|
||||
fps: 60
|
||||
});
|
||||
zCanvas.insertInPage( this.$refs.canvasContainer );
|
||||
},
|
||||
methods: {
|
||||
createCanvas() {
|
||||
zCanvas = new canvas({
|
||||
width: 160,
|
||||
height: 90,
|
||||
animate: true,
|
||||
smoothing: true,
|
||||
backgroundColor: "#FFFFFF",
|
||||
stretchToFit: false,
|
||||
fps: 60
|
||||
});
|
||||
},
|
||||
scaleCanvas() {
|
||||
const { width, height } = this.activeDocument;
|
||||
const size = this.$el.parentNode?.getBoundingClientRect();
|
||||
@@ -120,7 +129,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
console.warn("canvas must be resized");
|
||||
zCanvas.scale( size.width / width );
|
||||
zCanvas?.scale( size.width / width );
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -50,6 +50,7 @@ export default {
|
||||
width: 0,
|
||||
height: 0,
|
||||
ratio: 0,
|
||||
syncLock: false,
|
||||
maintainRatio: true,
|
||||
}),
|
||||
computed: {
|
||||
@@ -57,29 +58,37 @@ export default {
|
||||
"activeDocument",
|
||||
]),
|
||||
},
|
||||
watch: {
|
||||
width( value ) {
|
||||
if ( !this.maintainRatio || this.ratio === 0 ) {
|
||||
return;
|
||||
}
|
||||
this.height = Math.round( value * this.ratio );
|
||||
},
|
||||
height( value ) {
|
||||
if ( !this.maintainRatio || this.ratio === 0 ) {
|
||||
return;
|
||||
}
|
||||
this.width = Math.round( value / this.ratio );
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.width = this.activeDocument.width;
|
||||
this.height = this.activeDocument.height;
|
||||
this.ratio = this.width / this.height;
|
||||
|
||||
this.$watch( "width", function( value ) {
|
||||
if ( !this.maintainRatio || this.syncLock ) {
|
||||
return;
|
||||
}
|
||||
this.lockSync();
|
||||
this.height = Math.round( value / this.ratio );
|
||||
});
|
||||
|
||||
this.$watch( "height", function( value ) {
|
||||
if ( !this.maintainRatio || this.syncLock ) {
|
||||
return;
|
||||
}
|
||||
this.lockSync();
|
||||
this.width = Math.round( value * this.ratio );
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
...mapMutations([
|
||||
"setActiveDocumentSize",
|
||||
]),
|
||||
lockSync() {
|
||||
this.syncLock = true;
|
||||
this.$nextTick(() => {
|
||||
this.syncLock = false;
|
||||
});
|
||||
},
|
||||
save() {
|
||||
this.setActiveDocumentSize({ width: this.width, height: this.height });
|
||||
this.close();
|
||||
|
||||
@@ -90,7 +90,7 @@ export default {
|
||||
|
||||
image.src = source;
|
||||
|
||||
const currentDocumentIsEmpty = this.layers.length === 1 && !this.layers[ 0 ].graphics.length;
|
||||
const currentDocumentIsEmpty = this.layers?.length === 1 && !this.layers[ 0 ].graphics.length;
|
||||
|
||||
switch ( this.fileTarget) {
|
||||
default:
|
||||
|
||||
@@ -29,13 +29,13 @@ import { flushSpritesInLayer } from "@/utils/canvas-util";
|
||||
|
||||
export default {
|
||||
state: {
|
||||
documents : [ DocumentFactory.create() ],
|
||||
documents : [],
|
||||
activeIndex: 0,
|
||||
},
|
||||
getters: {
|
||||
documents: state => state.documents,
|
||||
activeDocument: state => state.documents[ state.activeIndex ],
|
||||
layers: ( state, getters ) => getters.activeDocument.layers,
|
||||
layers: ( state, getters ) => getters.activeDocument?.layers,
|
||||
},
|
||||
mutations: {
|
||||
setActiveDocument( state, index ) {
|
||||
|
||||
Reference in New Issue
Block a user