mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
Better color band rendering on resistors and smarter label positioning
This commit is contained in:
@@ -260,7 +260,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
}
|
||||
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
|
||||
// Don't offset in outline mode.
|
||||
int offset = outlineMode ? 0 : getLabelOffset((int) length, (int) textRect.getWidth());
|
||||
int offset = outlineMode ? 0 : getLabelOffset((int) length, (int) width, (int) textRect.getWidth());
|
||||
// Adjust label angle if needed to make sure that it's readable.
|
||||
if ((theta >= Math.PI / 2 && theta <= Math.PI) || (theta < -Math.PI / 2 && theta > -Math.PI)) {
|
||||
g2d.rotate(Math.PI, length / 2, width / 2);
|
||||
@@ -348,7 +348,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
return false;
|
||||
}
|
||||
|
||||
protected int getLabelOffset(int bodyWidth, int labelWidth) {
|
||||
protected int getLabelOffset(int bodyLength, int bodyWidth, int labelLength) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,12 @@ package org.diylc.components.passive;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.ResistorColorCode;
|
||||
import org.diylc.common.SimpleComponentTransformer;
|
||||
@@ -171,43 +173,41 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
||||
|
||||
@Override
|
||||
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
|
||||
// int width = getWidth().convertToPixels();
|
||||
if (colorCode == ResistorColorCode.NONE || outlineMode || value == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Area body = new Area(getBodyShape());
|
||||
Stroke stroke = ObjectCache.getInstance().fetchZoomableStroke(2);
|
||||
int width = getClosestOdd(getWidth().convertToPixels());
|
||||
if (getShape() == ResistorShape.Standard) {
|
||||
int x = width + FIRST_BAND;
|
||||
Color[] bands = value.getColorCode(colorCode);
|
||||
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);
|
||||
x += BAND_SPACING;
|
||||
}
|
||||
} else {
|
||||
int x = -FIRST_BAND;
|
||||
int height = getClosestOdd(getWidth().convertToPixels());
|
||||
Color[] bands = value.getColorCode(colorCode);
|
||||
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);
|
||||
x += BAND_SPACING;
|
||||
}
|
||||
}
|
||||
int x = getShape() == ResistorShape.Standard ? width + FIRST_BAND : -FIRST_BAND;
|
||||
Color[] bands = value.getColorCode(colorCode);
|
||||
for (int i = 0; i < bands.length; i++) {
|
||||
g2d.setColor(bands[i]);
|
||||
Area line = new Area(stroke.createStrokedShape(new Line2D.Double(x, 0, x, width)));
|
||||
line.intersect(body);
|
||||
g2d.fill(line);
|
||||
x += BAND_SPACING;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLabelOffset(int bodyWidth, int labelWidth) {
|
||||
if (value == null || getColorCode() == ResistorColorCode.NONE || getLabelOriantation() != AbstractLeadedComponent.LabelOriantation.Directional)
|
||||
return 0;
|
||||
int width = getClosestOdd(getWidth().convertToPixels());
|
||||
Color[] bands = value.getColorCode(colorCode);
|
||||
int bandArea =
|
||||
getShape() == ResistorShape.Standard ? width + FIRST_BAND + BAND_SPACING * (bands.length - 1) : -FIRST_BAND
|
||||
+ BAND_SPACING * (bands.length - 1);
|
||||
|
||||
protected int getLabelOffset(int bodyLength, int bodyWidth, int labelLength) {
|
||||
if (value == null || getColorCode() == ResistorColorCode.NONE || getLabelOriantation() != AbstractLeadedComponent.LabelOriantation.Directional)
|
||||
return 0;
|
||||
Color[] bands = value.getColorCode(colorCode);
|
||||
|
||||
int bandLenght = FIRST_BAND + BAND_SPACING * (bands.length - 1);
|
||||
|
||||
if (getShape() == ResistorShape.Standard) {
|
||||
if (labelLength < bodyLength - 2 * bodyWidth - bandLenght)
|
||||
return bandLenght;
|
||||
} else {
|
||||
if (labelLength < bodyLength - bandLenght)
|
||||
return bandLenght;
|
||||
}
|
||||
|
||||
int bandArea = getShape() == ResistorShape.Standard ? bodyWidth + bandLenght : -bandLenght;
|
||||
|
||||
return bandArea / 2;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
@@ -2203,7 +2203,7 @@
|
||||
<minor>49</minor>
|
||||
<build>0</build>
|
||||
</versionNumber>
|
||||
<releaseDate>2018-12-26 00:00:00.000 CET</releaseDate>
|
||||
<releaseDate>2019-01-16 00:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<org.diylc.appframework.update.Change>
|
||||
@@ -2236,7 +2236,7 @@
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Use hardware acceleration for rendering to improve performance</description>
|
||||
<description>Use hardware acceleration for rendering to improve performance and reduce memory usage</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
@@ -2248,6 +2248,22 @@
|
||||
</org.diylc.appframework.update.Change>
|
||||
</changes>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||
</org.diylc.appframework.update.Version>
|
||||
<org.diylc.appframework.update.Version>
|
||||
<versionNumber>
|
||||
<major>3</major>
|
||||
<minor>50</minor>
|
||||
<build>0</build>
|
||||
</versionNumber>
|
||||
<releaseDate>2019-01-16 00:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Better color band rendering on resistors and smarter label positioning</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
</changes>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||
</org.diylc.appframework.update.Version>
|
||||
</a>
|
||||
</java.util.Arrays_-ArrayList>
|
||||
|
||||
Reference in New Issue
Block a user