Option to rotate textures

Closes #1571
Add image edit options to texture context menu
This commit is contained in:
JannisX11 2022-09-27 23:22:26 +02:00
parent 4271c7382a
commit e073d6cd5e
6 changed files with 59 additions and 4 deletions

View File

@ -278,6 +278,8 @@ const MenuBar = {
'_',
'flip_texture_x',
'flip_texture_y',
'rotate_texture_cw',
'rotate_texture_ccw',
'resize_texture'
], {
condition: {modes: ['paint']}

View File

@ -94,7 +94,9 @@ async function loadImages(files, event) {
}
}
if (Project) {
options.texture = 'action.import_texture';
if (Condition(Panels.textures.condition)) {
options.texture = 'action.import_texture';
}
options.background = 'menu.view.background';
}
options.edit = 'message.load_images.edit_image';

View File

@ -474,6 +474,46 @@ BARS.defineActions(function() {
Undo.finishEdit('Flip texture Y')
}
})
new Action('rotate_texture_cw', {
icon: 'rotate_right',
category: 'textures',
condition: {modes: ['paint'], method: () => Texture.all.length},
click() {
let textures = getTextures();
Undo.initEdit({textures, bitmap: true});
textures.forEach(texture => {
texture.edit((canvas) => {
let ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.rotate(Math.PI/2);
ctx.drawImage(texture.img, 0, -canvas.height);
}, {no_undo: true});
})
Undo.finishEdit('Rotate texture clockwise')
}
})
new Action('rotate_texture_ccw', {
icon: 'rotate_left',
category: 'textures',
condition: {modes: ['paint'], method: () => Texture.all.length},
click() {
let textures = getTextures();
Undo.initEdit({textures, bitmap: true});
textures.forEach(texture => {
texture.edit((canvas) => {
let ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.rotate(-Math.PI/2);
ctx.drawImage(texture.img, -canvas.width, 0);
}, {no_undo: true});
})
Undo.finishEdit('Rotate texture counter-clockwise')
}
})
new Action('resize_texture', {
icon: 'photo_size_select_large',
category: 'textures',

View File

@ -1317,7 +1317,7 @@ class Texture {
'_',
{
icon: 'edit',
name: 'menu.texture.edit',
name: 'menu.texture.edit_externally',
condition: (texture) => texture.mode == 'link',
click(texture) { texture.openEditor() }
},
@ -1347,6 +1347,14 @@ class Texture {
}
}
},
{
icon: 'tune',
name: 'menu.texture.edit',
condition: {modes: ['paint']},
children() {
return MenuBar.menus.texture.structure
}
},
{
icon: 'folder',
name: 'menu.texture.folder',

File diff suppressed because one or more lines are too long

View File

@ -1237,6 +1237,8 @@
"action.adjust_curves.desc": "Adjust the brightness curves of the selected texture",
"action.flip_texture_x": "Flip Texture Horizontally",
"action.flip_texture_y": "Flip Texture Vertically",
"action.rotate_texture_cw": "Rotate Texture Clockwise",
"action.rotate_texture_ccw": "Rotate Texture Counter-clockwise",
"action.resize_texture": "Resize Texture...",
"action.add_display_preset": "New Preset",
@ -1546,7 +1548,8 @@
"menu.texture.render_mode.emissive": "Emissive",
"menu.texture.render_mode.layered": "Layered",
"menu.texture.merge_onto_texture": "Merge Onto Texture Above",
"menu.texture.edit": "Edit Externally",
"menu.texture.edit": "Edit",
"menu.texture.edit_externally": "Edit Externally",
"menu.texture.edit_in_blockbench": "Edit in Blockbench",
"menu.texture.particle": "Use for Particles",
"menu.texture.export": "Save As",