Skip to content

Commit

Permalink
Fix Window Icon
Browse files Browse the repository at this point in the history
  • Loading branch information
dawnlarsson committed Feb 26, 2021
1 parent b5cd4ac commit d4e644d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions amethyst_window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ log = "0.4"
serde = { version = "1", features = ["derive"] }
thread_profiler = { version = "0.3", optional = true }
winit = { version = "0.24", git = "https://github.com/rust-windowing/winit", rev = "38fccebe1fbc4226c75d6180e5317bd93c024951", features = ["serde"] }
image = "0.23.13"

[dev-dependencies]
amethyst = { path = "../", version = "0.15.3", features = ["renderer"] }
Expand Down
51 changes: 33 additions & 18 deletions amethyst_window/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use winit::{
};
#[cfg(target_os = "windows")]
use {
log::error,
winit::platform::windows::{IconExtWindows, WindowBuilderExtWindows},
winit::platform::windows::{WindowBuilderExtWindows},
};

use image;

use crate::monitor::{MonitorIdent, MonitorsAccess};

/// Configuration for a window display.
Expand Down Expand Up @@ -153,27 +154,41 @@ impl DisplayConfig {
{
builder = builder.with_drag_and_drop(false);
}

builder.window = attrs;
builder = builder.with_window_icon(self.loaded_icon);

#[cfg(target_os = "windows")]
if let Some(icon) = self.icon {
let icon = match Icon::from_path(&icon, None) {
Ok(x) => Some(x),
Err(e) => {
error!(
"Failed to load window icon from `{}`: {}",
icon.display(),
e
);

None
if self.loaded_icon.is_some() {
builder = builder.with_window_icon(self.loaded_icon);
}else{
match self.icon {
Some(icon_path) => {

let (icon_rgba, icon_width, icon_height) = {
let image = image::open(icon_path).expect("Failed to open icon path");
use image::{GenericImageView, Pixel};
let (width, height) = image.dimensions();
let mut rgba = Vec::with_capacity((width * height) as usize * 4);
for (_, _, pixel) in image.pixels() {
rgba.extend_from_slice(&pixel.to_rgba().channels());
}
(rgba, width, height)
};
match Icon::from_rgba(icon_rgba, icon_width, icon_height) {
Ok(res) => { builder = builder.with_window_icon(Option::from( res )); }

Err(e) => {
// TODO: Fallback amethyst icon.
}
};
()
}
};

builder = builder.with_window_icon(icon);
None => {
// TODO: Fallback amethyst icon.
}
}
}


builder
}
}

0 comments on commit d4e644d

Please sign in to comment.