mirror of
https://github.com/Akomry/makeyourownapp-jam.git
synced 2025-12-06 11:43:53 +00:00
feat: zoom possible, doit fix le scrollpane pour qu'il update ses scrollbars
This commit is contained in:
parent
c47b49a616
commit
b325204d7d
2 changed files with 59 additions and 2 deletions
|
|
@ -9,10 +9,14 @@ import javafx.scene.canvas.Canvas;
|
|||
import javafx.scene.control.Label;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.Slider;
|
||||
import javafx.scene.image.PixelReader;
|
||||
import javafx.scene.image.PixelWriter;
|
||||
import javafx.scene.image.WritableImage;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.input.ScrollEvent;
|
||||
import javafx.scene.input.ZoomEvent;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
import fr.emiko.graphicsElement.Stroke;
|
||||
|
|
@ -27,6 +31,9 @@ public class HelloController implements Initializable {
|
|||
public MenuItem saveButton;
|
||||
public MenuItem loadButton;
|
||||
public MenuItem newCanvasButton;
|
||||
public Slider brushSizeSlider;
|
||||
public Slider zoomSlider;
|
||||
public ScrollPane scrollPane;
|
||||
private double posX = 0;
|
||||
private double posY = 0;
|
||||
private Vector<Stroke> strokes = new Vector<>();
|
||||
|
|
@ -39,8 +46,28 @@ public class HelloController implements Initializable {
|
|||
saveButton.setOnAction(this::onActionSave);
|
||||
loadButton.setOnAction(this::onActionLoad);
|
||||
newCanvasButton.setOnAction(this::onActionCreateCanvas);
|
||||
scrollPane.setOnScroll(this::onScrollZoom);
|
||||
}
|
||||
|
||||
private void onScrollZoom(ScrollEvent event) {
|
||||
event.consume();
|
||||
double SCALE_DELTA = 1.1;
|
||||
if (event.getDeltaY() == 0) {
|
||||
return;
|
||||
}
|
||||
if (event.isControlDown()) {
|
||||
double scaleFactor =
|
||||
(event.getDeltaY() > 0) ? SCALE_DELTA : 1 / SCALE_DELTA;
|
||||
|
||||
drawingCanvas.setScaleX(drawingCanvas.getScaleX() * scaleFactor);
|
||||
drawingCanvas.setScaleY(drawingCanvas.getScaleY() * scaleFactor);
|
||||
scrollPane.setFitToHeight(true);
|
||||
scrollPane.setFitToWidth(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void onActionCreateCanvas(ActionEvent actionEvent) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.canvas.Canvas?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.Menu?>
|
||||
<?import javafx.scene.control.MenuBar?>
|
||||
<?import javafx.scene.control.MenuItem?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?import javafx.scene.control.Slider?>
|
||||
<?import javafx.scene.control.SplitPane?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
|
|
@ -35,7 +37,35 @@
|
|||
</MenuBar>
|
||||
<SplitPane dividerPositions="0.11195652173913044" VBox.vgrow="ALWAYS">
|
||||
<items>
|
||||
<VBox prefHeight="200.0" prefWidth="100.0" />
|
||||
<VBox prefHeight="200.0" prefWidth="100.0">
|
||||
<children>
|
||||
<GridPane>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label text="Zoom" />
|
||||
<Slider fx:id="zoomSlider" blockIncrement="0.1" max="5.0" min="1.0" showTickLabels="true" showTickMarks="true" snapToTicks="true" value="1.0" GridPane.rowIndex="1" />
|
||||
</children>
|
||||
</GridPane>
|
||||
<GridPane>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label text="Brush size" />
|
||||
<Slider fx:id="brushSizeSlider" GridPane.rowIndex="1" />
|
||||
</children>
|
||||
</GridPane>
|
||||
</children></VBox>
|
||||
<GridPane>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="ALWAYS" />
|
||||
|
|
@ -46,7 +76,7 @@
|
|||
<RowConstraints vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<ScrollPane hbarPolicy="ALWAYS" style="-fx-background-color: #666666; -fx-background: #666666;" vbarPolicy="ALWAYS" GridPane.hgrow="ALWAYS" GridPane.vgrow="ALWAYS">
|
||||
<ScrollPane fx:id="scrollPane" hbarPolicy="ALWAYS" style="-fx-background-color: #666666; -fx-background: #666666;" vbarPolicy="ALWAYS" GridPane.hgrow="ALWAYS" GridPane.vgrow="ALWAYS">
|
||||
<content>
|
||||
<Canvas fx:id="drawingCanvas" height="600.0" nodeOrientation="INHERIT" width="800.0" />
|
||||
</content>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue