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.setColor(bodyColor);
|
||||||
g2d.fill(shape);
|
g2d.fill(shape);
|
||||||
|
decorateComponentBody(g2d);
|
||||||
g2d.setComposite(oldComposite);
|
g2d.setComposite(oldComposite);
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||||
g2d.setColor(componentState == ComponentState.SELECTED
|
g2d.setColor(componentState == ComponentState.SELECTED
|
||||||
@@ -126,7 +127,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
|||||||
g2d.setFont(Constants.LABEL_FONT);
|
g2d.setFont(Constants.LABEL_FONT);
|
||||||
g2d
|
g2d
|
||||||
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
|
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
|
||||||
: LABEL_COLOR);
|
: getLabelColor());
|
||||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||||
String label = display == Display.NAME ? getName() : getValue().toString();
|
String label = display == Display.NAME ? getName() : getValue().toString();
|
||||||
// Adjust label angle if needed to make sure that it's readable.
|
// 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());
|
(int) (shapeRect.height - textRect.getHeight()) / 2 + fontMetrics.getAscent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void decorateComponentBody(Graphics2D g2d) {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Color getLabelColor() {
|
||||||
|
return LABEL_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean shouldShadeLeads() {
|
protected boolean shouldShadeLeads() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-11
@@ -652,14 +652,11 @@ public class Presenter implements IPlugInPort {
|
|||||||
// We're dragging control point(s).
|
// We're dragging control point(s).
|
||||||
int dx = (scaledPoint.x - previousDragPoint.x);
|
int dx = (scaledPoint.x - previousDragPoint.x);
|
||||||
int dy = (scaledPoint.y - previousDragPoint.y);
|
int dy = (scaledPoint.y - previousDragPoint.y);
|
||||||
if (snapToGrid) {
|
// After we make the transfer and snap to grid, calculate actual dx
|
||||||
dx = CalcUtils.roundToGrid(dx, currentProject.getGridSpacing());
|
// and dy. We'll use them to translate the previous drag point.
|
||||||
dy = CalcUtils.roundToGrid(dy, currentProject.getGridSpacing());
|
int actualDx = 0;
|
||||||
}
|
int actualDy = 0;
|
||||||
// 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
|
// Do a simulation of the move to see if any of them will
|
||||||
// collide.
|
// collide.
|
||||||
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
||||||
@@ -669,21 +666,22 @@ public class Presenter implements IPlugInPort {
|
|||||||
controlPoints[i] = new Point(c.getControlPoint(i));
|
controlPoints[i] = new Point(c.getControlPoint(i));
|
||||||
if (entry.getValue().contains(i)) {
|
if (entry.getValue().contains(i)) {
|
||||||
controlPoints[i].translate(dx, dy);
|
controlPoints[i].translate(dx, dy);
|
||||||
|
if (snapToGrid) {
|
||||||
|
CalcUtils.snapPointToGrid(controlPoints[i], currentProject
|
||||||
|
.getGridSpacing());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < controlPoints.length - 1; i++) {
|
for (int i = 0; i < controlPoints.length - 1; i++) {
|
||||||
for (int j = i + 1; j < controlPoints.length; j++) {
|
for (int j = i + 1; j < controlPoints.length; j++) {
|
||||||
if (controlPoints[i].equals(controlPoints[j])) {
|
if (controlPoints[i].equals(controlPoints[j])) {
|
||||||
LOG
|
LOG.error("Control points collision detected, cannot make this move.");
|
||||||
.error("Control points collision detected, cannot make this move.");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
previousDragPoint.translate(dx, dy);
|
|
||||||
|
|
||||||
// Update all points.
|
// Update all points.
|
||||||
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
||||||
IDIYComponent<?> c = entry.getKey();
|
IDIYComponent<?> c = entry.getKey();
|
||||||
@@ -691,9 +689,21 @@ public class Presenter implements IPlugInPort {
|
|||||||
for (Integer index : entry.getValue()) {
|
for (Integer index : entry.getValue()) {
|
||||||
Point p = new Point(c.getControlPoint(index));
|
Point p = new Point(c.getControlPoint(index));
|
||||||
p.translate(dx, dy);
|
p.translate(dx, dy);
|
||||||
|
if (snapToGrid) {
|
||||||
|
CalcUtils.snapPointToGrid(p, currentProject.getGridSpacing());
|
||||||
|
}
|
||||||
|
// 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);
|
c.setControlPoint(p, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (actualDx != 0 || actualDy != 0) {
|
||||||
|
previousDragPoint.translate(actualDx, actualDy);
|
||||||
|
repaint = true;
|
||||||
}
|
}
|
||||||
} else if (selectedComponents.isEmpty()
|
} else if (selectedComponents.isEmpty()
|
||||||
&& instantiationManager.getComponentTypeSlot() == null) {
|
&& instantiationManager.getComponentTypeSlot() == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user