configurable snap to grid

This commit is contained in:
bancika
2011-02-18 22:17:03 +00:00
parent 746aadd8a2
commit abdf02eac8
5 changed files with 45 additions and 16 deletions
@@ -1,22 +1,42 @@
<map>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
</entry>
<entry>
<string>stickyPoints</string>
<boolean>true</boolean>
</entry>
<entry>
<string>theme</string>
<org.diylc.core.Theme>
<name>Blueprint</name>
<name>Light</name>
<bgColor>
<red>3</red>
<green>122</green>
<blue>198</blue>
<red>255</red>
<green>255</green>
<blue>255</blue>
<alpha>255</alpha>
</bgColor>
<gridColor>
<red>29</red>
<green>140</green>
<blue>193</blue>
<alpha>255</alpha>
<red>240</red>
<green>240</green>
<blue>240</blue>
<alpha>240</alpha>
</gridColor>
</org.diylc.core.Theme>
</entry>
<entry>
<string>antiAliasing</string>
<boolean>true</boolean>
</entry>
<entry>
<string>snapToGrid</string>
<boolean>false</boolean>
</entry>
<entry>
<string>hiQualityRender</string>
<boolean>false</boolean>
</entry>
<entry>
<string>showTemplatesAtStartup</string>
<boolean>false</boolean>
@@ -36,6 +36,8 @@ public interface IPlugInPort {
public static final String HI_QUALITY_RENDER_KEY = "hiQualityRender";
public static final String EXPORT_GRID_KEY = "exportGrid";
public static final String STICKY_POINTS_KEY = "stickyPoints";
public static final String METRIC_KEY = "metric";
public static final String SNAP_TO_GRID_KEY = "snapToGrid";
/**
* Returns size of the canvas that takes project dimensions into account as
@@ -53,7 +53,6 @@ public class Presenter implements IPlugInPort {
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 0, 7);
public static final String DEFAULTS_KEY_PREFIX = "default.";
public static final String METRIC_KEY = "metric";
public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections.emptyList();
@@ -92,8 +91,6 @@ public class Presenter implements IPlugInPort {
private Point previousDragPoint = null;
private Project preDragProject = null;
private boolean snapToGrid = true;
public Presenter(IView view) {
super();
this.view = view;
@@ -361,7 +358,8 @@ public class Presenter implements IPlugInPort {
switch (componentTypeSlot.getCreationMethod()) {
case SINGLE_CLICK:
try {
if (snapToGrid) {
if (ConfigurationManager.getInstance().readBoolean(
IPlugInPort.SNAP_TO_GRID_KEY, true)) {
CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing());
}
IDIYComponent<?> component = instantiationManager.instantiateComponent(
@@ -385,7 +383,8 @@ public class Presenter implements IPlugInPort {
case POINT_BY_POINT:
// First click is just to set the controlPointSlot and
// componentSlot.
if (snapToGrid) {
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SNAP_TO_GRID_KEY,
true)) {
CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing());
}
if (instantiationManager.getComponentSlot() == null) {
@@ -460,7 +459,7 @@ public class Presenter implements IPlugInPort {
Map<IDIYComponent<?>, Set<Integer>> components = new HashMap<IDIYComponent<?>, Set<Integer>>();
Point scaledPoint = scalePoint(point);
if (instantiationManager.getComponentTypeSlot() != null) {
if (snapToGrid) {
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SNAP_TO_GRID_KEY, true)) {
CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing());
}
boolean refresh = false;
@@ -469,7 +468,8 @@ public class Presenter implements IPlugInPort {
refresh = instantiationManager.updatePointByPoint(scaledPoint);
break;
case SINGLE_CLICK:
refresh = instantiationManager.updateSingleClick(scaledPoint, snapToGrid,
refresh = instantiationManager.updateSingleClick(scaledPoint, ConfigurationManager
.getInstance().readBoolean(IPlugInPort.SNAP_TO_GRID_KEY, true),
currentProject.getGridSpacing());
break;
}
@@ -712,7 +712,8 @@ public class Presenter implements IPlugInPort {
if (isFirst) {
isFirst = false;
controlPoints[index].translate(dx, dy);
if (snapToGrid) {
if (ConfigurationManager.getInstance().readBoolean(
IPlugInPort.SNAP_TO_GRID_KEY, true)) {
CalcUtils.snapPointToGrid(controlPoints[index], currentProject
.getGridSpacing());
}
@@ -46,6 +46,8 @@ public class ConfigPlugin implements IPlugIn {
"Sticky Points", IPlugInPort.STICKY_POINTS_KEY, true), CONFIG_MENU);
swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
"Export Grid", IPlugInPort.EXPORT_GRID_KEY, false), CONFIG_MENU);
swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
"Snap to Grid", IPlugInPort.SNAP_TO_GRID_KEY, true), CONFIG_MENU);
File themeDir = new File("themes");
if (themeDir.exists()) {
XStream xStream = new XStream(new DomDriver());
@@ -244,6 +244,10 @@
<changeType>NEW_FEATURE</changeType>
<description>Sticky points may be turned off</description>
</com.diyfever.gui.update.Change>
<com.diyfever.gui.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Snap to Grid may be turned off</description>
</com.diyfever.gui.update.Change>
</changes>
<url>http://code.google.com/p/diy-layout-creator/downloads/list
</url>