Add option to copy-paste coordinates

closes #619
This commit is contained in:
JannisX11 2022-08-01 22:24:24 +02:00
parent eb2bce6cea
commit af97b8a302
5 changed files with 77 additions and 6 deletions

View File

@ -580,13 +580,13 @@ class NumSlider extends Widget {
addEventListeners(document, 'mouseup touchend', stop);
})
//Input
.keypress(function (e) {
.on('keypress', function (e) {
if (e.keyCode === 10 || e.keyCode === 13) {
e.preventDefault();
scope.stopInput();
}
})
.keyup(function (e) {
.on('keyup', function (e) {
if (e.keyCode !== 10 && e.keyCode !== 13) {
scope.input()
}
@ -598,15 +598,50 @@ class NumSlider extends Widget {
scope.update()
}
})
.focusout(function() {
.on('focusout', function() {
scope.stopInput()
})
.dblclick(function(event) {
.on('dblclick', function(event) {
if (event.target != this) return;
let value = scope.settings && scope.settings.default ? scope.settings.default.toString() : '0';
scope.jq_inner.text(value);
scope.stopInput()
})
.on('contextmenu', event => {
new Menu([
{
id: 'copy',
name: 'action.copy',
icon: 'fa-copy',
click: () => {
Clipbench.setText(this.value);
}
},
{
id: 'copy',
name: 'menu.text_edit.copy_vector',
icon: 'fa-copy',
condition: this.slider_vector instanceof Array,
click: () => {
let numbers = this.slider_vector.map(slider => slider.value);
let text = numbers.join(' ');
Clipbench.setText(text);
}
},
{
id: 'paste',
name: 'action.paste',
icon: 'fa-paste',
click: () => {
this.startInput()
document.execCommand('paste');
setTimeout(() => {
this.stopInput();
}, 20);
}
}
]).open(event);
});
//Arrows
this.jq_outer
@ -678,6 +713,29 @@ class NumSlider extends Widget {
if (typeof this.onBefore === 'function') {
this.onBefore()
}
if (this.slider_vector && text.split(/\s+/g).length == this.slider_vector.length) {
let components = text.split(/\s+/g);
console.log(text, components);
components.forEach((number, axis) => {
let slider = this.slider_vector[axis];
number = parseFloat(number);
if (isNaN(number)) {
number = 0;
}
slider.change(val => number);
this.jq_inner.removeClass('editing')
this.jq_inner.attr('contenteditable', 'false')
this.update()
})
this.onAfter()
return;
}
text = text.replace(/,(?=\d+$)/, '.');
if (text.match(/^-?\d*(\.\d+)?$/gm)) {
var number = parseFloat(text);

View File

@ -435,7 +435,7 @@ function setupInterface() {
Interface.text_edit_menu = new Menu([
{
id: 'copy',
name: 'Copy',
name: 'action.copy',
icon: 'fa-copy',
click() {
document.execCommand('copy');
@ -443,7 +443,7 @@ function setupInterface() {
},
{
id: 'paste',
name: 'Paste',
name: 'action.paste',
icon: 'fa-paste',
click() {
document.execCommand('paste');

View File

@ -928,6 +928,9 @@ BARS.defineActions(function() {
ColorPanel.updateFromHsv();
}
})
let slider_vector_color = [BarItems.slider_color_h, BarItems.slider_color_s, BarItems.slider_color_v];
slider_vector_color.forEach(slider => slider.slider_vector = slider_vector_color);
new Action('pick_screen_color', {
icon: 'colorize',
category: 'color',

View File

@ -1144,6 +1144,8 @@ BARS.defineActions(function() {
Undo.finishEdit('Change element position')
}
})
let slider_vector_pos = [BarItems.slider_pos_x, BarItems.slider_pos_y, BarItems.slider_pos_z];
slider_vector_pos.forEach(slider => slider.slider_vector = slider_vector_pos);
function resizeOnAxis(modify, axis) {
@ -1229,6 +1231,8 @@ BARS.defineActions(function() {
Undo.finishEdit('Change element size')
}
})
let slider_vector_size = [BarItems.slider_size_x, BarItems.slider_size_y, BarItems.slider_size_z];
slider_vector_size.forEach(slider => slider.slider_vector = slider_vector_size);
//Inflate
new NumSlider('slider_inflate', {
category: 'transform',
@ -1342,6 +1346,8 @@ BARS.defineActions(function() {
},
getInterval: getRotationInterval
})
let slider_vector_rotation = [BarItems.slider_rotation_x, BarItems.slider_rotation_y, BarItems.slider_rotation_z];
slider_vector_rotation.forEach(slider => slider.slider_vector = slider_vector_rotation);
//Origin
function moveOriginOnAxis(modify, axis) {
@ -1451,6 +1457,8 @@ BARS.defineActions(function() {
Undo.finishEdit('Change pivot point')
}
})
let slider_vector_origin = [BarItems.slider_origin_x, BarItems.slider_origin_y, BarItems.slider_origin_z];
slider_vector_origin.forEach(slider => slider.slider_vector = slider_vector_origin);
new Action('scale', {
icon: 'settings_overscan',

View File

@ -1490,6 +1490,8 @@
"menu.help.updating": "Updating (%0%)",
"menu.help.update_failed": "Update Failed",
"menu.text_edit.copy_vector": "Copy Vector",
"menu.cube.color": "Marker Color",
"menu.cube.texture": "Texture",
"menu.cube.texture.transparent": "Transparent",