mirror of
https://gitlab.freedesktop.org/pipewire/helvum.git
synced 2025-12-20 14:40:02 +01:00
graphview: Draw links using new gdk path API instead of cairo
This commit is contained in:
parent
f32559511d
commit
d7dd6033a6
4 changed files with 29 additions and 44 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -561,6 +561,7 @@ version = "0.5.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-channel",
|
"async-channel",
|
||||||
"glib",
|
"glib",
|
||||||
|
"gtk4",
|
||||||
"libadwaita",
|
"libadwaita",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ categories = ["gui", "multimedia"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pipewire = "0.8.0"
|
pipewire = "0.8.0"
|
||||||
adw = { version = "0.6", package = "libadwaita", features = ["v1_4"] }
|
adw = { version = "0.6", package = "libadwaita", features = ["v1_4"] }
|
||||||
|
gtk = { version = "0.8", package = "gtk4", features = ["v4_14"] }
|
||||||
glib = { version = "0.19", features = ["log"] }
|
glib = { version = "0.19", features = ["log"] }
|
||||||
async-channel = "2.2"
|
async-channel = "2.2"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ gnome = import('gnome')
|
||||||
base_id = 'org.pipewire.Helvum'
|
base_id = 'org.pipewire.Helvum'
|
||||||
|
|
||||||
dependency('glib-2.0', version: '>= 2.66')
|
dependency('glib-2.0', version: '>= 2.66')
|
||||||
dependency('gtk4', version: '>= 4.4.0')
|
dependency('gtk4', version: '>= 4.14.0')
|
||||||
dependency('libadwaita-1', version: '>= 1.4')
|
dependency('libadwaita-1', version: '>= 1.4')
|
||||||
dependency('libpipewire-0.3')
|
dependency('libpipewire-0.3')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -512,38 +512,24 @@ mod imp {
|
||||||
self.obj().add_controller(drag_controller);
|
self.obj().add_controller(drag_controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_link(
|
fn snapshot_link(
|
||||||
&self,
|
&self,
|
||||||
link_cr: &cairo::Context,
|
snapshot: >k::Snapshot,
|
||||||
output_anchor: &Point,
|
output_anchor: &Point,
|
||||||
input_anchor: &Point,
|
input_anchor: &Point,
|
||||||
active: bool,
|
active: bool,
|
||||||
color: &gdk::RGBA,
|
color: &gdk::RGBA,
|
||||||
) {
|
) {
|
||||||
let output_x: f64 = output_anchor.x().into();
|
let output_x = output_anchor.x();
|
||||||
let output_y: f64 = output_anchor.y().into();
|
let output_y = output_anchor.y();
|
||||||
let input_x: f64 = input_anchor.x().into();
|
let input_x = input_anchor.x();
|
||||||
let input_y: f64 = input_anchor.y().into();
|
let input_y = input_anchor.y();
|
||||||
|
|
||||||
// Use dashed line for inactive links, full line otherwise.
|
|
||||||
if active {
|
|
||||||
link_cr.set_dash(&[], 0.0);
|
|
||||||
} else {
|
|
||||||
link_cr.set_dash(&[10.0, 5.0], 0.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
link_cr.set_source_rgba(
|
|
||||||
color.red().into(),
|
|
||||||
color.green().into(),
|
|
||||||
color.blue().into(),
|
|
||||||
color.alpha().into(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// If the output port is farther right than the input port and they have
|
// If the output port is farther right than the input port and they have
|
||||||
// a similar y coordinate, apply a y offset to the control points
|
// a similar y coordinate, apply a y offset to the control points
|
||||||
// so that the curve sticks out a bit.
|
// so that the curve sticks out a bit.
|
||||||
let y_control_offset = if output_x > input_x {
|
let y_control_offset = if output_x > input_x {
|
||||||
f64::max(0.0, 25.0 - (output_y - input_y).abs())
|
f32::max(0.0, 25.0 - (output_y - input_y).abs())
|
||||||
} else {
|
} else {
|
||||||
0.0
|
0.0
|
||||||
};
|
};
|
||||||
|
|
@ -551,9 +537,10 @@ mod imp {
|
||||||
// Place curve control offset by half the x distance between the two points.
|
// Place curve control offset by half the x distance between the two points.
|
||||||
// This makes the curve scale well for varying distances between the two ports,
|
// This makes the curve scale well for varying distances between the two ports,
|
||||||
// especially when the output port is farther right than the input port.
|
// especially when the output port is farther right than the input port.
|
||||||
let half_x_dist = f64::abs(output_x - input_x) / 2.0;
|
let half_x_dist = f32::abs(output_x - input_x) / 2.0;
|
||||||
link_cr.move_to(output_x, output_y);
|
let path_builder = gsk::PathBuilder::new();
|
||||||
link_cr.curve_to(
|
path_builder.move_to(output_x, output_y);
|
||||||
|
path_builder.cubic_to(
|
||||||
output_x + half_x_dist,
|
output_x + half_x_dist,
|
||||||
output_y - y_control_offset,
|
output_y - y_control_offset,
|
||||||
input_x - half_x_dist,
|
input_x - half_x_dist,
|
||||||
|
|
@ -561,13 +548,20 @@ mod imp {
|
||||||
input_x,
|
input_x,
|
||||||
input_y,
|
input_y,
|
||||||
);
|
);
|
||||||
|
let path = path_builder.to_path();
|
||||||
|
|
||||||
if let Err(e) = link_cr.stroke() {
|
let stroke = gsk::Stroke::new(2.0 * (self.zoom_factor.get() as f32));
|
||||||
warn!("Failed to draw graphview links: {}", e);
|
// Use dashed line for inactive links, full line otherwise.
|
||||||
};
|
if active {
|
||||||
|
stroke.set_dash(&[]);
|
||||||
|
} else {
|
||||||
|
stroke.set_dash(&[10.0, 5.0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshot.append_stroke(&path, &stroke, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_dragged_link(&self, port: &Port, link_cr: &cairo::Context, colors: &Colors) {
|
fn snapshot_dragged_link(&self, snapshot: >k::Snapshot, port: &Port, colors: &Colors) {
|
||||||
let Some(port_anchor) = port.compute_point(&*self.obj(), &port.link_anchor()) else {
|
let Some(port_anchor) = port.compute_point(&*self.obj(), &port.link_anchor()) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
@ -597,21 +591,10 @@ mod imp {
|
||||||
|
|
||||||
let color = &colors.color_for_media_type(MediaType::from_raw(port.media_type()));
|
let color = &colors.color_for_media_type(MediaType::from_raw(port.media_type()));
|
||||||
|
|
||||||
self.draw_link(link_cr, output_anchor, input_anchor, false, color);
|
self.snapshot_link(snapshot, output_anchor, input_anchor, false, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot_links(&self, widget: &super::GraphView, snapshot: >k::Snapshot) {
|
fn snapshot_links(&self, widget: &super::GraphView, snapshot: >k::Snapshot) {
|
||||||
let alloc = widget.allocation();
|
|
||||||
|
|
||||||
let link_cr = snapshot.append_cairo(&graphene::Rect::new(
|
|
||||||
0.0,
|
|
||||||
0.0,
|
|
||||||
alloc.width() as f32,
|
|
||||||
alloc.height() as f32,
|
|
||||||
));
|
|
||||||
|
|
||||||
link_cr.set_line_width(2.0 * self.zoom_factor.get());
|
|
||||||
|
|
||||||
let colors = Colors {
|
let colors = Colors {
|
||||||
audio: widget
|
audio: widget
|
||||||
.style_context()
|
.style_context()
|
||||||
|
|
@ -640,8 +623,8 @@ mod imp {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.draw_link(
|
self.snapshot_link(
|
||||||
&link_cr,
|
snapshot,
|
||||||
&output_anchor,
|
&output_anchor,
|
||||||
&input_anchor,
|
&input_anchor,
|
||||||
link.active(),
|
link.active(),
|
||||||
|
|
@ -650,7 +633,7 @@ mod imp {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(port) = self.dragged_port.upgrade() {
|
if let Some(port) = self.dragged_port.upgrade() {
|
||||||
self.draw_dragged_link(&port, &link_cr, &colors);
|
self.snapshot_dragged_link(&snapshot, &port, &colors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue