mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-07 12:24:58 +10:00
optimize refresh when creating new component
This commit is contained in:
+13
-4
@@ -80,14 +80,22 @@ public class InstantiationManager {
|
||||
componentSlot.setControlPoint(firstControlPoint, 1);
|
||||
}
|
||||
|
||||
public void updatePointByPoint(Point scaledPoint) {
|
||||
/**
|
||||
* Updates component in the slot with the new second control point.
|
||||
*
|
||||
* @param scaledPoint
|
||||
* @return true, if any change is made
|
||||
*/
|
||||
public boolean updatePointByPoint(Point scaledPoint) {
|
||||
boolean changeMade = !scaledPoint.equals(potentialControlPoint);
|
||||
potentialControlPoint = scaledPoint;
|
||||
if (componentSlot != null) {
|
||||
componentSlot.setControlPoint(scaledPoint, 1);
|
||||
}
|
||||
return changeMade;
|
||||
}
|
||||
|
||||
public void updateSingleClick(Point scaledPoint, boolean snapToGrid, Size gridSpacing) {
|
||||
|
||||
public boolean updateSingleClick(Point scaledPoint, boolean snapToGrid, Size gridSpacing) {
|
||||
if (potentialControlPoint == null) {
|
||||
potentialControlPoint = new Point(0, 0);
|
||||
}
|
||||
@@ -99,7 +107,7 @@ public class InstantiationManager {
|
||||
}
|
||||
// Only repaint if there's an actual change.
|
||||
if (dx == 0 && dy == 0) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
potentialControlPoint.translate(dx, dy);
|
||||
if (componentSlot == null) {
|
||||
@@ -112,6 +120,7 @@ public class InstantiationManager {
|
||||
componentSlot.setControlPoint(p, i);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public IDIYComponent<?> instantiateComponent(ComponentType componentType, Point point,
|
||||
|
||||
+6
-3
@@ -439,16 +439,19 @@ public class Presenter implements IPlugInPort {
|
||||
if (snapToGrid) {
|
||||
CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing());
|
||||
}
|
||||
boolean refresh = false;
|
||||
switch (instantiationManager.getComponentTypeSlot().getCreationMethod()) {
|
||||
case POINT_BY_POINT:
|
||||
instantiationManager.updatePointByPoint(scaledPoint);
|
||||
refresh = instantiationManager.updatePointByPoint(scaledPoint);
|
||||
break;
|
||||
case SINGLE_CLICK:
|
||||
instantiationManager.updateSingleClick(scaledPoint, snapToGrid, currentProject
|
||||
refresh = instantiationManager.updateSingleClick(scaledPoint, snapToGrid, currentProject
|
||||
.getGridSpacing());
|
||||
break;
|
||||
}
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
if (refresh) {
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
} else {
|
||||
// Go backwards so we take the highest z-order components first.
|
||||
for (int i = currentProject.getComponents().size() - 1; i >= 0; i--) {
|
||||
|
||||
Reference in New Issue
Block a user