Compare commits
2 Commits
939120b08e
...
31c6eb0821
| Author | SHA1 | Date | |
|---|---|---|---|
| 31c6eb0821 | |||
| 82230299a4 |
@@ -9,3 +9,4 @@ Finally, an easy way to do graphics with rust.
|
||||
| F1 | Pause/Play the graph |
|
||||
| F2 | Dump the current data to a csv and graph it with gnuplot |
|
||||
| F3 | Show/Hide Debug info |
|
||||
| F4 | Show/Hide Cursor Location |
|
||||
|
||||
64
src/main.rs
64
src/main.rs
@@ -181,19 +181,11 @@ impl<'a> Graph<'a> {
|
||||
} else {
|
||||
self.head_tracker = self.head_tracker + (delta_time * self.px_per_s)
|
||||
}
|
||||
self.push(Point::new(
|
||||
self.head_tracker,
|
||||
self.y_origin - y,
|
||||
delta_time,
|
||||
));
|
||||
self.push(Point::new(self.head_tracker, self.y_origin - y, delta_time));
|
||||
}
|
||||
Axis::Two => {
|
||||
// both x and y will get displaced
|
||||
self.push(Point::new(
|
||||
self.x_origin + x,
|
||||
self.y_origin - y,
|
||||
delta_time,
|
||||
))
|
||||
self.push(Point::new(self.x_origin + x, self.y_origin - y, delta_time))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,7 +282,7 @@ async fn get_font() -> Option<Font> {
|
||||
let ttf = load_ttf_font(selection)
|
||||
.await
|
||||
.expect("Cannot load ttf {selection}");
|
||||
println!("Loaded \"{:?}\"", ttfs[0]);
|
||||
println!("Loaded {:?}", ttfs[0]);
|
||||
return Some(ttf);
|
||||
} else {
|
||||
eprintln!(
|
||||
@@ -314,13 +306,19 @@ async fn main() {
|
||||
let mut graph = Graph::new(Axis::One, font.as_ref());
|
||||
|
||||
// Tooling
|
||||
let mut show_debug = true;
|
||||
let mut show_debug = false;
|
||||
let mut plot_delta_time = 0.;
|
||||
let mut pause = false;
|
||||
|
||||
// Serial
|
||||
let (rx, _handle) = get_serial_port_or_demo();
|
||||
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);
|
||||
|
||||
graph.recalculate_origin();
|
||||
@@ -364,7 +362,7 @@ async fn main() {
|
||||
let mut x = 0.;
|
||||
for p in &graph.points {
|
||||
x += p.time_since_last;
|
||||
let _ = file.write_all(format!("{x},{}\n", p.y-graph.y_origin).as_bytes());
|
||||
let _ = file.write_all(format!("{x},{}\n", p.y - graph.y_origin).as_bytes());
|
||||
}
|
||||
let _ = file.flush();
|
||||
|
||||
@@ -399,15 +397,8 @@ async fn main() {
|
||||
show_debug = !show_debug;
|
||||
}
|
||||
|
||||
let (_, my) = mouse_wheel();
|
||||
graph.px_per_s += 10. * my;
|
||||
|
||||
// toggle debug box
|
||||
if show_debug {
|
||||
let mut debug = DebugWindow::new(font.as_ref());
|
||||
let params = debug.get_params();
|
||||
// Debug cursor information
|
||||
let (mouse_x, mouse_y) = mouse_position();
|
||||
if !pause {
|
||||
// Cursor information
|
||||
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);
|
||||
draw_rectangle(
|
||||
@@ -415,10 +406,33 @@ async fn main() {
|
||||
mouse_y + (size.offset_y / 4.),
|
||||
size.width,
|
||||
-(size.height),
|
||||
BLUE,
|
||||
DARKGRAY,
|
||||
);
|
||||
draw_text_ex(text, mouse_x, mouse_y, params);
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if show_debug {
|
||||
// Debug textbox
|
||||
debug.add_line(format!(
|
||||
"FPS {:04}, Frametime {:05.2}ms",
|
||||
@@ -431,12 +445,14 @@ async fn main() {
|
||||
));
|
||||
debug.add_line(format!("Cursor Pos {:?}", mouse_position()));
|
||||
|
||||
#[allow(static_mut_refs)]
|
||||
if let Some(port_name) = unsafe { PORT.clone() } {
|
||||
debug.add_line(format!("Serial Port {port_name}, Baud Rate {BAUD_RATE}"));
|
||||
}
|
||||
|
||||
debug.draw();
|
||||
}
|
||||
|
||||
next_frame().await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user