push
This commit is contained in:
parent
e8f3b2bc47
commit
27764ef23a
40
Cargo.lock
generated
40
Cargo.lock
generated
@ -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"
|
||||
|
||||
@ -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"]
|
||||
|
||||
|
||||
1
app-icon.rc
Normal file
1
app-icon.rc
Normal file
@ -0,0 +1 @@
|
||||
IDI_ICON1 ICON "resources/radar-gi.ico"
|
||||
16
build.rs
Normal file
16
build.rs
Normal file
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
import os
|
||||
|
||||
with open("resources/Dokdo-Regular/0-255.pbf","rb") as f:
|
||||
|
||||
pass
|
||||
BIN
resources/radar-gi.ico
Normal file
BIN
resources/radar-gi.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 100 KiB |
@ -25,6 +25,7 @@ pub struct Asset;
|
||||
use once_cell::sync::Lazy;
|
||||
static SETTING: Lazy<setting::Setting> = Lazy::new(|| setting::Setting::new());
|
||||
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
run(move |gl, helper| App::new(gl, helper).unwrap());
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
138
test.wgsl
Normal file
138
test.wgsl
Normal file
@ -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<f32>) -> vec4<f32> { return vec4<f32>(0.0, 0.0, 0.0, 0.0); };
|
||||
@optional @link fn getMask(color: vec4<f32>, uv: vec4<f32>, st: vec4<f32>) -> vec4<f32> { return color; }
|
||||
|
||||
@export fn getSDFRectangleFragment(
|
||||
uv: vec2<f32>,
|
||||
textureUV: vec2<f32>,
|
||||
textureST: vec2<f32>,
|
||||
clipUV: vec4<f32>,
|
||||
sdfUV: vec2<f32>,
|
||||
sdfConfig: vec4<f32>,
|
||||
repeat: i32,
|
||||
mode: i32,
|
||||
shape: vec4<f32>,
|
||||
radius: vec4<f32>,
|
||||
border: vec4<f32>,
|
||||
stroke: vec4<f32>,
|
||||
fill: vec4<f32>,
|
||||
) -> vec4<f32> {
|
||||
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<f32>(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<f32>(
|
||||
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<f32>(textureUV, 0.0, 0.0), vec4<f32>(textureST, 0.0, 0.0));
|
||||
}
|
||||
|
||||
if (!HAS_ALPHA_TO_COVERAGE) {
|
||||
color = vec4<f32>((color.rgb + mark) * color.a * mask, color.a * mask + mark);
|
||||
}
|
||||
else {
|
||||
color = vec4<f32>(color.rgb + mark, color.a * mask);
|
||||
}
|
||||
|
||||
if (DEBUG_SDF) {
|
||||
return vec4<f32>(mix(color.rgb, vec3<f32>(mark), 0.5), color.a);
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user