update paint support

This commit is contained in:
Shuanglei Tao
2025-06-03 14:19:00 +08:00
parent 03b33b46a9
commit 88b0998f58
3 changed files with 8 additions and 26 deletions

View File

@@ -164,8 +164,8 @@
</div>
</div>
<script type="text/javascript" src="js/dithering.js?v=20250519"></script>
<script type="text/javascript" src="js/main.js?v=20250519"></script>
<script type="text/javascript" src="js/paint.js?v=20250519"></script>
<script type="text/javascript" src="js/main.js?v=20250519"></script>
</body>
</html>

View File

@@ -378,6 +378,8 @@ function clearCanvas() {
if (confirm('清除画布已有内容?')) {
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, canvas.width, canvas.height);
textElements = []; // Clear stored text positions
lineSegments = []; // Clear stored line segments
return true;
}
return false;
@@ -393,6 +395,10 @@ function convertDithering() {
const threshold = document.getElementById('threshold').value;
dithering(ctx, canvas.width, canvas.height, parseInt(threshold), mode);
}
// Redraw text and lines
redrawTextElements();
redrawLineSegments();
}
function filterDitheringOptions() {
@@ -442,6 +448,7 @@ document.body.onload = () => {
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, canvas.width, canvas.height);
initPaintTools();
updateButtonStatus();
checkDebugMode();
}

View File

@@ -74,26 +74,6 @@ function initPaintTools() {
setupCanvasForPainting();
// Override the existing clear_canvas function to clear our text positions too
const originalClearCanvas = window.clear_canvas;
window.clear_canvas = function() {
if(originalClearCanvas()) {
textElements = []; // Clear stored text positions
lineSegments = []; // Clear stored line segments
return true;
}
return false;
};
// Override the existing convert_dithering function to preserve text and lines
const originalConvertDithering = window.convert_dithering;
window.convert_dithering = function() {
originalConvertDithering();
// Redraw text and lines after dithering
redrawTextElements();
redrawLineSegments();
};
// Update the brush color options based on dithering method
document.getElementById('dithering').addEventListener('change', updateBrushOptions);
@@ -451,8 +431,3 @@ function redrawLineSegments() {
ctx.stroke();
});
}
// Initialize paint functionality when the page loads
document.addEventListener('DOMContentLoaded', () => {
setTimeout(initPaintTools, 500); // Delay to ensure canvas is initialized
});