mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Render resistor color bands properly when zommed in
This commit is contained in:
@@ -43,6 +43,7 @@ public class ObjectCache {
|
||||
private ObjectCache() {}
|
||||
|
||||
private Map<Float, Stroke> basicStrokeMap = new HashMap<Float, Stroke>();
|
||||
private Map<Float, Stroke> zoomableStrokeMap = new HashMap<Float, Stroke>();
|
||||
private Map<String, Stroke> dashStrokeMap = new HashMap<String, Stroke>();
|
||||
|
||||
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;
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user