From b9f2640b3d916ced8e77710321151fa4826e9acc Mon Sep 17 00:00:00 2001 From: Mark MacKay Date: Thu, 15 Apr 2021 20:48:37 -0500 Subject: [PATCH] switching colors with opacity now works --- src/js/PaintBox.js | 15 +-------------- src/js/editor.js | 10 ++++++---- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/js/PaintBox.js b/src/js/PaintBox.js index 06a307d..cee855f 100644 --- a/src/js/PaintBox.js +++ b/src/js/PaintBox.js @@ -213,19 +213,6 @@ MD.PaintBox = function(container, type){ }); $('#tool_switch').on("click touchstart", function(){ - var stroke_rect = document.querySelector('#tool_stroke rect'); - $("#tool_stroke").toggleClass('active') - $("#tool_fill").toggleClass('active') - var fill_rect = document.querySelector('#tool_fill rect'); - var fill_color = fill_rect.getAttribute("fill"); - var stroke_color = stroke_rect.getAttribute("fill"); - var stroke_opacity = parseFloat(stroke_rect.getAttribute("stroke-opacity")); - if (isNaN(stroke_opacity)) {stroke_opacity = 100;} - var fill_opacity = parseFloat(fill_rect.getAttribute("fill-opacity")); - if (isNaN(fill_opacity)) {fill_opacity = 100;} - var stroke = editor.paintBox.stroke.getPaint(stroke_color, stroke_opacity, "stroke"); - var fill = editor.paintBox.fill.getPaint(fill_color, fill_opacity, "fill"); - editor.paintBox.fill.setPaint(stroke, true); - editor.paintBox.stroke.setPaint(fill, true); + editor.switchPaint(); }); })(); \ No newline at end of file diff --git a/src/js/editor.js b/src/js/editor.js index 2c82f30..0bb12a4 100644 --- a/src/js/editor.js +++ b/src/js/editor.js @@ -120,10 +120,12 @@ MD.Editor = function(){ var fill_rect = document.querySelector('#tool_fill rect'); var fill_color = fill_rect.getAttribute("fill"); var stroke_color = stroke_rect.getAttribute("fill"); - var stroke_opacity = parseFloat(stroke_rect.getAttribute("stroke-opacity")); - if (isNaN(stroke_opacity)) {stroke_opacity = 100;} - var fill_opacity = parseFloat(fill_rect.getAttribute("fill-opacity")); - if (isNaN(fill_opacity)) {fill_opacity = 100;} + var stroke_opacity = parseFloat(stroke_rect.getAttribute("opacity")); + if (isNaN(stroke_opacity)) {stroke_opacity = 1;} + var fill_opacity = parseFloat(fill_rect.getAttribute("opacity")); + if (isNaN(fill_opacity)) {fill_opacity = 1;} + stroke_opacity *= 100; + fill_opacity *= 100; var stroke = editor.paintBox.stroke.getPaint(stroke_color, stroke_opacity, "stroke"); var fill = editor.paintBox.fill.getPaint(fill_color, fill_opacity, "fill"); editor.paintBox.fill.setPaint(stroke, true);