2022-05-15 21:30:05 +00:00
|
|
|
use cyborg::camera::Flycam;
|
|
|
|
|
2022-05-15 17:31:22 +00:00
|
|
|
pub struct UserInterface {
|
|
|
|
developer_mode: bool,
|
|
|
|
show_profiler: bool,
|
|
|
|
quit: bool,
|
|
|
|
show_about: bool,
|
|
|
|
log_contents: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UserInterface {
|
2022-05-15 21:30:05 +00:00
|
|
|
pub fn new() -> Self {
|
2022-05-15 17:31:22 +00:00
|
|
|
Self {
|
|
|
|
developer_mode: true,
|
|
|
|
show_profiler: false,
|
|
|
|
quit: false,
|
|
|
|
show_about: false,
|
|
|
|
log_contents: "Hello logging!\n".to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn should_quit(&self) -> bool {
|
|
|
|
self.quit
|
|
|
|
}
|
|
|
|
|
2022-05-15 21:30:05 +00:00
|
|
|
pub fn run(&mut self, ctx: &egui::Context, viewport: &mut ViewportWidget) {
|
2022-05-15 17:31:22 +00:00
|
|
|
egui::TopBottomPanel::top("menu_bar").show(ctx, |ui| {
|
|
|
|
egui::menu::bar(ui, |ui| {
|
|
|
|
ui.menu_button("File", |ui| {
|
|
|
|
if self.developer_mode {
|
|
|
|
if ui.button("fuck").clicked() {
|
|
|
|
println!("fuck");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ui.button("Save").clicked() {
|
|
|
|
println!("Saving!");
|
|
|
|
ui.close_menu();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ui.button("Save as...").clicked() {
|
|
|
|
println!("Saving as!");
|
|
|
|
ui.close_menu();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ui.button("Open...").clicked() {
|
|
|
|
println!("Opening!");
|
|
|
|
ui.close_menu();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ui.button("Quit").clicked() {
|
|
|
|
println!("Quitting!");
|
|
|
|
ui.close_menu();
|
|
|
|
self.quit = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ui.menu_button("Edit", |ui| {
|
|
|
|
if ui.button("Undo").clicked() {
|
|
|
|
println!("Undoing!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ui.button("Redo").clicked() {
|
|
|
|
println!("Redoing!");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ui.menu_button("View", |ui| {
|
|
|
|
ui.checkbox(&mut self.developer_mode, "Developer mode");
|
2022-05-15 17:55:57 +00:00
|
|
|
|
|
|
|
if ui.checkbox(&mut self.show_profiler, "Profiler").changed() {
|
|
|
|
puffin_egui::puffin::set_scopes_on(self.show_profiler);
|
|
|
|
}
|
2022-05-15 17:31:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ui.menu_button("Help", |ui| {
|
|
|
|
if ui.button("About").clicked() {
|
|
|
|
self.show_about = true;
|
|
|
|
ui.close_menu();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
egui::Window::new("example_window").show(ctx, |ui| {
|
|
|
|
ui.heading("Hello world!");
|
|
|
|
});
|
|
|
|
|
2022-05-15 17:55:57 +00:00
|
|
|
if self.show_profiler {
|
|
|
|
self.show_profiler = puffin_egui::profiler_window(ctx);
|
|
|
|
}
|
|
|
|
|
2022-05-15 17:31:22 +00:00
|
|
|
if self.show_about {
|
|
|
|
egui::Window::new("About")
|
|
|
|
.open(&mut self.show_about)
|
|
|
|
.resizable(false)
|
|
|
|
.collapsible(false)
|
|
|
|
.show(ctx, |ui| {
|
|
|
|
ui.vertical_centered(|ui| {
|
|
|
|
ui.heading("Cyborg Editor");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
egui::TopBottomPanel::bottom("info_panel")
|
|
|
|
.resizable(true)
|
|
|
|
.show(ctx, |ui| {
|
|
|
|
ui.heading("Log Output");
|
|
|
|
|
|
|
|
egui::containers::ScrollArea::vertical()
|
|
|
|
.auto_shrink([false, false])
|
|
|
|
.max_width(f32::INFINITY)
|
|
|
|
.max_height(f32::INFINITY)
|
|
|
|
.show(ui, |ui| {
|
|
|
|
let text_edit = egui::TextEdit::multiline(&mut self.log_contents)
|
|
|
|
.desired_width(f32::INFINITY)
|
|
|
|
.frame(false);
|
|
|
|
ui.add(text_edit);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-05-15 20:25:17 +00:00
|
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
2022-05-15 21:30:05 +00:00
|
|
|
ui.add(viewport);
|
2022-05-15 20:25:17 +00:00
|
|
|
ui.heading("Viewport");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ViewportWidget {
|
2022-05-15 21:30:05 +00:00
|
|
|
pub texture: egui::TextureId,
|
|
|
|
pub flycam: Flycam,
|
2022-05-15 20:25:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ViewportWidget {
|
2022-05-15 20:49:50 +00:00
|
|
|
pub fn new(texture: egui::TextureId) -> Self {
|
2022-05-15 21:30:05 +00:00
|
|
|
Self {
|
|
|
|
texture,
|
|
|
|
flycam: Flycam::new(0.002, 10.0, 0.25),
|
|
|
|
}
|
2022-05-15 20:25:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl egui::Widget for &mut ViewportWidget {
|
|
|
|
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
|
|
|
ui.style_mut().spacing.window_margin = egui::style::Margin::same(0.0);
|
|
|
|
let rect = ui.max_rect();
|
|
|
|
let id = egui::Id::new("viewport_widget");
|
|
|
|
let sense = egui::Sense::click_and_drag();
|
|
|
|
let response = ui.interact(rect, id, sense);
|
|
|
|
|
2022-05-15 21:30:05 +00:00
|
|
|
use egui::{pos2, Color32, Mesh, Rect, Shape};
|
2022-05-15 20:49:50 +00:00
|
|
|
let mut mesh = Mesh::with_texture(self.texture);
|
2022-05-15 20:25:17 +00:00
|
|
|
let uv = Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0));
|
|
|
|
let tint = Color32::WHITE;
|
|
|
|
mesh.add_rect_with_uv(rect, uv, tint);
|
|
|
|
ui.painter().add(Shape::mesh(mesh));
|
|
|
|
|
2022-05-15 21:30:05 +00:00
|
|
|
if response.dragged() {
|
|
|
|
println!("dragging");
|
|
|
|
let delta = response.drag_delta();
|
|
|
|
self.flycam.process_mouse(delta.x as f64, delta.y as f64);
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("{:#?}", self.flycam);
|
|
|
|
|
|
|
|
self.flycam.update();
|
|
|
|
|
2022-05-15 20:25:17 +00:00
|
|
|
response
|
2022-05-15 17:31:22 +00:00
|
|
|
}
|
|
|
|
}
|