make pause menu better
This commit is contained in:
@@ -9,3 +9,4 @@ Finally, an easy way to do graphics with rust.
|
|||||||
| F1 | Pause/Play the graph |
|
| F1 | Pause/Play the graph |
|
||||||
| F2 | Dump the current data to a csv and graph it with gnuplot |
|
| F2 | Dump the current data to a csv and graph it with gnuplot |
|
||||||
| F3 | Show/Hide Debug info |
|
| F3 | Show/Hide Debug info |
|
||||||
|
| F4 | Show/Hide Cursor Location |
|
||||||
|
|||||||
44
src/main.rs
44
src/main.rs
@@ -282,7 +282,7 @@ async fn get_font() -> Option<Font> {
|
|||||||
let ttf = load_ttf_font(selection)
|
let ttf = load_ttf_font(selection)
|
||||||
.await
|
.await
|
||||||
.expect("Cannot load ttf {selection}");
|
.expect("Cannot load ttf {selection}");
|
||||||
println!("Loaded \"{:?}\"", ttfs[0]);
|
println!("Loaded {:?}", ttfs[0]);
|
||||||
return Some(ttf);
|
return Some(ttf);
|
||||||
} else {
|
} else {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
@@ -306,13 +306,19 @@ async fn main() {
|
|||||||
let mut graph = Graph::new(Axis::One, font.as_ref());
|
let mut graph = Graph::new(Axis::One, font.as_ref());
|
||||||
|
|
||||||
// Tooling
|
// Tooling
|
||||||
let mut show_debug = true;
|
let mut show_debug = false;
|
||||||
let mut plot_delta_time = 0.;
|
let mut plot_delta_time = 0.;
|
||||||
let mut pause = false;
|
let mut pause = false;
|
||||||
|
|
||||||
// Serial
|
// Serial
|
||||||
let (rx, _handle) = get_serial_port_or_demo();
|
let (rx, _handle) = get_serial_port_or_demo();
|
||||||
loop {
|
loop {
|
||||||
|
let mut debug = DebugWindow::new(font.as_ref());
|
||||||
|
let params = debug.get_params();
|
||||||
|
let (mouse_x, mouse_y) = mouse_position();
|
||||||
|
let (_, my) = mouse_wheel();
|
||||||
|
graph.px_per_s += 10. * my;
|
||||||
|
|
||||||
clear_background(BLACK);
|
clear_background(BLACK);
|
||||||
|
|
||||||
graph.recalculate_origin();
|
graph.recalculate_origin();
|
||||||
@@ -391,14 +397,8 @@ async fn main() {
|
|||||||
show_debug = !show_debug;
|
show_debug = !show_debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (_, my) = mouse_wheel();
|
if !pause {
|
||||||
graph.px_per_s += 10. * my;
|
|
||||||
|
|
||||||
let mut debug = DebugWindow::new(font.as_ref());
|
|
||||||
let params = debug.get_params();
|
|
||||||
|
|
||||||
// Cursor information
|
// Cursor information
|
||||||
let (mouse_x, mouse_y) = mouse_position();
|
|
||||||
let text = &format!("x{mouse_x}, y{}", -(mouse_y - graph.y_origin));
|
let text = &format!("x{mouse_x}, y{}", -(mouse_y - graph.y_origin));
|
||||||
let size = measure_text(text, params.font, params.font_size, params.font_scale);
|
let size = measure_text(text, params.font, params.font_size, params.font_scale);
|
||||||
draw_rectangle(
|
draw_rectangle(
|
||||||
@@ -408,9 +408,30 @@ async fn main() {
|
|||||||
-(size.height),
|
-(size.height),
|
||||||
DARKGRAY,
|
DARKGRAY,
|
||||||
);
|
);
|
||||||
|
draw_text_ex(text, mouse_x, mouse_y, params.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
if pause {
|
||||||
|
for i in graph.points {
|
||||||
|
let distance = 15.;
|
||||||
|
if (i.x - mouse_x).abs() < distance && (i.y - mouse_y).abs() < distance {
|
||||||
|
let size = 10.;
|
||||||
|
draw_rectangle(i.x - size / 2., i.y - size / 2., size, size, YELLOW);
|
||||||
|
|
||||||
|
let text = &format!("x{}, y{}", i.x, i.y);
|
||||||
|
let size = measure_text(text, params.font, params.font_size, params.font_scale);
|
||||||
|
draw_rectangle(
|
||||||
|
i.x,
|
||||||
|
i.y + (size.offset_y / 4.),
|
||||||
|
size.width,
|
||||||
|
-(size.height),
|
||||||
|
DARKGRAY,
|
||||||
|
);
|
||||||
|
draw_text_ex(text, i.x, i.y, params.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
draw_text_ex(text, mouse_x, mouse_y, params);
|
|
||||||
// toggle debug box
|
|
||||||
if show_debug {
|
if show_debug {
|
||||||
// Debug textbox
|
// Debug textbox
|
||||||
debug.add_line(format!(
|
debug.add_line(format!(
|
||||||
@@ -431,6 +452,7 @@ async fn main() {
|
|||||||
|
|
||||||
debug.draw();
|
debug.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
next_frame().await;
|
next_frame().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user