QnD fix for drawing

( seen when joining cells touching only by one point )
This commit is contained in:
philippe lhardy
2017-12-05 21:52:12 +01:00
parent c5d8503dbb
commit b360320570
3 changed files with 72 additions and 27 deletions

View File

@@ -319,7 +319,12 @@ public class Display extends JFrame
{
return maxdepth;
}
public void setName(String n)
{
name = n;
}
public String getName()
{
if (name == null)
@@ -447,6 +452,7 @@ public class Display extends JFrame
setAutoSize( autoSlide.isSelected());
}
});
final JTextField saveName = new JTextField("newlaby ");
final JButton savePngButton = new JButton(labels.getString("save") +" png");
Action savePngAction = new AbstractAction() {
public void actionPerformed(ActionEvent evt)
@@ -463,7 +469,9 @@ public class Display extends JFrame
{
//
System.out.println("save");
save((MazeParamsFixed) params,model);
MazeParamsFixed p = (MazeParamsFixed) params;
p.setName(saveName.getText());
save(p,model);
}
};
saveButton.addActionListener(saveAction);
@@ -483,6 +491,7 @@ public class Display extends JFrame
resizecontrol.add(showAll);
resizecontrol.add(slider);
resizecontrol.add(autoSlide);
resizecontrol.add(saveName);
resizecontrol.add(savePngButton);
resizecontrol.add(saveButton);
resizecontrol.add(quitButton);
@@ -709,6 +718,7 @@ public class Display extends JFrame
// not set by default for debug, will show any path
boolean showAll = false;
// for a given (x,y) pixel return cell position.
Position getPosition(int x, int y)
{
int pX = (int) ((double) (x - cp.getOffsetX()) / cp.getWidth());
@@ -725,32 +735,34 @@ public class Display extends JFrame
if (drawingPath == null )
{
drawingPath = new LinkedList<>();
last = new DirectionPosition((short) 0,newPosition);
System.out.println("Mouse dragged Cell " + newPosition + " Button " + e.getModifiersEx() + " " + InputEvent.BUTTON1_DOWN_MASK);
drawingPath.addLast(last);
}
else
{
// setShowAll(true);
last = drawingPath.getLast();
if ( last.getPosition().equals(newPosition))
DirectionPosition first = drawingPath.getLast();
last = first;
// construct as many move form last to new position as needed.
while ( ! last.getPosition().equals(newPosition))
{
// no move.
return;
path=LabyModel.getDirection(last.getPosition(),newPosition);
last.setDirection(path);
// button 1 : add direction; button 2 : replace with direction.
if ( ( e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK ) != 0 )
{
map.addDirection(last.getPosition().getX(),last.getPosition().getY(),path);
}
else
{
map.setDirection(last.getPosition().getX(),last.getPosition().getY(),path);
}
last = last.moveToAdjacentDirection();
drawingPath.addLast(last);
}
path=LabyModel.getDirection(last.getPosition(),newPosition);
last.setDirection(path);
// button 1 : add direction; button 2 : replace with direction.
if ( ( e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK ) != 0 )
{
map.addDirection(last.getPosition().getX(),last.getPosition().getY(),path);
}
else
{
map.setDirection(last.getPosition().getX(),last.getPosition().getY(),path);
}
System.out.println("Mouse dragged from Cell " + first.getPosition() + "To" + newPosition + " Button " + e.getModifiersEx() + " " + InputEvent.BUTTON1_DOWN_MASK);
}
last = new DirectionPosition((short) 0,newPosition);
System.out.println("Mouse dragged Cell " + newPosition + " Button " + e.getModifiersEx() + " " + InputEvent.BUTTON1_DOWN_MASK);
drawingPath.addLast(last);
// map.noWalls(pX,pY);
changed(null,null,map);
}
@@ -862,6 +874,7 @@ public class Display extends JFrame
sX=0;
sY=0;
cp.resetMazeWidthHeight(map.getWidth(),map.getHeight());
setPreferredSize(cp.getDimension());
}
public void setWallSize(int size)