can now add and remove windows

pull/3/head
Milk.H 2023-03-23 16:21:05 +01:00
parent 0c39d1b1e4
commit 542223ddd9
No known key found for this signature in database
GPG Key ID: 3D9DAE46AAC37BD8
2 changed files with 86 additions and 51 deletions

View File

@ -1,7 +1,7 @@
use imgui_glow_renderer::AutoRenderer;
use imgui_sdl2_support::SdlPlatform;
use std::collections::HashMap;
use sdl2::event::Event;
const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/models/TestCarModel/CarW1.obj",
"resources/models/TestCarModel/CarW0.obj"];
@ -13,6 +13,8 @@ pub enum dEvent
{
loadModel(i32),
setTest(f32, i32),
addWindow(OpenWindows),
removeWindow(OpenWindows),
exit,
}
@ -33,7 +35,9 @@ pub struct Debug {
imgui: imgui::Context,
renderer: AutoRenderer,
platform: SdlPlatform,
pub windows: Vec<OpenWindows>,
pub windows: HashMap<i16, OpenWindows>,
next_id: i16,
free_ids:Vec<i16>
}
@ -53,11 +57,16 @@ impl Debug {
Ok(ret) => ret,
Err(s) => panic!("Failed to initialize Imgui Platform Renderer: {}", s),
};
let mut windows = HashMap::new();
windows.insert(0,OpenWindows::TestWind,);
Debug {
imgui,
renderer,
platform,
windows: vec![OpenWindows::TestWind, OpenWindows::ModelInfo],
windows,
next_id: 2,
free_ids: Vec::new(),
}
}
@ -65,16 +74,11 @@ impl Debug {
{
self.platform.handle_event(&mut self.imgui, event);
}
pub fn windows(self) -> Vec<OpenWindows>
{
let ret = self.windows.clone();
ret
}
pub fn drawImgui(&mut self, events_loop: &sdl2::EventPump, window: &sdl2::video::Window,
callback: Vec<Callback>) -> Vec<dEvent>
{
self.platform.prepare_frame(&mut self.imgui, &window, &events_loop );
self.platform.prepare_frame(&mut self.imgui, &window, &events_loop);
let ui = self.imgui.new_frame();
let mut ret = Vec::new();
for call in callback
@ -82,10 +86,10 @@ impl Debug {
match call {
Callback::ModelInfo(a) =>
{
Debug::displayModel(ui, &a)
ret.append(&mut Debug::displayModel(ui, &a))
},
Callback::TestWind(mut a) =>
ret = Debug::displayTest(ui, &mut a),
ret.append(&mut Debug::displayTest(ui, &mut a)),
}
}
@ -97,47 +101,74 @@ impl Debug {
ret
}
pub fn addWindow(&mut self, window: OpenWindows)
{
if (self.free_ids.is_empty())
{
self.windows.insert(self.next_id, window);
}
else {
self.windows.insert(self.free_ids.pop().unwrap(), window);
}
}
pub fn removeWindow(&mut self, window: OpenWindows)
{
println!("searching for a match...");
let mut id = 0;
for (hashId, windowType) in &self.windows
{
if let _window = windowType {id = *hashId; println!("found a match!")};
}
self.windows.remove(&id);
self.free_ids.push(id);
}
fn displayTest(ui: &mut imgui::Ui, testI: &mut info::testI) -> Vec<dEvent>
{
let mut ret = Vec::new();
let mut selectedModel = testI.selectedModel;
let mut spinSpeed = testI.spinSpeed;
ui.window("POLY I WILL FUCKING")
.size([500.0, 100.0], imgui::Condition::FirstUseEver)
.build(|| {
ui.text("you serve no purpose in life");
ui.text("Your Purpose in life is to suck my dick");
ui.slider("The Spin Speed", 0.1, 10.0, &mut spinSpeed);
if ui
.button("Quit") {
ret.push(dEvent::exit);
}
if ui.list_box("Select Model to Load", &mut selectedModel, &MODELS, 5) {
ret.push(dEvent::loadModel(selectedModel));
{
let mut ret = Vec::new();
let mut selectedModel = testI.selectedModel;
let mut spinSpeed = testI.spinSpeed;
ui.window("POLY I WILL FUCKING")
.size([500.0, 100.0], imgui::Condition::FirstUseEver)
.build(|| {
ui.text("you serve no purpose in life");
ui.text("Your Purpose in life is to suck my dick");
ui.slider("The Spin Speed", 0.1, 10.0, &mut spinSpeed);
if ui
.button("Quit") {
ret.push(dEvent::exit);
}
});
ret.push(dEvent::setTest(spinSpeed, selectedModel
));
ret
}
if ui.list_box("Select Model to Load", &mut selectedModel, &MODELS, 5) {
ret.push(dEvent::loadModel(selectedModel));
}
});
ret.push(dEvent::setTest(spinSpeed, selectedModel
));
ret
}
fn displayModel(ui: &mut imgui::Ui ,model: &info::ModelI)
{
ui.window("Stats")
.size([300.0, 500.0], imgui::Condition::Always)
.build(|| {
ui.text("Model Information");
ui.text(format!("count meshes: {}", model.meshesCount));
ui.separator();
for i in 0..model.meshesCount
{
ui.text(format!("Mesh Number {}", i));
ui.text(format!("count Vertices: {}", model.vertCount[i]));
ui.separator();
}
});
}
fn displayModel(ui: &mut imgui::Ui ,model: &info::ModelI) -> Vec<dEvent>
{
let mut ret = Vec::new();
ui.window("Stats")
.size([300.0, 500.0], imgui::Condition::Always)
.build(|| {
ui.text("Model Information");
ui.text(format!("count meshes: {}", model.meshesCount));
ui.separator();
for i in 0..model.meshesCount
{
ui.text(format!("Mesh Number {}", i));
ui.text(format!("count Vertices: {}", model.vertCount[i]));
ui.separator();
}
if ui.button("close") {
ret.push(dEvent::removeWindow(OpenWindows::ModelInfo))
}
});
ret
}
}

View File

@ -120,7 +120,7 @@ impl Scene{
if self.tempData.DebugMode{
let mut Callbacks = Vec::new();
let windows = self.debug.windows.clone();
for window in windows
for (id, window) in windows
{
match window {
debug::OpenWindows::ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car)),
@ -140,8 +140,9 @@ impl Scene{
dEvent::setTest(a, b) => {
self.tempData.spinSpeed = a;
self.tempData.selectedModel = b;
}
},
dEvent::addWindow(a) => self.debug.addWindow(a),
dEvent::removeWindow(a) => self.debug.removeWindow(a),
}
}
}
@ -159,6 +160,9 @@ impl Scene{
},
Event::KeyDown {keycode: Some(Keycode::D), ..} => {
self.tempData.DebugMode = !self.tempData.DebugMode
}
Event::KeyDown {keycode: Some(Keycode::M), ..} => {
self.debug.addWindow(debug::OpenWindows::ModelInfo)
}
_ => {}
}