mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
draw leads on the top, useful for radial components
This commit is contained in:
@@ -7,12 +7,12 @@
|
|||||||
</org.diylc.core.measures.Resistance>
|
</org.diylc.core.measures.Resistance>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>lastPath</string>
|
<string>metric</string>
|
||||||
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
<boolean>false</boolean>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>metric</string>
|
<string>lastPath</string>
|
||||||
<boolean>true</boolean>
|
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>default.org.diylc.components.passive.AxialFilmCapacitor:Width</string>
|
<string>default.org.diylc.components.passive.AxialFilmCapacitor:Width</string>
|
||||||
|
|||||||
Binary file not shown.
+48
-48
@@ -52,6 +52,54 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
||||||
|
g2d.setStroke(new BasicStroke(getLeadThickness().convertToPixels()));
|
||||||
|
double distance = points[0].distance(points[1]);
|
||||||
|
Shape shape = getBodyShape();
|
||||||
|
if (shape == null) {
|
||||||
|
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Rectangle shapeRect = shape.getBounds();
|
||||||
|
double leadLenght = (distance - shapeRect.width) / 2;
|
||||||
|
Double theta = Math.atan2(points[1].y - points[0].y, points[1].x - points[0].x);
|
||||||
|
// Transform graphics to draw the body in the right place and at the
|
||||||
|
// right angle.
|
||||||
|
g2d.translate((points[0].x + points[1].x - shapeRect.width) / 2,
|
||||||
|
(points[0].y + points[1].y - shapeRect.height) / 2);
|
||||||
|
g2d.rotate(theta, shapeRect.width / 2, shapeRect.height / 2);
|
||||||
|
// Draw body.
|
||||||
|
if (componentState != ComponentState.DRAGGING) {
|
||||||
|
Composite oldComposite = g2d.getComposite();
|
||||||
|
if (alpha < MAX_ALPHA) {
|
||||||
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||||
|
/ MAX_ALPHA));
|
||||||
|
}
|
||||||
|
g2d.setColor(bodyColor);
|
||||||
|
g2d.fill(shape);
|
||||||
|
g2d.setComposite(oldComposite);
|
||||||
|
}
|
||||||
|
// Draw leads.
|
||||||
|
g2d.setColor(getLeadColor());
|
||||||
|
g2d.drawLine((int) (shapeRect.width - distance) / 2, (int) shapeRect.height / 2,
|
||||||
|
(int) ((shapeRect.width - distance) / 2 + leadLenght), (int) shapeRect.height / 2);
|
||||||
|
g2d.drawLine((int) (shapeRect.width + distance) / 2, (int) shapeRect.height / 2,
|
||||||
|
(int) ((shapeRect.width + distance) / 2 - leadLenght), (int) shapeRect.height / 2);
|
||||||
|
g2d.setStroke(new BasicStroke(1));
|
||||||
|
g2d.setColor(borderColor);
|
||||||
|
g2d.draw(shape);
|
||||||
|
// Draw label.
|
||||||
|
g2d.setFont(Constants.LABEL_FONT);
|
||||||
|
g2d
|
||||||
|
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
|
||||||
|
: LABEL_COLOR);
|
||||||
|
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
||||||
|
java.awt.geom.Rectangle2D textRect = fontMetrics.getStringBounds(getName(), g2d);
|
||||||
|
g2d.drawString(getName(), (int) (shapeRect.width - textRect.getWidth()) / 2,
|
||||||
|
(int) (shapeRect.height - textRect.getHeight()) / 2 + fontMetrics.getAscent());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return default component width.
|
* @return default component width.
|
||||||
*/
|
*/
|
||||||
@@ -109,54 +157,6 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
points[index].setLocation(point);
|
points[index].setLocation(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
|
||||||
g2d.setColor(getLeadColor());
|
|
||||||
g2d.setStroke(new BasicStroke(getLeadThickness().convertToPixels()));
|
|
||||||
double distance = points[0].distance(points[1]);
|
|
||||||
Shape shape = getBodyShape();
|
|
||||||
if (shape == null) {
|
|
||||||
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Rectangle shapeRect = shape.getBounds();
|
|
||||||
double leadLenght = (distance - shapeRect.width) / 2;
|
|
||||||
Double theta = Math.atan2(points[1].y - points[0].y, points[1].x - points[0].x);
|
|
||||||
// Draw leads.
|
|
||||||
g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + leadLenght * Math.cos(theta)),
|
|
||||||
(int) (points[0].y + leadLenght * Math.sin(theta)));
|
|
||||||
g2d.drawLine(points[1].x, points[1].y, (int) (points[1].x - leadLenght * Math.cos(theta)),
|
|
||||||
(int) (points[1].y - leadLenght * Math.sin(theta)));
|
|
||||||
// Transform graphics to draw the body in the right place and at the
|
|
||||||
// right angle.
|
|
||||||
g2d.translate((points[0].x + points[1].x - shapeRect.width) / 2,
|
|
||||||
(points[0].y + points[1].y - shapeRect.height) / 2);
|
|
||||||
g2d.rotate(theta, shapeRect.width / 2, shapeRect.height / 2);
|
|
||||||
// Draw body.
|
|
||||||
if (componentState != ComponentState.DRAGGING) {
|
|
||||||
Composite oldComposite = g2d.getComposite();
|
|
||||||
if (alpha < MAX_ALPHA) {
|
|
||||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
|
||||||
/ MAX_ALPHA));
|
|
||||||
}
|
|
||||||
g2d.setColor(bodyColor);
|
|
||||||
g2d.fill(shape);
|
|
||||||
g2d.setComposite(oldComposite);
|
|
||||||
}
|
|
||||||
g2d.setStroke(new BasicStroke(1));
|
|
||||||
g2d.setColor(borderColor);
|
|
||||||
g2d.draw(shape);
|
|
||||||
// Draw label.
|
|
||||||
g2d.setFont(Constants.LABEL_FONT);
|
|
||||||
g2d
|
|
||||||
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
|
|
||||||
: LABEL_COLOR);
|
|
||||||
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
|
||||||
java.awt.geom.Rectangle2D textRect = fontMetrics.getStringBounds(getName(), g2d);
|
|
||||||
g2d.drawString(getName(), (int) (shapeRect.width - textRect.getWidth()) / 2,
|
|
||||||
(int) (shapeRect.height - textRect.getHeight()) / 2 + fontMetrics.getAscent());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EditableProperty(name = "Color")
|
@EditableProperty(name = "Color")
|
||||||
public Color getBodyColor() {
|
public Color getBodyColor() {
|
||||||
return bodyColor;
|
return bodyColor;
|
||||||
|
|||||||
+7
-5
@@ -59,7 +59,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
public static final String DEFAULTS_KEY = "default.";
|
public static final String DEFAULTS_KEY = "default.";
|
||||||
public static final String METRIC_KEY = "metric";
|
public static final String METRIC_KEY = "metric";
|
||||||
|
|
||||||
public static final int CONTROL_POINT_SENSITIVITY = 4;
|
public static final int CONTROL_POINT_SIZE = 5;
|
||||||
public static final int ICON_SIZE = 32;
|
public static final int ICON_SIZE = 32;
|
||||||
public static boolean ENABLE_ANTIALIASING = true;
|
public static boolean ENABLE_ANTIALIASING = true;
|
||||||
public static boolean DEBUG_COMPONENT_AREAS = false;
|
public static boolean DEBUG_COMPONENT_AREAS = false;
|
||||||
@@ -292,9 +292,11 @@ public class Presenter implements IPlugInPort {
|
|||||||
if (shouldShowControlPointsFor(component)) {
|
if (shouldShowControlPointsFor(component)) {
|
||||||
g2d.setColor(Constants.CONTROL_POINT_COLOR);
|
g2d.setColor(Constants.CONTROL_POINT_COLOR);
|
||||||
g2d.setStroke(new BasicStroke(2));
|
g2d.setStroke(new BasicStroke(2));
|
||||||
g2d.drawOval(controlPoint.x - 2, controlPoint.y - 2, 4, 4);
|
// g2d.drawOval(controlPoint.x - 2,
|
||||||
// g2d.fillOval(point.getValue().x - 2, point
|
// controlPoint.y - 2, 4, 4);
|
||||||
// .getValue().y - 2, 5, 5);
|
g2d.fillOval(controlPoint.x - CONTROL_POINT_SIZE / 2,
|
||||||
|
controlPoint.y - CONTROL_POINT_SIZE / 2,
|
||||||
|
CONTROL_POINT_SIZE, CONTROL_POINT_SIZE);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Could not obtain control points for component of type "
|
LOG.error("Could not obtain control points for component of type "
|
||||||
@@ -411,7 +413,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
// Only consider selected components.
|
// Only consider selected components.
|
||||||
if (selectedComponents.contains(component)) {
|
if (selectedComponents.contains(component)) {
|
||||||
try {
|
try {
|
||||||
if (scaledPoint.distance(controlPoint) < CONTROL_POINT_SENSITIVITY) {
|
if (scaledPoint.distance(controlPoint) < CONTROL_POINT_SIZE) {
|
||||||
Set<Integer> indices = new HashSet<Integer>();
|
Set<Integer> indices = new HashSet<Integer>();
|
||||||
ComponentType componentType = componentTypeMap
|
ComponentType componentType = componentTypeMap
|
||||||
.get(component.getClass());
|
.get(component.getClass());
|
||||||
|
|||||||
Binary file not shown.
+1
-1
@@ -29,7 +29,7 @@ public class HookupWire extends AbstractCurvedComponent<AWG> {
|
|||||||
@Override
|
@Override
|
||||||
protected void drawCurve(CubicCurve2D curve, Graphics2D g2d) {
|
protected void drawCurve(CubicCurve2D curve, Graphics2D g2d) {
|
||||||
int thickness = (int) (Math.pow(Math.E, -1.12436 - 0.11594 * value.getValue())
|
int thickness = (int) (Math.pow(Math.E, -1.12436 - 0.11594 * value.getValue())
|
||||||
* Constants.PIXELS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT));
|
* Constants.GRID * Constants.GRIDS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT));
|
||||||
g2d.setColor(color.darker());
|
g2d.setColor(color.darker());
|
||||||
g2d.setStroke(new BasicStroke(thickness));
|
g2d.setStroke(new BasicStroke(thickness));
|
||||||
g2d.draw(curve);
|
g2d.draw(curve);
|
||||||
|
|||||||
Reference in New Issue
Block a user