aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock47
-rw-r--r--Cargo.toml7
-rw-r--r--src/app.rs3
-rw-r--r--src/lisp/error.rs2
-rw-r--r--src/lisp/prelude.rs15
5 files changed, 69 insertions, 5 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2ac9444..0857ef2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,12 @@
3version = 3 3version = 3
4 4
5[[package]] 5[[package]]
6name = "adler32"
7version = "1.2.0"
8source = "registry+https://github.com/rust-lang/crates.io-index"
9checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
10
11[[package]]
6name = "aho-corasick" 12name = "aho-corasick"
7version = "0.7.15" 13version = "0.7.15"
8source = "registry+https://github.com/rust-lang/crates.io-index" 14source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -59,6 +65,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
59checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 65checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
60 66
61[[package]] 67[[package]]
68name = "crc32fast"
69version = "1.2.1"
70source = "registry+https://github.com/rust-lang/crates.io-index"
71checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a"
72dependencies = [
73 "cfg-if 1.0.0",
74]
75
76[[package]]
77name = "deflate"
78version = "0.8.6"
79source = "registry+https://github.com/rust-lang/crates.io-index"
80checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174"
81dependencies = [
82 "adler32",
83 "byteorder",
84]
85
86[[package]]
62name = "env_logger" 87name = "env_logger"
63version = "0.8.3" 88version = "0.8.3"
64source = "registry+https://github.com/rust-lang/crates.io-index" 89source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -120,11 +145,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
120checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" 145checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
121 146
122[[package]] 147[[package]]
148name = "miniz_oxide"
149version = "0.3.7"
150source = "registry+https://github.com/rust-lang/crates.io-index"
151checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435"
152dependencies = [
153 "adler32",
154]
155
156[[package]]
123name = "obi" 157name = "obi"
124version = "0.1.0" 158version = "0.1.0"
125dependencies = [ 159dependencies = [
126 "bitvec", 160 "bitvec",
127 "byteorder", 161 "byteorder",
162 "png",
128] 163]
129 164
130[[package]] 165[[package]]
@@ -134,6 +169,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
134checksum = "d70072c20945e1ab871c472a285fc772aefd4f5407723c206242f2c6f94595d6" 169checksum = "d70072c20945e1ab871c472a285fc772aefd4f5407723c206242f2c6f94595d6"
135 170
136[[package]] 171[[package]]
172name = "png"
173version = "0.16.8"
174source = "registry+https://github.com/rust-lang/crates.io-index"
175checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6"
176dependencies = [
177 "bitflags",
178 "crc32fast",
179 "deflate",
180 "miniz_oxide",
181]
182
183[[package]]
137name = "radium" 184name = "radium"
138version = "0.6.2" 185version = "0.6.2"
139source = "registry+https://github.com/rust-lang/crates.io-index" 186source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 311e10b..01e7e31 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,8 +8,11 @@ edition = "2018"
8 8
9[dependencies] 9[dependencies]
10sdl2 = {version = "0.34", features = ["ttf"]} 10sdl2 = {version = "0.34", features = ["ttf"]}
11# obi = { git = "https://github.com/nerdypepper/obi", rev = "63af58d6a3fd68bdb313305881627dab534346e2" } 11# obi = { git = "https://github.com/nerdypepper/obi", rev = "7773bfb4c63ab3ea49b428e20ef0946b713fd5f5" }
12obi = { path = "../obi"}
13env_logger = "0.8.3" 12env_logger = "0.8.3"
14log = "0.4.0" 13log = "0.4.0"
15pico-args = "0.4.0" 14pico-args = "0.4.0"
15
16[dependencies.obi]
17path = "../obi"
18features = ["png"]
diff --git a/src/app.rs b/src/app.rs
index d0089e9..66a27e3 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -904,8 +904,7 @@ impl<'ctx> AppState<'ctx> {
904 }); 904 });
905 } 905 }
906 } 906 }
907 Brush::Circle(CircleBrush { size }) 907 Brush::Circle(CircleBrush { size }) => {
908 | Brush::Line(LineBrush { size, .. }) => {
909 let pt = (x, y); 908 let pt = (x, y);
910 let val = self.active_color; 909 let val = self.active_color;
911 if let Ok(o) = self.paint_point(pt, val, size) { 910 if let Ok(o) = self.paint_point(pt, val, size) {
diff --git a/src/lisp/error.rs b/src/lisp/error.rs
index f323bb8..9e9dc90 100644
--- a/src/lisp/error.rs
+++ b/src/lisp/error.rs
@@ -98,6 +98,7 @@ pub enum EvalError {
98 DivByZero, 98 DivByZero,
99 TypeMismatch, 99 TypeMismatch,
100 NoFileName, 100 NoFileName,
101 FileError(io::Error),
101 AccessEmptyList, 102 AccessEmptyList,
102 InvalidCoordinates((LispNumber, LispNumber)), 103 InvalidCoordinates((LispNumber, LispNumber)),
103 AssertionError { expected: LispExpr, got: LispExpr }, 104 AssertionError { expected: LispExpr, got: LispExpr },
@@ -126,6 +127,7 @@ impl fmt::Display for EvalError {
126 Self::TypeMismatch => write!(f, "mismatched types"), 127 Self::TypeMismatch => write!(f, "mismatched types"),
127 Self::DivByZero => write!(f, "attempt to divide by zero"), 128 Self::DivByZero => write!(f, "attempt to divide by zero"),
128 Self::NoFileName => write!(f, "no file name specified"), 129 Self::NoFileName => write!(f, "no file name specified"),
130 Self::FileError(e) => write!(f, "file error: {}", e),
129 Self::AccessEmptyList => write!(f, "attempted to access empty list"), 131 Self::AccessEmptyList => write!(f, "attempted to access empty list"),
130 Self::InvalidCoordinates((x, y)) => write!(f, "invalid coordinates: {} {}", x, y), 132 Self::InvalidCoordinates((x, y)) => write!(f, "invalid coordinates: {} {}", x, y),
131 Self::AssertionError { expected, got } => { 133 Self::AssertionError { expected, got } => {
diff --git a/src/lisp/prelude.rs b/src/lisp/prelude.rs
index 7cb46ff..8088510 100644
--- a/src/lisp/prelude.rs
+++ b/src/lisp/prelude.rs
@@ -14,7 +14,7 @@ use crate::{
14 utils::{load_script, rect_coords}, 14 utils::{load_script, rect_coords},
15}; 15};
16 16
17use std::convert::TryInto; 17use std::{convert::TryInto, fs::File, io::BufWriter, path::Path};
18 18
19#[macro_export] 19#[macro_export]
20macro_rules! primitive { 20macro_rules! primitive {
@@ -260,6 +260,18 @@ pub fn new_env() -> Result<Environment, LispError> {
260 } 260 }
261 }); 261 });
262 262
263 primitive!(env, Arity::Exact(1), "export-png", |args, app| {
264 if let LispExpr::StringLit(s) = &args[0] {
265 let export_path = Path::new(&s);
266 let file = File::create(export_path).map_err(EvalError::FileError)?;
267 let w = BufWriter::new(file);
268 app.export().write_png(w);
269 Ok(LispExpr::Unit)
270 } else {
271 Err(EvalError::TypeMismatch.into())
272 }
273 });
274
263 primitive!(env, Arity::Exact(0), "grid-enabled?", |_, app| { 275 primitive!(env, Arity::Exact(0), "grid-enabled?", |_, app| {
264 Ok(LispExpr::BoolLit(app.grid.enabled)) 276 Ok(LispExpr::BoolLit(app.grid.enabled))
265 }); 277 });
@@ -524,5 +536,6 @@ pub fn new_env() -> Result<Environment, LispError> {
524 primitive!(env, Arity::Exact(1), "id", |args, _| { 536 primitive!(env, Arity::Exact(1), "id", |args, _| {
525 Ok(args[0].clone()) 537 Ok(args[0].clone())
526 }); 538 });
539
527 Ok(env) 540 Ok(env)
528} 541}