Skip to content

Commit

Permalink
Disable layer field right click, start to add animation system #3,
Browse files Browse the repository at this point in the history
add R key to reset zoom and scroll, add Ctrl + X
  • Loading branch information
MinusKube committed Jan 25, 2018
1 parent 9743e60 commit 48f4295
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/fr/minuskube/editor/animation/FrameRepeat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.minuskube.editor.animation;

public class FrameRepeat {

private int start;
private int end;
private int times;

private int currentTimes = 0;

public FrameRepeat(int start, int end, int times) {
this.start = start;
this.end = end;
this.times = times;
}

public int getStart() { return start; }
public int getEnd() { return end; }
public int getTimes() { return times; }

public int getCurrentTimes() { return currentTimes; }
public void setCurrentTimes(int currentTimes) { this.currentTimes = currentTimes; }

}
6 changes: 6 additions & 0 deletions src/main/java/fr/minuskube/editor/layer/LayersPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.ListView;
import javafx.scene.control.MultipleSelectionModel;
import javafx.scene.control.ScrollPane;
Expand All @@ -18,6 +19,7 @@
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
Expand Down Expand Up @@ -95,8 +97,12 @@ private HBox newImage(SceneImage image) {

TextField field = new TextField(image.getName());
field.setEditable(false);
field.setContextMenu(new ContextMenu());

field.setOnMouseClicked(event -> {
if(event.getButton() != MouseButton.PRIMARY)
return;

if(event.getClickCount() >= 2)
field.setEditable(true);
else if(event.getClickCount() == 1) {
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/fr/minuskube/editor/scene/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,43 @@ else if(event.getCode() == KeyCode.LEFT)
else if(event.getCode() == KeyCode.RIGHT)
moveSelectedObjects(distance, 0);

else if(event.getCode() == KeyCode.R) {
zoom = 1;

scrollX = ((canvas.getWidth() - width) / 2) / getWidth();
scrollY = ((canvas.getHeight() - height) / 2) / getHeight();
}

else if(event.getCode() == KeyCode.DELETE) {
objects.removeIf(SceneObject::isSelected);
selectedObjects.clear();
}

else if(event.isControlDown() && event.getCode() == KeyCode.X) {
ClipboardContent content = new ClipboardContent();

List<SceneObject> selected = new ArrayList<>();
List<File> files = new ArrayList<>();

for(SceneObject object : selectedObjects) {
if(object instanceof SceneImage) {
SceneImage image = (SceneImage) object;

files.add(image.getSource());
selected.add(new SceneImage(image));
}
}

content.put(SceneImage.DATA_FORMAT, selected);
content.putFiles(files);

Clipboard clipboard = Clipboard.getSystemClipboard();
clipboard.setContent(content);

objects.removeIf(SceneObject::isSelected);
selectedObjects.clear();
}

else if(event.isControlDown() && event.getCode() == KeyCode.C) {
ClipboardContent content = new ClipboardContent();

Expand Down
69 changes: 69 additions & 0 deletions src/main/java/fr/minuskube/editor/scene/object/SceneAnimation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package fr.minuskube.editor.scene.object;

import fr.minuskube.editor.animation.FrameRepeat;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import java.util.ArrayList;
import java.util.List;

public class SceneAnimation {

private ObservableList<SceneAnimationFrame> frames;
private List<FrameRepeat> repeats;

private boolean playing = false;
private boolean looping = false;

private int width, height;
private boolean autoCrop;
private float speed = 1;

private int currentFrame = 0;
private float currentFrameState = 0;

public SceneAnimation() {
this.frames = FXCollections.observableArrayList();
this.repeats = new ArrayList<>();
}

public void update() {
SceneAnimationFrame frame = frames.get(currentFrame);

currentFrameState += (1 / 60f) * speed; // TODO: Replace by deltaTime

if(currentFrameState >= frame.getDuration()) {
currentFrame++;

for(FrameRepeat repeat : repeats) {
if(repeat.getTimes() != -1 && repeat.getTimes() >= repeat.getCurrentTimes())
continue;

if(currentFrame > repeat.getEnd())
currentFrame = repeat.getStart();

repeat.setCurrentTimes(repeat.getCurrentTimes() + 1);
}

currentFrameState = 0;
}
}

public ObservableList<SceneAnimationFrame> getFrames() { return frames; }
public List<FrameRepeat> getRepeats() { return repeats; }

public boolean isPlaying() { return playing; }

public boolean isLooping() { return looping; }
public void setLooping(boolean looping) { this.looping = looping; }

public int getWidth() { return width; }
public void setWidth(int width) { this.width = width; }

public int getHeight() { return height; }
public void setHeight(int height) { this.height = height; }

public float getSpeed() { return speed; }
public void setSpeed(float speed) { this.speed = speed; }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.minuskube.editor.scene.object;

import java.io.File;
import java.io.FileNotFoundException;

public class SceneAnimationFrame extends SceneImage {

private float duration;
private int offsetX, offsetY;

public SceneAnimationFrame(File source) throws FileNotFoundException {
super(source);
}

public float getDuration() { return duration; }
public void setDuration(float duration) { this.duration = duration; }

public int getOffsetX() { return offsetX; }
public void setOffsetX(int offsetX) { this.offsetX = offsetX; }

public int getOffsetY() { return offsetY; }
public void setOffsetY(int offsetY) { this.offsetY = offsetY; }

}

0 comments on commit 48f4295

Please sign in to comment.