mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
fixed drag&drop when spacing changes
This commit is contained in:
+10
-1
@@ -94,6 +94,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
}
|
||||
g2d.setColor(bodyColor);
|
||||
g2d.fill(shape);
|
||||
decorateComponentBody(g2d);
|
||||
g2d.setComposite(oldComposite);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
@@ -126,7 +127,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
g2d.setFont(Constants.LABEL_FONT);
|
||||
g2d
|
||||
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
|
||||
: LABEL_COLOR);
|
||||
: getLabelColor());
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
String label = display == Display.NAME ? getName() : getValue().toString();
|
||||
// Adjust label angle if needed to make sure that it's readable.
|
||||
@@ -139,6 +140,14 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
(int) (shapeRect.height - textRect.getHeight()) / 2 + fontMetrics.getAscent());
|
||||
}
|
||||
|
||||
protected void decorateComponentBody(Graphics2D g2d) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
protected Color getLabelColor() {
|
||||
return LABEL_COLOR;
|
||||
}
|
||||
|
||||
protected boolean shouldShadeLeads() {
|
||||
return true;
|
||||
}
|
||||
|
||||
+47
-37
@@ -652,49 +652,59 @@ public class Presenter implements IPlugInPort {
|
||||
// We're dragging control point(s).
|
||||
int dx = (scaledPoint.x - previousDragPoint.x);
|
||||
int dy = (scaledPoint.y - previousDragPoint.y);
|
||||
if (snapToGrid) {
|
||||
dx = CalcUtils.roundToGrid(dx, currentProject.getGridSpacing());
|
||||
dy = CalcUtils.roundToGrid(dy, currentProject.getGridSpacing());
|
||||
// After we make the transfer and snap to grid, calculate actual dx
|
||||
// and dy. We'll use them to translate the previous drag point.
|
||||
int actualDx = 0;
|
||||
int actualDy = 0;
|
||||
|
||||
// Do a simulation of the move to see if any of them will
|
||||
// collide.
|
||||
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
||||
IDIYComponent<?> c = entry.getKey();
|
||||
Point[] controlPoints = new Point[c.getControlPointCount()];
|
||||
for (int i = 0; i < controlPoints.length; i++) {
|
||||
controlPoints[i] = new Point(c.getControlPoint(i));
|
||||
if (entry.getValue().contains(i)) {
|
||||
controlPoints[i].translate(dx, dy);
|
||||
if (snapToGrid) {
|
||||
CalcUtils.snapPointToGrid(controlPoints[i], currentProject
|
||||
.getGridSpacing());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < controlPoints.length - 1; i++) {
|
||||
for (int j = i + 1; j < controlPoints.length; j++) {
|
||||
if (controlPoints[i].equals(controlPoints[j])) {
|
||||
LOG.error("Control points collision detected, cannot make this move.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Only repaint if there's an actual change.
|
||||
repaint = dx != 0 || dy != 0;
|
||||
|
||||
if (repaint) {
|
||||
// Do a simulation of the move to see if any of them will
|
||||
// collide.
|
||||
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
||||
IDIYComponent<?> c = entry.getKey();
|
||||
Point[] controlPoints = new Point[c.getControlPointCount()];
|
||||
for (int i = 0; i < controlPoints.length; i++) {
|
||||
controlPoints[i] = new Point(c.getControlPoint(i));
|
||||
if (entry.getValue().contains(i)) {
|
||||
controlPoints[i].translate(dx, dy);
|
||||
}
|
||||
// Update all points.
|
||||
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
||||
IDIYComponent<?> c = entry.getKey();
|
||||
drawingManager.invalidateComponent(c);
|
||||
for (Integer index : entry.getValue()) {
|
||||
Point p = new Point(c.getControlPoint(index));
|
||||
p.translate(dx, dy);
|
||||
if (snapToGrid) {
|
||||
CalcUtils.snapPointToGrid(p, currentProject.getGridSpacing());
|
||||
}
|
||||
for (int i = 0; i < controlPoints.length - 1; i++) {
|
||||
for (int j = i + 1; j < controlPoints.length; j++) {
|
||||
if (controlPoints[i].equals(controlPoints[j])) {
|
||||
LOG
|
||||
.error("Control points collision detected, cannot make this move.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
previousDragPoint.translate(dx, dy);
|
||||
|
||||
// Update all points.
|
||||
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
||||
IDIYComponent<?> c = entry.getKey();
|
||||
drawingManager.invalidateComponent(c);
|
||||
for (Integer index : entry.getValue()) {
|
||||
Point p = new Point(c.getControlPoint(index));
|
||||
p.translate(dx, dy);
|
||||
c.setControlPoint(p, index);
|
||||
// When the first point is moved, calculate how much it
|
||||
// actually moved after snapping.
|
||||
if (actualDx == 0 && actualDy == 0) {
|
||||
actualDx = p.x - c.getControlPoint(index).x;
|
||||
actualDy = p.y - c.getControlPoint(index).y;
|
||||
}
|
||||
c.setControlPoint(p, index);
|
||||
}
|
||||
}
|
||||
if (actualDx != 0 || actualDy != 0) {
|
||||
previousDragPoint.translate(actualDx, actualDy);
|
||||
repaint = true;
|
||||
}
|
||||
} else if (selectedComponents.isEmpty()
|
||||
&& instantiationManager.getComponentTypeSlot() == null) {
|
||||
// If there's no selection, the only thing to do is update the
|
||||
|
||||
Reference in New Issue
Block a user