Combine tiger and splash screen

Always show the tiger, and include key bindings.
This commit is contained in:
Raph Levien 2023-04-28 17:13:37 -07:00
parent 152fa00843
commit 495229bf10

View file

@ -24,10 +24,15 @@ macro_rules! scene {
} }
pub fn test_scenes() -> SceneSet { pub fn test_scenes() -> SceneSet {
// For WASM below, must be mutable let splash_scene = ExampleScene {
#[allow(unused_mut)] config: SceneConfig {
let mut scenes = vec![ animated: false,
scene!(splash_screen), name: "splash_with_tiger".to_owned(),
},
function: Box::new(splash_with_tiger()),
};
let scenes = vec![
splash_scene,
scene!(funky_paths), scene!(funky_paths),
scene!(cardioid_and_friends), scene!(cardioid_and_friends),
scene!(animated_text: animated), scene!(animated_text: animated),
@ -37,14 +42,6 @@ pub fn test_scenes() -> SceneSet {
scene!(labyrinth), scene!(labyrinth),
scene!(base_color_test: animated), scene!(base_color_test: animated),
]; ];
#[cfg(any(target_arch = "wasm32", target_os = "android"))]
scenes.push(ExampleScene {
config: SceneConfig {
animated: false,
name: "included_tiger".to_owned(),
},
function: Box::new(included_tiger()),
});
SceneSet { scenes } SceneSet { scenes }
} }
@ -278,15 +275,6 @@ fn blend_grid(sb: &mut SceneBuilder, _: &mut SceneParams) {
} }
} }
#[cfg(any(target_arch = "wasm32", target_os = "android"))]
fn included_tiger() -> impl FnMut(&mut SceneBuilder, &mut SceneParams) {
let contents = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../assets/Ghostscript_Tiger.svg"
));
crate::svg::svg_function_of("Ghostscript Tiger".to_string(), move || contents)
}
// Support functions // Support functions
fn render_cardioid(sb: &mut SceneBuilder) { fn render_cardioid(sb: &mut SceneBuilder) {
@ -632,13 +620,14 @@ fn make_diamond(cx: f64, cy: f64) -> [PathEl; 5] {
fn splash_screen(sb: &mut SceneBuilder, params: &mut SceneParams) { fn splash_screen(sb: &mut SceneBuilder, params: &mut SceneParams) {
let strings = [ let strings = [
"Vello test", "Vello test",
"key bindings:",
" Arrow keys: switch scenes", " Arrow keys: switch scenes",
" Space: reset transform",
" S: toggle stats", " S: toggle stats",
" V: toggle vsync", " V: toggle vsync",
" Q, E: rotate", " Q, E: rotate",
" Space: reset transform",
]; ];
// Tweak to make it fit with tiger
let a = Affine::scale(0.12) * Affine::translate((-90.0, -50.0));
for (i, s) in strings.iter().enumerate() { for (i, s) in strings.iter().enumerate() {
let text_size = if i == 0 { 60.0 } else { 40.0 }; let text_size = if i == 0 { 60.0 } else { 40.0 };
params.text.add( params.text.add(
@ -646,8 +635,20 @@ fn splash_screen(sb: &mut SceneBuilder, params: &mut SceneParams) {
None, None,
text_size, text_size,
None, None,
Affine::translate((100.0, 100.0 + 60.0 * i as f64)), a * Affine::translate((100.0, 100.0 + 60.0 * i as f64)),
s, s,
); );
} }
} }
fn splash_with_tiger() -> impl FnMut(&mut SceneBuilder, &mut SceneParams) {
let contents = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../assets/Ghostscript_Tiger.svg"
));
let mut tiger = crate::svg::svg_function_of("Ghostscript Tiger".to_string(), move || contents);
move |sb, params| {
tiger(sb, params);
splash_screen(sb, params);
}
}