From 7cdf168020f00afd012c70d136d0af123b7efa30 Mon Sep 17 00:00:00 2001 From: Joshua Simmons Date: Sun, 19 Oct 2025 20:24:58 +0200 Subject: [PATCH] shark: Tone down the 2d drawing --- title/shark/src/fonts.rs | 1 + title/shark/src/main.rs | 121 +++++++++------------------------------ 2 files changed, 29 insertions(+), 93 deletions(-) diff --git a/title/shark/src/fonts.rs b/title/shark/src/fonts.rs index 3674f61..23e5b47 100644 --- a/title/shark/src/fonts.rs +++ b/title/shark/src/fonts.rs @@ -1,6 +1,7 @@ use narcissus_font::{Font, FontCollection}; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[allow(unused)] pub enum FontFamily { NotoSansJapanese, RobotoRegular, diff --git a/title/shark/src/main.rs b/title/shark/src/main.rs index 281f992..12a1e8a 100644 --- a/title/shark/src/main.rs +++ b/title/shark/src/main.rs @@ -17,7 +17,7 @@ use narcissus_gpu::{ ColorSpace, ImageFormat, ImageUsageFlags, PresentMode, SwapchainConfigurator, SwapchainImage, ThreadToken, create_device, }; -use narcissus_maths::{Vec2, sin_cos_pi_f32, vec2}; +use narcissus_maths::{Vec2, vec2}; mod draw; mod fonts; @@ -44,6 +44,7 @@ struct UiState<'a> { draw_cmds: Vec, } +#[allow(unused)] impl<'a> UiState<'a> { fn new(fonts: &'a Fonts<'a>) -> Self { let glyph_cache = GlyphCache::new(fonts, GLYPH_CACHE_SIZE, GLYPH_CACHE_SIZE, 1); @@ -143,6 +144,7 @@ impl<'a> UiState<'a> { y: f32, font_family: FontFamily, font_size_px: f32, + color: u32, args: std::fmt::Arguments, ) -> f32 { let scissor_index = self.scissor_stack.last().copied().unwrap_or(0); @@ -182,7 +184,7 @@ impl<'a> UiState<'a> { self.draw_cmds.push(Draw2dCmd::glyph( scissor_index, touched_glyph_index, - microshades::GRAY_RGBA8[4].rotate_right(8), + color, vec2(x, y), )); @@ -280,8 +282,6 @@ pub fn main() { } let mut swapchain_configurator = Configurator(); - let mut draw_duration = Duration::ZERO; - 'main: loop { let frame = gpu.begin_frame(); { @@ -374,102 +374,39 @@ pub fn main() { { let width = width as f32; - let height = height as f32; - - let (s, c) = sin_cos_pi_f32(game_state.time * 0.1); - - let w = width / 5.0; - let h = height / 5.0; - let x = width / 2.0 + w * s; - let y = height / 2.0 + w * c; - ui_state.push_scissor(vec2(x - w, y - h), vec2(x + w, y + h), true); - for _ in 0..200 { - ui_state.rect( - 0.0, 0.0, width, height, 0.0, [0.0; 4], 0x10101010, 0x10101010, - ); - } - ui_state.pop_scissor(); - - ui_state.push_scissor(vec2(x - w, y - h), vec2(x + w, y + h), true); - - let mut y = 8.0 * ui_state.scale; - for i in 0..224 { - if i & 1 == 0 { - ui_state.push_fullscreen_scissor(); - } - let vertical_advance = ui_state.text_fmt( - 5.0, - y, - FontFamily::NotoSansJapanese, - 16.0 + s * 8.0, - format_args!( - "お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████" - ), - ); - y += vertical_advance; - if i & 1 == 0 { - ui_state.pop_scissor(); - } - } + let font_size_px = 20.0; - ui_state.pop_scissor(); + let font = ui_state.fonts.font(FontFamily::NotoSansJapanese); + let font_size_px_scaled = font_size_px * ui_state.scale; + let font_scale = font.scale_for_size_px(font_size_px_scaled); - for i in 0..500 { - let (s, c) = sin_cos_pi_f32(game_state.time * 0.1 + i as f32 * 0.01); + let y = font.ascent() * font_scale; + let h = (font.ascent() - font.descent()) * font_scale; - let x = width / 2.0 + w * s; - let y = height / 2.0 + w * c; - ui_state.rect( - x - 200.0, - y - 200.0, - 400.0, - 400.0, - 50.0, - [100.0, 50.0, 25.0, 0.0], - 0x33333333, - (microshades::BLUE_RGBA8[4] >> 8) | 0xff00_0000, - ); - } + ui_state.rect(0.0, 0.0, width, h, 0.0, [0.0; 4], 0x0, 0x40000000); - for i in 0..50 { - let (s, c) = sin_cos_pi_f32(game_state.time * 0.1 + i as f32 * 0.04); + ui_state.text_fmt( + 10.0, + y, + FontFamily::NotoSansJapanese, + font_size_px, + 0xffffffff, + format_args!("tick: {:?}", tick_duration), + ); - let x = width / 2.0 + w * 0.5 * s; - let y = height / 2.0 + w * 0.5 * c; + for i in 1..=3 { ui_state.rect( - x - 200.0, - y - 200.0, - 400.0, - 400.0, - 10.0, - [10.0, 10.0, 10.0, 10.0], - 0xffff0000, - 0x0, + width - font_size_px_scaled * i as f32, + 0.0, + font_size_px_scaled * 0.75, + font_size_px_scaled * 0.75, + 4.0 * ui_state.scale, + [5.0 * ui_state.scale; 4], + microshades::GREEN_RGBA8[3].rotate_right(8), + microshades::GRAY_RGBA8[0].rotate_right(8), ); } - - let x = 10.0 * ui_state.scale; - let mut y = 20.0 * ui_state.scale; - for i in 0..10 { - if i & 1 != 0 { - y += ui_state.text_fmt( - x, - y, - FontFamily::RobotoRegular, - 20.0, - format_args!("this tick: {:?}", tick_duration), - ); - } else { - y += ui_state.text_fmt( - x, - y, - FontFamily::NotoSansJapanese, - 20.0, - format_args!("last draw: {:?}", draw_duration), - ); - } - } } draw_state.draw( @@ -481,8 +418,6 @@ pub fn main() { height, swapchain_image, ); - - draw_duration = Instant::now() - draw_start; } gpu.end_frame(frame); -- 2.51.1