|
@@ -1,14 +1,18 @@
|
|
|
-use crate::data::{Config, Mapping};
|
|
|
-use crate::image::Image;
|
|
|
+use crate::data::Config;
|
|
|
+use crate::file::ThymeFile;
|
|
|
|
|
|
pub struct Pattern {
|
|
|
- pub image: Image,
|
|
|
+ pub thyme: ThymeFile,
|
|
|
+ // pub image: Image,
|
|
|
pub config: Config,
|
|
|
- pub mapping: Mapping,
|
|
|
+ // pub mapping: Mapping,
|
|
|
}
|
|
|
|
|
|
impl Pattern {
|
|
|
pub fn draw(&self, ctx: cairo::Context) -> Result<(), Box<dyn std::error::Error>> {
|
|
|
+ let width = self.thyme.width;
|
|
|
+ let height = self.thyme.height;
|
|
|
+
|
|
|
ctx.set_source_rgb(1.0, 1.0, 1.0);
|
|
|
ctx.paint()?;
|
|
|
|
|
@@ -18,9 +22,9 @@ impl Pattern {
|
|
|
layout.set_font_description(Some(&font));
|
|
|
|
|
|
ctx.set_source_rgb(0.0, 0.0, 0.0);
|
|
|
- for i in 0..=self.image.width {
|
|
|
+ for i in 0..=width {
|
|
|
ctx.move_to(self.config.scale(i), 0.0);
|
|
|
- ctx.line_to(self.config.scale(i), self.config.scale(self.image.height));
|
|
|
+ ctx.line_to(self.config.scale(i), self.config.scale(height));
|
|
|
ctx.set_line_width(if i % self.config.grid_every == 0 {
|
|
|
self.config.major_line_weight
|
|
|
} else {
|
|
@@ -28,9 +32,9 @@ impl Pattern {
|
|
|
});
|
|
|
ctx.stroke()?;
|
|
|
}
|
|
|
- for j in 0..=self.image.height {
|
|
|
+ for j in 0..=height {
|
|
|
ctx.move_to(0.0, self.config.scale(j));
|
|
|
- ctx.line_to(self.config.scale(self.image.width), self.config.scale(j));
|
|
|
+ ctx.line_to(self.config.scale(width), self.config.scale(j));
|
|
|
ctx.set_line_width(if j % self.config.grid_every == 0 {
|
|
|
self.config.major_line_weight
|
|
|
} else {
|
|
@@ -41,12 +45,10 @@ impl Pattern {
|
|
|
|
|
|
ctx.set_source_rgb(0.0, 0.0, 0.0);
|
|
|
|
|
|
- for ((x, y), pixel) in self.image.iter() {
|
|
|
- let l = self.mapping.lookup(pixel);
|
|
|
-
|
|
|
- if !l.is_empty() {
|
|
|
+ for ((x, y), stitch) in self.thyme.iter() {
|
|
|
+ if let Some((_, color)) = stitch {
|
|
|
ctx.move_to(self.config.scale(x) + 5.0, self.config.scale(y) + 3.0);
|
|
|
- layout.set_text(l);
|
|
|
+ layout.set_text(&color.symbol);
|
|
|
pangocairo::functions::show_layout(&ctx, &layout);
|
|
|
}
|
|
|
}
|