Save brush settings individually per tool

This commit is contained in:
JannisX11 2020-09-27 18:05:20 +02:00
parent 01ed8ccbad
commit 9cac4af541
2 changed files with 16 additions and 2 deletions

View File

@ -286,6 +286,7 @@ class Tool extends Action {
this.transformerMode = data.transformerMode;
this.animation_channel = data.animation_channel;
this.allowWireframe = data.allowWireframe !== false;
this.tool_settings = {};
if (!this.condition) {
this.condition = function() {
@ -370,6 +371,7 @@ class NumSlider extends Widget {
this.value = 0;
this.width = 69;
this.uniqueNode = true;
if (data.tool_setting) this.tool_setting = data.tool_setting;
if (typeof data.get === 'function') this.get = data.get;
this.onBefore = data.onBefore;
this.onAfter = data.onAfter;
@ -642,11 +644,20 @@ class NumSlider extends Widget {
if (this.settings && typeof this.settings.min === 'number') {
num = limitNumber(num, this.settings.min, this.settings.max)
}
this.value = num
this.value = num;
if (this.tool_setting) {
Toolbox.selected.tool_settings[this.tool_setting] = num;
}
}
get() {
//Solo Sliders only
return parseFloat(this.value);
if (this.tool_setting) {
return Toolbox.selected.tool_settings[this.tool_setting] != undefined
? Toolbox.selected.tool_settings[this.tool_setting]
: (this.settings.default||0)
} else {
return parseFloat(this.value);
}
}
update() {
if (!BARS.condition(this.condition)) return;

View File

@ -982,6 +982,7 @@ BARS.defineActions(function() {
new NumSlider('slider_brush_size', {
condition: () => (Toolbox && ['brush_tool', 'eraser', 'draw_shape_tool'].includes(Toolbox.selected.id)),
tool_setting: 'brush_size',
category: 'paint',
settings: {
min: 1, max: 50, interval: 1, default: 1,
@ -990,6 +991,7 @@ BARS.defineActions(function() {
new NumSlider('slider_brush_softness', {
category: 'paint',
condition: () => (Toolbox && ['brush_tool', 'eraser'].includes(Toolbox.selected.id)),
tool_setting: 'brush_softness',
settings: {
min: 0, max: 100, default: 0,
interval: function(event) {
@ -1008,6 +1010,7 @@ BARS.defineActions(function() {
new NumSlider('slider_brush_opacity', {
category: 'paint',
condition: () => (Toolbox && ['brush_tool', 'eraser', 'fill_tool', 'draw_shape_tool'].includes(Toolbox.selected.id)),
tool_setting: 'brush_opacity',
settings: {
min: 0, max: 100, default: 100,
interval: function(event) {