🚧 wip: I'm excited egui is working but now the code is so ugly

main
_ 2023-09-10 20:12:19 -05:00
parent 53017cefa1
commit f87d3fc00e
2 changed files with 27 additions and 4 deletions

View File

@ -23,7 +23,8 @@ impl Capture
{
let x = Device::open ("/dev/video0")?;
dbg! (x.formats (linuxvideo::BufType::VIDEO_CAPTURE).collect::<Vec <_>> ());
let x = x.video_capture (PixFormat::new (u32::MAX, u32::MAX, PixelFormat::YUYV))?;
let x = x.video_capture (PixFormat::new (1920, 1080, PixelFormat::MJPG))?;
x.set_frame_interval(linuxvideo::Fract::new(1, 30)).unwrap ();
dbg! (x.format ());
let size_image = usize::try_from (x.format ().size_image ()).unwrap ();
let stream = x.into_stream ()?;

View File

@ -131,6 +131,8 @@ struct MyEguiApp {
img: egui::ColorImage,
texture: Option <egui::TextureHandle>,
capture: capture::Capture,
gui_frames: usize,
camera_frames: usize,
}
impl MyEguiApp {
@ -140,13 +142,15 @@ impl MyEguiApp {
// Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use
// for e.g. egui::PaintCallback.
let img = egui::ColorImage::new ([1920,1080], egui::Color32::TEMPORARY_COLOR);
let img = egui::ColorImage::new ([1280,720], egui::Color32::TEMPORARY_COLOR);
Self
{
img,
texture: None,
capture: capture::Capture::new ().unwrap (),
gui_frames: 0,
camera_frames: 0,
}
}
}
@ -165,15 +169,33 @@ impl eframe::App for MyEguiApp {
{
self.capture.wait_for_frame(self.img.as_raw_mut()).unwrap ();
texture.set (self.img.clone (), Default::default ());
self.camera_frames += 1;
},
_ => (),
}
let texture: &egui::TextureHandle = texture;
ui.heading("Hello World!");
ui.image (texture, texture.size_vec2());
ui.heading (format! ("{0}, {1}", self.camera_frames, self.gui_frames));
let available = ui.available_size();
let tex_size = egui::Vec2::new (texture.size()[0] as f32, texture.size()[1] as f32);
let scaled_width = available.y * tex_size.x / tex_size.y;
let scaled_height = available.x * tex_size.y / tex_size.x;
let size = if scaled_width <= available.x
{
egui::Vec2::new (scaled_width, available.y)
}
else
{
egui::Vec2::new (available.x, scaled_height)
};
ui.image (texture, size);
self.gui_frames += 1;
});
ctx.request_repaint();
}
}