Add improved texture copy pasting

Add minimum size for backgrounds
This commit is contained in:
JannisX11 2022-05-20 17:53:18 +02:00
parent 623f4c961a
commit 876aa0e580
2 changed files with 31 additions and 14 deletions

View File

@ -1079,7 +1079,7 @@ class Preview {
if (this.movingBackground) {
if (event.shiftKey || Pressing.overrides.shift) {
let diff = event.clientY - this.selection.client_y;
this.background.size = limitNumber( this.background.before.size + (diff * (0.6 + this.background.size/1200)), 0, 10e3)
this.background.size = limitNumber( this.background.before.size + (diff * (0.6 + this.background.size/1200)), 40, 10e3)
} else {
this.background.x = this.background.before.x + (event.clientX - this.selection.client_x);
this.background.y = this.background.before.y + (event.clientY - this.selection.client_y);
@ -1319,7 +1319,7 @@ class Preview {
clearBackground() {
this.loadBackground()
this.background.image = false
this.background.size = limitNumber(this.background.size, 100, 2400)
this.background.size = limitNumber(this.background.size, 40, 2400)
this.background.x = limitNumber(this.background.x, 0, this.width-30)
this.background.y = limitNumber(this.background.y, 0, this.height-30)
this.loadBackground()
@ -1378,7 +1378,7 @@ class Preview {
title: tl('message.set_background_position.title'),
form: {
position: {label: 'message.set_background_position.position', type: 'vector', dimensions: 2, value: [scope.background.x, scope.background.y]},
size: {label: 'message.set_background_position.size', type: 'number', value: scope.background.size}
size: {label: 'message.set_background_position.size', type: 'number', value: scope.background.size, min: 40, max: 10000}
},
onConfirm(form) {
if (!scope.background) return;

View File

@ -1496,29 +1496,46 @@ Clipbench.setTexture = function(texture) {
//Sets the raw image of the texture
if (!isApp) return;
if (texture.mode === 'bitmap') {
var img = nativeImage.createFromDataURL(texture.source)
} else {
var img = nativeImage.createFromPath(texture.source.split('?')[0])
Clipbench.texture = texture.getUndoCopy();
delete Clipbench.texture.path;
Clipbench.texture.mode = 'bitmap';
Clipbench.texture.saved = false;
Clipbench.texture.source = 'data:image/png;base64,'+texture.getBase64();
if (isApp) {
if (texture.mode === 'bitmap') {
var img = nativeImage.createFromDataURL(texture.source);
} else {
var img = nativeImage.createFromPath(texture.source.split('?')[0]);
}
clipboard.writeImage(img);
}
clipboard.writeImage(img)
}
Clipbench.pasteTextures = function() {
function loadImage(dataUrl) {
var texture = new Texture({name: 'pasted', folder: 'block' }).fromDataURL(dataUrl).fillParticle().add(true)
function loadFromDataUrl(dataUrl) {
if (!dataUrl || dataUrl.length < 32) return;
var texture = new Texture({name: 'pasted', folder: 'block' }).fromDataURL(dataUrl).fillParticle().add(true);
setTimeout(function() {
texture.openMenu()
texture.openMenu();
}, 40)
}
if (isApp) {
if (Clipbench.texture) {
var texture = new Texture(Clipbench.texture).fillParticle().load().add(true);
setTimeout(function() {
texture.openMenu();
}, 40)
Clipbench.texture = null;
} else if (isApp) {
var image = clipboard.readImage().toDataURL();
loadImage(image);
loadFromDataUrl(image);
} else {
navigator.clipboard.read().then(content => {
if (content && content[0] && content[0].types.includes('image/png')) {
content[0].getType('image/png').then(blob => {
let url = URL.createObjectURL(blob);
loadImage(url);
loadFromDataUrl(url);
})
}
}).catch(() => {})