mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
fixed d&d jumping issue
This commit is contained in:
Binary file not shown.
+58
-38
@@ -1,9 +1,7 @@
|
|||||||
package org.diylc.presenter;
|
package org.diylc.presenter;
|
||||||
|
|
||||||
import java.awt.AlphaComposite;
|
|
||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Composite;
|
|
||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
@@ -297,8 +295,9 @@ public class Presenter implements IPlugInPort {
|
|||||||
g2dWrapper.scale(zoomLevel, zoomLevel);
|
g2dWrapper.scale(zoomLevel, zoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
Composite mainComposite = g2d.getComposite();
|
// Composite mainComposite = g2d.getComposite();
|
||||||
Composite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
|
// Composite alphaComposite =
|
||||||
|
// AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
|
||||||
|
|
||||||
// g2dWrapper.resetTx();
|
// g2dWrapper.resetTx();
|
||||||
|
|
||||||
@@ -318,15 +317,15 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
// If the component is being dragged, draw it in a separate
|
// If the component is being dragged, draw it in a separate
|
||||||
// composite.
|
// composite.
|
||||||
if (state == ComponentState.DRAGGING) {
|
// if (state == ComponentState.DRAGGING) {
|
||||||
g2dWrapper.setComposite(alphaComposite);
|
// g2dWrapper.setComposite(alphaComposite);
|
||||||
}
|
// }
|
||||||
// Draw the component through the g2dWrapper.
|
// Draw the component through the g2dWrapper.
|
||||||
component.draw(g2dWrapper, state, currentProject);
|
component.draw(g2dWrapper, state, currentProject);
|
||||||
// Restore the composite if needed.
|
// Restore the composite if needed.
|
||||||
if (state == ComponentState.DRAGGING) {
|
// if (state == ComponentState.DRAGGING) {
|
||||||
g2dWrapper.setComposite(mainComposite);
|
// g2dWrapper.setComposite(mainComposite);
|
||||||
}
|
// }
|
||||||
componentAreaMap.put(component, g2dWrapper.finishedDrawingComponent());
|
componentAreaMap.put(component, g2dWrapper.finishedDrawingComponent());
|
||||||
|
|
||||||
// Draw control points
|
// Draw control points
|
||||||
@@ -483,9 +482,11 @@ public class Presenter implements IPlugInPort {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!components.equals(controlPointMap)) {
|
if (!components.equals(controlPointMap)) {
|
||||||
controlPointMap = components;
|
controlPointMap = components;
|
||||||
messageDispatcher.dispatchMessage(EventType.AVAILABLE_CTRL_POINTS_CHANGED, components);
|
messageDispatcher.dispatchMessage(EventType.AVAILABLE_CTRL_POINTS_CHANGED,
|
||||||
|
new HashMap<IDIYComponent<?>, Set<Integer>>(components));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,11 +535,25 @@ public class Presenter implements IPlugInPort {
|
|||||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
}
|
}
|
||||||
|
// If there aren't any control points, try to add all the selected
|
||||||
|
// components with all their control points. That will allow the
|
||||||
|
// user to
|
||||||
|
// drag the whole component.
|
||||||
|
for (IDIYComponent<?> c : selectedComponents) {
|
||||||
|
Set<Integer> pointIndices = new HashSet<Integer>();
|
||||||
|
if (component.getControlPointCount() > 0) {
|
||||||
|
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||||
|
pointIndices.add(i);
|
||||||
|
}
|
||||||
|
controlPointMap.put(c, pointIndices);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dragOver(Point point) {
|
public boolean dragOver(Point point) {
|
||||||
|
// System.err.println("DragOver: " + point);
|
||||||
if (point == null) {
|
if (point == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -567,7 +582,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
dy = (int) (Math.round(dy / Constants.GRID) * Constants.GRID);
|
dy = (int) (Math.round(dy / Constants.GRID) * Constants.GRID);
|
||||||
}
|
}
|
||||||
// Only repaint if there's an actual change.
|
// Only repaint if there's an actual change.
|
||||||
repaint = dx != 0 && dy != 0;
|
repaint = dx != 0 || dy != 0;
|
||||||
|
|
||||||
previousDragPoint.translate(dx, dy);
|
previousDragPoint.translate(dx, dy);
|
||||||
|
|
||||||
@@ -588,10 +603,12 @@ public class Presenter implements IPlugInPort {
|
|||||||
repaint = true;
|
repaint = true;
|
||||||
// messageDispatcher.dispatchMessage(EventType.SELECTION_RECT_CHANGED,
|
// messageDispatcher.dispatchMessage(EventType.SELECTION_RECT_CHANGED,
|
||||||
// selectionRect);
|
// selectionRect);
|
||||||
} else {
|
// } else {
|
||||||
// If there are components selected translate their control points.
|
// // If there are components selected translate their control
|
||||||
repaint = translateSelectedComponents(previousDragPoint, scaledPoint);
|
// points.
|
||||||
// dragStartPoint = point;
|
// repaint = translateSelectedComponents(previousDragPoint,
|
||||||
|
// scaledPoint);
|
||||||
|
// // dragStartPoint = point;
|
||||||
}
|
}
|
||||||
if (repaint) {
|
if (repaint) {
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
@@ -633,29 +650,32 @@ public class Presenter implements IPlugInPort {
|
|||||||
dragInProgress = false;
|
dragInProgress = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean translateSelectedComponents(Point fromPoint, Point toPoint) {
|
// private boolean translateSelectedComponents(Point fromPoint, Point
|
||||||
if (toPoint == null) {
|
// toPoint) {
|
||||||
LOG.debug("Drag ended outside the drawing area.");
|
// if (toPoint == null) {
|
||||||
return false;
|
// LOG.debug("Drag ended outside the drawing area.");
|
||||||
}
|
// return false;
|
||||||
int dx = (int) (Math.round((toPoint.x - fromPoint.x) / zoomLevel / Constants.GRID) * Constants.GRID);
|
// }
|
||||||
int dy = (int) (Math.round((toPoint.y - fromPoint.y) / zoomLevel / Constants.GRID) * Constants.GRID);
|
// int dx = (int) (Math.round((toPoint.x - fromPoint.x) / zoomLevel /
|
||||||
fromPoint.translate(dx, dy);
|
// Constants.GRID) * Constants.GRID);
|
||||||
for (IDIYComponent<?> component : selectedComponents) {
|
// int dy = (int) (Math.round((toPoint.y - fromPoint.y) / zoomLevel /
|
||||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
// Constants.GRID) * Constants.GRID);
|
||||||
Point controlPoint = new Point(component.getControlPoint(i));
|
// fromPoint.translate(dx, dy);
|
||||||
translateControlPoint(controlPoint, dx, dy);
|
// for (IDIYComponent<?> component : selectedComponents) {
|
||||||
component.setControlPoint(controlPoint, i);
|
// for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||||
}
|
// Point controlPoint = new Point(component.getControlPoint(i));
|
||||||
}
|
// translateControlPoint(controlPoint, dx, dy);
|
||||||
return dx != 0 && dy != 0;
|
// component.setControlPoint(controlPoint, i);
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
// return dx != 0 && dy != 0;
|
||||||
|
// }
|
||||||
|
|
||||||
private void translateControlPoint(Point controlPoint, int dx, int dy) {
|
// private void translateControlPoint(Point controlPoint, int dx, int dy) {
|
||||||
int x = controlPoint.x + dx;
|
// int x = controlPoint.x + dx;
|
||||||
int y = controlPoint.y + dy;
|
// int y = controlPoint.y + dy;
|
||||||
controlPoint.setLocation(x, y);
|
// controlPoint.setLocation(x, y);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addComponents(List<IDIYComponent<?>> components, Point preferredPoint) {
|
public void addComponents(List<IDIYComponent<?>> components, Point preferredPoint) {
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ import java.awt.Toolkit;
|
|||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
|
||||||
public static final float GRID = (int) (Toolkit.getDefaultToolkit().getScreenResolution() / 10f);
|
public static final int GRID = (int) (Toolkit.getDefaultToolkit().getScreenResolution() / 10f);
|
||||||
|
|
||||||
public static Color CANVAS_COLOR = Color.white;
|
public static Color CANVAS_COLOR = Color.white;
|
||||||
public static Color GRID_COLOR = new Color(240, 240, 240);
|
public static Color GRID_COLOR = new Color(240, 240, 240);
|
||||||
|
|||||||
Binary file not shown.
+5
-3
@@ -28,9 +28,11 @@ public abstract class AbstractBoard implements IDIYComponent<String> {
|
|||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
||||||
g2d.setStroke(new BasicStroke());
|
g2d.setStroke(new BasicStroke());
|
||||||
g2d.setColor(getBoardColor());
|
if (componentState != ComponentState.DRAGGING) {
|
||||||
g2d.fillRect(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x
|
g2d.setColor(getBoardColor());
|
||||||
- controlPoints[0].x, controlPoints[1].y - controlPoints[0].y);
|
g2d.fillRect(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x
|
||||||
|
- controlPoints[0].x, controlPoints[1].y - controlPoints[0].y);
|
||||||
|
}
|
||||||
g2d.setColor(getBorderColor());
|
g2d.setColor(getBorderColor());
|
||||||
g2d.drawRect(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x
|
g2d.drawRect(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x
|
||||||
- controlPoints[0].x, controlPoints[1].y - controlPoints[0].y);
|
- controlPoints[0].x, controlPoints[1].y - controlPoints[0].y);
|
||||||
|
|||||||
+19
-14
@@ -26,7 +26,7 @@ public class PerfBoard extends AbstractBoard {
|
|||||||
private static Size PAD_SIZE = new Size(0.08d, SizeUnit.in);
|
private static Size PAD_SIZE = new Size(0.08d, SizeUnit.in);
|
||||||
private static Size HOLE_SIZE = new Size(0.8d, SizeUnit.mm);
|
private static Size HOLE_SIZE = new Size(0.8d, SizeUnit.mm);
|
||||||
|
|
||||||
// private Area copperArea;
|
// private Area copperArea;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
|
||||||
@@ -41,20 +41,25 @@ public class PerfBoard extends AbstractBoard {
|
|||||||
|
|
||||||
// long t = System.nanoTime();
|
// long t = System.nanoTime();
|
||||||
super.draw(g2d, componentState, project);
|
super.draw(g2d, componentState, project);
|
||||||
Point p = new Point(controlPoints[0]);
|
|
||||||
int radius = PAD_SIZE.convertToPixels() / 2;
|
|
||||||
int holeRadius = HOLE_SIZE.convertToPixels() / 2;
|
|
||||||
g2d.setStroke(new BasicStroke(radius));
|
|
||||||
|
|
||||||
while (p.y < controlPoints[1].y - SPACING.convertToPixels()) {
|
if (componentState != ComponentState.DRAGGING) {
|
||||||
p.x = controlPoints[0].x;
|
Point p = new Point(controlPoints[0]);
|
||||||
p.y += SPACING.convertToPixels();
|
int radius = PAD_SIZE.convertToPixels() / 2;
|
||||||
while (p.x < controlPoints[1].x - SPACING.convertToPixels()) {
|
int holeRadius = HOLE_SIZE.convertToPixels() / 2;
|
||||||
p.x += SPACING.convertToPixels();
|
g2d.setStroke(new BasicStroke(radius));
|
||||||
g2d.setColor(COPPER_COLOR);
|
|
||||||
g2d.fillOval(p.x - radius, p.y - radius, radius * 2, radius * 2);
|
while (p.y < controlPoints[1].y - SPACING.convertToPixels()) {
|
||||||
g2d.setColor(Constants.CANVAS_COLOR);
|
p.x = controlPoints[0].x;
|
||||||
g2d.fillOval(p.x - holeRadius, p.y - holeRadius, holeRadius * 2, holeRadius * 2);
|
p.y += SPACING.convertToPixels();
|
||||||
|
while (p.x < controlPoints[1].x - SPACING.convertToPixels()) {
|
||||||
|
p.x += SPACING.convertToPixels();
|
||||||
|
g2d.setColor(COPPER_COLOR);
|
||||||
|
g2d.fillOval(p.x - radius, p.y - radius, radius * 2, radius * 2);
|
||||||
|
g2d.setColor(Constants.CANVAS_COLOR);
|
||||||
|
g2d
|
||||||
|
.fillOval(p.x - holeRadius, p.y - holeRadius, holeRadius * 2,
|
||||||
|
holeRadius * 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// System.err.println("OldDraw: " + (System.nanoTime() - t));
|
// System.err.println("OldDraw: " + (System.nanoTime() - t));
|
||||||
|
|||||||
Reference in New Issue
Block a user