mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
Improved resistor rendering to look more realistic
This commit is contained in:
@@ -3,6 +3,8 @@ 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.geom.Area;
|
||||||
|
import java.awt.geom.Ellipse2D;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
import org.diylc.common.ObjectCache;
|
import org.diylc.common.ObjectCache;
|
||||||
@@ -30,7 +32,7 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
public static Color BODY_COLOR = Color.decode("#82CFFD");
|
public static Color BODY_COLOR = Color.decode("#82CFFD");
|
||||||
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||||
public static int BAND_SPACING = 5;
|
public static int BAND_SPACING = 5;
|
||||||
public static int FIRST_BAND = 4;
|
public static int FIRST_BAND = -4;
|
||||||
|
|
||||||
private Resistance value = null;
|
private Resistance value = null;
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@@ -87,15 +89,18 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
g2d.setColor(LEAD_COLOR_ICON);
|
g2d.setColor(LEAD_COLOR_ICON);
|
||||||
g2d.drawLine(0, height / 2, width, height / 2);
|
g2d.drawLine(0, height / 2, width, height / 2);
|
||||||
g2d.setColor(BODY_COLOR);
|
g2d.setColor(BODY_COLOR);
|
||||||
g2d.fillRect(4, height / 2 - 3, width - 8, 6);
|
Area a = new Area(new Rectangle2D.Double(6, height / 2 - 3, width - 14, 6));
|
||||||
|
a.add(new Area(new Ellipse2D.Double(4, height / 2 - 4, 8, 8)));
|
||||||
|
a.add(new Area(new Ellipse2D.Double(width - 12, height / 2 - 4, 8, 8)));
|
||||||
|
g2d.fill(a);
|
||||||
g2d.setColor(Color.red);
|
g2d.setColor(Color.red);
|
||||||
g2d.drawLine(7, height / 2 - 3, 7, height / 2 + 3);
|
|
||||||
g2d.setColor(Color.orange);
|
|
||||||
g2d.drawLine(11, height / 2 - 3, 11, height / 2 + 3);
|
g2d.drawLine(11, height / 2 - 3, 11, height / 2 + 3);
|
||||||
|
g2d.setColor(Color.orange);
|
||||||
|
g2d.drawLine(14, height / 2 - 3, 14, height / 2 + 3);
|
||||||
g2d.setColor(Color.black);
|
g2d.setColor(Color.black);
|
||||||
g2d.drawLine(15, height / 2 - 3, 15, height / 2 + 3);
|
g2d.drawLine(17, height / 2 - 3, 17, height / 2 + 3);
|
||||||
g2d.setColor(BORDER_COLOR);
|
g2d.setColor(BORDER_COLOR);
|
||||||
g2d.drawRect(4, height / 2 - 3, width - 8, 6);
|
g2d.draw(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -119,7 +124,13 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Shape getBodyShape() {
|
protected Shape getBodyShape() {
|
||||||
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth().convertToPixels()));
|
double length = getLength().convertToPixels();
|
||||||
|
double width = getClosestOdd(getWidth().convertToPixels());
|
||||||
|
Rectangle2D rect = new Rectangle2D.Double(width / 2, width / 10, length - width, width * 8 / 10);
|
||||||
|
Area a = new Area(rect);
|
||||||
|
a.add(new Area(new Ellipse2D.Double(0, 0, width, width)));
|
||||||
|
a.add(new Area(new Ellipse2D.Double(length - width, 0, width, width)));
|
||||||
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -128,13 +139,13 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
if (colorCode == ResistorColorCode.NONE || outlineMode || value == null) {
|
if (colorCode == ResistorColorCode.NONE || outlineMode || value == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int height = getClosestOdd(getWidth().convertToPixels());
|
int width = getClosestOdd(getWidth().convertToPixels());
|
||||||
Color[] bands = value.getColorCode(colorCode);
|
Color[] bands = value.getColorCode(colorCode);
|
||||||
int x = FIRST_BAND;
|
int x = width + FIRST_BAND;
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
|
||||||
for (int i = 0; i < bands.length; i++) {
|
for (int i = 0; i < bands.length; i++) {
|
||||||
g2d.setColor(bands[i]);
|
g2d.setColor(bands[i]);
|
||||||
g2d.drawLine(x, 1, x, height - 1);
|
g2d.drawLine(x, width / 10 + 2, x, width * 8 / 10 + 1);
|
||||||
x += BAND_SPACING;
|
x += BAND_SPACING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,11 +154,12 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
protected int getLabelOffset(int bodyWidth, int labelWidth) {
|
protected int getLabelOffset(int bodyWidth, int labelWidth) {
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
int width = getClosestOdd(getWidth().convertToPixels());
|
||||||
Color[] bands = value.getColorCode(colorCode);
|
Color[] bands = value.getColorCode(colorCode);
|
||||||
int bandArea = FIRST_BAND + BAND_SPACING * (bands.length - 1);
|
int bandArea = width + FIRST_BAND + BAND_SPACING * (bands.length - 1);
|
||||||
// Only offset the label if overlaping with the band area.
|
// Only offset the label if overlapping with the band area.
|
||||||
if (labelWidth > bodyWidth - 2 * bandArea)
|
if (labelWidth > bodyWidth - 2 * bandArea)
|
||||||
return bandArea / 2;
|
return BAND_SPACING * (bands.length - 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1582,6 +1582,10 @@
|
|||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Improved rotation and mirroring of multiple components at the same time</description>
|
<description>Improved rotation and mirroring of multiple components at the same time</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Improved resistor rendering to look more realistic</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
</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>
|
||||||
|
|||||||
Reference in New Issue
Block a user