Skip to content

Commit

Permalink
Rewrite new image project dialog
Browse files Browse the repository at this point in the history
Fix #2142 stretched image size
Fix missing image when canceling dialog
Fix "toggle all grids" icon
  • Loading branch information
JannisX11 committed Dec 6, 2023
1 parent d5bf608 commit ed85a4a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
4 changes: 2 additions & 2 deletions js/interface/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ window.Dialog = class Dialog {
}
return form_result;
}
setFormValues(values) {
setFormValues(values, update = true) {
for (let form_id in this.form) {
let data = this.form[form_id];
if (values[form_id] != undefined && typeof data == 'object' && data.bar) {
Expand Down Expand Up @@ -642,7 +642,7 @@ window.Dialog = class Dialog {
}
}
}
this.updateFormValues();
if (update) this.updateFormValues();
}
getFormResult() {
let result = {}
Expand Down
54 changes: 44 additions & 10 deletions js/io/formats/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,50 @@ new ModelFormat('image', {
]
},
new() {
if (newProject(this)) {
TextureGenerator.addBitmapDialog(() => {
setTimeout(() => {
Undo.history.empty();
Undo.index = 0;
UVEditor.vue.centerView();
}, 1);
});
return true;
}
newProject(this);
let callback = () => {
setTimeout(() => {
Undo.history.empty();
Undo.index = 0;
UVEditor.vue.centerView();
}, 1);
};
let size_presets = {
'': 'Unset',
'16x16': '16 x 16',
'32x32': '32 x 32',
'64x64': '64 x 64',
'128x128': '128 x 128',
'256x256': '256 x 256',
'512x512': '512 x 512',
'1920x1080': '1920 x 1080',
};
let previous_size_preset = '';
let dialog = new Dialog({
id: 'add_bitmap',
title: tl('action.create_texture'),
buttons: ['dialog.confirm'],
form: {
name: {label: 'generic.name', value: 'texture'},
section2: "_",

size_preset:{label: 'dialog.create_texture.resolution', type: 'select', options: size_presets},
resolution: {label: 'dialog.create_texture.resolution', type: 'vector', dimensions: 2, value: [16, 16], min: 1, max: 2048},
color: {label: 'data.color', type: 'color', colorpicker: TextureGenerator.background_color, toggle_enabled: true, toggle_default: false},
},
onFormChange(result) {
console.log(result)
if (result.size_preset && result.size_preset != previous_size_preset) {
let size = result.size_preset.split('x').map(v => parseInt(v));
dialog.setFormValues({resolution: size}, false);
}
previous_size_preset = result.size_preset;
},
onConfirm: function(results) {
results.type = 'blank';
TextureGenerator.addBitmap(results, callback);
}
}).show();
},
onActivation() {
Interface.preview.classList.add('image_mode');
Expand Down
2 changes: 1 addition & 1 deletion js/preview/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,7 @@ BARS.defineActions(function() {
new Toggle('toggle_all_grids', {
name: tl('settings.grids'),
description: tl('settings.grids.desc'),
icon: 'grid',
icon: 'grid_on',
category: 'view',
linked_setting: 'grids',
condition: () => !Modes.paint
Expand Down
8 changes: 5 additions & 3 deletions js/texturing/texture_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const TextureGenerator = {
TextureGenerator.generateColorMapTemplate(options, makeTexture);
} else {
Undo.initEdit({textures: [], selected_texture: true})
TextureGenerator.generateBlank(options.resolution[1], options.resolution[0], options.color, makeTexture)
TextureGenerator.generateBlank(options.resolution[1], options.resolution[0], options.color, makeTexture);
}
},
generateBlank(height, width, color, cb) {
Expand All @@ -158,8 +158,10 @@ const TextureGenerator = {
ctx.fillStyle = new tinycolor(color).toRgbString();
ctx.fillRect(0, 0, width, height);
}

cb(canvas.toDataURL())
let texture = cb(canvas.toDataURL());
texture.uv_width = width;
texture.uv_height = height;
return texture;
},
//constructors
boxUVCubeTemplate: function(obj, min_size) {
Expand Down

0 comments on commit ed85a4a

Please sign in to comment.