Compare commits
2 Commits
939120b08e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 31c6eb0821 | |||
| 82230299a4 |
@@ -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 |
|
||||||
|
|||||||
62
src/main.rs
62
src/main.rs
@@ -181,19 +181,11 @@ impl<'a> Graph<'a> {
|
|||||||
} else {
|
} else {
|
||||||
self.head_tracker = self.head_tracker + (delta_time * self.px_per_s)
|
self.head_tracker = self.head_tracker + (delta_time * self.px_per_s)
|
||||||
}
|
}
|
||||||
self.push(Point::new(
|
self.push(Point::new(self.head_tracker, self.y_origin - y, delta_time));
|
||||||
self.head_tracker,
|
|
||||||
self.y_origin - y,
|
|
||||||
delta_time,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
Axis::Two => {
|
Axis::Two => {
|
||||||
// both x and y will get displaced
|
// both x and y will get displaced
|
||||||
self.push(Point::new(
|
self.push(Point::new(self.x_origin + x, self.y_origin - y, delta_time))
|
||||||
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)
|
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!(
|
||||||
@@ -314,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();
|
||||||
@@ -399,15 +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;
|
// Cursor information
|
||||||
|
|
||||||
// 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();
|
|
||||||
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(
|
||||||
@@ -415,10 +406,33 @@ async fn main() {
|
|||||||
mouse_y + (size.offset_y / 4.),
|
mouse_y + (size.offset_y / 4.),
|
||||||
size.width,
|
size.width,
|
||||||
-(size.height),
|
-(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 textbox
|
||||||
debug.add_line(format!(
|
debug.add_line(format!(
|
||||||
"FPS {:04}, Frametime {:05.2}ms",
|
"FPS {:04}, Frametime {:05.2}ms",
|
||||||
@@ -431,12 +445,14 @@ async fn main() {
|
|||||||
));
|
));
|
||||||
debug.add_line(format!("Cursor Pos {:?}", mouse_position()));
|
debug.add_line(format!("Cursor Pos {:?}", mouse_position()));
|
||||||
|
|
||||||
|
#[allow(static_mut_refs)]
|
||||||
if let Some(port_name) = unsafe { PORT.clone() } {
|
if let Some(port_name) = unsafe { PORT.clone() } {
|
||||||
debug.add_line(format!("Serial Port {port_name}, Baud Rate {BAUD_RATE}"));
|
debug.add_line(format!("Serial Port {port_name}, Baud Rate {BAUD_RATE}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
debug.draw();
|
debug.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
next_frame().await;
|
next_frame().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user