mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
switchable sticky points
added themes fixed ruler precision improved board rendering
This commit is contained in:
+39
-20
@@ -26,6 +26,7 @@ import org.diylc.common.ObjectCache;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@@ -44,14 +45,17 @@ public class DrawingManager {
|
||||
|
||||
public static int CONTROL_POINT_SIZE = 7;
|
||||
|
||||
public static final String ANTIALIASING_KEY = "anti-aliasing";
|
||||
public static final String ZOOM_KEY = "zoom";
|
||||
public static final String THEME_KEY = "theme";
|
||||
public static boolean DEBUG_COMPONENT_AREAS = false;
|
||||
|
||||
public static Color GRID_COLOR = new Color(240, 240, 240);
|
||||
public static Color CONTROL_POINT_COLOR = Color.black;
|
||||
public static Color SELECTED_CONTROL_POINT_COLOR = Color.green;
|
||||
|
||||
private Theme theme = new Theme("White Realistic", Constants.CANVAS_COLOR, GRID_COLOR, null,
|
||||
null, null);
|
||||
|
||||
// Keeps Area object of each drawn component.
|
||||
private Map<IDIYComponent<?>, Area> componentAreaMap;
|
||||
// Maps components to the last state they are drawn in. Also, used to
|
||||
@@ -72,6 +76,10 @@ public class DrawingManager {
|
||||
this.messageDispatcher = messageDispatcher;
|
||||
componentAreaMap = new HashMap<IDIYComponent<?>, Area>();
|
||||
lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>();
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(THEME_KEY, null);
|
||||
if (theme != null) {
|
||||
this.theme = theme;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,12 +153,11 @@ public class DrawingManager {
|
||||
// AffineTransform initialTx = g2d.getTransform();
|
||||
Dimension d = getCanvasDimensions(project, zoom, true);
|
||||
|
||||
g2dWrapper.setColor(Constants.CANVAS_COLOR);
|
||||
g2dWrapper.setColor(theme.getBgColor());
|
||||
g2dWrapper.fillRect(0, 0, d.width, d.height);
|
||||
g2d.clip(new Rectangle(new Point(0, 0), d));
|
||||
|
||||
GridType gridType = (GridType) ConfigurationManager.getInstance().readObject(
|
||||
ANTIALIASING_KEY, GridType.LINES);
|
||||
GridType gridType = GridType.LINES;
|
||||
if (drawOptions.contains(DrawOption.GRID) && gridType != GridType.NONE) {
|
||||
double zoomStep = project.getGridSpacing().convertToPixels() * zoom;
|
||||
if (gridType == GridType.CROSSHAIR) {
|
||||
@@ -162,7 +169,7 @@ public class DrawingManager {
|
||||
10f, new float[] { 1f, (float) zoomStep - 1 }, 0f));
|
||||
}
|
||||
|
||||
g2dWrapper.setColor(GRID_COLOR);
|
||||
g2dWrapper.setColor(theme.getGridColor());
|
||||
for (double i = zoomStep; i < d.width; i += zoomStep) {
|
||||
g2dWrapper.drawLine((int) i, 0, (int) i, d.height - 1);
|
||||
}
|
||||
@@ -224,22 +231,24 @@ public class DrawingManager {
|
||||
// Draw control points.
|
||||
if (drawOptions.contains(DrawOption.CONTROL_POINTS)) {
|
||||
// Draw unselected points first to make sure they are below.
|
||||
for (IDIYComponent<?> component : project.getComponents()) {
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
VisibilityPolicy visibilityPolicy = component
|
||||
.getControlPointVisibilityPolicy(i);
|
||||
if ((groupedComponents.contains(component)
|
||||
&& (visibilityPolicy == VisibilityPolicy.ALWAYS || (selectedComponents
|
||||
.contains(component) && visibilityPolicy == VisibilityPolicy.WHEN_SELECTED)) || (!groupedComponents
|
||||
.contains(component)
|
||||
&& !selectedComponents.contains(component) && component
|
||||
.getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS))) {
|
||||
g2dWrapper.setColor(CONTROL_POINT_COLOR);
|
||||
if (dragInProgress) {
|
||||
for (IDIYComponent<?> component : project.getComponents()) {
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
VisibilityPolicy visibilityPolicy = component
|
||||
.getControlPointVisibilityPolicy(i);
|
||||
if ((groupedComponents.contains(component)
|
||||
&& (visibilityPolicy == VisibilityPolicy.ALWAYS || (selectedComponents
|
||||
.contains(component) && visibilityPolicy == VisibilityPolicy.WHEN_SELECTED)) || (!groupedComponents
|
||||
.contains(component)
|
||||
&& !selectedComponents.contains(component) && component
|
||||
.getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS))) {
|
||||
g2dWrapper.setColor(CONTROL_POINT_COLOR);
|
||||
|
||||
Point controlPoint = component.getControlPoint(i);
|
||||
int pointSize = CONTROL_POINT_SIZE - 2;
|
||||
g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y
|
||||
- pointSize / 2, pointSize, pointSize);
|
||||
Point controlPoint = component.getControlPoint(i);
|
||||
int pointSize = CONTROL_POINT_SIZE - 2;
|
||||
g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y
|
||||
- pointSize / 2, pointSize, pointSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,4 +382,14 @@ public class DrawingManager {
|
||||
messageDispatcher.dispatchMessage(EventType.ZOOM_CHANGED, zoomLevel);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
|
||||
public Theme getTheme() {
|
||||
return theme;
|
||||
}
|
||||
|
||||
public void setTheme(Theme theme) {
|
||||
this.theme = theme;
|
||||
ConfigurationManager.getInstance().writeValue(THEME_KEY, theme);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
}
|
||||
|
||||
+34
-8
@@ -30,6 +30,7 @@ import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.swing.plugins.edit.ComponentTransferable;
|
||||
import org.diylc.utils.Constants;
|
||||
@@ -594,7 +595,12 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
// Expand control points to include all stuck components.
|
||||
if (!ctrlDown) {
|
||||
boolean sticky = ConfigurationManager.getInstance().readBoolean(
|
||||
IPlugInPort.STICKY_POINTS_KEY, true);
|
||||
if (ctrlDown) {
|
||||
sticky = !sticky;
|
||||
}
|
||||
if (sticky) {
|
||||
includeStuckComponents(controlPointMap);
|
||||
}
|
||||
}
|
||||
@@ -691,8 +697,9 @@ public class Presenter implements IPlugInPort {
|
||||
int actualDy = 0;
|
||||
|
||||
// For each component, do a simulation of the move to see if any of
|
||||
// them will
|
||||
// overlap.
|
||||
// them will overlap or go out of bounds.
|
||||
int width = (int) currentProject.getWidth().convertToPixels();
|
||||
int height = (int) currentProject.getHeight().convertToPixels();
|
||||
boolean isFirst = true;
|
||||
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
||||
IDIYComponent<?> component = entry.getKey();
|
||||
@@ -715,8 +722,15 @@ public class Presenter implements IPlugInPort {
|
||||
// Nothing to move.
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
controlPoints[index].translate(actualDx, actualDy);
|
||||
}
|
||||
// else {
|
||||
controlPoints[index].translate(actualDx, actualDy);
|
||||
if (controlPoints[index].x < 0 || controlPoints[index].y < 0
|
||||
|| controlPoints[index].x > width
|
||||
|| controlPoints[index].y > height) {
|
||||
// At least one control point went out of bounds.
|
||||
return true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
// For control points that may overlap, just write null,
|
||||
@@ -730,7 +744,7 @@ public class Presenter implements IPlugInPort {
|
||||
for (int j = i + 1; j < controlPoints.length; j++) {
|
||||
if (controlPoints[i] != null && controlPoints[j] != null
|
||||
&& controlPoints[i].equals(controlPoints[j])) {
|
||||
LOG.error("Control points collision detected, cannot make this move.");
|
||||
LOG.warn("Control points collision detected, cannot make this move.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -977,12 +991,22 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Theme getSelectedTheme() {
|
||||
return drawingManager.getTheme();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedTheme(Theme theme) {
|
||||
drawingManager.setTheme(theme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the selection with the specified {@link ComponentTransferable}.
|
||||
* Also, updates control point map with all components that are stuck to the
|
||||
@@ -1000,7 +1024,9 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
controlPointMap.put(component, indices);
|
||||
}
|
||||
includeStuckComponents(controlPointMap);
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.STICKY_POINTS_KEY, true)) {
|
||||
includeStuckComponents(controlPointMap);
|
||||
}
|
||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents,
|
||||
controlPointMap.keySet());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user