can now add and remove windows
parent
0c39d1b1e4
commit
542223ddd9
55
src/debug.rs
55
src/debug.rs
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
use imgui_glow_renderer::AutoRenderer;
|
use imgui_glow_renderer::AutoRenderer;
|
||||||
use imgui_sdl2_support::SdlPlatform;
|
use imgui_sdl2_support::SdlPlatform;
|
||||||
|
use std::collections::HashMap;
|
||||||
use sdl2::event::Event;
|
use sdl2::event::Event;
|
||||||
const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/models/TestCarModel/CarW1.obj",
|
const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/models/TestCarModel/CarW1.obj",
|
||||||
"resources/models/TestCarModel/CarW0.obj"];
|
"resources/models/TestCarModel/CarW0.obj"];
|
||||||
|
@ -13,6 +13,8 @@ pub enum dEvent
|
||||||
{
|
{
|
||||||
loadModel(i32),
|
loadModel(i32),
|
||||||
setTest(f32, i32),
|
setTest(f32, i32),
|
||||||
|
addWindow(OpenWindows),
|
||||||
|
removeWindow(OpenWindows),
|
||||||
exit,
|
exit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +35,9 @@ pub struct Debug {
|
||||||
imgui: imgui::Context,
|
imgui: imgui::Context,
|
||||||
renderer: AutoRenderer,
|
renderer: AutoRenderer,
|
||||||
platform: SdlPlatform,
|
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,
|
Ok(ret) => ret,
|
||||||
Err(s) => panic!("Failed to initialize Imgui Platform Renderer: {}", s),
|
Err(s) => panic!("Failed to initialize Imgui Platform Renderer: {}", s),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut windows = HashMap::new();
|
||||||
|
windows.insert(0,OpenWindows::TestWind,);
|
||||||
Debug {
|
Debug {
|
||||||
imgui,
|
imgui,
|
||||||
renderer,
|
renderer,
|
||||||
platform,
|
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);
|
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,
|
pub fn drawImgui(&mut self, events_loop: &sdl2::EventPump, window: &sdl2::video::Window,
|
||||||
callback: Vec<Callback>) -> Vec<dEvent>
|
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 ui = self.imgui.new_frame();
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
for call in callback
|
for call in callback
|
||||||
|
@ -82,10 +86,10 @@ impl Debug {
|
||||||
match call {
|
match call {
|
||||||
Callback::ModelInfo(a) =>
|
Callback::ModelInfo(a) =>
|
||||||
{
|
{
|
||||||
Debug::displayModel(ui, &a)
|
ret.append(&mut Debug::displayModel(ui, &a))
|
||||||
},
|
},
|
||||||
Callback::TestWind(mut a) =>
|
Callback::TestWind(mut a) =>
|
||||||
ret = Debug::displayTest(ui, &mut a),
|
ret.append(&mut Debug::displayTest(ui, &mut a)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +101,28 @@ impl Debug {
|
||||||
|
|
||||||
ret
|
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>
|
fn displayTest(ui: &mut imgui::Ui, testI: &mut info::testI) -> Vec<dEvent>
|
||||||
{
|
{
|
||||||
|
@ -122,8 +148,9 @@ impl Debug {
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
fn displayModel(ui: &mut imgui::Ui ,model: &info::ModelI)
|
fn displayModel(ui: &mut imgui::Ui ,model: &info::ModelI) -> Vec<dEvent>
|
||||||
{
|
{
|
||||||
|
let mut ret = Vec::new();
|
||||||
ui.window("Stats")
|
ui.window("Stats")
|
||||||
.size([300.0, 500.0], imgui::Condition::Always)
|
.size([300.0, 500.0], imgui::Condition::Always)
|
||||||
.build(|| {
|
.build(|| {
|
||||||
|
@ -136,7 +163,11 @@ impl Debug {
|
||||||
ui.text(format!("count Vertices: {}", model.vertCount[i]));
|
ui.text(format!("count Vertices: {}", model.vertCount[i]));
|
||||||
ui.separator();
|
ui.separator();
|
||||||
}
|
}
|
||||||
|
if ui.button("close") {
|
||||||
|
ret.push(dEvent::removeWindow(OpenWindows::ModelInfo))
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
10
src/scene.rs
10
src/scene.rs
|
@ -120,7 +120,7 @@ impl Scene{
|
||||||
if self.tempData.DebugMode{
|
if self.tempData.DebugMode{
|
||||||
let mut Callbacks = Vec::new();
|
let mut Callbacks = Vec::new();
|
||||||
let windows = self.debug.windows.clone();
|
let windows = self.debug.windows.clone();
|
||||||
for window in windows
|
for (id, window) in windows
|
||||||
{
|
{
|
||||||
match window {
|
match window {
|
||||||
debug::OpenWindows::ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car)),
|
debug::OpenWindows::ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car)),
|
||||||
|
@ -140,8 +140,9 @@ impl Scene{
|
||||||
dEvent::setTest(a, b) => {
|
dEvent::setTest(a, b) => {
|
||||||
self.tempData.spinSpeed = a;
|
self.tempData.spinSpeed = a;
|
||||||
self.tempData.selectedModel = b;
|
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), ..} => {
|
Event::KeyDown {keycode: Some(Keycode::D), ..} => {
|
||||||
self.tempData.DebugMode = !self.tempData.DebugMode
|
self.tempData.DebugMode = !self.tempData.DebugMode
|
||||||
|
}
|
||||||
|
Event::KeyDown {keycode: Some(Keycode::M), ..} => {
|
||||||
|
self.debug.addWindow(debug::OpenWindows::ModelInfo)
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue