mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
Ability to change resistor shape (tubular or standard "dog bone")
This commit is contained in:
@@ -258,7 +258,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) width);
|
int offset = outlineMode ? 0 : getLabelOffset((int) length, (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);
|
||||||
|
|||||||
Binary file not shown.
@@ -154,10 +154,10 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
if (colorCode == ResistorColorCode.NONE || outlineMode || value == null) {
|
if (colorCode == ResistorColorCode.NONE || outlineMode || value == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
int width = getClosestOdd(getWidth().convertToPixels());
|
||||||
if (shape == ResistorShape.Standard) {
|
if (shape == ResistorShape.Standard) {
|
||||||
int width = getClosestOdd(getWidth().convertToPixels());
|
|
||||||
Color[] bands = value.getColorCode(colorCode);
|
|
||||||
int x = width + FIRST_BAND;
|
int x = width + FIRST_BAND;
|
||||||
|
Color[] bands = value.getColorCode(colorCode);
|
||||||
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]);
|
||||||
@@ -165,9 +165,9 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
x += BAND_SPACING;
|
x += BAND_SPACING;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
int x = -FIRST_BAND;
|
||||||
int height = getClosestOdd(getWidth().convertToPixels());
|
int height = getClosestOdd(getWidth().convertToPixels());
|
||||||
Color[] bands = value.getColorCode(colorCode);
|
Color[] bands = value.getColorCode(colorCode);
|
||||||
int x = 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]);
|
||||||
@@ -183,11 +183,11 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
|
|||||||
return 0;
|
return 0;
|
||||||
int width = getClosestOdd(getWidth().convertToPixels());
|
int width = getClosestOdd(getWidth().convertToPixels());
|
||||||
Color[] bands = value.getColorCode(colorCode);
|
Color[] bands = value.getColorCode(colorCode);
|
||||||
int bandArea = width + FIRST_BAND + BAND_SPACING * (bands.length - 1);
|
int bandArea =
|
||||||
// Only offset the label if overlapping with the band area.
|
shape == ResistorShape.Standard ? width + FIRST_BAND + BAND_SPACING * (bands.length - 1) : -FIRST_BAND
|
||||||
if (labelWidth > bodyWidth - 2 * bandArea)
|
+ BAND_SPACING * (bands.length - 1);
|
||||||
return BAND_SPACING * (bands.length - 1);
|
|
||||||
return 0;
|
return (bodyWidth - bandArea - labelWidth) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty(name = "Reverse (standing)")
|
@EditableProperty(name = "Reverse (standing)")
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user