From df72a688156764773ff7c8009805b47ce45e5902 Mon Sep 17 00:00:00 2001 From: "Tom A. Wagner" Date: Tue, 3 May 2022 14:04:54 +0200 Subject: [PATCH] graphview: draw the background grid via CSS instead of manually with cairo This makes gtk draw the background grid for us via CSS, instead of manually drawing each line via cairo. This improves performance, as the grid may now be drawn via GPU, and gets rid of the custom drawing code we had. --- src/style.css | 6 +++++- src/view/graph_view.rs | 23 ----------------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/style.css b/src/style.css index 5733d22..97d9e9e 100644 --- a/src/style.css +++ b/src/style.css @@ -18,6 +18,7 @@ @define-color audio rgb(50,100,240); @define-color video rgb(200,200,0); @define-color midi rgb(200,0,50); +@define-color graphview-grid rgb(35,35,35); @define-color graphview-link #808080; .audio { @@ -36,5 +37,8 @@ } graphview { - background: @text_view_bg; + background-image: linear-gradient(@graphview-grid 1px, transparent 1px), + linear-gradient(to right, @graphview-grid 1px, transparent 1px); + background-size: 20px 20px; + background-color: @text_view_bg; } \ No newline at end of file diff --git a/src/view/graph_view.rs b/src/view/graph_view.rs index e695033..529f661 100644 --- a/src/view/graph_view.rs +++ b/src/view/graph_view.rs @@ -115,29 +115,6 @@ mod imp { Try to use relative units (em) and colours from the theme as much as possible. */ let alloc = widget.allocation(); - let widget_bounds = - graphene::Rect::new(0.0, 0.0, alloc.width() as f32, alloc.height() as f32); - - let background_cr = snapshot.append_cairo(&widget_bounds); - - // Draw a nice grid on the background. - background_cr.set_source_rgb(0.18, 0.18, 0.18); - background_cr.set_line_width(0.2); // TODO: Set to 1px - let mut y = 0.0; - while y < alloc.height().into() { - background_cr.move_to(0.0, y); - background_cr.line_to(alloc.width().into(), y); - y += 20.0; // TODO: Change to em; - } - let mut x = 0.0; - while x < alloc.width().into() { - background_cr.move_to(x, 0.0); - background_cr.line_to(x, alloc.height().into()); - x += 20.0; // TODO: Change to em; - } - if let Err(e) = background_cr.stroke() { - warn!("Failed to draw graphview grid: {}", e); - }; // Draw all children self.nodes