diff --git a/README.md b/README.md
index 45a4777..191c069 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
- Piccaso Code
+ Picasso Code
Creativity + Logic + Math
A code based image editor created 100% in java
|
@@ -15,8 +15,8 @@
[](https://github.com/Glimmr-Lang/PicassoCode/actions/workflows/maven.yml)
## About
-Piccasso code is an image editor that uses code to create/edit an image. This allows powerful designs to be created with ease and
-automation. The editor uses *glimr* as the scripting language for writing the image editing code.
+Picasso code is an image editor that uses code to create/edit an image. This allows powerful designs to be created with ease and
+automation. The editor uses *PiccodeScript* as the scripting language for writing the image editing code.
## Download
>> Coming soon
@@ -24,8 +24,8 @@ automation. The editor uses *glimr* as the scripting language for writing the im
## Building
```sh
-$ git clone git@github.com:hexaredecimal/Piccode.git
-$ cd Piccode
+$ git clone https://github.com/Glimmr-Lang/PicassoCode.git
+$ cd PicassoCode
$ mvn package
```
### Test your build
@@ -35,7 +35,7 @@ $ java -jar target/Piccode-1.0-SNAPSHOT-jar-with-dependencies.jar
## Inspired by
-Piccassocode is heavily inspired by the [OpenSCAD](https://openscad.org/) program and tries to mimic its functionality
+PicassoCode is heavily inspired by the [OpenSCAD](https://openscad.org/) program and tries to mimic its functionality
as much as it can while still being an image editor. I was stoked when I tried OpenSCAD for the first time and ended up
challenging myself to start a new project based araound the idea. A friend suggested something that has to do with graphics
and my first though was OpenSCAD, but 2D. The idea quickly grew and the small program became an image editor.
@@ -47,7 +47,7 @@ and my first though was OpenSCAD, but 2D. The idea quickly grew and the small pr
## License
```sh
-drawString("
+Render::drawString("
+-----------------------------------+
| ▄▖▘ ▌ |
| ▙▌▌▛▘▀▌▛▘▛▘▛▌▛▘▛▌▛▌█▌ |
diff --git a/piccode/render/context.pics b/piccode/render/context.pics
new file mode 100644
index 0000000..23fdb26
--- /dev/null
+++ b/piccode/render/context.pics
@@ -0,0 +1,8 @@
+
+
+Render :: module {
+ getContext :: () = pic_nat_get_gfx()
+
+ drawLine :: (ctx, startx, starty, endx, endy) = pic_nat_draw_line(ctx, startx, starty, endx, endy)
+}
+
diff --git a/pom.xml b/pom.xml
index 79a9f33..0c67325 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,6 +15,15 @@
jitpack.io
https://jitpack.io
+
+
+ true
+ always
+
+
+ always
+
+
@@ -66,7 +75,7 @@
com.github.Glimmr-Lang
PiccodeScript
- -SNAPSHOT
+ main-SNAPSHOT
diff --git a/src/main/java/org/editor/CanvasFrame.java b/src/main/java/org/editor/CanvasFrame.java
index 7315838..96f76cb 100644
--- a/src/main/java/org/editor/CanvasFrame.java
+++ b/src/main/java/org/editor/CanvasFrame.java
@@ -116,12 +116,8 @@ protected void paintComponent(Graphics g) {
g2.setColor(Color.BLACK);
gfx = g2;
if (start && file != null && code != null) {
- SwingUtilities.invokeLater(() -> {
AccessFrame.msgs.setText("");
- new Thread(() -> compileFrame())
- .start();
- });
- start = false;
+ compileFrame();
}
drawSelection(g2);
@@ -131,6 +127,7 @@ protected void paintComponent(Graphics g) {
}
private PiccodeValue compileFrame() {
+ Context.top.resetContext();
var result = Compiler.compile(file, code);
return result;
}
diff --git a/src/main/java/org/editor/nativemods/PiccodeGfxModule.java b/src/main/java/org/editor/nativemods/PiccodeGfxModule.java
new file mode 100644
index 0000000..22987c6
--- /dev/null
+++ b/src/main/java/org/editor/nativemods/PiccodeGfxModule.java
@@ -0,0 +1,88 @@
+package org.editor.nativemods;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.util.HashMap;
+import java.util.List;
+import org.editor.CanvasFrame;
+import org.piccode.rt.Context;
+import org.piccode.rt.PiccodeException;
+import org.piccode.rt.PiccodeNumber;
+import org.piccode.rt.PiccodeObject;
+import org.piccode.rt.PiccodeString;
+import org.piccode.rt.PiccodeUnit;
+import org.piccode.rt.PiccodeValue;
+import org.piccode.rt.PiccodeValue.Type;
+import org.piccode.rt.modules.NativeFunctionFactory;
+
+/**
+ *
+ * @author hexaredecimal
+ */
+public class PiccodeGfxModule {
+
+ public static void addFunctions() {
+ NativeFunctionFactory.create("get_gfx", List.of(), (args, namedArgs, frame) -> {
+ var gfx = CanvasFrame.gfx;
+ var obj = Context.getObject(gfx.hashCode());
+ if (obj == null) {
+ Context.allocate(gfx);
+ return makeObj(gfx);
+ }
+ return makeObj(gfx);
+ }, null);
+
+ NativeFunctionFactory.create("draw_line", List.of("ctx", "x1", "y1", "x2", "y2"), (args, namedArgs, frame) -> {
+ var _ctx = namedArgs.get("ctx");
+ var _x1 = namedArgs.get("x1");
+ var _y1 = namedArgs.get("y1");
+ var _x2 = namedArgs.get("x2");
+ var _y2 = namedArgs.get("y2");
+
+ var ctx = frame == null ?
+ Context.top
+ : Context.getContextAt(frame);
+ var caller = ctx.getTopFrame().caller;
+
+ PiccodeValue.verifyType(caller, _ctx, Type.OBJECT);
+ PiccodeValue.verifyType(caller, _x1, Type.NUMBER);
+ PiccodeValue.verifyType(caller, _y1, Type.NUMBER);
+ PiccodeValue.verifyType(caller, _x2, Type.NUMBER);
+ PiccodeValue.verifyType(caller, _y2, Type.NUMBER);
+
+ var obj = (PiccodeObject) _ctx;
+ var map = obj.obj;
+ if (!map.containsKey("hash")) {
+ throw new PiccodeException(caller.file, caller.line, caller.column, "Context is not an object");
+ }
+
+ var _hash = map.get("hash");
+ PiccodeValue.verifyType(caller, _hash, Type.NUMBER);
+ var hash = (int) (double) ((PiccodeNumber) _hash).raw();
+ var _gfx = Context.getObject(hash);
+ if (_gfx == null) {
+ throw new PiccodeException(caller.file, caller.line, caller.column, "Context is not allocated");
+ }
+ if (!(_gfx instanceof Graphics2D)) {
+ throw new PiccodeException(caller.file, caller.line, caller.column, "Context is not a correct object. Expected Graphics2D");
+ }
+
+ var gfx = (Graphics2D) _gfx;
+ var x1 = (int) (double) ((PiccodeNumber) _x1).raw();
+ var y1 = (int) (double) ((PiccodeNumber) _y1).raw();
+ var x2 = (int) (double) ((PiccodeNumber) _x2).raw();
+ var y2 = (int) (double) ((PiccodeNumber) _y2).raw();
+
+ gfx.drawLine(x1, y1, x2, y2);
+ return obj;
+ }, null);
+
+ }
+
+ private static PiccodeValue makeObj(Graphics2D obj) {
+ var _obj = new HashMap();
+ _obj.put("hash", new PiccodeNumber(obj.hashCode()));
+ _obj.put("class", new PiccodeString(obj.getClass().getName()));
+ return new PiccodeObject(_obj);
+ }
+}
diff --git a/src/main/java/org/piccode/piccode/Piccode.java b/src/main/java/org/piccode/piccode/Piccode.java
index 9f2b0c1..7375af2 100644
--- a/src/main/java/org/piccode/piccode/Piccode.java
+++ b/src/main/java/org/piccode/piccode/Piccode.java
@@ -2,6 +2,7 @@
import org.editor.AccessFrame;
import org.editor.EditorWindow;
+import org.editor.nativemods.PiccodeGfxModule;
import org.piccode.backend.Compiler;
import org.piccode.piccodescript.ErrorAsciiKind;
@@ -15,7 +16,11 @@ public static void main(String[] args) {
Compiler.exitOnError = false;
Compiler.errorKind = ErrorAsciiKind.EMACS_COMP_STYLE;
Compiler.out = AccessFrame.AccessFrameOutputStream.out;
-
+ initializeNativeAppModules();
EditorWindow.the();
}
+
+ private static void initializeNativeAppModules() {
+ Compiler.addNativeFunctions(PiccodeGfxModule::addFunctions);
+ }
}