summaryrefslogtreecommitdiffstats
path: root/cairo-renderer/src/drawing/cairo/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cairo-renderer/src/drawing/cairo/mod.rs')
-rw-r--r--cairo-renderer/src/drawing/cairo/mod.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/cairo-renderer/src/drawing/cairo/mod.rs b/cairo-renderer/src/drawing/cairo/mod.rs
new file mode 100644
index 0000000..09baa9c
--- /dev/null
+++ b/cairo-renderer/src/drawing/cairo/mod.rs
@@ -0,0 +1,35 @@
1use super::Engine;
2use crate::core::{shapes::Shape as CoreShape, types::DefinitelyBounded};
3
4use cairo::Context;
5
6pub struct CairoEngine {
7 ctx: Context,
8}
9
10impl Engine for CairoEngine {
11 fn new() -> Self {
12 let surface = cairo::SvgSurface::for_stream(200., 100., std::io::stdout()).unwrap();
13 let ctx = cairo::Context::new(&surface);
14
15 CairoEngine { ctx }
16 }
17
18 fn draw(&mut self, shape: &DefinitelyBounded<CoreShape>) {
19 let bounds = &shape.bounds;
20
21 self.ctx.move_to(bounds.left, bounds.top);
22
23 match &shape.shape {
24 CoreShape::Rectangle(_rectangle) => {
25 self.ctx
26 .rectangle(bounds.left, bounds.top, bounds.width, bounds.height);
27 self.ctx.stroke();
28 }
29 CoreShape::Text(text) => {
30 // TODO: properly shape it, with font, etc.
31 self.ctx.show_text(&text.content);
32 }
33 }
34 }
35}