mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
better default label position on schematic symbols
This commit is contained in:
Binary file not shown.
@@ -98,6 +98,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
} catch (NullPointerException e) {
|
||||
// This will happen if components do not have any shape.
|
||||
}
|
||||
if (newPoints != null)
|
||||
newPoints[2] = calculateLabelPosition(newPoints[0], newPoints[1]);
|
||||
}
|
||||
|
||||
protected boolean IsCopperArea() {
|
||||
|
||||
@@ -21,13 +21,14 @@
|
||||
*/
|
||||
package org.diylc.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.common.LabelPosition;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.common.LabelPosition;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedComponent<T> {
|
||||
|
||||
@@ -68,6 +69,15 @@ public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedCom
|
||||
} else {
|
||||
return (int) (shapeRect.getHeight() + textRect.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Point calculateLabelPosition(Point point1, Point point2) {
|
||||
double x = (point1.x + point2.x) / 2.0;
|
||||
double y = (point1.y + point2.y) / 2.0;
|
||||
double theta = Math.atan2(point2.y - point1.y, point2.x - point2.x) - Math.PI / 2;
|
||||
double r = width.convertToPixels() / 2 + LABEL_FONT.getSize() / 2;
|
||||
return new Point((int) (x + Math.cos(theta) * r), (int) (y + Math.sin(theta) * r));
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Label Position")
|
||||
|
||||
Reference in New Issue
Block a user