Add a context menu to edit boxes type
model: * New methods to directly set boxes type instead of only toggling (setXBox methods) * toggleBox now calls setXBox methods ui: * Add a context menu, enabled on right click, to directly choose the type of a box in the maze * Defer the calculation of the box coordinates in the matrix to two new methods, getBoxRow and getBoxLine
This commit is contained in:
1 parent
37def85f5b
commit
81df80e7ea
7 files changed
+196
-34
No files matched your search
+19
-7
@@ -117,16 +117,28 @@ public class MazeDrawing extends JPanel implements MouseListener {
|
||||
return;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int x = e.getX();
|
||||
int y = e.getY();
|
||||
private int getBoxRow(int x) {
|
||||
int dimensionX = mazeApp.getMazeAppModel().getMaze().getDimensionX();
|
||||
int dimensionY = mazeApp.getMazeAppModel().getMaze().getDimensionY();
|
||||
int boxWidth = getWidth() / dimensionX;
|
||||
return x / boxWidth;
|
||||
}
|
||||
|
||||
private int getBoxLine(int y) {
|
||||
int dimensionY = mazeApp.getMazeAppModel().getMaze().getDimensionY();
|
||||
int boxHeight = getHeight() / dimensionY;
|
||||
int boxX = x / boxWidth;
|
||||
int boxY = y / boxHeight;
|
||||
mazeApp.getMazeAppModel().toggleBox(boxX, boxY);
|
||||
return y / boxHeight;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int boxRow = getBoxRow(e.getX());
|
||||
int boxLine = getBoxLine(e.getY());
|
||||
if (e.getButton() == MouseEvent.BUTTON3) {
|
||||
BoxTypeEditionMenu boxTypeEditionMenu = new BoxTypeEditionMenu(mazeApp, boxLine, boxRow);
|
||||
boxTypeEditionMenu.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
else if (e.getButton() == MouseEvent.BUTTON1) {
|
||||
mazeApp.getMazeAppModel().toggleBox(boxLine, boxRow);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user