use rlvgl_core::packed_font::PackedFont;
use rlvgl_platform::blit::Surface;
use rlvgl_platform::effect::CrawlParams;
use super::text::TextCrawl;
use crate::motion::background::StarField;
use crate::motion::direction::Direction;
use crate::motion::jumbo::JumboBuffer;
use crate::motion::rate::SubPixelRate;
pub const DISCO_PRESET_PIXELS_PER_SEC: u32 = 40;
pub const DISCO_PRESET_LINE_SPACING: (u32, u32) = (2, 1);
pub const DISCO_PRESET_TOP_WIDTH: u16 = 360;
pub const DISCO_PRESET_BOTTOM_WIDTH: u16 = 600;
pub type StarCrawl<'buf> = TextCrawl<'buf, SubPixelRate, StarField>;
#[allow(clippy::too_many_arguments)]
pub fn disco_demo_preset<'buf>(
font: &'static PackedFont,
lines: &'static [&'static str],
frame_hz: u32,
jumbo_bg: JumboBuffer<'buf>,
text_src: Surface<'buf>,
scanline: &'buf mut [u8],
) -> StarCrawl<'buf> {
let mut crawl = TextCrawl::new(
Direction::Up,
SubPixelRate::new(DISCO_PRESET_PIXELS_PER_SEC, frame_hz),
StarField::default(),
font,
0xFFFF_D700,
lines,
jumbo_bg,
text_src,
scanline,
);
let (num, den) = DISCO_PRESET_LINE_SPACING;
let spacing = (font.height as u32 * num / den.max(1)) as u16;
crawl.line_spacing = spacing.max(1);
crawl.background_scroll_divisor = 3;
crawl.perspective_top_width = DISCO_PRESET_TOP_WIDTH;
crawl.perspective_bottom_width = DISCO_PRESET_BOTTOM_WIDTH;
crawl
}
#[allow(clippy::too_many_arguments)]
pub fn build_star_crawl<'buf>(
params: &CrawlParams,
font: &'static PackedFont,
lines: &'static [&'static str],
jumbo_bg: JumboBuffer<'buf>,
text_src: Surface<'buf>,
scanline: &'buf mut [u8],
) -> StarCrawl<'buf> {
let mut crawl = TextCrawl::new(
Direction::Up,
SubPixelRate::new(params.pixels_per_sec, params.frame_hz.max(1)),
StarField::default(),
font,
params.text_color_argb,
lines,
jumbo_bg,
text_src,
scanline,
);
crawl.line_spacing = params.line_spacing_px.max(1);
crawl.background_scroll_divisor = params.background_scroll_divisor.max(1);
crawl.perspective_top_width = params.perspective_top_width;
crawl.perspective_bottom_width = params.perspective_bottom_width;
crawl
}