update brush on dithering change

This commit is contained in:
Shuanglei Tao
2025-05-31 21:21:08 +08:00
parent 135da8b025
commit 986bb49f8e

View File

@@ -93,9 +93,13 @@ function initPaintTools() {
redrawTextElements();
redrawLineSegments();
};
// Update the brush color options based on dithering method
document.getElementById('dithering').addEventListener('change', updateBrushOptions);
// Ensure no tool is selected by default
updateToolUI();
updateBrushOptions();
}
function setActiveTool(tool, title) {
@@ -108,6 +112,23 @@ function setActiveTool(tool, title) {
cancelTextPlacement();
}
function updateBrushOptions() {
const dithering = document.getElementById('dithering').value;
const brushColor = document.getElementById('brush-color');
for (option of brushColor.getElementsByTagName('option')) {
if (option.value === '#FF0000') {
if (dithering.startsWith('bwr'))
option.removeAttribute('disabled');
else
option.setAttribute('disabled', 'disabled');
}
}
// Revert brush color to black if red is not allowed
if (!dithering.startsWith('bwr') && brushColor.value === '#FF0000') {
brushColor.value = '#000000';
}
}
function updateToolUI() {
// Update UI to reflect active tool or no tool
document.getElementById('brush-mode').classList.toggle('active', currentTool === 'brush');