diff --git a/Cargo.lock b/Cargo.lock index 6aed3f9..46be7b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -496,6 +496,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "concat-string" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7439becb5fafc780b6f4de382b1a7a3e70234afe783854a4702ee8adbb838609" + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -804,6 +810,17 @@ dependencies = [ "web-sys", ] +[[package]] +name = "find-winsdk" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8cbf17b871570c1f8612b763bac3e86290602bcf5dc3c5ce657e0e1e9071d9e" +dependencies = [ + "serde", + "serde_derive", + "winreg", +] + [[package]] name = "flate2" version = "1.0.30" @@ -1407,7 +1424,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -2077,6 +2094,7 @@ dependencies = [ "tinyfiledialogs", "toml", "tracker", + "windres", "winit", ] @@ -3382,6 +3400,16 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "windres" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82115619221b2b66001a39088b8059d171b1f9005a00d6a10c6e8a71a30a4cdc" +dependencies = [ + "concat-string", + "find-winsdk", +] + [[package]] name = "winit" version = "0.29.15" @@ -3449,6 +3477,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a27a759395c1195c4cc5cda607ef6f8f6498f64e78f7900f5de0a127a424704a" +dependencies = [ + "serde", + "winapi", +] + [[package]] name = "x11-clipboard" version = "0.9.2" diff --git a/Cargo.toml b/Cargo.toml index 14ac301..6367591 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,12 @@ edition = "2021" name = "radar-g" version = "0.1.0" +build = "build.rs" + +[[bin]] +name = "radar-gi" +path = "src/main.rs" +windows = true [dependencies] @@ -50,6 +56,9 @@ femtovg = "0.9.2" rust-embed = "8.5.0" tempfile = "3.12.0" +[target.'cfg(windows)'.build-dependencies] +windres = "0.2.2" + [features] default = ["sdf_font"] diff --git a/app-icon.rc b/app-icon.rc new file mode 100644 index 0000000..fd1821a --- /dev/null +++ b/app-icon.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON "resources/radar-gi.ico" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..06fc41e --- /dev/null +++ b/build.rs @@ -0,0 +1,16 @@ +extern crate windres; + +#[cfg(windows)] +use windres::Build; + +fn main() { + #[cfg(windows)] + { + println!("cargo:rustc-link-arg=/SUBSYSTEM:WINDOWS"); + println!("cargo:rustc-link-arg=/ENTRY:mainCRTStartup"); + + Build::new().compile("app-icon.rc").unwrap(); + } + + +} diff --git a/check_sdf.py b/check_sdf.py deleted file mode 100644 index 4847199..0000000 --- a/check_sdf.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - -with open("resources/Dokdo-Regular/0-255.pbf","rb") as f: - - pass \ No newline at end of file diff --git a/resources/radar-gi.ico b/resources/radar-gi.ico new file mode 100644 index 0000000..36ba014 Binary files /dev/null and b/resources/radar-gi.ico differ diff --git a/radar.toml b/resources/radar.toml similarity index 100% rename from radar.toml rename to resources/radar.toml diff --git a/src/main.rs b/src/main.rs index 25c6810..f9e93c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,7 @@ pub struct Asset; use once_cell::sync::Lazy; static SETTING: Lazy = Lazy::new(|| setting::Setting::new()); + fn main() { env_logger::init(); run(move |gl, helper| App::new(gl, helper).unwrap()); diff --git a/src/setting.rs b/src/setting.rs index 55d4ed3..2b14a8a 100644 --- a/src/setting.rs +++ b/src/setting.rs @@ -1,6 +1,6 @@ -use crate::errors::*; +use crate::{errors::*, Asset}; use serde::{Deserialize, Serialize}; -use std::fs::{read, read_to_string}; +use std::{env, fs::{read, read_to_string}, io::Write}; use crate::{data_loader::DataType, utils::color_tools::hex_to_rgba_u8}; @@ -45,7 +45,20 @@ impl Setting { impl Setting { pub fn new() -> Self { - let file = read_to_string("./radar.toml").unwrap(); + let current_dir = env::current_dir().unwrap(); + + if !current_dir.join("radar.toml").exists() { + + let default_config = Asset::get("radar.toml").unwrap(); + + let mut folder_path = current_dir.clone(); + let mut conf = folder_path.join("radar.toml"); + + let mut file = std::fs::File::create_new(&conf).unwrap(); + file.write_all(&default_config.data).unwrap(); + } + + let file = read_to_string(current_dir.join("radar.toml")).unwrap(); let setting: Setting = toml::from_str(&file).unwrap(); setting } diff --git a/src/support/supporter.rs b/src/support/supporter.rs index f2f97c3..6a04c46 100644 --- a/src/support/supporter.rs +++ b/src/support/supporter.rs @@ -223,7 +223,7 @@ fn imgui_init(window: &Window) -> (WinitPlatform, imgui::Context) { config: Some(font_conf), }]); - println!("imgui global scale: {}", winit_platform.hidpi_factor()); + // println!("imgui global scale: {}", winit_platform.hidpi_factor()); imgui_context.io_mut().font_global_scale = (1.0 / 1.5) as f32; diff --git a/test.png b/test.png deleted file mode 100644 index 1612f62..0000000 Binary files a/test.png and /dev/null differ diff --git a/test.wgsl b/test.wgsl new file mode 100644 index 0000000..5501740 --- /dev/null +++ b/test.wgsl @@ -0,0 +1,138 @@ +use '@use-gpu/wgsl/fragment/sdf-2d'::{ SDF, getUVScale, getBoxSDF, getBorderBoxSDF, getRoundedBorderBoxSDF }; +use '@use-gpu/wgsl/use/color'::{ premultiply }; + +@optional @link fn getTexture(uv: vec2) -> vec4 { return vec4(0.0, 0.0, 0.0, 0.0); }; +@optional @link fn getMask(color: vec4, uv: vec4, st: vec4) -> vec4 { return color; } + +@export fn getSDFRectangleFragment( + uv: vec2, + textureUV: vec2, + textureST: vec2, + clipUV: vec4, + sdfUV: vec2, + sdfConfig: vec4, + repeat: i32, + mode: i32, + shape: vec4, + radius: vec4, + border: vec4, + stroke: vec4, + fill: vec4, +) -> vec4 { + var fillColor = fill; + var strokeColor = stroke; + + var scale = getUVScale(sdfUV); + + var sdf: SDF; + var texture = getTexture(textureUV); + var sdfRaw = 0.0; + var mark = 0.0; + + if (mode == -1 || mode == -2) { + // SDF Glyph + let sdfRadius = sdfConfig.x; + var expand = border.x; + var bleed = border.y; + + var d = (texture.a - 0.75) * sdfRadius; + var s = (d + expand / sdfConfig.y) / scale + 0.5 + bleed; + sdf = SDF(s, s); + + if (mode == -2) { + fillColor = vec4(texture.rgb, fillColor.a); + } + } + else { + // Textured box + if (texture.a > 0.0) { + if ( + ((repeat == 0 || repeat == 1) && (textureUV.x < 0.0 || textureUV.x > 1.0)) || + ((repeat == 0 || repeat == 2) && (textureUV.y < 0.0 || textureUV.y > 1.0)) + ) { + texture.a = 0.0; + } + + if (texture.a > 0.0) { + fillColor = vec4( + premultiply(fillColor).rgb * (1.0 - texture.a) + texture.rgb, + mix(fillColor.a, 1.0, texture.a), + ); + } + } + else { + fillColor = premultiply(fillColor); + } + + // Get appropriate SDF + if (mode == 0) { + if (fillColor.a <= 0.0) { discard; } + sdf = getBoxSDF(shape.xy, uv, scale); + } + else if (mode == 1) { sdf = getBorderBoxSDF(shape.xy, border, uv, scale); } + else { sdf = getRoundedBorderBoxSDF(shape.xy, border, radius, uv, scale); } + + // Bleed by 0.5px to account for filter radius + let bleed = 0.5; + sdf.outer += bleed; + sdf.inner += bleed; + } + + // Clipping this late because sooner than this causes issues in edge pixels + if (uv.x < clipUV.x || uv.y < clipUV.y || uv.x > clipUV.z || uv.y > clipUV.w) { discard; } + + var mask = clamp(sdf.outer, 0.0, 1.0); + + // SDF iso-contours + if (DEBUG_SDF) { + var s = 4.0; + var b = 0.0; + if (mode == -1 || mode == -2) { + s = 1.0; + b = 6.0; + } + + let o = (sdf.outer - 0.5) * scale / s; + var m = (max(0.0, o + 0.5 + b) % 1.0) - 0.5; + if (o < -b) { m = 1.0 + (o + b - 1.0); } + mark = clamp(1.0 - abs(m / scale) * s, 0.0, 1.0); + + if ((border.x != border.y) || (border.z != border.w) || (border.x != border.z)) { + let o = (sdf.inner - 0.5) * scale / s; + let m = ((o + 0.5 + b) % 1.0) - 0.5; + let mark2 = 1.0 * clamp(1.0 - abs(m / scale) * s, 0.0, 1.0); + + if (sdf.inner > -0.5) { mark = mark2 + mark * 0.5; } + } + } + if (mask == 0.0 && mark == 0.0) { discard; } + + // Blend stroke/fill + var color = fillColor; + if (sdf.outer != sdf.inner) { + // If less than 1px border, render 1px with opacity instead + var reduce = 1.0; + if (sdf.outer - sdf.inner < 1.0) { + reduce = sdf.outer - sdf.inner; + sdf.inner = sdf.outer - 1.0; + } + color = mix(fillColor, strokeColor, reduce * clamp(1.0 - sdf.inner, 0.0, 1.0)); + } + + if (HAS_MASK) { + color = getMask(color, vec4(textureUV, 0.0, 0.0), vec4(textureST, 0.0, 0.0)); + } + + if (!HAS_ALPHA_TO_COVERAGE) { + color = vec4((color.rgb + mark) * color.a * mask, color.a * mask + mark); + } + else { + color = vec4(color.rgb + mark, color.a * mask); + } + + if (DEBUG_SDF) { + return vec4(mix(color.rgb, vec3(mark), 0.5), color.a); + } + + return color; +}