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);
|
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
|
||||||
// Don't offset in outline mode.
|
// 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.
|
// 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)) {
|
if ((theta >= Math.PI / 2 && theta <= Math.PI) || (theta < -Math.PI / 2 && theta > -Math.PI)) {
|
||||||
g2d.rotate(Math.PI, length / 2, width / 2);
|
g2d.rotate(Math.PI, length / 2, width / 2);
|
||||||
@@ -348,7 +348,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getLabelOffset(int bodyWidth, int labelWidth) {
|
protected int getLabelOffset(int bodyLength, int bodyWidth, int labelLength) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ package org.diylc.components.passive;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
|
import java.awt.Stroke;
|
||||||
import java.awt.geom.Area;
|
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.common.ObjectCache;
|
import org.diylc.common.ObjectCache;
|
||||||
@@ -171,42 +173,40 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
|
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
|
||||||
// int width = getWidth().convertToPixels();
|
|
||||||
if (colorCode == ResistorColorCode.NONE || outlineMode || value == null) {
|
if (colorCode == ResistorColorCode.NONE || outlineMode || value == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Area body = new Area(getBodyShape());
|
||||||
|
Stroke stroke = ObjectCache.getInstance().fetchZoomableStroke(2);
|
||||||
int width = getClosestOdd(getWidth().convertToPixels());
|
int width = getClosestOdd(getWidth().convertToPixels());
|
||||||
if (getShape() == ResistorShape.Standard) {
|
int x = getShape() == ResistorShape.Standard ? width + FIRST_BAND : -FIRST_BAND;
|
||||||
int x = width + FIRST_BAND;
|
Color[] bands = value.getColorCode(colorCode);
|
||||||
Color[] bands = value.getColorCode(colorCode);
|
for (int i = 0; i < bands.length; i++) {
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchZoomableStroke(2));
|
g2d.setColor(bands[i]);
|
||||||
for (int i = 0; i < bands.length; i++) {
|
Area line = new Area(stroke.createStrokedShape(new Line2D.Double(x, 0, x, width)));
|
||||||
g2d.setColor(bands[i]);
|
line.intersect(body);
|
||||||
g2d.drawLine(x, width / 10 + 2, x, width * 8 / 10 + 1);
|
g2d.fill(line);
|
||||||
x += BAND_SPACING;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getLabelOffset(int bodyWidth, int labelWidth) {
|
protected int getLabelOffset(int bodyLength, int bodyWidth, int labelLength) {
|
||||||
if (value == null || getColorCode() == ResistorColorCode.NONE || getLabelOriantation() != AbstractLeadedComponent.LabelOriantation.Directional)
|
if (value == null || getColorCode() == ResistorColorCode.NONE || getLabelOriantation() != AbstractLeadedComponent.LabelOriantation.Directional)
|
||||||
return 0;
|
return 0;
|
||||||
int width = getClosestOdd(getWidth().convertToPixels());
|
|
||||||
Color[] bands = value.getColorCode(colorCode);
|
Color[] bands = value.getColorCode(colorCode);
|
||||||
int bandArea =
|
|
||||||
getShape() == ResistorShape.Standard ? width + FIRST_BAND + BAND_SPACING * (bands.length - 1) : -FIRST_BAND
|
int bandLenght = FIRST_BAND + BAND_SPACING * (bands.length - 1);
|
||||||
+ 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;
|
return bandArea / 2;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -2203,7 +2203,7 @@
|
|||||||
<minor>49</minor>
|
<minor>49</minor>
|
||||||
<build>0</build>
|
<build>0</build>
|
||||||
</versionNumber>
|
</versionNumber>
|
||||||
<releaseDate>2018-12-26 00:00:00.000 CET</releaseDate>
|
<releaseDate>2019-01-16 00:00:00.000 CET</releaseDate>
|
||||||
<name></name>
|
<name></name>
|
||||||
<changes>
|
<changes>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
@@ -2236,7 +2236,7 @@
|
|||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<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>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
@@ -2249,5 +2249,21 @@
|
|||||||
</changes>
|
</changes>
|
||||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||||
</org.diylc.appframework.update.Version>
|
</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>
|
</a>
|
||||||
</java.util.Arrays_-ArrayList>
|
</java.util.Arrays_-ArrayList>
|
||||||
|
|||||||
Reference in New Issue
Block a user