Skip to content

armgit / klad

Public Imported from GitHub
0

A drawing app built for agent/human collaboration

Rust

The real size panel opens with the first pixel drawing, and the four-green palette loses its console's name

Indicode BV735c6b7f0e06
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d50b7ff..05fddce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,7 @@ The first builds, and klad's licences.
- A new icon, painted in klad: a K in two brush strokes.
- Sprites as text, for agents. `klad pixel sprite.klad l1 --grid sprite.txt` draws a sprite from a legend (`i = ink`) and rows of characters, one per pixel, each character becoming one mark bound to its palette colour; `klad pixels sprite.klad l1` reads a pixel layer back the same way, with its legend and numbered rows and columns (`--plain` in the form `--grid` reads, `--json`).
- The pixel pencil and eraser. On a pixel layer the brush tool (**B**) draws whole pixels in the current colour, which joins the palette, and the eraser (**E**, or the pen's eraser end) clears them; each drag is one mark. A one-pixel line is pixel perfect (no doubled corners), the size is a square of whole pixels (**[** and **]**), and shift click draws a straight line from the last pixel. From the command line, `klad pixel` takes `--path` (SVG path data as a line of pixels) and `--size`.
-- The palette of a pixel drawing. Changing a palette colour changes every pixel painted with it: click the colour in the palette, change it, and press **update** (or `klad palette art.klad --recolour skin --to '#e8b796'`). **palettes** adds the colours of a palette that comes with klad (PICO-8, Sweetie 16, DawnBringer 16 and 32, Endesga 32, Resurrect 64, AAP-64, Game Boy, 1-bit; `klad palettes` lists them) or of a palette file, a list of hex colours or a GIMP palette (`klad palette art.klad --load pico-8`). **ramp** adds five steps of the current colour, from dark and cool to light and warm (`klad palette art.klad --ramp wood --base '#8b5a2b'`), and `--ramp skin --of skin-dark,skin,skin-light` groups colours the palette has.
+- The palette of a pixel drawing. Changing a palette colour changes every pixel painted with it: click the colour in the palette, change it, and press **update** (or `klad palette art.klad --recolour skin --to '#e8b796'`). **palettes** adds the colours of a palette that comes with klad (PICO-8, Sweetie 16, DawnBringer 16 and 32, Endesga 32, Resurrect 64, AAP-64, four greens, 1-bit; `klad palettes` lists them) or of a palette file, a list of hex colours or a GIMP palette (`klad palette art.klad --load pico-8`). **ramp** adds five steps of the current colour, from dark and cool to light and warm (`klad palette art.klad --ramp wood --base '#8b5a2b'`), and `--ramp skin --of skin-dark,skin,skin-light` groups colours the palette has.
- A sharp view for pixel drawings. In the editor the zoom steps in whole pixels, so every pixel is the same size; a grid shows between the pixels once you are zoomed in (**View > Pixel grid**), the pixel under the pointer is outlined and its position shows in the status line, and the **Real size** panel shows the drawing as the player sees it, at 1x, 2x or 4x. `klad render` enlarges a pixel drawing to about 512 px, and `--overlay grid` numbers its pixels along the top and the left.
- Pixel layers, the start of pixel art in klad. A pixel drawing (**Pixel art** in the start window, or `klad new sprite.klad --pixel 64x64`) is a small drawing of whole pixels with no soft edges; **Layer > New pixel layer** or `klad add art.klad layer pixel` adds a pixel layer to any drawing. `klad pixel sprite.klad l1 --color skin --cells '4-11,5-9'` puts pixels on it as one mark bound to a palette colour (a colour the palette lacks is added), and `--erase` clears them. Each mark stays editable: recolour it with `klad set`, move it with `klad transform`, remove it with `klad rm`; `klad strokes` lists them. Exports above full size keep the pixels square. Brush strokes and fills stay off pixel layers. The format is now `klad/7` (stroke files version 3); older drawings open unchanged.
- Align and distribute shapes. With **V**, shift click adds a shape to the selection and a loop dragged on a vector layer takes the shapes inside; several shapes move, scale, turn, flip, duplicate and delete together. The bar under them lines up their left, right, top or bottom edges or their centres and spaces three or more evenly; one shape lines up on the canvas (**Edit > Align**). From the command line: `klad align art.klad n3 n4 n7 --y middle --spread x`, with `--to canvas` or `--to <shape>` and `--gap`.
diff --git a/Cargo.lock b/Cargo.lock
index 4149c83..3c75751 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1744,7 +1744,7 @@ dependencies = [
[[package]]
name = "klad-app"
-version = "0.1.17"
+version = "0.1.18"
dependencies = [
"anyhow",
"block2 0.6.2",
@@ -1773,7 +1773,7 @@ dependencies = [
[[package]]
name = "klad-brush"
-version = "0.1.17"
+version = "0.1.18"
dependencies = [
"anyhow",
"bytemuck",
@@ -1789,7 +1789,7 @@ dependencies = [
[[package]]
name = "klad-cli"
-version = "0.1.17"
+version = "0.1.18"
dependencies = [
"anyhow",
"clap",
@@ -1815,7 +1815,7 @@ dependencies = [
[[package]]
name = "klad-core"
-version = "0.1.17"
+version = "0.1.18"
dependencies = [
"anyhow",
"half",
@@ -1827,7 +1827,7 @@ dependencies = [
[[package]]
name = "klad-render"
-version = "0.1.17"
+version = "0.1.18"
dependencies = [
"anyhow",
"bytemuck",
diff --git a/Cargo.toml b/Cargo.toml
index fbc08e2..944e1ac 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/*"]
[workspace.package]
-version = "0.1.17"
+version = "0.1.18"
edition = "2024"
license-file = "LICENSE"
repository = "https://github.com/klad-app/klad"
diff --git a/crates/app/src/editor.rs b/crates/app/src/editor.rs
index 2894627..73e0d6b 100644
--- a/crates/app/src/editor.rs
+++ b/crates/app/src/editor.rs
@@ -764,13 +764,7 @@ impl Editor {
);
let settings_path = settings::default_path();
let mut settings = settings_path.as_deref().map(Settings::load).unwrap_or_default();
- let offered = scene.bundle.doc.pixel_art() && !settings.real_size_shown;
- if offered {
- settings.real_size_shown = true;
- if !settings.layout.is_open(crate::layout::Pane::Preview) {
- settings.layout.toggle(crate::layout::Pane::Preview);
- }
- }
+ let offered = settings.offer_real_size(scene.bundle.doc.pixel_art());
let open = format!(
"{} layers, opened in {:.0} ms",
scene.bundle.doc.all_layers().len(),
diff --git a/crates/app/src/editor/commands.rs b/crates/app/src/editor/commands.rs
index 017f9ab..abef28e 100644
--- a/crates/app/src/editor/commands.rs
+++ b/crates/app/src/editor/commands.rs
@@ -730,7 +730,10 @@ impl Editor {
self.apply(vec![Op::Palette(edit)])?;
}
Cmd::NewPaintLayer => self.add_layer("paint")?,
- Cmd::NewPixelLayer => self.add_layer("pixel")?,
+ Cmd::NewPixelLayer => {
+ self.add_layer("pixel")?;
+ self.settings_dirty |= self.settings.offer_real_size(true);
+ }
Cmd::NewGroupLayer => self.new_group(false)?,
Cmd::NewBonesLayer => {
self.new_skeleton()?;
diff --git a/crates/app/src/home.rs b/crates/app/src/home.rs
index 3b23878..0cd9067 100644
--- a/crates/app/src/home.rs
+++ b/crates/app/src/home.rs
@@ -127,6 +127,7 @@ impl Home {
editor.say(Tone::Done, words);
}
settings.opened(path);
+ settings.offer_real_size(editor.scene.bundle.doc.pixel_art());
editor.settings = settings.clone();
editor.settings_path = self.settings_path.clone();
editor.settings_dirty = true;
@@ -524,6 +525,29 @@ mod tests {
let doc = Bundle::open(&made).unwrap().doc;
assert_eq!(doc, cli.doc);
assert!(doc.layers[0].pixel() && doc.layers[0].name == "pixel 1");
+ let real_size = |h: &Harness<'static, Home>| {
+ h.state()
+ .editor
+ .as_ref()
+ .unwrap()
+ .settings
+ .layout
+ .is_open(crate::layout::Pane::Preview)
+ };
+ assert!(real_size(&h), "the first pixel drawing opens the real size panel");
+ assert!(h.query_by_label("Real size").is_some(), "and it shows in the dock");
+ h.state_mut()
+ .editor
+ .as_mut()
+ .unwrap()
+ .settings
+ .layout
+ .toggle(crate::layout::Pane::Preview);
+ h.run_steps(2);
+ let ctx = h.ctx.clone();
+ h.state_mut().open(&ctx, &dir.join("cli.klad")).unwrap();
+ h.run_steps(3);
+ assert!(!real_size(&h), "once closed, the next pixel drawing leaves it closed");
std::fs::remove_dir_all(&dir).unwrap();
}
diff --git a/crates/app/src/settings.rs b/crates/app/src/settings.rs
index ee301f7..8f732a4 100644
--- a/crates/app/src/settings.rs
+++ b/crates/app/src/settings.rs
@@ -188,6 +188,17 @@ impl Settings {
settings
}
+ pub fn offer_real_size(&mut self, pixel_art: bool) -> bool {
+ if !pixel_art || self.real_size_shown {
+ return false;
+ }
+ self.real_size_shown = true;
+ if !self.layout.is_open(crate::layout::Pane::Preview) {
+ self.layout.toggle(crate::layout::Pane::Preview);
+ }
+ true
+ }
+
pub fn save(&self, path: &Path) -> Result<()> {
let mut text = serde_json::to_string_pretty(self)?;
text.push('\n');
diff --git a/crates/cli/tests/binary.rs b/crates/cli/tests/binary.rs
index 54961fe..fb851ef 100644
--- a/crates/cli/tests/binary.rs
+++ b/crates/cli/tests/binary.rs
@@ -689,14 +689,14 @@ fn the_palette_recolours_its_pixels_loads_palettes_and_groups_ramps_from_the_com
);
assert!(draw(&["palettes"]).contains("pico-8"));
assert_eq!(json(&["palettes", "--json"])[2]["colors"].as_array().unwrap().len(), 16);
- draw(&["palette", path, "--load", "gameboy"]);
+ draw(&["palette", path, "--load", "four-greens"]);
let file = dir.join("mine.hex");
std::fs::write(&file, "081820\nabcdef\n").unwrap();
draw(&["palette", path, "--load", file.to_str().unwrap()]);
assert_eq!(
json(&["palette", path, "--json"]).as_array().unwrap().len(),
8,
- "three of the ramp, four of the game boy, one new from the file"
+ "three of the ramp, the four greens, one new from the file"
);
draw(&["palette", path, "--ramp", "greens", "--of", "#081820,#346856,#88c070"]);
assert!(draw(&["palette", path]).contains("ramp greens"));
diff --git a/crates/core/src/palettes.rs b/crates/core/src/palettes.rs
index 7fd8379..3581415 100644
--- a/crates/core/src/palettes.rs
+++ b/crates/core/src/palettes.rs
@@ -17,8 +17,8 @@ pub const SHIPPED: [Shipped; 9] = [
colors: "000000 ffffff",
},
Shipped {
- id: "gameboy",
- title: "Game Boy (bgb)",
+ id: "four-greens",
+ title: "Four greens",
by: "",
colors: "081820 346856 88c070 e0f8d0",
},
@@ -209,7 +209,7 @@ mod tests {
counts,
[
("1-bit", 2),
- ("gameboy", 4),
+ ("four-greens", 4),
("pico-8", 16),
("sweetie-16", 16),
("dawnbringer-16", 16),
diff --git a/docs/skill/SKILL.md b/docs/skill/SKILL.md
index f6b75f0..a5fda80 100644
--- a/docs/skill/SKILL.md
+++ b/docs/skill/SKILL.md
@@ -128,7 +128,7 @@ klad export sprite.klad --scale 8 -o [email protected] square pixels, to keep
- For a few pixels use `--cells`: `x,y` for one pixel, `x0-x1,y` for a run along a row, `x,y0-y1` for a run down a column and `x0-x1,y0-y1` for a block, separated by spaces. Pixels off the canvas are dropped.
- `--path` draws SVG path data as a line of pixels, for outlines and curves that would be tedious as cells. A pixel is the square from `x,y` to `x+1,y+1`, so aim at pixel middles (`3.5`, not `3`). Straight segments keep the corners they are given; curves come out one pixel thin with no doubled corners. `--size 2` (1 to 64) makes the pencil a square of that many pixels, for `--cells` and `--path` alike. In `apply`: `"path":"M3.5 3.5 L9.5 3.5"` in place of `cells`, and `"size":2`.
- `--color` is a palette name, a palette index or `#rrggbb`. Every pixel mark is bound to a palette entry: a colour the palette lacks is added to it, so name the colours first (`klad palette sprite.klad --add '#f0c8a0' --name skin`) and draw with the names. `klad palette` lists the entries with their ids.
-- The palette is the drawing's colours, and changing one changes the picture: `klad palette sprite.klad --recolour skin --to '#e8b796'` (a name, a colour, an index or an id) recolours every pixel mark drawn with it, on every frame. So fix a colour in the palette, not mark by mark. `klad palette sprite.klad --load pico-8` adds a palette that comes with klad (`klad palettes` lists them: pico-8, sweetie-16, dawnbringer-16, dawnbringer-32, endesga-32, resurrect-64, aap-64, gameboy, 1-bit) or a file (`.hex`, one colour per line, or a GIMP `.gpl`); colours the palette holds are not added twice. A ramp is a row of colours for one material, dark to light: `klad palette sprite.klad --ramp wood --base '#8b5a2b' --steps 5` makes `wood-1` (dark, cooler) to `wood-5` (light, warmer) around the base, and `--ramp skin --of skin-dark,skin,skin-light` groups colours it has. Shade a form with the steps of its ramp, not with new colours.
+- The palette is the drawing's colours, and changing one changes the picture: `klad palette sprite.klad --recolour skin --to '#e8b796'` (a name, a colour, an index or an id) recolours every pixel mark drawn with it, on every frame. So fix a colour in the palette, not mark by mark. `klad palette sprite.klad --load pico-8` adds a palette that comes with klad (`klad palettes` lists them: pico-8, sweetie-16, dawnbringer-16, dawnbringer-32, endesga-32, resurrect-64, aap-64, four-greens, 1-bit) or a file (`.hex`, one colour per line, or a GIMP `.gpl`); colours the palette holds are not added twice. A ramp is a row of colours for one material, dark to light: `klad palette sprite.klad --ramp wood --base '#8b5a2b' --steps 5` makes `wood-1` (dark, cooler) to `wood-5` (light, warmer) around the base, and `--ramp skin --of skin-dark,skin,skin-light` groups colours it has. Shade a form with the steps of its ramp, not with new colours.
- Each mark, `<cel>:s<id>`, stays editable: `klad set sprite.klad c2:s1 color=shadow` recolours it (and binds it to that entry), `klad transform ... --move 2,0` moves it by whole pixels, `--flip h` and `--rotate 90` keep it hard, `klad rm` removes it. `klad strokes sprite.klad l1` lists the marks with their entry and cell count; `--json` gives each one's `cells`.
- Later marks cover earlier ones; `--erase` (or `erase` in a grid's legend) makes a mark that clears what was drawn before it at those pixels (remove that mark and the pixels come back).
- Looking: `klad render` and the `--render` preview of an edit enlarge a pixel drawing by a whole number to about 512 px, so every pixel is a square you can see (`--scale 1` gives the real size, which is how the player sees it: check there too). `--overlay grid` draws a line between pixels and numbers them along the top and the left, so a pixel's `x,y` can be read off the picture: the number is on the line where that column or row starts. `klad export --scale 8` (whole numbers) writes the enlarged PNG to keep.