diff --git a/Cargo.lock b/Cargo.lock index dd225e6..26cc39d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -717,7 +717,6 @@ checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "dpi" version = "0.1.1" -source = "git+https://github.com/iced-rs/winit.git?rev=11414b6aa45699f038114e61b4ddf5102b2d3b4b#11414b6aa45699f038114e61b4ddf5102b2d3b4b" [[package]] name = "drm" @@ -965,6 +964,7 @@ dependencies = [ "futures-core", "futures-task", "futures-util", + "num_cpus", ] [[package]] @@ -1357,6 +1357,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + [[package]] name = "hermit-abi" version = "0.4.0" @@ -1372,7 +1378,6 @@ checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" [[package]] name = "iced" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "iced_core", "iced_debug", @@ -1389,7 +1394,6 @@ dependencies = [ [[package]] name = "iced_beacon" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "bincode", "futures", @@ -1404,7 +1408,6 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "bitflags 2.9.0", "bytes", @@ -1422,7 +1425,6 @@ dependencies = [ [[package]] name = "iced_debug" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "iced_beacon", "iced_core", @@ -1432,7 +1434,6 @@ dependencies = [ [[package]] name = "iced_devtools" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "iced_debug", "iced_program", @@ -1442,13 +1443,11 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "futures", "iced_core", "log", "rustc-hash 2.1.1", - "tokio", "wasm-bindgen-futures", "wasmtimer", ] @@ -1456,7 +1455,6 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "bitflags 2.9.0", "bytemuck", @@ -1476,7 +1474,6 @@ dependencies = [ [[package]] name = "iced_program" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "iced_graphics", "iced_runtime", @@ -1485,7 +1482,6 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -1497,7 +1493,6 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "bytes", "iced_core", @@ -1510,7 +1505,6 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "bytemuck", "cosmic-text", @@ -1542,7 +1536,6 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "bitflags 2.9.0", "bytemuck", @@ -1561,7 +1554,6 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "iced_renderer", "iced_runtime", @@ -1575,7 +1567,6 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.14.0-dev" -source = "git+https://github.com/iced-rs/iced.git?rev=388a419#388a419ed5c229aadbca57bb09b474b1475b1ef9" dependencies = [ "iced_debug", "iced_program", @@ -2236,6 +2227,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi 0.3.9", + "libc", +] + [[package]] name = "num_enum" version = "0.7.3" @@ -2620,7 +2621,7 @@ checksum = "a604568c3202727d1507653cb121dbd627a58684eb09a820fd746bee38b4442f" dependencies = [ "cfg-if", "concurrent-queue", - "hermit-abi", + "hermit-abi 0.4.0", "pin-project-lite", "rustix 0.38.44", "tracing", @@ -4417,7 +4418,6 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winit" version = "0.30.8" -source = "git+https://github.com/iced-rs/winit.git?rev=11414b6aa45699f038114e61b4ddf5102b2d3b4b#11414b6aa45699f038114e61b4ddf5102b2d3b4b" dependencies = [ "ahash", "android-activity", diff --git a/Cargo.toml b/Cargo.toml index 4ede84d..d4df189 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ #![feature(let_chains)] [package] name = "reversed-rooms-launcher" -version = "0.1.0" +version = "0.2.0" edition = "2024" [dependencies] directories = "6.0.0" -iced = { git = "https://github.com/iced-rs/iced.git", rev = "388a419", features = ["tokio", "tiny-skia", "wgpu", "image", "debug"], default-features = false } +iced = { git = "https://github.com/rabbydevs/iced.git", rev = "388a419", features = ["tokio", "tiny-skia", "wgpu", "image", "debug"], default-features = false } image = "0.25.6" serde = { version = "1.0.219", features = ["serde_derive"] } serde_json = "1.0.140" diff --git a/iced b/iced new file mode 160000 index 0000000..24ccb05 --- /dev/null +++ b/iced @@ -0,0 +1 @@ +Subproject commit 24ccb057b5b0750f2bcee7a4ef306260259ef94e diff --git a/iced_video_player/.envrc b/iced_video_player/.envrc deleted file mode 100644 index c79d6d7..0000000 --- a/iced_video_player/.envrc +++ /dev/null @@ -1 +0,0 @@ -use flake || use nix shell.nix diff --git a/iced_video_player/Cargo.toml b/iced_video_player/Cargo.toml index a8e3de9..63bd620 100644 --- a/iced_video_player/Cargo.toml +++ b/iced_video_player/Cargo.toml @@ -16,8 +16,8 @@ exclude = [ ] [dependencies] -iced = { git = "https://github.com/iced-rs/iced.git", rev = "388a419", features = ["tokio", "wgpu", "image", "advanced"], default-features = false } -iced_wgpu = { git = "https://github.com/iced-rs/iced.git", rev = "388a419" } +iced = { path = "https://github.com/rabbydevs/iced.git", features = ["thread-pool", "wgpu", "image", "advanced"], default-features = false } +iced_wgpu = { path = "https://github.com/rabbydevs/iced.git/wgpu" } gstreamer = "0.23.5" gstreamer-app = "0.23.5" # appsink gstreamer-base = "0.23.5" # basesrc diff --git a/iced_video_player/flake.lock b/iced_video_player/flake.lock deleted file mode 100644 index 672ed1d..0000000 --- a/iced_video_player/flake.lock +++ /dev/null @@ -1,98 +0,0 @@ -{ - "nodes": { - "devshell": { - "locked": { - "lastModified": 1629275356, - "narHash": "sha256-R17M69EKXP6q8/mNHaK53ECwjFo1pdF+XaJC9Qq8zjg=", - "owner": "numtide", - "repo": "devshell", - "rev": "26f25a12265f030917358a9632cd600b51af1d97", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, - "flakeCompat": { - "flake": false, - "locked": { - "lastModified": 1627913399, - "narHash": "sha256-hY8g6H2KFL8ownSiFeMOjwPC8P0ueXpCVEbxgda3pko=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "12c64ca55c1014cdc1b16ed5a804aa8576601ff2", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "nixCargoIntegration": { - "inputs": { - "devshell": "devshell", - "nixpkgs": [ - "nixpkgs" - ], - "rustOverlay": "rustOverlay" - }, - "locked": { - "lastModified": 1629871751, - "narHash": "sha256-QjnDg34ApcnjmXlNLnbHswT9OroCPY7Wip6r9Zkgkfo=", - "owner": "yusdacra", - "repo": "nix-cargo-integration", - "rev": "4f164ecad242537d5893426eef02c47c9e5ced59", - "type": "github" - }, - "original": { - "owner": "yusdacra", - "repo": "nix-cargo-integration", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1629618782, - "narHash": "sha256-2K8SSXu3alo/URI3MClGdDSns6Gb4ZaW4LET53UWyKk=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "870959c7fb3a42af1863bed9e1756086a74eb649", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "flakeCompat": "flakeCompat", - "nixCargoIntegration": "nixCargoIntegration", - "nixpkgs": "nixpkgs" - } - }, - "rustOverlay": { - "flake": false, - "locked": { - "lastModified": 1629857564, - "narHash": "sha256-dClWiHkbaCDaIl520Miri66UOA8OecWbaVTWJBajHyM=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "88848c36934318e16c86097f65dbf97a57968d81", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/iced_video_player/flake.nix b/iced_video_player/flake.nix deleted file mode 100644 index 07f4620..0000000 --- a/iced_video_player/flake.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ - inputs = { - flakeCompat = { - url = "github:edolstra/flake-compat"; - flake = false; - }; - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - nixCargoIntegration = { - url = "github:yusdacra/nix-cargo-integration"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - - outputs = inputs: - inputs.nixCargoIntegration.lib.makeOutputs { - root = ./.; - overrides = { - shell = common: prev: { - env = prev.env ++ [ - { - name = "GST_PLUGIN_PATH"; - value = "${common.pkgs.gst_all_1.gstreamer}:${common.pkgs.gst_all_1.gst-plugins-bad}:${common.pkgs.gst_all_1.gst-plugins-ugly}:${common.pkgs.gst_all_1.gst-plugins-good}:${common.pkgs.gst_all_1.gst-plugins-base}"; - } - ]; - }; - }; - }; -} diff --git a/iced_video_player/shell.nix b/iced_video_player/shell.nix deleted file mode 100644 index bd18cba..0000000 --- a/iced_video_player/shell.nix +++ /dev/null @@ -1,12 +0,0 @@ -# Flake's devShell for non-flake-enabled nix instances -(import - ( - let lock = builtins.fromJSON (builtins.readFile ./flake.lock); - in - fetchTarball { - url = - "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flakeCompat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flakeCompat.locked.narHash; - } - ) - { src = ./.; }).shellNix.default diff --git a/resources/wutheringwaves-bg.mp4 b/resources/wutheringwaves-bg.mp4 index 6ee8e79..690b94a 100644 Binary files a/resources/wutheringwaves-bg.mp4 and b/resources/wutheringwaves-bg.mp4 differ diff --git a/src/main.rs b/src/main.rs index ebf8c65..bc44c6e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,17 +4,27 @@ mod utils; use file_format::FileFormat; use ::image::{DynamicImage, ImageReader}; use iced::{ - alignment::Vertical::{Bottom, Top}, border, font::{self, Family, Stretch, Weight}, gradient, mouse::{self, Interaction}, wgpu::naga::back, widget::{button, center, column, container, image, mouse_area, opaque, row, stack, text, Column, Space}, window::{self, icon, Settings}, Alignment::Center, Color, Element, Font, Length, Point, Renderer, Size, Subscription, Task, Theme + alignment::Vertical::{Bottom, Top}, border, font::{self, Family, Stretch, Weight}, gradient, mouse::{self, Interaction}, wgpu::naga::back, widget::{button, center, column, container, image, mouse_area, opaque, row, stack, text, Column, Space}, window::{self, icon, Settings}, Alignment::Center, Color, Element, Font, Length::{self, Fill}, Point, Renderer, Size, Subscription, Task, Theme }; use iced_video_player::{Video, VideoPlayer}; use serde::{Deserialize, Serialize}; use strum::IntoEnumIterator; use strum_macros::EnumIter; -use utils::{img_utils::round_image, visual_helper::{get_game_background, get_game_icon, get_game_icon_handle}}; +use utils::{img_utils::round_image, visual_helper::{get_game_background, get_game_icon_dynamic_image, style_container}}; use std::{ collections::HashMap, env, fs::{self, create_dir_all, read_to_string}, io::{Cursor, Read, Write}, path::PathBuf, sync::Arc }; +trait InterfaceImage { + fn into_handle(&self) -> image::Handle; +} + +impl InterfaceImage for DynamicImage { + fn into_handle(&self) -> image::Handle { + image::Handle::from_rgba(self.width(), self.height(), self.to_rgba8().into_raw()) + } +} + #[derive(rust_embed::Embed)] #[folder = "resources"] struct Assets; @@ -61,8 +71,8 @@ pub fn main() -> iced::Result { enum PossibleGames { #[default] WutheringWaves, - ZenlessZoneZero, HonkaiStarRail, + ZenlessZoneZero, GenshinImpact, } @@ -75,7 +85,7 @@ enum Launcher { #[derive(Debug)] enum LauncherBackground { Video(Video), - Image(image::Handle), + Image(DynamicImage), } #[derive(Debug, Default)] @@ -85,7 +95,46 @@ struct State { installed_game_servers: Vec, db_software_installed: bool, background: Option, - icon_images: HashMap + icon_images: HashMap +} + +impl State { + fn get_background_element(&self) -> Element { + match self.background.as_ref().unwrap() { + LauncherBackground::Video(video) => VideoPlayer::new(video).into(), + LauncherBackground::Image(img) => image(image::Handle::from_rgba(img.width(), img.height(), img.to_rgba8().into_raw())).into(), + } + } + + fn get_game_icon_row(&self) -> Element { + container(row![ + self.create_game_icon(&PossibleGames::WutheringWaves), + self.create_game_icon(&PossibleGames::HonkaiStarRail), + self.create_game_icon(&PossibleGames::ZenlessZoneZero), + self.create_game_icon(&PossibleGames::GenshinImpact), + ] + .spacing(10) + ).align_x(Center).width(Length::Fill).into() + } + fn create_game_icon(&self, game: &PossibleGames) -> Element { + let icon = self.icon_images.get(game).unwrap(); + let img = if &self.selected_game == game { + image(icon.into_handle()) + .width(Length::Fixed(52.0)) + .height(Length::Fixed(68.0)) + } else { + image(icon.brighten(-85).blur(2.5).adjust_contrast(-15.0).into_handle()) + .width(Length::Fixed(48.0)) + .height(Length::Fixed(64.0)) + }; + + mouse_area( + img + ) + .on_press(Message::GameSelected(game.clone())) + .interaction(Interaction::Pointer) + .into() + } } #[derive(Debug, Default, Clone, Serialize, Deserialize)] @@ -168,29 +217,12 @@ impl State { // } } -fn rad(deg: f32) -> f32 { - deg * std::f32::consts::PI / 180.0 -} - -fn style_container(direction: f32, use_gradient: bool) -> container::Style { - let angle = rad(direction); - let gradient: Option = if use_gradient { - Some(gradient::Linear::new(angle) - .add_stop(0.0, Color::from_rgba8(0, 0, 0, 0.0)) - .add_stop(0.75, Color::from_rgba8(0, 0, 0, 0.75)).into()) - } else {None}; - container::Style { - text_color: Color::from_rgba8(255, 255, 255, 1.0).into(), - background: gradient, - ..container::Style::default() - } -} impl Launcher { fn boot() -> (Self, Task) { let launcher_bg = get_game_background(&State::default()); let mut icons = HashMap::new(); for game in PossibleGames::iter() { - let icon = get_game_icon_handle(&game); + let icon = get_game_icon_dynamic_image(&game); icons.insert(game, icon); } let final_state = State { @@ -220,7 +252,7 @@ impl Launcher { window::get_latest().and_then(move |id: window::Id| { window::drag(id) }) - }, + } Message::Close => { window::get_latest().and_then(move |id: window::Id| { window::close(id) @@ -245,35 +277,34 @@ impl Launcher { match self { Launcher::Loading => center(text("Loading...").size(50)).into(), Launcher::Loaded(state) => { - let game_selector = mouse_area(container( - row![ - get_game_icon(state, &PossibleGames::WutheringWaves), - get_game_icon(state, &PossibleGames::ZenlessZoneZero), - get_game_icon(state, &PossibleGames::HonkaiStarRail), - get_game_icon(state, &PossibleGames::GenshinImpact), - ] - .spacing(10), - ) - .padding(10) - .align_y(Top) - .align_x(Center) - .width(Length::Fill) - .style(move |_| style_container(0.0, true))) - .on_press(Message::DragStarted()) - .interaction(Interaction::Grab); + let top_bar = stack![ + mouse_area(container( + stack![ + row![ + text("Reversed Rooms").size(35).font(font).color(Color::from_rgb8(255, 255, 255)), + Space::new(Length::Fill, Length::Fixed(0.0)), + row![ + opaque(mouse_area(text("\u{E949}").font(Font::with_name("Segoe MDL2 Assets")).size(25)).on_release(Message::Minimize).interaction(Interaction::Pointer)), + opaque(mouse_area(text("\u{E106}").font(Font::with_name("Segoe MDL2 Assets")).size(25)).on_release(Message::Close).interaction(Interaction::Pointer)) + ].spacing(20) + ].align_y(Center).padding(4), + state.get_game_icon_row(), - let topbar = container( - row![ - text("Reversed Rooms").size(25).font(font), - Space::new(Length::Fill, Length::Fixed(0.0)), - row![ - opaque(mouse_area(text("\u{E949}").font(Font::with_name("Segoe MDL2 Assets")).size(25)).on_release(Message::Minimize).interaction(Interaction::Pointer)), - opaque(mouse_area(text("\u{E106}").font(Font::with_name("Segoe MDL2 Assets")).size(25)).on_release(Message::Close).interaction(Interaction::Pointer)) - ].spacing(20) - ]) - .width(Length::Fill) - .style(move |_| style_container(0.0, false)) - .padding(20); + ] + ) + .padding(5) + .align_y(Top) + .align_x(Center) + .width(Length::Fill) + .style(move |_| + container::Style { + text_color: Color::from_rgba8(255, 255, 255, 1.0).into(), + background: Some(Color::from_rgba8(0, 0, 0, 0.75).into()), + ..container::Style::default() + })) + .on_press(Message::DragStarted()) + .interaction(Interaction::Grab) + ]; let bottom_bar = container(row![ text("The quick brown fox jumped over the lazy dog.").size(25).font(font).align_y(Bottom), @@ -294,17 +325,13 @@ impl Launcher { .style(move |_theme| style_container(180.0, true)) .padding(20); - let user_area = column![topbar, Space::new(Length::Fill, Length::Fill), bottom_bar] + let user_area = column![top_bar, Space::new(Length::Fill, Length::Fill), bottom_bar] .width(Length::Fill) .height(Length::Fill); - let background = state.background.as_ref().unwrap(); - let bg_element: Element = match background { - LauncherBackground::Video(video) => VideoPlayer::new(video).into(), - LauncherBackground::Image(handle) => image(handle.clone()).into(), - }; + let bg_element: Element = state.get_background_element(); - stack![bg_element, game_selector, user_area].into() + stack![bg_element, user_area].into() } } } diff --git a/src/utils/img_utils.rs b/src/utils/img_utils.rs index 6c64cc3..96cec38 100644 --- a/src/utils/img_utils.rs +++ b/src/utils/img_utils.rs @@ -33,18 +33,12 @@ pub fn is_in_rounded_rect(x: u32, y: u32, width: u32, height: u32, radius: f32) x >= 0.0 && x < width && y >= 0.0 && y < height } -pub fn round_image(img_data: Cursor>) -> Result> { - let img = ImageReader::new(img_data) - .with_guessed_format() - .unwrap() - .decode() - .unwrap(); - +pub fn round_image(img: DynamicImage) -> Result> { let (width, height) = img.dimensions(); let mut rounded_img = ImageBuffer::new(width, height); - let radius = 50.0; + let radius = 10.0; for (x, y, pixel) in img.pixels() { if is_in_rounded_rect(x, y, width, height, radius) { diff --git a/src/utils/visual_helper.rs b/src/utils/visual_helper.rs index f40459d..74c5783 100644 --- a/src/utils/visual_helper.rs +++ b/src/utils/visual_helper.rs @@ -2,11 +2,11 @@ use std::{io::{Cursor, Write}, sync::Arc}; use file_format::FileFormat; use iced_video_player::Video; -use ::image::ImageReader; -use iced::{widget::{container, image}, Element, Length}; +use ::image::{DynamicImage, ImageReader}; +use iced::{gradient, widget::{container, image}, Color}; use tempfile::NamedTempFile; -use crate::{Assets, LauncherBackground, Message, PossibleGames, State}; +use crate::{Assets, LauncherBackground, PossibleGames, State}; use super::img_utils::round_image; @@ -41,11 +41,7 @@ pub fn get_game_background(state: &State) -> LauncherBackground { .unwrap() .decode() .unwrap(); - LauncherBackground::Image(image::Handle::from_rgba( - img.width(), - img.height(), - img.to_rgba8().into_raw() - )) + LauncherBackground::Image(img) } } else { @@ -53,7 +49,7 @@ pub fn get_game_background(state: &State) -> LauncherBackground { } } -pub fn get_game_icon_handle(game: &PossibleGames) -> image::Handle { +pub fn get_game_icon_dynamic_image(game: &PossibleGames) -> DynamicImage { let file_path: &str = match game { PossibleGames::WutheringWaves => "wutheringwaves-icon.png", PossibleGames::ZenlessZoneZero => "zenlesszonezero-icon.png", @@ -62,21 +58,35 @@ pub fn get_game_icon_handle(game: &PossibleGames) -> image::Handle { }; if let Some(img_file) = Assets::get(file_path) { let data_cursor = Cursor::new(img_file.data); - let img = round_image(data_cursor) - .unwrap() - .resize(126, 126, ::image::imageops::FilterType::Lanczos3); - image::Handle::from_rgba( - img.width(), - img.height(), - img.to_rgba8().into_raw() - ) + let img = ImageReader::new(data_cursor) + .with_guessed_format() + .unwrap() + .decode() + .unwrap() + .resize(128, 128, ::image::imageops::FilterType::Lanczos3); + + round_image(img) + .unwrap() } else { panic!("Missing icon for {:?}, path: {}", game, file_path) } } -pub fn get_game_icon<'a>(state: &'a State, game: &'a PossibleGames) -> Element<'a, Message> { - let handle = state.icon_images.get(game).unwrap(); - container(image(handle).content_fit(iced::ContentFit::Contain).height(Length::Fixed(64.0)).filter_method(image::FilterMethod::Linear)).into() +fn rad(deg: f32) -> f32 { + deg * std::f32::consts::PI / 180.0 +} + +pub fn style_container(direction: f32, use_gradient: bool) -> container::Style { + let angle = rad(direction); + let gradient: Option = if use_gradient { + Some(gradient::Linear::new(angle) + .add_stop(0.0, Color::from_rgba8(0, 0, 0, 0.0)) + .add_stop(0.75, Color::from_rgba8(0, 0, 0, 0.75)).into()) + } else {None}; + container::Style { + text_color: Color::from_rgba8(255, 255, 255, 1.0).into(), + background: gradient, + ..container::Style::default() + } } \ No newline at end of file diff --git a/winit b/winit new file mode 160000 index 0000000..61e07f0 --- /dev/null +++ b/winit @@ -0,0 +1 @@ +Subproject commit 61e07f0aa59f988dba5960e47011466d5aaa1870