Skip to content

Commit

Permalink
add resetZoom, remove setCellSize, fire a property called cellSize
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed Jun 17, 2024
1 parent a52fae1 commit 97e9970
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ private void resetCanvasView() {
model.setXZero(canvas.getWidth() / 2);
model.setYZero(canvas.getHeight() / 2);

// reset zoom level
model.setCellSize(CanvasModel.DEFAULT_CELL_SIZE);
model.resetZoom();
canvas.repaint();
}

Expand All @@ -195,7 +194,8 @@ public void propertyChange(PropertyChangeEvent e) {
}

// if guidelines were toggled or zoom was changed or axes were toggled
if ("enableGuidelines".equals(propertyName) || "zoomChange".equals(propertyName) || "axesVisible".equals(propertyName)) {
if ("enableGuidelines".equals(propertyName) || "cellSize".equals(propertyName)
|| "axesVisible".equals(propertyName)) {
canvas.repaint();
return;
}
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/com/github/creme332/model/CanvasModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,25 @@ public Point2D toPolySpace(Point2D point) {
* @param zoomIn Zoom in if true, zoom out otherwise
*/
public void updateCanvasZoom(boolean zoomIn) {
support.firePropertyChange("guidelines", null, zoomIn);
int newCellSize;
if (zoomIn) {
setCellSize(Math.min(CanvasModel.MAX_CELL_SIZE, getCellSize() + CanvasModel.ZOOM_INCREMENT));
newCellSize = (Math.min(CanvasModel.MAX_CELL_SIZE, getCellSize() + CanvasModel.ZOOM_INCREMENT));
} else {
setCellSize(Math.max(CanvasModel.MIN_CELL_SIZE, getCellSize() - CanvasModel.ZOOM_INCREMENT));
newCellSize = (Math.max(CanvasModel.MIN_CELL_SIZE, getCellSize() - CanvasModel.ZOOM_INCREMENT));
}
support.firePropertyChange("cellSize", cellSize, newCellSize);
cellSize = newCellSize;
}

public void resetZoom() {
support.firePropertyChange("cellSize", cellSize, DEFAULT_CELL_SIZE);
cellSize = DEFAULT_CELL_SIZE;
}

public void addPropertyChangeListener(PropertyChangeListener listener) {
support.addPropertyChangeListener("enableGuidelines", listener);
support.addPropertyChangeListener("axesVisible", listener);
support.addPropertyChangeListener("cellSize", listener);
}

public List<ShapeWrapper> getShapes() {
Expand All @@ -174,10 +182,6 @@ public float getLabelFontSizeSF() {
return labelFontSizeScaleFactor;
}

public void setCellSize(int newCellSize) {
cellSize = newCellSize;
}

public int getXZero() {
return xZero;
}
Expand Down

0 comments on commit 97e9970

Please sign in to comment.