diff --git a/Cargo.toml b/Cargo.toml index 5af9b44..0cfef68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ nom = "5.0.0" colored = "1.8" ansi_term = "0.11.0" hexdump = "0.1.0" -sdl2 = "0.32.2" +sdl2 = {version = "0.32.2", features = ["image"]} minifb = "0.11.2" time = "0.1.42" bitfield = "0.13.1" diff --git a/README.md b/README.md index 167f7e9..b07ce69 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![Build Status](https://travis-ci.com/michelhe/rustboyadvance-ng.svg?branch=master)](https://travis-ci.com/michelhe/rustboyadvance-ng) +![icon ](assets/icon.png) + RustBoyAdvance-NG Nintendo GameBoy Advance emulator and debugger, written in the rust programming language. Currently passing armwrestler tests, and displays some of TONC's Demos. diff --git a/assets/icon.png b/assets/icon.png new file mode 100644 index 0000000..568b524 Binary files /dev/null and b/assets/icon.png differ diff --git a/src/plat/sdl2/main.rs b/src/plat/sdl2/main.rs index 5db6020..d13f036 100644 --- a/src/plat/sdl2/main.rs +++ b/src/plat/sdl2/main.rs @@ -1,6 +1,9 @@ extern crate sdl2; use sdl2::event::Event; +use sdl2::image::{InitFlag, LoadTexture}; use sdl2::keyboard::Keycode; +use sdl2::pixels::Color; +use sdl2::rect::Rect; use sdl2::EventPump; extern crate spin_sleep; @@ -52,10 +55,11 @@ fn main() { let debug = matches.occurrences_of("debug") != 0; - let sdl_context = sdl2::init().unwrap(); + let sdl_context = sdl2::init().expect("failed to initialize sdl2"); let mut event_pump = sdl_context.event_pump().unwrap(); let video_subsystem = sdl_context.video().unwrap(); + let _image_context = sdl2::image::init(InitFlag::PNG | InitFlag::JPG).unwrap(); let window = video_subsystem .window( "RustBoyAdvance", @@ -66,7 +70,27 @@ fn main() { .position_centered() .build() .unwrap(); - let video = Rc::new(RefCell::new(create_video_interface(window))); + let mut canvas = window.into_canvas().accelerated().build().unwrap(); + + // Display the icon as a placeholder + canvas.set_draw_color(Color::RGB(0x80, 0x75, 0x85)); // default background color for the icon + canvas.clear(); + let texture_creator = canvas.texture_creator(); + let icon_texture = texture_creator + .load_texture("assets/icon.png") + .expect("failed to load icon"); + canvas + .copy( + &icon_texture, + None, + Some(Rect::new(0, 0, SCREEN_WIDTH * SCALE, SCREEN_HEIGHT * SCALE)), + ) + .unwrap(); + canvas.present(); + + // TODO also set window icon + + let video = Rc::new(RefCell::new(create_video_interface(canvas))); let audio = Rc::new(RefCell::new(create_audio_player(&sdl_context))); let input = Rc::new(RefCell::new(create_input())); diff --git a/src/plat/sdl2/video.rs b/src/plat/sdl2/video.rs index ed78983..99164e9 100644 --- a/src/plat/sdl2/video.rs +++ b/src/plat/sdl2/video.rs @@ -1,7 +1,7 @@ -use sdl2::pixels::{Color, PixelFormatEnum}; +use sdl2::pixels::PixelFormatEnum; use sdl2::rect::Rect; use sdl2::render::{Texture, TextureCreator, WindowCanvas}; -use sdl2::video::{Window, WindowContext}; +use sdl2::video::WindowContext; use rustboyadvance_ng::core::gpu::{DISPLAY_HEIGHT, DISPLAY_WIDTH}; use rustboyadvance_ng::VideoInterface; @@ -42,11 +42,7 @@ impl<'a> VideoInterface for Sdl2Video<'a> { } } -pub fn create_video_interface<'a>(window: Window) -> Sdl2Video<'a> { - let mut canvas = window.into_canvas().accelerated().build().unwrap(); - canvas.set_draw_color(Color::RGB(0, 0, 0)); - canvas.clear(); - canvas.present(); +pub fn create_video_interface<'a>(canvas: WindowCanvas) -> Sdl2Video<'a> { let mut tc = canvas.texture_creator(); let texture = unsafe { let tc_ptr = &mut tc as *mut TextureCreator;