diff --git a/diylc/diylc-core/src/org/diylc/common/ObjectCache.java b/diylc/diylc-core/src/org/diylc/common/ObjectCache.java index f6a67504..7b29facf 100644 --- a/diylc/diylc-core/src/org/diylc/common/ObjectCache.java +++ b/diylc/diylc-core/src/org/diylc/common/ObjectCache.java @@ -43,6 +43,7 @@ public class ObjectCache { private ObjectCache() {} private Map basicStrokeMap = new HashMap(); + private Map zoomableStrokeMap = new HashMap(); private Map dashStrokeMap = new HashMap(); public Stroke fetchBasicStroke(float width) { @@ -53,6 +54,15 @@ public class ObjectCache { basicStrokeMap.put(width, stroke); return stroke; } + + public Stroke fetchZoomableStroke(float width) { + if (zoomableStrokeMap.containsKey(width)) { + return zoomableStrokeMap.get(width); + } + Stroke stroke = new ZoomableStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); + zoomableStrokeMap.put(width, stroke); + return stroke; + } public Stroke fetchStroke(float width, float[] dash, float phase) { String key = width + "|" + Arrays.toString(dash) + "|" + phase; diff --git a/diylc/diylc-core/src/org/diylc/common/ZoomableStroke.java b/diylc/diylc-core/src/org/diylc/common/ZoomableStroke.java new file mode 100644 index 00000000..383498fe --- /dev/null +++ b/diylc/diylc-core/src/org/diylc/common/ZoomableStroke.java @@ -0,0 +1,57 @@ +/* + + DIY Layout Creator (DIYLC). + Copyright (c) 2009-2018 held jointly by the individual authors. + + This file is part of DIYLC. + + DIYLC is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DIYLC is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DIYLC. If not, see . + +*/ +package org.diylc.common; + +import java.awt.BasicStroke; + +/*** + * {@link BasicStroke} that will always be zoomed in when rendered. + * + * @author Branislav Stojkovic + */ +public class ZoomableStroke extends BasicStroke { + + public ZoomableStroke() { + // TODO Auto-generated constructor stub + } + + public ZoomableStroke(float width) { + super(width); + // TODO Auto-generated constructor stub + } + + public ZoomableStroke(float width, int cap, int join) { + super(width, cap, join); + // TODO Auto-generated constructor stub + } + + public ZoomableStroke(float width, int cap, int join, float miterlimit) { + super(width, cap, join, miterlimit); + // TODO Auto-generated constructor stub + } + + public ZoomableStroke(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase) { + super(width, cap, join, miterlimit, dash, dash_phase); + // TODO Auto-generated constructor stub + } + +} diff --git a/diylc/diylc-core/src/org/diylc/presenter/G2DWrapper.java b/diylc/diylc-core/src/org/diylc/presenter/G2DWrapper.java index 09eaf0b2..2500123f 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/G2DWrapper.java +++ b/diylc/diylc-core/src/org/diylc/presenter/G2DWrapper.java @@ -55,6 +55,7 @@ import java.util.List; import java.util.Map; import org.diylc.common.ObjectCache; +import org.diylc.common.ZoomableStroke; import org.diylc.core.IDrawingObserver; /** @@ -406,7 +407,7 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver { if (this.zoom > 1 && s instanceof BasicStroke) { BasicStroke bs = (BasicStroke) s; // make thin lines even thinner to compensate for zoom factor - if (bs.getLineWidth() <= 2) + if (bs.getLineWidth() <= 2 && !(s instanceof ZoomableStroke)) s = ObjectCache.getInstance().fetchStroke((float) (bs.getLineWidth() / zoom), bs.getDashArray(), bs.getDashPhase()); } canvasGraphics.setStroke(s); diff --git a/diylc/diylc-library/lib/diylc-core.jar b/diylc/diylc-library/lib/diylc-core.jar index f7b0cf93..8e1a4bd9 100644 Binary files a/diylc/diylc-library/lib/diylc-core.jar and b/diylc/diylc-library/lib/diylc-core.jar differ diff --git a/diylc/diylc-library/src/org/diylc/components/passive/Resistor.java b/diylc/diylc-library/src/org/diylc/components/passive/Resistor.java index ac7427f7..be7eb36c 100644 --- a/diylc/diylc-library/src/org/diylc/components/passive/Resistor.java +++ b/diylc/diylc-library/src/org/diylc/components/passive/Resistor.java @@ -179,7 +179,7 @@ public class Resistor extends AbstractLeadedComponent { if (getShape() == ResistorShape.Standard) { int x = width + FIRST_BAND; Color[] bands = value.getColorCode(colorCode); - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2)); + g2d.setStroke(ObjectCache.getInstance().fetchZoomableStroke(2)); for (int i = 0; i < bands.length; i++) { g2d.setColor(bands[i]); g2d.drawLine(x, width / 10 + 2, x, width * 8 / 10 + 1); @@ -189,7 +189,7 @@ public class Resistor extends AbstractLeadedComponent { int x = -FIRST_BAND; int height = getClosestOdd(getWidth().convertToPixels()); Color[] bands = value.getColorCode(colorCode); - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2)); + g2d.setStroke(ObjectCache.getInstance().fetchZoomableStroke(2)); for (int i = 0; i < bands.length; i++) { g2d.setColor(bands[i]); g2d.drawLine(x, 1, x, height - 1); diff --git a/diylc/diylc-swing/lib/diylc-core.jar b/diylc/diylc-swing/lib/diylc-core.jar index f7b0cf93..8e1a4bd9 100644 Binary files a/diylc/diylc-swing/lib/diylc-core.jar and b/diylc/diylc-swing/lib/diylc-core.jar differ diff --git a/diylc/diylc-swing/library/main.jar b/diylc/diylc-swing/library/main.jar index 8aa0da3d..0f7f8061 100644 Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ diff --git a/diylc/diylc-swing/update.xml b/diylc/diylc-swing/update.xml index 66c2fc18..6f575a13 100644 --- a/diylc/diylc-swing/update.xml +++ b/diylc/diylc-swing/update.xml @@ -2146,6 +2146,10 @@ NEW_FEATURE "P-Bass Pickup" added + + IMPROVEMENT + Render resistor color bands properly when zommed in + https://github.com/bancika/diy-layout-creator/releases