mirror of
https://github.com/aNNiMON/HotaruFX.git
synced 2024-09-19 14:14:21 +03:00
Add library nodes
This commit is contained in:
parent
ee1c00b92c
commit
b4214b0489
54
app/src/main/java/com/annimon/hotarufx/ui/LibraryItem.java
Normal file
54
app/src/main/java/com/annimon/hotarufx/ui/LibraryItem.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package com.annimon.hotarufx.ui;
|
||||||
|
|
||||||
|
import javafx.beans.binding.ObjectBinding;
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
import javafx.beans.property.StringProperty;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Tooltip;
|
||||||
|
|
||||||
|
public class LibraryItem extends Button {
|
||||||
|
|
||||||
|
private final StringProperty code = new SimpleStringProperty("");
|
||||||
|
|
||||||
|
public LibraryItem() {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LibraryItem(String text) {
|
||||||
|
super(text);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LibraryItem(String text, Node graphic) {
|
||||||
|
super(text, graphic);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
setMnemonicParsing(false);
|
||||||
|
tooltipProperty().bind(new ObjectBinding<Tooltip>() {
|
||||||
|
{ bind(code); }
|
||||||
|
@Override
|
||||||
|
protected Tooltip computeValue() {
|
||||||
|
return new Tooltip(code.get());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringProperty codeProperty() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code.set(code
|
||||||
|
.replace("\\n", "\n")
|
||||||
|
.replaceAll("\\n\\s+", "\n")
|
||||||
|
.replace('_', ' ')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -5,13 +5,14 @@ import com.annimon.hotarufx.bundles.BundleLoader;
|
|||||||
import com.annimon.hotarufx.bundles.CompositionBundle;
|
import com.annimon.hotarufx.bundles.CompositionBundle;
|
||||||
import com.annimon.hotarufx.bundles.NodesBundle;
|
import com.annimon.hotarufx.bundles.NodesBundle;
|
||||||
import com.annimon.hotarufx.io.DocumentListener;
|
import com.annimon.hotarufx.io.DocumentListener;
|
||||||
|
import com.annimon.hotarufx.io.DocumentManager;
|
||||||
|
import com.annimon.hotarufx.io.FileManager;
|
||||||
import com.annimon.hotarufx.io.IOStream;
|
import com.annimon.hotarufx.io.IOStream;
|
||||||
import com.annimon.hotarufx.lexer.HotaruLexer;
|
import com.annimon.hotarufx.lexer.HotaruLexer;
|
||||||
import com.annimon.hotarufx.lib.Context;
|
import com.annimon.hotarufx.lib.Context;
|
||||||
import com.annimon.hotarufx.parser.HotaruParser;
|
import com.annimon.hotarufx.parser.HotaruParser;
|
||||||
import com.annimon.hotarufx.parser.visitors.InterpreterVisitor;
|
import com.annimon.hotarufx.parser.visitors.InterpreterVisitor;
|
||||||
import com.annimon.hotarufx.io.DocumentManager;
|
import com.annimon.hotarufx.ui.LibraryItem;
|
||||||
import com.annimon.hotarufx.io.FileManager;
|
|
||||||
import com.annimon.hotarufx.ui.SyntaxHighlighter;
|
import com.annimon.hotarufx.ui.SyntaxHighlighter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -29,6 +30,7 @@ import javafx.scene.Scene;
|
|||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.TextArea;
|
import javafx.scene.control.TextArea;
|
||||||
import javafx.scene.control.TitledPane;
|
import javafx.scene.control.TitledPane;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.stage.Modality;
|
import javafx.stage.Modality;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
@ -43,6 +45,9 @@ public class EditorController implements Initializable, DocumentListener {
|
|||||||
@FXML
|
@FXML
|
||||||
private CodeArea editor;
|
private CodeArea editor;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Pane library;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextArea log;
|
private TextArea log;
|
||||||
@FXML
|
@FXML
|
||||||
@ -156,6 +161,7 @@ public class EditorController implements Initializable, DocumentListener {
|
|||||||
initUndoRedo();
|
initUndoRedo();
|
||||||
openSample();
|
openSample();
|
||||||
editor.getUndoManager().forgetHistory();
|
editor.getUndoManager().forgetHistory();
|
||||||
|
initializeLibrary();
|
||||||
Platform.runLater(editor::requestFocus);
|
Platform.runLater(editor::requestFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,6 +174,15 @@ public class EditorController implements Initializable, DocumentListener {
|
|||||||
redoButton.setOnAction(a -> editor.redo());
|
redoButton.setOnAction(a -> editor.redo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initializeLibrary() {
|
||||||
|
library.getChildren().stream()
|
||||||
|
.map(LibraryItem.class::cast)
|
||||||
|
.forEach(item -> item.setOnAction(a -> {
|
||||||
|
editor.insertText(editor.getCaretPosition(), item.getCode());
|
||||||
|
editor.requestFocus();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
public void setPrimaryStage(Stage primaryStage) {
|
public void setPrimaryStage(Stage primaryStage) {
|
||||||
this.primaryStage = primaryStage;
|
this.primaryStage = primaryStage;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,6 @@ public class Composition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Scene produceAnimationScene() {
|
public Scene produceAnimationScene() {
|
||||||
return new Scene(scene.getGroup(), sceneWidth, sceneHeight, Color.WHITE);
|
return new Scene(scene.getGroup(), sceneWidth, sceneHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,20 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import com.annimon.hotarufx.ui.ColorPickerBox?>
|
<?import com.annimon.hotarufx.ui.*?>
|
||||||
<?import com.annimon.hotarufx.ui.FontAwesomeIcon?>
|
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.BorderPane?>
|
<?import javafx.scene.layout.BorderPane?>
|
||||||
|
<?import javafx.scene.layout.FlowPane?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
<?import javafx.scene.shape.Arc?>
|
||||||
|
<?import javafx.scene.shape.Circle?>
|
||||||
|
<?import javafx.scene.shape.Ellipse?>
|
||||||
|
<?import javafx.scene.shape.Line?>
|
||||||
|
<?import javafx.scene.shape.Polygon?>
|
||||||
|
<?import javafx.scene.shape.Polyline?>
|
||||||
|
<?import javafx.scene.shape.Rectangle?>
|
||||||
|
<?import javafx.scene.shape.SVGPath?>
|
||||||
|
<?import javafx.scene.text.Text?>
|
||||||
<?import org.fxmisc.richtext.CodeArea?>
|
<?import org.fxmisc.richtext.CodeArea?>
|
||||||
|
|
||||||
<BorderPane xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1"
|
<BorderPane xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
prefWidth="800.0" prefHeight="600.0"
|
prefWidth="800.0" prefHeight="600.0"
|
||||||
minWidth="NaN" minHeight="NaN"
|
minWidth="NaN" minHeight="NaN"
|
||||||
@ -64,7 +72,201 @@
|
|||||||
<TitledPane animated="false" text="Color picker">
|
<TitledPane animated="false" text="Color picker">
|
||||||
<ColorPickerBox />
|
<ColorPickerBox />
|
||||||
</TitledPane>
|
</TitledPane>
|
||||||
<TitledPane animated="false" minWidth="150.0" text="Library"/>
|
<TitledPane animated="false" expanded="false" text="Library">
|
||||||
|
<FlowPane fx:id="library" prefWidth="200">
|
||||||
|
<LibraryItem text="Circle">
|
||||||
|
<graphic>
|
||||||
|
<Circle radius="15.0"
|
||||||
|
fill="#c0c033"
|
||||||
|
strokeWidth="2" stroke="#ddd" />
|
||||||
|
</graphic>
|
||||||
|
<code>
|
||||||
|
circle({\n
|
||||||
|
__cx: 0,\n
|
||||||
|
__cy: 0,\n
|
||||||
|
__radius: 100,\n
|
||||||
|
__fill: '#c0c033',\n
|
||||||
|
__strokeWidth: 4,\n
|
||||||
|
__stroke: "#ddd"\n
|
||||||
|
})
|
||||||
|
</code>
|
||||||
|
</LibraryItem>
|
||||||
|
<LibraryItem text="Rectangle">
|
||||||
|
<graphic>
|
||||||
|
<Rectangle width="15.0" height="22.0"
|
||||||
|
fill="#4233c0"
|
||||||
|
strokeWidth="2" stroke="#819bed"
|
||||||
|
rotate="30" />
|
||||||
|
</graphic>
|
||||||
|
<code>
|
||||||
|
rectangle({\n
|
||||||
|
__x: -50,\n
|
||||||
|
__y: -75,\n
|
||||||
|
__width: 100,\n
|
||||||
|
__height: 150,\n
|
||||||
|
__fill: '#4233c0'\n
|
||||||
|
__strokeWidth: 4,\n
|
||||||
|
__stroke: '#819bed',\n
|
||||||
|
__rotate: 30\n
|
||||||
|
})
|
||||||
|
</code>
|
||||||
|
</LibraryItem>
|
||||||
|
<LibraryItem text="Rounded rectangle">
|
||||||
|
<graphic>
|
||||||
|
<Rectangle width="25.0" height="20.0"
|
||||||
|
arcWidth="10.0" arcHeight="10.0"
|
||||||
|
fill="#4233c0"
|
||||||
|
strokeWidth="2" stroke="#819bed" />
|
||||||
|
</graphic>
|
||||||
|
<code>
|
||||||
|
rectangle({\n
|
||||||
|
__x: -175,\n
|
||||||
|
__y: -100,\n
|
||||||
|
__width: 350,\n
|
||||||
|
__height: 200,\n
|
||||||
|
__arcWidth: 25,\n
|
||||||
|
__arcHeight: 25,\n
|
||||||
|
__fill: '#4233c0'\n
|
||||||
|
__strokeWidth: 4,\n
|
||||||
|
__stroke: '#819bed'\n
|
||||||
|
})
|
||||||
|
</code>
|
||||||
|
</LibraryItem>
|
||||||
|
<LibraryItem text="Ellipse">
|
||||||
|
<graphic>
|
||||||
|
<Ellipse radiusX="10.0" radiusY="12.0"
|
||||||
|
fill="#9f40b8"
|
||||||
|
strokeWidth="2" stroke="#f29797" />
|
||||||
|
</graphic>
|
||||||
|
<code>
|
||||||
|
ellipse({\n
|
||||||
|
__cx: 0,\n
|
||||||
|
__cy: 0,\n
|
||||||
|
__radiusX: 150,\n
|
||||||
|
__radiusY: 200,\n
|
||||||
|
__fill: '#9f40b8',\n
|
||||||
|
__strokeWidth: 4,\n
|
||||||
|
__stroke: '#f29797'\n
|
||||||
|
})
|
||||||
|
</code>
|
||||||
|
</LibraryItem>
|
||||||
|
<LibraryItem text="Text">
|
||||||
|
<graphic>
|
||||||
|
<Text text="txt" underline="true"
|
||||||
|
fill="WHITE"
|
||||||
|
strokeWidth="0.2" stroke="red" />
|
||||||
|
</graphic>
|
||||||
|
<code>
|
||||||
|
text({\n
|
||||||
|
__x: -50,\n
|
||||||
|
__y: 0,\n
|
||||||
|
__text: 'txt',\n
|
||||||
|
__fill: 'white',\n
|
||||||
|
__stroke: 'red',\n
|
||||||
|
__font: 100,\n
|
||||||
|
__underline: true\n
|
||||||
|
})
|
||||||
|
</code>
|
||||||
|
</LibraryItem>
|
||||||
|
<LibraryItem text="Polygon">
|
||||||
|
<graphic>
|
||||||
|
<Polygon points="-10,-10,0,-5,10,-10,10,10,0,5,-10,10"
|
||||||
|
fill="58c033"
|
||||||
|
strokeWidth="2" stroke="#259b3e" />
|
||||||
|
</graphic>
|
||||||
|
<code>
|
||||||
|
points = [\n
|
||||||
|
__-50, -50,\n
|
||||||
|
__0, -25,\n
|
||||||
|
__50, -50,\n
|
||||||
|
__50, 50,\n
|
||||||
|
__0, 25,\n
|
||||||
|
__-50, 50\n
|
||||||
|
]\n
|
||||||
|
polygon(points, {\n
|
||||||
|
__fill: '#58c033',\n
|
||||||
|
__strokeWidth: 4,\n
|
||||||
|
__stroke: '#259b3e'\n
|
||||||
|
})
|
||||||
|
</code>
|
||||||
|
</LibraryItem>
|
||||||
|
<LibraryItem text="Polyline">
|
||||||
|
<graphic>
|
||||||
|
<Polyline points="-10,-10,0,-5,10,-10,10,10,0,5,-10,10,-10,-10"
|
||||||
|
strokeWidth="2" stroke="#cf3636" />
|
||||||
|
</graphic>
|
||||||
|
<code>
|
||||||
|
points = [\n
|
||||||
|
__-50, -50,\n
|
||||||
|
__0, -25,\n
|
||||||
|
__50, -50,\n
|
||||||
|
__50, 50,\n
|
||||||
|
__0, 25,\n
|
||||||
|
__-50, 50\n
|
||||||
|
__-50,-50\n
|
||||||
|
]\n
|
||||||
|
polyline(points, {\n
|
||||||
|
__strokeWidth: 4,\n
|
||||||
|
__stroke: '#cf3636'\n
|
||||||
|
})
|
||||||
|
</code>
|
||||||
|
</LibraryItem>
|
||||||
|
<LibraryItem text="SVG Hearth">
|
||||||
|
<graphic>
|
||||||
|
<SVGPath content="M23.6,0c-3.4,0-6.3,2.7-7.6,5.6C14.7,2.7,11.8,0,8.4,0C3.8,0,0,3.8,0,8.4c0,9.4,9.5,11.9,16,21.2 6.1-9.3,16-12.1,16-21.2C32,3.8,28.2,0,23.6,0z"
|
||||||
|
fill="#c91720"
|
||||||
|
scaleX="0.6" scaleY="0.6"
|
||||||
|
strokeWidth="2" stroke="#edabab" />
|
||||||
|
</graphic>
|
||||||
|
<code>
|
||||||
|
svgPath({\n
|
||||||
|
__content: "M23.6,0c-3.4,0-6.3,2.7-7.6,5.6C14.7,2.7,11.8,0,8.4,0C3.8,0,0,3.8,0,8.4c0,9.4,9.5,11.9,16,21.2 6.1-9.3,16-12.1,16-21.2C32,3.8,28.2,0,23.6,0z",\n
|
||||||
|
__fill: "#c91720",\n
|
||||||
|
__strokeWidth: 2,\n
|
||||||
|
__stroke: "#edabab"\n
|
||||||
|
})
|
||||||
|
</code>
|
||||||
|
</LibraryItem>
|
||||||
|
<LibraryItem text="Line">
|
||||||
|
<graphic>
|
||||||
|
<Line startX="-20" startY="-20"
|
||||||
|
strokeWidth="3" stroke="#aaa" />
|
||||||
|
</graphic>
|
||||||
|
<code>
|
||||||
|
line({\n
|
||||||
|
__startX: -600\n
|
||||||
|
__startY: -300\n
|
||||||
|
__endX: 600\n
|
||||||
|
__endY: 300,\n
|
||||||
|
__stroke: "#AAA",\n
|
||||||
|
__strokeWidth: 5\n
|
||||||
|
})
|
||||||
|
</code>
|
||||||
|
</LibraryItem>
|
||||||
|
<LibraryItem text="Arc">
|
||||||
|
<graphic>
|
||||||
|
<Arc type="ROUND"
|
||||||
|
radiusX="12" radiusY="12"
|
||||||
|
startAngle="60" length="240"
|
||||||
|
fill="#1b8118"
|
||||||
|
strokeWidth="2" stroke="#4cbc72" />
|
||||||
|
</graphic>
|
||||||
|
<code>
|
||||||
|
arc({\n
|
||||||
|
__cx: 0\n
|
||||||
|
__cy: 0\n
|
||||||
|
__radiusX: 50,\n
|
||||||
|
__radiusY: 50,\n
|
||||||
|
__startAngle: 60,\n
|
||||||
|
__length: 240\n
|
||||||
|
__fill: "#1b8118",\n
|
||||||
|
__strokeWidth: 4,\n
|
||||||
|
__stroke: "#4cbc72"\n
|
||||||
|
})
|
||||||
|
</code>
|
||||||
|
</LibraryItem>
|
||||||
|
</FlowPane>
|
||||||
|
</TitledPane>
|
||||||
</VBox>
|
</VBox>
|
||||||
</ScrollPane>
|
</ScrollPane>
|
||||||
</right>
|
</right>
|
||||||
|
Loading…
Reference in New Issue
Block a user