QnD fix for drawing
( seen when joining cells touching only by one point )
This commit is contained in:
@@ -41,5 +41,37 @@ public class DirectionPosition
|
||||
return "?";
|
||||
}
|
||||
|
||||
// create a new DirectionPosition from this using one possible direction.
|
||||
DirectionPosition moveToAdjacentDirection()
|
||||
{
|
||||
short pointingdirection = 0;
|
||||
Position p = null;
|
||||
if (LabyModel.isFlagSet(direction,LabyModel.RIGHT))
|
||||
{
|
||||
p = new Position(position.getX() + 1, position.getY());
|
||||
pointingdirection |= LabyModel.LEFT;
|
||||
}
|
||||
else if (LabyModel.isFlagSet(direction,LabyModel.LEFT))
|
||||
{
|
||||
p = new Position(position.getX() -1 ,position.getY());
|
||||
pointingdirection |= LabyModel.RIGHT;
|
||||
}
|
||||
else if (LabyModel.isFlagSet(direction,LabyModel.UP))
|
||||
{
|
||||
p = new Position(position.getX(),position.getY() -1);
|
||||
pointingdirection |= LabyModel.DOWN;
|
||||
}
|
||||
else if (LabyModel.isFlagSet(direction,LabyModel.DOWN))
|
||||
{
|
||||
p = new Position(position.getX(),position.getY() + 1);
|
||||
pointingdirection |= LabyModel.UP;
|
||||
}
|
||||
else
|
||||
{
|
||||
p = position;
|
||||
}
|
||||
|
||||
return new DirectionPosition((short) pointingdirection, p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -320,6 +320,11 @@ 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,16 +735,18 @@ 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.
|
||||
@@ -746,11 +758,11 @@ public class Display extends JFrame
|
||||
{
|
||||
map.setDirection(last.getPosition().getX(),last.getPosition().getY(),path);
|
||||
}
|
||||
}
|
||||
last = new DirectionPosition((short) 0,newPosition);
|
||||
System.out.println("Mouse dragged Cell " + newPosition + " Button " + e.getModifiersEx() + " " + InputEvent.BUTTON1_DOWN_MASK);
|
||||
last = last.moveToAdjacentDirection();
|
||||
drawingPath.addLast(last);
|
||||
// map.noWalls(pX,pY);
|
||||
}
|
||||
System.out.println("Mouse dragged from Cell " + first.getPosition() + "To" + newPosition + " Button " + e.getModifiersEx() + " " + InputEvent.BUTTON1_DOWN_MASK);
|
||||
}
|
||||
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)
|
||||
|
||||
@@ -40,11 +40,11 @@ public class LabyModel implements WallsProvider
|
||||
// completed
|
||||
private final static short CLOSED = 64; // can be reused once generation is
|
||||
// completed
|
||||
private final static short LEFT = Brick.LEFT << FLAGLENGTH | DIRECTION | HORIZONTAL | NEGATIVE;
|
||||
private final static short DOWN = Brick.DOWN << FLAGLENGTH | DIRECTION | VERTICAL | POSITIVE;
|
||||
private final static short RIGHT = Brick.RIGHT << FLAGLENGTH | DIRECTION | HORIZONTAL | POSITIVE;
|
||||
private final static short UP = Brick.UP << FLAGLENGTH | DIRECTION | VERTICAL | NEGATIVE;
|
||||
private final static short ENTRY = Brick.ENTRY << FLAGLENGTH; // flag when a
|
||||
public final static short LEFT = Brick.LEFT << FLAGLENGTH | DIRECTION | HORIZONTAL | NEGATIVE;
|
||||
public final static short DOWN = Brick.DOWN << FLAGLENGTH | DIRECTION | VERTICAL | POSITIVE;
|
||||
public final static short RIGHT = Brick.RIGHT << FLAGLENGTH | DIRECTION | HORIZONTAL | POSITIVE;
|
||||
public final static short UP = Brick.UP << FLAGLENGTH | DIRECTION | VERTICAL | NEGATIVE;
|
||||
public final static short ENTRY = Brick.ENTRY << FLAGLENGTH; // flag when a
|
||||
// wall should
|
||||
// be open to
|
||||
// access
|
||||
|
||||
Reference in New Issue
Block a user