Skip to content

Commit

Permalink
allow connection width control
Browse files Browse the repository at this point in the history
connection_with op
  • Loading branch information
tomara-x committed May 7, 2024
1 parent 9ab26bf commit b55be2e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ some ops make a circle do things to its targets. like `process`, `del_targets`,
- when color changes, set the color of the selection lasso circle (and draw mode indicator)
- `connection_color`
- when color changes, set the color of connection arrows
- `connection_width`
- when this circle's num changes, set the width of the connection arrows
- `connecting_line_color`
- when color changes, set the connect mode indicator
- `command_color`
Expand Down
4 changes: 4 additions & 0 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ pub struct ConnectionColor(pub Color);
#[reflect(Resource)]
pub struct CommandColor(pub Color);

#[derive(Resource, Reflect, Default)]
#[reflect(Resource)]
pub struct ConnectionWidth(pub f32);

#[derive(Resource)]
pub struct DefaultLT(pub (i8, i8));

Expand Down
5 changes: 3 additions & 2 deletions src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub fn update_connection_arrows(
trans_query: Query<&Transform, With<Vertices>>,
mut arrow_trans: Query<&mut Transform, Without<Vertices>>,
arrow_query: Query<&ConnectionArrow>,
connection_width: Res<ConnectionWidth>,
) {
for (id, bh) in bh_query.iter() {
if wh_query.contains(bh.wh) { continue; }
Expand All @@ -189,7 +190,7 @@ pub fn update_connection_arrows(
let f = bh_trans + bh_radius * norm;
*arrow_trans.get_mut(arrow_id.0).unwrap() = Transform {
translation: ((i+f) / 2.).extend(100.),
scale: Vec3::new(4., wh_trans.distance(bh_trans) - (bh_radius + wh_radius), 1.),
scale: Vec3::new(connection_width.0, wh_trans.distance(bh_trans) - (bh_radius + wh_radius), 1.),
rotation: Quat::from_rotation_z(perp.to_angle()),
};
}
Expand All @@ -208,7 +209,7 @@ pub fn update_connection_arrows(
let f = bh_trans + bh_radius * norm;
*arrow_trans.get_mut(arrow_id.0).unwrap() = Transform {
translation: ((i+f) / 2.).extend(100.),
scale: Vec3::new(4., wh_trans.distance(bh_trans) - (bh_radius + wh_radius), 1.),
scale: Vec3::new(connection_width.0, wh_trans.distance(bh_trans) - (bh_radius + wh_radius), 1.),
rotation: Quat::from_rotation_z(perp.to_angle()),
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fn main() {
.insert_resource(DefaultDrawVerts(4))
.insert_resource(HighlightColor(Color::hsl(0.0,1.0,0.5)))
.insert_resource(ConnectionColor(Color::hsla(0., 1., 1., 0.7)))
.insert_resource(ConnectionWidth(4.))
.insert_resource(CommandColor(Color::hsla(0., 0., 0.7, 1.)))
.insert_resource(DefaultLT((0, 0)))
.insert_resource(SystemClipboard(ClipboardContext::new().unwrap()))
Expand Down Expand Up @@ -150,6 +151,7 @@ fn main() {
.register_type::<DefaultDrawVerts>()
.register_type::<HighlightColor>()
.register_type::<ConnectionColor>()
.register_type::<ConnectionWidth>()
.register_type::<CommandColor>()
.register_type::<Version>()
.register_type::<Holes>()
Expand Down Expand Up @@ -292,6 +294,7 @@ fn save_scene(world: &mut World) {
.allow_resource::<DefaultDrawVerts>()
.allow_resource::<HighlightColor>()
.allow_resource::<ConnectionColor>()
.allow_resource::<ConnectionWidth>()
.allow_resource::<ClearColor>()
.allow_resource::<CommandColor>()
.allow_resource::<Version>()
Expand Down
10 changes: 10 additions & 0 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ pub struct Access<'w, 's> {
default_verts: ResMut<'w, DefaultDrawVerts>,
highlight_color: ResMut<'w, HighlightColor>,
connection_color: ResMut<'w, ConnectionColor>,
connection_width: ResMut<'w, ConnectionWidth>,
arrow_query: Query<'w, 's, &'static ConnectionArrow>,
selection_circle: Res<'w, SelectionCircle>,
connecting_line: Res<'w, ConnectingLine>,
command_line_text: Query<'w, 's, &'static mut Text, With<CommandText>>,
Expand Down Expand Up @@ -707,6 +709,14 @@ pub fn process(
let clt = &mut access.command_line_text.single_mut();
clt.sections[0].style.color = color.0;
}
} else if op == "connection_width" {
let n = access.num_query.get_mut(*id).unwrap();
if n.is_changed() {
access.connection_width.0 = n.0;
for e in access.arrow_query.iter() {
access.trans_query.get_mut(e.0).unwrap().scale.x = n.0;
}
}
} else if op == "tonemapping" {
let mut tm = access.tonemapping.single_mut();
for hole in holes {
Expand Down

0 comments on commit b55be2e

Please sign in to comment.