Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finished resizeable windows #6

Merged
merged 1 commit into from Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/args.rs
Expand Up @@ -35,12 +35,12 @@ pub struct CLIArgs {
averaging_window: u32,

/// Window width
#[arg(long = "width", default_value_t = 1000)]
window_width: i32,
#[arg(long = "width", default_value_t = 1000.0)]
window_width: f32,

/// Window height
#[arg(long = "height", default_value_t = 700)]
window_height: i32,
#[arg(long = "height", default_value_t = 700.0)]
window_height: f32,

/// Border size for each bar
#[arg(long = "border-size", default_value_t = 1)]
Expand Down
5 changes: 2 additions & 3 deletions src/main.rs
Expand Up @@ -56,8 +56,8 @@ struct FFTArgs {
fft_fps: u32,
bar_smoothness: u32,
freq_resolution: u32,
window_width: i32,
window_height: i32,
window_width: f32,
window_height: f32,
averaging_window: u32,
min_freq: f32,
max_freq: f32,
Expand Down Expand Up @@ -128,7 +128,6 @@ fn main() {
.into(),
name: Some("fftviz".into()),
resolution: (args.window_width as f32, args.window_height as f32).into(),
resizable: false,
prevent_default_event_handling: false,
enabled_buttons: bevy::window::EnabledButtons {
maximize: false,
Expand Down
2 changes: 1 addition & 1 deletion src/systems/startup.rs
Expand Up @@ -42,7 +42,7 @@ fn spawn_bars(
transform: Transform::from_xyz(
bar_size * i as f32 + (bar_size / 2.0) - (w / 2.0) as f32,
0.0,
0.0,
-1.0,
),
..default()
})
Expand Down
53 changes: 53 additions & 0 deletions src/systems/update_view_settings.rs
Expand Up @@ -29,9 +29,62 @@ pub fn update_view_settings (
mut clear_color: ResMut<ClearColor>,
mut text_query: Query<&mut Text>,
mut differencing_args_query: Query<&mut FFTArgs>,
mut bar_query: Query<&mut Transform, Without<Text>>
) {
let mut differencing_args = differencing_args_query.get_single_mut().unwrap();

// Update bar sizes and positions on resize
let w = window.single_mut().width();
if differencing_args.window_width != w {
let bar_size = w / app_state.fft[0].len() as f32;
for (i, b) in app_state.despawn_handles.chunks(2).enumerate() {
bar_query.get_mut(b[0]).unwrap().translation.x = bar_size * i as f32 + bar_size / 2.0 - w / 2.0;
bar_query.get_mut(b[1]).unwrap().translation.x = bar_size * i as f32 + bar_size / 2.0 - w / 2.0;
}


let outer_bar_size = bar_size / 2.0;
let inner_bar_size = (bar_size - args.border_size as f32) / 2.0;

for handle in app_state.curr_bars.chunks(2) {
let handle1 = handle[0].0.clone_weak();
let handle2 = handle[1].0.clone_weak();

let dims = meshes
.get_mut(handle1)
.unwrap()
.attribute_mut(Mesh::ATTRIBUTE_POSITION)
.unwrap();

match dims {
VertexAttributeValues::Float32x3(x) => {
x[0][0] = outer_bar_size;
x[1][0] = -outer_bar_size;
x[2][0] = -outer_bar_size;
x[3][0] = outer_bar_size;
}
_ => {}
}

let dims = meshes
.get_mut(handle2)
.unwrap()
.attribute_mut(Mesh::ATTRIBUTE_POSITION)
.unwrap();

match dims {
VertexAttributeValues::Float32x3(x) => {
x[0][0] = inner_bar_size;
x[1][0] = -inner_bar_size;
x[2][0] = -inner_bar_size;
x[3][0] = inner_bar_size;
}
_ => {}
}
}
differencing_args.window_width = w;
}

// Update text color + visibility + size
if differencing_args.text_color != args.text_color || differencing_args.track_name != args.track_name || differencing_args.font_size != args.font_size {
for mut text in &mut text_query {
Expand Down