From b980c7aa7dcbc5e3c1a6ec9edac837693c13461e Mon Sep 17 00:00:00 2001 From: Tibor Nagy Date: Tue, 12 May 2020 09:29:49 +0200 Subject: [PATCH] sdl2: Add window icon Former-commit-id: 920d73c22836099234db2c1fe096f2d4268174e0 Former-commit-id: e2d6902830e3887255e0d816c056f199f1dc453b --- platform/rustboyadvance-sdl2/src/main.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/platform/rustboyadvance-sdl2/src/main.rs b/platform/rustboyadvance-sdl2/src/main.rs index 995742f..aed53b0 100644 --- a/platform/rustboyadvance-sdl2/src/main.rs +++ b/platform/rustboyadvance-sdl2/src/main.rs @@ -1,12 +1,13 @@ use sdl2; -use sdl2::event::{Event, WindowEvent}; -use sdl2::image::{InitFlag, LoadTexture}; -use sdl2::keyboard::Scancode; use sdl2::controller::Button; +use sdl2::event::{Event, WindowEvent}; +use sdl2::image::{InitFlag, LoadSurface, LoadTexture}; +use sdl2::keyboard::Scancode; use sdl2::messagebox::*; use sdl2::pixels::Color; use sdl2::rect::Rect; use sdl2::render::WindowCanvas; +use sdl2::surface::Surface; use sdl2::EventPump; @@ -194,14 +195,17 @@ fn main() -> Result<(), Box> { let video_subsystem = sdl_context.video()?; let _image_context = sdl2::image::init(InitFlag::PNG | InitFlag::JPG)?; - let window = video_subsystem + let mut window = video_subsystem .window("RustBoyAdvance", SCREEN_WIDTH * 3, SCREEN_HEIGHT * 3) .opengl() .position_centered() .resizable() .build()?; - let mut canvas = window.into_canvas().accelerated().build()?; + let window_icon = Surface::from_file("assets/icon.png")?; + window.set_icon(window_icon); + + let mut canvas = window.into_canvas().accelerated().build()?; canvas.set_logical_size(CANVAS_WIDTH, CANVAS_HEIGHT)?; let controller_subsystem = sdl_context.game_controller()?;