Skip to content

Commit

Permalink
Merge pull request #49 from thetawavegame/window-icon
Browse files Browse the repository at this point in the history
Set Window Icon
  • Loading branch information
cdsupina authored May 5, 2023
2 parents fda4229 + 831d4b8 commit 2e72587
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ strum_macros = "0.24.3"
console_error_panic_hook = "0.1.7"
bevy_kira_audio = { version = "0.15.0", features = ["mp3", "wav"] }
bevy_editor_pls = "0.4.0"
winit = "0.28.4"
image = "0.24.6"

# optimize dev packages as we don't need them in debug version
[profile.dev.package."*"]
Expand Down
Binary file added assets/texture/window_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions src/options/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use crate::game::GameParametersResource;
use bevy::{
prelude::*,
window::{PrimaryWindow, WindowMode},
winit::WinitWindows,
};
use serde::Deserialize;
use winit::window::Icon;

/// Display settings of the window
#[derive(Deserialize)]
Expand Down Expand Up @@ -82,3 +84,27 @@ pub fn toggle_zoom_system(
}
}
}

// set the window icon
pub fn set_window_icon(
windows: NonSend<WinitWindows>,
window_query: Query<Entity, With<PrimaryWindow>>,
) {
let window = windows
.get_window(window_query.get_single().unwrap())
.unwrap();

// set icon using image crate
let (icon_rgba, icon_width, icon_height) = {
let image = image::open("assets/texture/window_icon.png")
.expect("Failed to open icon path")
.into_rgba8();
let (width, height) = image.dimensions();
let rgba = image.into_raw();
(rgba, width, height)
};

let icon = Icon::from_rgba(icon_rgba, icon_width, icon_height).unwrap();

window.set_window_icon(Some(icon));
}
6 changes: 5 additions & 1 deletion src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ mod display;

use crate::states;

pub use self::display::{toggle_fullscreen_system, toggle_zoom_system, DisplayConfig};
pub use self::display::{
set_window_icon, toggle_fullscreen_system, toggle_zoom_system, DisplayConfig,
};

pub struct OptionsPlugin;

impl Plugin for OptionsPlugin {
fn build(&self, app: &mut App) {
app.add_startup_systems((set_window_icon,));

app.add_system(toggle_fullscreen_system);

app.add_systems((toggle_zoom_system,).in_set(OnUpdate(states::AppStates::Game)));
Expand Down

0 comments on commit 2e72587

Please sign in to comment.