mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
new fonts
cleaner lead rendering 3D shading for leaded components
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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.awt;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Paint;
|
||||||
|
import java.awt.PaintContext;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.image.ColorModel;
|
||||||
|
|
||||||
|
public class ShadedPaint implements Paint {
|
||||||
|
|
||||||
|
private ShadedPaintContext context;
|
||||||
|
private Point2D p1;
|
||||||
|
private Point2D p2;
|
||||||
|
private Color c1;
|
||||||
|
private Color c2;
|
||||||
|
|
||||||
|
public ShadedPaint(Point2D p1, Point2D p2, Color c, double shadeFactor) {
|
||||||
|
this.p1 = p1;
|
||||||
|
this.p2 = p2;
|
||||||
|
int r = c.getRed();
|
||||||
|
int g = c.getGreen();
|
||||||
|
int b = c.getBlue();
|
||||||
|
|
||||||
|
this.c1 = new Color(
|
||||||
|
Math.max((int) (r * shadeFactor), 0),
|
||||||
|
Math.max((int) (g * shadeFactor), 0),
|
||||||
|
Math.max((int) (b * shadeFactor), 0));
|
||||||
|
|
||||||
|
|
||||||
|
int i = (int)(1.0/(1.0-shadeFactor));
|
||||||
|
if ( r == 0 && g == 0 && b == 0) {
|
||||||
|
this.c2 = new Color(i, i, i);
|
||||||
|
} else {
|
||||||
|
if ( r > 0 && r < i ) r = i;
|
||||||
|
if ( g > 0 && g < i ) g = i;
|
||||||
|
if ( b > 0 && b < i ) b = i;
|
||||||
|
|
||||||
|
this.c2 = new Color(Math.min((int)(r / shadeFactor), 255),
|
||||||
|
Math.min((int)(g / shadeFactor), 255),
|
||||||
|
Math.min((int)(b / shadeFactor), 255));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShadedPaint(Point2D p1, Point2D p2, Color c2) {
|
||||||
|
this(p1, p2, c2, 0.9f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTransparency() {
|
||||||
|
return OPAQUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds,
|
||||||
|
AffineTransform xform, RenderingHints hints) {
|
||||||
|
if (context == null || !context.getColorModel().equals(cm))
|
||||||
|
context = new ShadedPaintContext(cm, p1, p2, xform, c1, c2);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,264 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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.awt;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.PaintContext;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.NoninvertibleTransformException;
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
import java.awt.image.ColorModel;
|
||||||
|
import java.awt.image.DirectColorModel;
|
||||||
|
import java.awt.image.Raster;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
import sun.awt.image.IntegerComponentRaster;
|
||||||
|
|
||||||
|
public class ShadedPaintContext implements PaintContext {
|
||||||
|
|
||||||
|
static ColorModel xrgbmodel =
|
||||||
|
new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff);
|
||||||
|
static ColorModel xbgrmodel =
|
||||||
|
new DirectColorModel(24, 0x000000ff, 0x0000ff00, 0x00ff0000);
|
||||||
|
|
||||||
|
static ColorModel cachedModel;
|
||||||
|
static WeakReference<Raster> cached;
|
||||||
|
|
||||||
|
static synchronized Raster getCachedRaster(ColorModel cm, int w, int h) {
|
||||||
|
if (cm == cachedModel) {
|
||||||
|
if (cached != null) {
|
||||||
|
Raster ras = (Raster) cached.get();
|
||||||
|
if (ras != null &&
|
||||||
|
ras.getWidth() >= w &&
|
||||||
|
ras.getHeight() >= h)
|
||||||
|
{
|
||||||
|
cached = null;
|
||||||
|
return ras;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cm.createCompatibleWritableRaster(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
static synchronized void putCachedRaster(ColorModel cm, Raster ras) {
|
||||||
|
if (cached != null) {
|
||||||
|
Raster cras = (Raster) cached.get();
|
||||||
|
if (cras != null) {
|
||||||
|
int cw = cras.getWidth();
|
||||||
|
int ch = cras.getHeight();
|
||||||
|
int iw = ras.getWidth();
|
||||||
|
int ih = ras.getHeight();
|
||||||
|
if (cw >= iw && ch >= ih) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (cw * ch >= iw * ih) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cachedModel = cm;
|
||||||
|
cached = new WeakReference<Raster>(ras);
|
||||||
|
}
|
||||||
|
|
||||||
|
double x1;
|
||||||
|
double y1;
|
||||||
|
double dx;
|
||||||
|
double dy;
|
||||||
|
int interp[];
|
||||||
|
Raster saved;
|
||||||
|
ColorModel model;
|
||||||
|
|
||||||
|
public ShadedPaintContext(ColorModel cm,
|
||||||
|
Point2D p1, Point2D p2, AffineTransform xform,
|
||||||
|
Color c1, Color c2) {
|
||||||
|
// First calculate the distance moved in user space when
|
||||||
|
// we move a single unit along the X & Y axes in device space.
|
||||||
|
Point2D xvec = new Point2D.Double(1, 0);
|
||||||
|
Point2D yvec = new Point2D.Double(0, 1);
|
||||||
|
try {
|
||||||
|
AffineTransform inverse = xform.createInverse();
|
||||||
|
inverse.deltaTransform(xvec, xvec);
|
||||||
|
inverse.deltaTransform(yvec, yvec);
|
||||||
|
} catch (NoninvertibleTransformException e) {
|
||||||
|
xvec.setLocation(0, 0);
|
||||||
|
yvec.setLocation(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now calculate the (square of the) user space distance
|
||||||
|
// between the anchor points. This value equals:
|
||||||
|
// (UserVec . UserVec)
|
||||||
|
double udx = p2.getX() - p1.getX();
|
||||||
|
double udy = p2.getY() - p1.getY();
|
||||||
|
double ulenSq = udx * udx + udy * udy;
|
||||||
|
|
||||||
|
if (ulenSq <= Double.MIN_VALUE) {
|
||||||
|
dx = 0;
|
||||||
|
dy = 0;
|
||||||
|
} else {
|
||||||
|
// Now calculate the proportional distance moved along the
|
||||||
|
// vector from p1 to p2 when we move a unit along X & Y in
|
||||||
|
// device space.
|
||||||
|
//
|
||||||
|
// The length of the projection of the Device Axis Vector is
|
||||||
|
// its dot product with the Unit User Vector:
|
||||||
|
// (DevAxisVec . (UserVec / Len(UserVec))
|
||||||
|
//
|
||||||
|
// The "proportional" length is that length divided again
|
||||||
|
// by the length of the User Vector:
|
||||||
|
// (DevAxisVec . (UserVec / Len(UserVec))) / Len(UserVec)
|
||||||
|
// which simplifies to:
|
||||||
|
// ((DevAxisVec . UserVec) / Len(UserVec)) / Len(UserVec)
|
||||||
|
// which simplifies to:
|
||||||
|
// (DevAxisVec . UserVec) / LenSquared(UserVec)
|
||||||
|
dx = (xvec.getX() * udx + xvec.getY() * udy) / ulenSq;
|
||||||
|
dy = (yvec.getX() * udx + yvec.getY() * udy) / ulenSq;
|
||||||
|
|
||||||
|
|
||||||
|
// We are acyclic
|
||||||
|
if (dx < 0) {
|
||||||
|
// If we are using the acyclic form below, we need
|
||||||
|
// dx to be non-negative for simplicity of scanning
|
||||||
|
// across the scan lines for the transition points.
|
||||||
|
// To ensure that constraint, we negate the dx/dy
|
||||||
|
// values and swap the points and colors.
|
||||||
|
Point2D p = p1; p1 = p2; p2 = p;
|
||||||
|
Color c = c1; c1 = c2; c2 = c;
|
||||||
|
dx = -dx;
|
||||||
|
dy = -dy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Point2D dp1 = xform.transform(p1, null);
|
||||||
|
this.x1 = dp1.getX();
|
||||||
|
this.y1 = dp1.getY();
|
||||||
|
|
||||||
|
int rgb1 = c1.getRGB();
|
||||||
|
int rgb2 = c2.getRGB();
|
||||||
|
int a1 = (rgb1 >> 24) & 0xff;
|
||||||
|
int r1 = (rgb1 >> 16) & 0xff;
|
||||||
|
int g1 = (rgb1 >> 8) & 0xff;
|
||||||
|
int b1 = (rgb1 ) & 0xff;
|
||||||
|
int da = ((rgb2 >> 24) & 0xff) - a1;
|
||||||
|
int dr = ((rgb2 >> 16) & 0xff) - r1;
|
||||||
|
int dg = ((rgb2 >> 8) & 0xff) - g1;
|
||||||
|
int db = ((rgb2 ) & 0xff) - b1;
|
||||||
|
if (a1 == 0xff && da == 0) {
|
||||||
|
model = xrgbmodel;
|
||||||
|
if (cm instanceof DirectColorModel) {
|
||||||
|
DirectColorModel dcm = (DirectColorModel) cm;
|
||||||
|
int tmp = dcm.getAlphaMask();
|
||||||
|
if ((tmp == 0 || tmp == 0xff) &&
|
||||||
|
dcm.getRedMask() == 0xff &&
|
||||||
|
dcm.getGreenMask() == 0xff00 &&
|
||||||
|
dcm.getBlueMask() == 0xff0000)
|
||||||
|
{
|
||||||
|
model = xbgrmodel;
|
||||||
|
tmp = r1; r1 = b1; b1 = tmp;
|
||||||
|
tmp = dr; dr = db; db = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
model = ColorModel.getRGBdefault();
|
||||||
|
}
|
||||||
|
interp = new int[257];
|
||||||
|
for (int i = 0; i <= 256; i++) {
|
||||||
|
float rel = i / 256.0f;
|
||||||
|
int rgb =
|
||||||
|
(((int) (a1 + da * rel)) << 24) |
|
||||||
|
(((int) (r1 + dr * rel)) << 16) |
|
||||||
|
(((int) (g1 + dg * rel)) << 8) |
|
||||||
|
(((int) (b1 + db * rel)) );
|
||||||
|
interp[i] = rgb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release the resources allocated for the operation.
|
||||||
|
*/
|
||||||
|
public void dispose() {
|
||||||
|
if (saved != null) {
|
||||||
|
putCachedRaster(model, saved);
|
||||||
|
saved = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the ColorModel of the output.
|
||||||
|
*/
|
||||||
|
public ColorModel getColorModel() {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a Raster containing the colors generated for the graphics
|
||||||
|
* operation.
|
||||||
|
* @param x,y,w,h The area in device space for which colors are
|
||||||
|
* generated.
|
||||||
|
*/
|
||||||
|
public Raster getRaster(int x, int y, int w, int h) {
|
||||||
|
double rowrel = (x - x1) * dx + (y - y1) * dy;
|
||||||
|
|
||||||
|
Raster rast = saved;
|
||||||
|
if (rast == null || rast.getWidth() < w || rast.getHeight() < h) {
|
||||||
|
rast = getCachedRaster(model, w, h);
|
||||||
|
saved = rast;
|
||||||
|
}
|
||||||
|
IntegerComponentRaster irast = (IntegerComponentRaster) rast;
|
||||||
|
int off = irast.getDataOffset(0);
|
||||||
|
int adjust = irast.getScanlineStride() - w;
|
||||||
|
int[] pixels = irast.getDataStorage();
|
||||||
|
|
||||||
|
clipFillRaster(pixels, off, adjust, w, h, rowrel, dx, dy);
|
||||||
|
|
||||||
|
// irast.markDirty();
|
||||||
|
|
||||||
|
return rast;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clipFillRaster(int[] pixels, int off, int adjust, int w, int h,
|
||||||
|
double rowrel, double dx, double dy) {
|
||||||
|
while (--h >= 0) {
|
||||||
|
double colrel = rowrel;
|
||||||
|
int j = w;
|
||||||
|
if (colrel <= 0.0) {
|
||||||
|
int rgb = interp[0];
|
||||||
|
do {
|
||||||
|
pixels[off++] = rgb;
|
||||||
|
colrel += dx;
|
||||||
|
} while (--j > 0 && colrel <= 0.0);
|
||||||
|
}
|
||||||
|
while (colrel < 1.0 && --j >= 0) {
|
||||||
|
pixels[off++] = interp[(int) (colrel < 0.5 ? colrel * 2 * 256 : (2 - colrel * 2) * 256)];
|
||||||
|
colrel += dx;
|
||||||
|
}
|
||||||
|
if (j > 0) {
|
||||||
|
int rgb = interp[256];
|
||||||
|
do {
|
||||||
|
pixels[off++] = rgb;
|
||||||
|
} while (--j > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
off += adjust;
|
||||||
|
rowrel += dy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+34
-29
@@ -28,7 +28,9 @@ import java.awt.Rectangle;
|
|||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
import java.awt.Stroke;
|
import java.awt.Stroke;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Area;
|
||||||
import java.awt.geom.Ellipse2D;
|
import java.awt.geom.Ellipse2D;
|
||||||
|
import java.awt.geom.Line2D;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
@@ -147,16 +149,30 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
float leadThickness = getLeadThickness();
|
float leadThickness = getLeadThickness();
|
||||||
double leadLength = (distance - calculatePinSpacing(shapeRect)) / 2;
|
double leadLength = (distance - calculatePinSpacing(shapeRect)) / 2;
|
||||||
|
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
|
||||||
Color leadColor =
|
|
||||||
shouldShadeLeads() ? getLeadColorForPainting(componentState).darker()
|
|
||||||
: getLeadColorForPainting(componentState);
|
|
||||||
g2d.setColor(leadColor);
|
|
||||||
drawLeads(g2d, theta, leadLength);
|
|
||||||
|
|
||||||
if (shouldShadeLeads()) {
|
if (shouldShadeLeads()) {
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
Stroke leadStroke = ObjectCache.getInstance().fetchBasicStroke(leadThickness - 1);
|
||||||
leadColor = getLeadColorForPainting(componentState);
|
Color leadColor = getLeadColorForPainting(componentState);
|
||||||
|
|
||||||
|
Area leadArea = new Area();
|
||||||
|
|
||||||
|
int endX = (int) (points[0].x + Math.cos(theta) * leadLength);
|
||||||
|
int endY = (int) (points[0].y + Math.sin(theta) * leadLength);
|
||||||
|
Line2D line = new Line2D.Double(points[0].x, points[0].y, endX, endY);
|
||||||
|
leadArea.add(new Area(leadStroke.createStrokedShape(line)));
|
||||||
|
|
||||||
|
endX = (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength);
|
||||||
|
endY = (int) (points[1].y + Math.sin(theta - Math.PI) * leadLength);
|
||||||
|
line = new Line2D.Double(points[1].x, points[1].y, endX, endY);
|
||||||
|
leadArea.add(new Area(leadStroke.createStrokedShape(line)));
|
||||||
|
|
||||||
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f));
|
||||||
|
g2d.setColor(leadColor);
|
||||||
|
g2d.fill(leadArea);
|
||||||
|
g2d.setColor(leadColor.darker());
|
||||||
|
g2d.draw(leadArea);
|
||||||
|
} else {
|
||||||
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||||
|
Color leadColor = getLeadColorForPainting(componentState);
|
||||||
g2d.setColor(leadColor);
|
g2d.setColor(leadColor);
|
||||||
drawLeads(g2d, theta, leadLength);
|
drawLeads(g2d, theta, leadLength);
|
||||||
}
|
}
|
||||||
@@ -278,7 +294,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
if (isCopperArea)
|
if (isCopperArea)
|
||||||
observer.startTrackingContinuityArea(true);
|
observer.startTrackingContinuityArea(true);
|
||||||
|
|
||||||
float thickness = getLeadThickness();
|
float thickness = getLeadThickness() - 1;
|
||||||
Stroke stroke = null;
|
Stroke stroke = null;
|
||||||
switch (getStyle()) {
|
switch (getStyle()) {
|
||||||
case SOLID:
|
case SOLID:
|
||||||
@@ -293,33 +309,22 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
g2d.setStroke(stroke);
|
Line2D line = new Line2D.Double(points[0].x, points[0].y, points[1].x, points[1].y);
|
||||||
|
Shape lineShape = stroke.createStrokedShape(line);
|
||||||
|
|
||||||
Color leadColor =
|
Color leadColor =
|
||||||
shouldShadeLeads() ? getLeadColorForPainting(componentState).darker() : getLeadColorForPainting(componentState);
|
shouldShadeLeads() ? getLeadColorForPainting(componentState) : getLeadColorForPainting(componentState);
|
||||||
g2d.setColor(leadColor);
|
g2d.setColor(leadColor);
|
||||||
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
|
g2d.fill(lineShape);
|
||||||
|
|
||||||
if (isCopperArea)
|
if (isCopperArea)
|
||||||
observer.stopTrackingContinuityArea();
|
observer.stopTrackingContinuityArea();
|
||||||
|
|
||||||
if (shouldShadeLeads()) {
|
if (shouldShadeLeads()) {
|
||||||
switch (getStyle()) {
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f));
|
||||||
case SOLID:
|
|
||||||
stroke = ObjectCache.getInstance().fetchBasicStroke(thickness - 2);
|
|
||||||
break;
|
|
||||||
case DASHED:
|
|
||||||
stroke =
|
|
||||||
ObjectCache.getInstance().fetchStroke(thickness - 2, new float[] {thickness * 2, thickness * 4},
|
|
||||||
thickness * 4);
|
|
||||||
break;
|
|
||||||
case DOTTED:
|
|
||||||
stroke = ObjectCache.getInstance().fetchStroke(thickness - 2, new float[] {thickness / 4, thickness * 4}, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
g2d.setStroke(stroke);
|
|
||||||
leadColor = getLeadColorForPainting(componentState);
|
leadColor = getLeadColorForPainting(componentState);
|
||||||
g2d.setColor(leadColor);
|
g2d.setColor(leadColor.darker());
|
||||||
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
|
g2d.draw(lineShape);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@ package org.diylc.components.connectivity;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Shape;
|
||||||
import java.awt.Stroke;
|
import java.awt.Stroke;
|
||||||
import java.awt.geom.Path2D;
|
import java.awt.geom.Path2D;
|
||||||
|
|
||||||
@@ -54,10 +55,10 @@ public class HookupWire extends AbstractCurvedComponent<Void> {
|
|||||||
@Override
|
@Override
|
||||||
protected void drawCurve(Path2D curve, Graphics2D g2d, ComponentState componentState, IDrawingObserver drawingObserver) {
|
protected void drawCurve(Path2D curve, Graphics2D g2d, ComponentState componentState, IDrawingObserver drawingObserver) {
|
||||||
int thickness =
|
int thickness =
|
||||||
(int) (Math.pow(Math.E, -1.12436 - 0.11594 * gauge.getValue()) * Constants.PIXELS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT));
|
(int) (Math.pow(Math.E, -1.12436 - 0.11594 * gauge.getValue()) * Constants.PIXELS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT)) - 1;
|
||||||
Color curveColor =
|
Color curveColor =
|
||||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||||
: color.darker();
|
: color;
|
||||||
g2d.setColor(curveColor);
|
g2d.setColor(curveColor);
|
||||||
Stroke stroke = null;
|
Stroke stroke = null;
|
||||||
switch (getStyle()) {
|
switch (getStyle()) {
|
||||||
@@ -72,24 +73,25 @@ public class HookupWire extends AbstractCurvedComponent<Void> {
|
|||||||
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness / 4, thickness * 3}, 0);
|
stroke = ObjectCache.getInstance().fetchStroke(thickness, new float[] {thickness / 4, thickness * 3}, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
g2d.setStroke(stroke);
|
Shape s = stroke.createStrokedShape(curve);
|
||||||
g2d.draw(curve);
|
g2d.fill(s);
|
||||||
if (componentState == ComponentState.NORMAL) {
|
if (componentState == ComponentState.NORMAL) {
|
||||||
g2d.setColor(color);
|
g2d.setColor(color.darker());
|
||||||
switch (getStyle()) {
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f));
|
||||||
case SOLID:
|
// switch (getStyle()) {
|
||||||
stroke = ObjectCache.getInstance().fetchBasicStroke(thickness - 2);
|
// case SOLID:
|
||||||
break;
|
// stroke = ObjectCache.getInstance().fetchBasicStroke(thickness - 2);
|
||||||
case DASHED:
|
// break;
|
||||||
stroke =
|
// case DASHED:
|
||||||
ObjectCache.getInstance().fetchStroke(thickness - 2, new float[] {thickness * 2, thickness * 3},
|
// stroke =
|
||||||
thickness * 4);
|
// ObjectCache.getInstance().fetchStroke(thickness - 2, new float[] {thickness * 2, thickness * 3},
|
||||||
break;
|
// thickness * 4);
|
||||||
case DOTTED:
|
// break;
|
||||||
stroke = ObjectCache.getInstance().fetchStroke(thickness - 2, new float[] {thickness / 4, thickness * 3}, 0);
|
// case DOTTED:
|
||||||
}
|
// stroke = ObjectCache.getInstance().fetchStroke(thickness - 2, new float[] {thickness / 4, thickness * 3}, 0);
|
||||||
g2d.setStroke(stroke);
|
// }
|
||||||
g2d.draw(curve);
|
// g2d.setStroke(stroke);
|
||||||
|
g2d.draw(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user