mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Better lead and label rendering when lead spacing is smaller than component body
This commit is contained in:
+36
-28
@@ -143,6 +143,41 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
}
|
}
|
||||||
g2d.setColor(finalBorderColor);
|
g2d.setColor(finalBorderColor);
|
||||||
g2d.draw(shape);
|
g2d.draw(shape);
|
||||||
|
|
||||||
|
// Go back to the original transformation to draw leads.
|
||||||
|
if (!outlineMode) {
|
||||||
|
AffineTransform textTransform = g2d.getTransform();
|
||||||
|
g2d.setTransform(oldTransform);
|
||||||
|
if (length.convertToPixels() > points[0].distance(points[1])) {
|
||||||
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
|
||||||
|
}
|
||||||
|
int leadThickness = getClosestOdd(getLeadThickness());
|
||||||
|
double leadLength = (distance - shapeRect.width) / 2 - leadThickness / 2;
|
||||||
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||||
|
Color leadColor = shouldShadeLeads() ? getLeadColor(componentState).darker()
|
||||||
|
: getLeadColor(componentState);
|
||||||
|
g2d.setColor(leadColor);
|
||||||
|
int endX = (int) (points[0].x + Math.cos(theta) * leadLength);
|
||||||
|
int endY = (int) Math.round(points[0].y + Math.sin(theta) * leadLength);
|
||||||
|
g2d.drawLine(points[0].x, points[0].y, endX, endY);
|
||||||
|
endX = (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength);
|
||||||
|
endY = (int) Math.round(points[1].y + Math.sin(theta - Math.PI) * leadLength);
|
||||||
|
g2d.drawLine(points[1].x, points[1].y, endX, endY);
|
||||||
|
if (shouldShadeLeads()) {
|
||||||
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||||
|
leadColor = getLeadColor(componentState);
|
||||||
|
g2d.setColor(leadColor);
|
||||||
|
g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + Math.cos(theta)
|
||||||
|
* leadLength), (int) (points[0].y + Math.sin(theta) * leadLength));
|
||||||
|
g2d.drawLine(points[1].x, points[1].y, (int) (points[1].x + Math.cos(theta
|
||||||
|
- Math.PI)
|
||||||
|
* leadLength), (int) (points[1].y + Math.sin(theta - Math.PI)
|
||||||
|
* leadLength));
|
||||||
|
}
|
||||||
|
g2d.setComposite(oldComposite);
|
||||||
|
g2d.setTransform(textTransform);
|
||||||
|
}
|
||||||
|
|
||||||
// Draw label.
|
// Draw label.
|
||||||
g2d.setFont(LABEL_FONT);
|
g2d.setFont(LABEL_FONT);
|
||||||
Color finalLabelColor;
|
Color finalLabelColor;
|
||||||
@@ -168,34 +203,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
|
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
|
||||||
g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) / 2,
|
g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) / 2,
|
||||||
calculateLabelYCoordinate(shapeRect, textRect, fontMetrics));
|
calculateLabelYCoordinate(shapeRect, textRect, fontMetrics));
|
||||||
|
g2d.setTransform(oldTransform);
|
||||||
// Go back to the original transformation to draw leads.
|
|
||||||
if (!outlineMode) {
|
|
||||||
g2d.setTransform(oldTransform);
|
|
||||||
int leadThickness = getClosestOdd(getLeadThickness());
|
|
||||||
double leadLength = (distance - shapeRect.width) / 2 - leadThickness / 2;
|
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
|
||||||
Color leadColor = shouldShadeLeads() ? getLeadColor(componentState).darker()
|
|
||||||
: getLeadColor(componentState);
|
|
||||||
g2d.setColor(leadColor);
|
|
||||||
int endX = (int) (points[0].x + Math.cos(theta) * leadLength);
|
|
||||||
int endY = (int) Math.round(points[0].y + Math.sin(theta) * leadLength);
|
|
||||||
g2d.drawLine(points[0].x, points[0].y, endX, endY);
|
|
||||||
endX = (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength);
|
|
||||||
endY = (int) Math.round(points[1].y + Math.sin(theta - Math.PI) * leadLength);
|
|
||||||
g2d.drawLine(points[1].x, points[1].y, endX, endY);
|
|
||||||
if (shouldShadeLeads()) {
|
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
|
||||||
leadColor = getLeadColor(componentState);
|
|
||||||
g2d.setColor(leadColor);
|
|
||||||
g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + Math.cos(theta)
|
|
||||||
* leadLength), (int) (points[0].y + Math.sin(theta) * leadLength));
|
|
||||||
g2d.drawLine(points[1].x, points[1].y, (int) (points[1].x + Math.cos(theta
|
|
||||||
- Math.PI)
|
|
||||||
* leadLength), (int) (points[1].y + Math.sin(theta - Math.PI)
|
|
||||||
* leadLength));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -390,6 +390,10 @@
|
|||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Select All should not include locked components</description>
|
<description>Select All should not include locked components</description>
|
||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
|
<com.diyfever.gui.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Better lead and label rendering when lead spacing is smaller than component body</description>
|
||||||
|
</com.diyfever.gui.update.Change>
|
||||||
</changes>
|
</changes>
|
||||||
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url>
|
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url>
|
||||||
</com.diyfever.gui.update.Version>
|
</com.diyfever.gui.update.Version>
|
||||||
|
|||||||
Reference in New Issue
Block a user