Skip to content

Commit

Permalink
Adding drag/paint functionality to drawing pane
Browse files Browse the repository at this point in the history
  • Loading branch information
RaneWallin committed Dec 11, 2018
1 parent 7b450f0 commit ee22974
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/DrawingPane.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import javafx.event.EventHandler;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.FlowPane;
import javafx.scene.paint.Color;
Expand All @@ -15,6 +14,7 @@ public class DrawingPane extends FlowPane {
private int bitStyle;
private Map<Integer, Color> colorMap = new HashMap<>();
Color curColor;
boolean mouseDown = false;

public DrawingPane(int workspaceSize, int bitStyle) {
super(Orientation.HORIZONTAL, 0, 0);
Expand Down Expand Up @@ -46,6 +46,20 @@ public void handle(MouseEvent event) {
}
});

pix.setOnDragDetected(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
pix.startFullDrag();
}
});

pix.setOnMouseDragOver(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
doDraw(pix);
}
});

getChildren().add(pix);

}
Expand Down
4 changes: 1 addition & 3 deletions src/PixiePal.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
Stroke inside rectangle: https://stackoverflow.com/questions/40451544/javafx-setting-a-border-within-a-rectangle-to-keep-the-width-and-height
Mouse event for rectangle: https://stackoverflow.com/questions/13359382/creating-a-mouselistner-to-javafx-rectangle
Colorpicker: https://docs.oracle.com/javafx/2/ui_controls/color-picker.htm
MouseDrag event: https://stackoverflow.com/questions/40702559/javafx-node-doesnt-recognize-when-mouse-is-being-dragged-over-it
*/

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class PixiePal extends Application {
Expand Down
35 changes: 35 additions & 0 deletions src/PreviewPane.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import javafx.scene.layout.FlowPane;
import javafx.scene.paint.Color;
import java.util.Map;

public class PreviewPane extends FlowPane {
private Map<Pixel, Color> pixelMap;
private int workspaceSize = 32;
private int bitStyle;

public PreviewPane(int bitStyle) {
this.bitStyle = bitStyle;
updateSpace();
}

public void updateColors(Map<Pixel, Color> pixelMap) {
this.pixelMap = pixelMap;

}

private void updateSpace() {
for(int i = 1; i <= bitStyle*bitStyle; i++) {
int dim = workspaceSize/bitStyle;
Pixel pix = new Pixel(dim);
pixelMap.put(pix, Color.WHITE);

pix.setFill(pixelMap.get(pix.getPixID()));

getChildren().add(pix);
}
}

private void updateSpace(Map<Pixel, Color> pixelMap) {

}
}

0 comments on commit ee22974

Please sign in to comment.