Initial commit
This commit is contained in:
Generated
+7
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "trevors_chip8_toy"
|
||||
version = "0.1.0"
|
||||
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "trevors_chip8_toy"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
trevors_chip8_core = { path = "../chip8_core" }
|
||||
easy-imgui-sys = { version = "=0.6.0" }
|
||||
easy-imgui = { version = "=0.6.0" }
|
||||
easy-imgui-renderer = { version = "=0.6.0" }
|
||||
easy-imgui-window = { version = "0.6.0" }
|
||||
log ="0.4"
|
||||
glutin = "0.32"
|
||||
glutin-winit = { version = "0.5", optional = true }
|
||||
raw-window-handle = "0.6"
|
||||
arboard = { version = "3", optional = true, default-features = false }
|
||||
winit = { version = "0.30", features = ["x11", "mint"] }
|
||||
@@ -0,0 +1,79 @@
|
||||
use easy_imgui::{Ui, UiBuilder};
|
||||
use easy_imgui_window::{MainWindow, MainWindowWithRenderer};
|
||||
use winit::{application::ApplicationHandler, event_loop::ActiveEventLoop, window::{Window, WindowAttributes}};
|
||||
|
||||
|
||||
pub struct Chip8Display {
|
||||
pub window: MainWindowWithRenderer,
|
||||
}
|
||||
|
||||
impl Chip8Display {
|
||||
pub fn new(event_loop: &ActiveEventLoop) -> Chip8Display {
|
||||
Chip8Display { window: MainWindowWithRenderer::new(
|
||||
MainWindow::new::<()>(&event_loop, Window::default_attributes().with_title("Chip8 Display")).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render<M>(ui: &Ui<M>) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
impl UiBuilder for Chip8AppHandler {
|
||||
fn do_ui(&mut self, ui: &Ui<Self>) {
|
||||
|
||||
ui.text("This is where the Chip8 UI Goes");
|
||||
ui.text("Controls for Start/Stop/Load/Run Maybe?");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Chip8AppHandler {
|
||||
pub windows: Vec<MainWindowWithRenderer>,
|
||||
// pub display: Chip8Display
|
||||
}
|
||||
|
||||
impl ApplicationHandler for Chip8AppHandler {
|
||||
fn suspended(&mut self, _event_loop: &ActiveEventLoop) {
|
||||
self.windows.clear();
|
||||
}
|
||||
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
self.windows.push(Chip8Display::new(event_loop).window);
|
||||
}
|
||||
|
||||
fn window_event(
|
||||
&mut self,
|
||||
event_loop: &ActiveEventLoop,
|
||||
window_id: winit::window::WindowId,
|
||||
event: winit::event::WindowEvent,
|
||||
) {
|
||||
for window in &mut self.windows {
|
||||
if window.main_window().window().id() != window_id {
|
||||
continue;
|
||||
}
|
||||
let res = window.window_event(
|
||||
&mut self,
|
||||
&event,
|
||||
easy_imgui_window::EventFlags::empty(),
|
||||
);
|
||||
if res.window_closed {
|
||||
event_loop.exit();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
fn new_events(&mut self, _event_loop: &ActiveEventLoop, _cause: winit::event::StartCause) {
|
||||
for window in &mut self.windows {
|
||||
window.new_events();
|
||||
}
|
||||
}
|
||||
fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) {
|
||||
for window in &mut self.windows {
|
||||
window.about_to_wait();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod gui {
|
||||
pub mod display;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
use easy_imgui_window::{
|
||||
easy_imgui as imgui,
|
||||
easy_imgui_renderer::Renderer,
|
||||
winit::{
|
||||
event_loop::{ActiveEventLoop, EventLoop},
|
||||
window::Window,
|
||||
},
|
||||
MainWindow, MainWindowWithRenderer,
|
||||
};
|
||||
use trevors_chip8_toy::gui::display::{Chip8App, Chip8AppHandler};
|
||||
use std::rc::Rc;
|
||||
|
||||
fn main() {
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
|
||||
let mut main = Chip8AppHandler {
|
||||
windows: vec![],
|
||||
app: Chip8App,
|
||||
};
|
||||
|
||||
event_loop.run_app(&mut main).unwrap();
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct AppHandler {
|
||||
windows: Vec<MainWindowWithRenderer>,
|
||||
app: App,
|
||||
}
|
||||
|
||||
impl winit::application::ApplicationHandler for AppHandler {
|
||||
fn suspended(&mut self, _event_loop: &ActiveEventLoop) {
|
||||
self.windows.clear();
|
||||
}
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let wattr_1 = Window::default_attributes().with_title("Example #1");
|
||||
let main_window_1 = MainWindow::new::<()>(&event_loop, wattr_1).unwrap();
|
||||
let mut window_1 = MainWindowWithRenderer::new(main_window_1);
|
||||
|
||||
let wattr_2 = Window::default_attributes().with_title("Example #2");
|
||||
let main_window_2 = MainWindow::new::<()>(&event_loop, wattr_2).unwrap();
|
||||
// The GL context can be reused, but the imgui context cannot
|
||||
let mut renderer_2 = Renderer::new(Rc::clone(window_1.renderer().gl_context())).unwrap();
|
||||
renderer_2.set_background_color(Some(imgui::Color::GREEN));
|
||||
let window_2 = MainWindowWithRenderer::new_with_renderer(main_window_2, renderer_2);
|
||||
|
||||
self.windows.push(window_1);
|
||||
self.windows.push(window_2);
|
||||
}
|
||||
fn window_event(
|
||||
&mut self,
|
||||
event_loop: &ActiveEventLoop,
|
||||
window_id: winit::window::WindowId,
|
||||
event: winit::event::WindowEvent,
|
||||
) {
|
||||
for window in &mut self.windows {
|
||||
if window.main_window().window().id() != window_id {
|
||||
continue;
|
||||
}
|
||||
let res = window.window_event(
|
||||
&mut self.app,
|
||||
&event,
|
||||
easy_imgui_window::EventFlags::empty(),
|
||||
);
|
||||
if res.window_closed {
|
||||
event_loop.exit();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
fn new_events(&mut self, _event_loop: &ActiveEventLoop, _cause: winit::event::StartCause) {
|
||||
for window in &mut self.windows {
|
||||
window.new_events();
|
||||
}
|
||||
}
|
||||
fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) {
|
||||
for window in &mut self.windows {
|
||||
window.about_to_wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct App;
|
||||
|
||||
impl imgui::UiBuilder for App {
|
||||
fn do_ui(&mut self, ui: &imgui::Ui<Self>) {
|
||||
#[cfg(feature = "docking")]
|
||||
{
|
||||
ui.dock_space_over_viewport(0, imgui::DockNodeFlags::None);
|
||||
}
|
||||
|
||||
ui.show_demo_window(None);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user