Skip to content

Commit

Permalink
Comments and Tutorial added
Browse files Browse the repository at this point in the history
+Comment Node, allows you to store text alongside the node layout to
annotate and clarify stuff

+Created a tutorial for new users which will be distributed with the
GUI.

~Fixed some bugs
  • Loading branch information
tiggerbiggo committed Oct 18, 2018
1 parent 04a326d commit 954b66c
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ target/
imgs/
*.prim
*.jar
*.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@

/**
*/
public class HueCycleGradient extends Gradient {

/**
* Abstract method for evaluating gradients
*
* @param a The vector to evaluate
* @return The evaluated color
*/
@Override
public Color evaluate(Vector2 a) {
public class HueCycleGradient{
public static Color evaluate(Vector2 a) {
Color c = Color.getHSBColor((a.fX() + a.fY()) / 2, 1, 1);
return c;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.tiggerbiggo.prima.primaplay.node.implemented.io;

import ch.hephaistos.utilities.loki.util.annotations.TransferGrid;
import ch.hephaistos.utilities.loki.util.interfaces.ChangeListener;
import com.tiggerbiggo.prima.primaplay.core.RenderParams;
import com.tiggerbiggo.prima.primaplay.graphics.Gradient;
import com.tiggerbiggo.prima.primaplay.graphics.HueCycleGradient;
Expand All @@ -8,14 +10,25 @@
import com.tiggerbiggo.prima.primaplay.node.link.type.ColorArrayOutputLink;
import com.tiggerbiggo.prima.primaplay.node.link.type.ColorInputLink;
import com.tiggerbiggo.prima.primaplay.node.link.type.VectorArrayInputLink;
import com.tiggerbiggo.utils.calculation.ReflectionHelper;
import com.tiggerbiggo.utils.calculation.Vector2;
import java.awt.Color;
import java.lang.reflect.Field;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.CheckBox;

public class GradientNode extends NodeInOut {

@TransferGrid
boolean hueCycle;

Field f_hueCycle = ReflectionHelper.getFieldFromClass(GradientNode.class, "hueCycle");

VectorArrayInputLink inputLink;
ColorInputLink A, B;


ColorArrayOutputLink out;

public GradientNode() {
Expand All @@ -32,7 +45,10 @@ public Color[] get(RenderParams p) {
Vector2[] in = inputLink.get(p);
Color[] toReturn = new Color[in.length];
for (int i = 0; i < in.length; i++) {
toReturn[i] = SimpleGradient.evaluate(in[i], A.get(p), B.get(p), true);
if(hueCycle)
toReturn[i] = HueCycleGradient.evaluate(in[i]);
else
toReturn[i] = SimpleGradient.evaluate(in[i], A.get(p), B.get(p), true);
}
return toReturn;
}
Expand All @@ -49,4 +65,18 @@ public String getName() {
public String getDescription() {
return "Takes an array of Vectors and turns them into an array of Colors.";
}

@Override
public Node getFXNode(ChangeListener listener) {
CheckBox cb = new CheckBox("Hue Cycle");
cb.setSelected(hueCycle);

Object thisObj = this;

cb.setOnAction(event -> {
hueCycle = cb.isSelected();
listener.onObjectValueChanged(f_hueCycle, !hueCycle, hueCycle, thisObj);
});
return cb;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import javafx.scene.Node;
import javafx.scene.control.ColorPicker;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;

public class ColorNode extends NodeHasOutput {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.tiggerbiggo.prima.primaplay.node.implemented.output;

import ch.hephaistos.utilities.loki.util.annotations.TransferGrid;
import ch.hephaistos.utilities.loki.util.interfaces.ChangeListener;
import com.tiggerbiggo.prima.primaplay.node.core.NodeHasOutput;
import com.tiggerbiggo.utils.calculation.GUITools;
import javafx.beans.binding.DoubleBinding;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.TextArea;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.Pane;

public class CommentNode extends NodeHasOutput{

@TransferGrid
String comment;

@TransferGrid
double x = 100;
@TransferGrid
double y = 100;

@Override
public String getName() {
return "Comment Node";
}

@Override
public String getDescription() {
return "Write comments";
}

public static final double MIN_SIZE = 100;
public static final double DRAG_SIZE = 20;

private double offsetX, offsetY;

@Override
public Node getFXNode(ChangeListener listener) {
TextArea ta = new TextArea(comment);
Pane dragPane = new Pane();
Pane p = new Pane(ta, dragPane);

//20x20 pane
//bind bottom right of anchor pane to the drag pane

ta.setPrefWidth(Double.MAX_VALUE);
ta.setPrefHeight(Double.MAX_VALUE);

ta.maxWidthProperty().bind(p.widthProperty());
ta.maxHeightProperty().bind(p.heightProperty().subtract(DRAG_SIZE));

ta.setOnKeyReleased(event -> comment = ta.getText());
ta.setWrapText(true);

dragPane.setMinWidth(DRAG_SIZE);
dragPane.setMinHeight(DRAG_SIZE);

dragPane.setTranslateX(x);
dragPane.setTranslateY(y);
dragPane.getStyleClass().add("button");

offsetX = offsetY = 0;

dragPane.setOnMousePressed(event -> {
if(event.getButton() != MouseButton.PRIMARY)
return;

offsetX = dragPane.getTranslateX() - event.getSceneX();
offsetY = dragPane.getTranslateY() - event.getSceneY();

event.consume();
});

dragPane.setOnMouseDragged(e -> {
if(e.getButton() != MouseButton.PRIMARY)
return;
if(e.getSceneX() + offsetX >= MIN_SIZE)
dragPane.setTranslateX(e.getSceneX() + offsetX);
else
dragPane.setTranslateX(MIN_SIZE);

if(e.getSceneY() + offsetY >= MIN_SIZE)
dragPane.setTranslateY(e.getSceneY() + offsetY);
else
dragPane.setTranslateY(MIN_SIZE);

x = dragPane.getTranslateX();
y = dragPane.getTranslateY();

e.consume();
});

dragPane.toFront();


p.setPrefWidth(Double.MAX_VALUE);
p.setPrefHeight(Double.MAX_VALUE);
p.maxWidthProperty().bind(dragPane.translateXProperty().add(DRAG_SIZE));
p.maxHeightProperty().bind(dragPane.translateYProperty().add(DRAG_SIZE));

p.getStyleClass().add("CommentPane");

return p;
}
}
12 changes: 12 additions & 0 deletions PrimaView/src/main/java/sample/NodeReflection.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import org.reflections.Reflections;
Expand All @@ -17,6 +18,17 @@ public static List<Class<? extends INode>> getAllImplementedNodes() {
if (allImplementedNodes == null) {
setNodeList();
}
allImplementedNodes.sort((o1, o2) -> {
try {
String s1, s2;
s1 = o1.newInstance().getName();
s2 = o2.newInstance().getName();
return s1.compareTo(s2);
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
return 0;
});
return Collections.unmodifiableList(allImplementedNodes);
}

Expand Down
4 changes: 2 additions & 2 deletions PrimaView/src/main/java/sample/NodeSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ public static NodePane parseNodes(String toParse, ChangeListener listen){

currentLine++;

do{
while(currentLine < lines.length){
int[] links = parseLinks(lines[currentLine]);

GUIOutputLink output = nodeList.get(links[0]).getOutputs().get(links[1]);
GUIInputLink input = nodeList.get(links[2]).getInputs().get(links[3]);

input.link(output);
currentLine++;
}while(currentLine < lines.length);
}

return pane;
}
Expand Down
4 changes: 4 additions & 0 deletions PrimaView/src/main/resources/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@
}
.ColorLink{
-fx-fill: '#ffffff';
}
.CommentPane{
-fx-width : 300;
-fx-height: 300;
}

0 comments on commit 954b66c

Please sign in to comment.