riscii

An emulator for the RISC II
Log | Files | Refs | LICENSE

commit 0feed5fef9e151f73fb0c657b8f80231d851ff81
parent c90302e7c736484e0a5bb66117837dbdea047029
Author: Ryan Jeffrey <ryan@ryanmj.xyz>
Date:   Sat, 12 Nov 2022 15:33:59 -0800

Delete main window and update debug window screensho

Diffstat:
Mriscii_data_path.png | 0
Msrc/main.rs | 68+++++++++++++++-----------------------------------------------------
Dsrc/window.rs | 69---------------------------------------------------------------------
3 files changed, 15 insertions(+), 122 deletions(-)

diff --git a/riscii_data_path.png b/riscii_data_path.png Binary files differ. diff --git a/src/main.rs b/src/main.rs @@ -38,7 +38,6 @@ pub mod sdl; pub mod shifter; pub mod system; pub mod util; -pub mod window; use config::Config; use debug_window::DebugWindow; @@ -48,7 +47,6 @@ use std::cell::RefCell; use std::error::Error; use std::rc::Rc; use system::System; -use window::MainWindow; // Struct/enum declarations. @@ -58,14 +56,9 @@ enum GlobalAction { CloseDebugWindow, } -fn handle_events( - context: &mut Context, - win: &mut MainWindow, - debug_window: &mut Option<DebugWindow>, -) -> GlobalAction { +fn handle_events(context: &mut Context, debug_window: &mut DebugWindow) -> GlobalAction { let event_pump = &mut context.event_pump; let mut result = GlobalAction::None; - let main_win_id = win.get_window_id(); for event in event_pump.poll_iter() { match event { Event::Quit { .. } => { @@ -73,48 +66,19 @@ fn handle_events( } Event::Window { win_event: WindowEvent::Close, - window_id: id, .. } => { - if id == main_win_id { - return GlobalAction::QuitProgram; - } else if let Some(dwin) = debug_window { - if dwin.get_window_id() == id { - result = GlobalAction::CloseDebugWindow; - continue; - } - } - eprintln!("Close for window id {}, but it does not exist!", id); + return GlobalAction::QuitProgram; } Event::KeyDown { - keycode: Some(kc), - window_id: id, - .. + keycode: Some(kc), .. } => { - if id == main_win_id { - win.handle_key_down(kc); - } else if let Some(dwin) = debug_window { - if dwin.get_window_id() == id { - dwin.handle_key_down(kc); - continue; - } - } - eprintln!("Keydown event for window id {}, but it does not exist!", id); + debug_window.handle_key_down(kc); } Event::KeyUp { - keycode: Some(kc), - window_id: id, - .. + keycode: Some(kc), .. } => { - if id == main_win_id { - win.handle_key_up(kc); - } else if let Some(dwin) = debug_window { - if dwin.get_window_id() == id { - dwin.handle_key_up(kc); - continue; - } - } - eprintln!("Keyup event for window id {}, but it does not exist!", id); + debug_window.handle_key_up(kc); } _ => {} } @@ -135,7 +99,6 @@ fn main() -> Result<(), Box<dyn Error>> { let mut sdl_context = Context::new()?; let mut font_context = make_font_context()?; - let mut main_window = MainWindow::new(&config, system.clone(), &mut sdl_context)?; let mut debug_window = if config.is_debug_mode() { Some(DebugWindow::new( &config, @@ -148,23 +111,22 @@ fn main() -> Result<(), Box<dyn Error>> { }; 'running: loop { - match { handle_events(&mut sdl_context, &mut main_window, &mut debug_window) } { - GlobalAction::QuitProgram => { - break 'running; - } - GlobalAction::CloseDebugWindow => { - debug_window = None; - } - _ => {} - } system.borrow_mut().tick(); debug_window = if let Some(mut win) = debug_window { + match { handle_events(&mut sdl_context, &mut win) } { + GlobalAction::QuitProgram => { + break 'running; + } + GlobalAction::CloseDebugWindow => { + debug_window = None; + } + _ => {} + } win.draw(&mut sdl_context)?; Some(win) } else { None }; - main_window.draw(&mut sdl_context)?; } Ok(()) } diff --git a/src/window.rs b/src/window.rs @@ -1,69 +0,0 @@ -// RISC II emulator window. -// (C) Ryan Jeffrey <ryan@ryanmj.xyz>, 2022 -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or (at -// your option) any later version. - -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. - -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see <https://www.gnu.org/licenses/>. - -// Struct definitions. - -use config::Config; -use sdl::{Context, Drawable, Pane}; -use sdl2::keyboard::Keycode; -use sdl2::pixels::*; -use std::cell::RefCell; -use std::rc::Rc; -use system::System; -use util::Result; - -pub struct MainWindow<'a> { - pane: Pane, - system: Rc<RefCell<System>>, - config: &'a Config, -} - -// Struct impls. - -impl<'a> Drawable for MainWindow<'a> { - fn draw(&mut self, context: &mut Context) -> Result<()> { - self.pane.canvas.set_draw_color(Color::RGB(0, 0, 0)); - self.pane.canvas.clear(); - // - self.pane.canvas.present(); - - Ok(()) - } - - fn handle_key_down(&mut self, kc: Keycode) {} - fn handle_key_up(&mut self, kc: Keycode) {} - fn get_window_id(&self) -> u32 { - self.pane.get_id() - } -} - -impl<'a> MainWindow<'a> { - pub fn new( - config: &'a Config, - system: Rc<RefCell<System>>, - context: &mut Context, - ) -> Result<Self> { - Ok(Self { - pane: Pane::new( - config.get_win_width(), - config.get_debug_win_height(), - format!("RISC II"), - context, - )?, - system, - config, - }) - } -}