mirror of
https://gitlab.freedesktop.org/pipewire/helvum.git
synced 2026-05-19 14:48:12 +02:00
Merge branch 'gtk-gsk' into 'main'
Use native GskPath GTK4 API See merge request pipewire/helvum!79
This commit is contained in:
commit
01ac0aef68
2 changed files with 26 additions and 39 deletions
|
|
@ -19,7 +19,7 @@ libspa = "0.9.2"
|
|||
async-channel = "2.5.0"
|
||||
adw = { version = "0.9.1", package = "libadwaita", features = ["v1_7", "gtk_v4_18"] }
|
||||
glib = { version = "0.22.7", features = ["log", "v2_84"] }
|
||||
gtk4 = "0.11.3"
|
||||
gtk4 = { version = "0.11.3", features = ["v4_14"] }
|
||||
|
||||
log = "0.4.29"
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use adw::{
|
|||
gio,
|
||||
glib::{self, clone},
|
||||
gtk::{
|
||||
self, cairo,
|
||||
self,
|
||||
graphene::{self, Point},
|
||||
gsk,
|
||||
},
|
||||
|
|
@ -545,36 +545,25 @@ mod imp {
|
|||
|
||||
fn draw_link(
|
||||
&self,
|
||||
link_cr: &cairo::Context,
|
||||
snapshot: >k::Snapshot,
|
||||
output_anchor: &Point,
|
||||
input_anchor: &Point,
|
||||
active: bool,
|
||||
color: &gdk::RGBA,
|
||||
) {
|
||||
let output_x: f64 = output_anchor.x().into();
|
||||
let output_y: f64 = output_anchor.y().into();
|
||||
let input_x: f64 = input_anchor.x().into();
|
||||
let input_y: f64 = input_anchor.y().into();
|
||||
let output_x = output_anchor.x();
|
||||
let output_y = output_anchor.y();
|
||||
let input_x = input_anchor.x();
|
||||
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(),
|
||||
);
|
||||
let builder = gsk::PathBuilder::new();
|
||||
builder.move_to(output_x, output_y);
|
||||
|
||||
// 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
|
||||
// so that the curve sticks out a bit.
|
||||
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 {
|
||||
0.0
|
||||
};
|
||||
|
|
@ -582,9 +571,8 @@ mod imp {
|
|||
// 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,
|
||||
// especially when the output port is farther right than the input port.
|
||||
let half_x_dist = f64::abs(output_x - input_x) / 2.0;
|
||||
link_cr.move_to(output_x, output_y);
|
||||
link_cr.curve_to(
|
||||
let half_x_dist = f32::abs(output_x - input_x) / 2.0;
|
||||
builder.cubic_to(
|
||||
output_x + half_x_dist,
|
||||
output_y - y_control_offset,
|
||||
input_x - half_x_dist,
|
||||
|
|
@ -593,12 +581,18 @@ mod imp {
|
|||
input_y,
|
||||
);
|
||||
|
||||
if let Err(e) = link_cr.stroke() {
|
||||
warn!("Failed to draw graphview links: {}", e);
|
||||
};
|
||||
let path = builder.to_path();
|
||||
let stroke = gsk::Stroke::new(2.0 * self.zoom_factor.get() as f32);
|
||||
|
||||
// Use dashed line for inactive links, full line otherwise.
|
||||
if !active {
|
||||
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 draw_dragged_link(&self, port: &Port, snapshot: >k::Snapshot, colors: &Colors) {
|
||||
let Some(port_anchor) = port.compute_point(&*self.obj(), &port.link_anchor()) else {
|
||||
return;
|
||||
};
|
||||
|
|
@ -628,17 +622,10 @@ mod imp {
|
|||
|
||||
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.draw_link(snapshot, output_anchor, input_anchor, false, color);
|
||||
}
|
||||
|
||||
fn snapshot_links(&self, widget: &super::GraphView, snapshot: >k::Snapshot) {
|
||||
let (width, height) = (widget.width(), widget.height());
|
||||
|
||||
let link_cr =
|
||||
snapshot.append_cairo(&graphene::Rect::new(0.0, 0.0, width as f32, height as f32));
|
||||
|
||||
link_cr.set_line_width(2.0 * self.zoom_factor.get());
|
||||
|
||||
fn snapshot_links(&self, _widget: &super::GraphView, snapshot: >k::Snapshot) {
|
||||
let colors = Colors {
|
||||
audio: gdk::RGBA::new(50.0 / 255.0, 100.0 / 255.0, 240.0 / 255.0, 1.0),
|
||||
video: gdk::RGBA::new(200.0 / 255.0, 200.0 / 255.0, 0.0, 1.0),
|
||||
|
|
@ -656,7 +643,7 @@ mod imp {
|
|||
};
|
||||
|
||||
self.draw_link(
|
||||
&link_cr,
|
||||
snapshot,
|
||||
&output_anchor,
|
||||
&input_anchor,
|
||||
link.active(),
|
||||
|
|
@ -665,7 +652,7 @@ mod imp {
|
|||
}
|
||||
|
||||
if let Some(port) = self.dragged_port.upgrade() {
|
||||
self.draw_dragged_link(&port, &link_cr, &colors);
|
||||
self.draw_dragged_link(&port, snapshot, &colors);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue