-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a new renderer for the web that renders to a canvas, which can then be easily attached anywhere in the DOM with any size. This should allow the web LiveSplit One to replace its React / HTML based renderer, bringing the rendering more in line with the native renderer, with features like arbitrary resizing and horizontal splits. Additionally this should improve the performance a lot and help remove a lot of the code from the web LiveSplit One.
- Loading branch information
Showing
22 changed files
with
1,186 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//! Provides a renderer for the web that renders into a canvas. The element can | ||
//! then be attached anywhere in the DOM with any desired positioning and size. | ||
//! | ||
use livesplit_core::{layout::LayoutState, rendering::web, settings::ImageCache}; | ||
use wasm_bindgen::prelude::*; | ||
use web_sys::Element; | ||
|
||
/// The web renderer renders into a canvas element. The element can then be | ||
/// attached anywhere in the DOM with any desired positioning and size. | ||
#[wasm_bindgen] | ||
pub struct CanvasRenderer { | ||
inner: web::Renderer, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl CanvasRenderer { | ||
/// Creates a new web renderer that renders into a canvas element. The | ||
/// element can then be attached anywhere in the DOM with any desired | ||
/// positioning and size. There are two CSS fonts that are used as the | ||
/// default fonts. They are called "timer" and "fira". Make sure they are | ||
/// fully loaded before creating the renderer as otherwise information about | ||
/// a fallback font is cached instead. | ||
#[allow(clippy::new_without_default)] | ||
pub fn new() -> CanvasRenderer { | ||
Self { | ||
inner: web::Renderer::new(), | ||
} | ||
} | ||
|
||
/// Returns the HTML element. This can be attached anywhere in the DOM with | ||
/// any desired positioning and size. | ||
pub fn element(&self) -> Element { | ||
self.inner.element().clone() | ||
} | ||
|
||
/// Renders the layout state into the canvas. The image cache is used to | ||
/// retrieve images that are used in the layout state. | ||
pub unsafe fn render(&mut self, state: usize, image_cache: usize) { | ||
let state = unsafe { core::mem::transmute::<usize, &LayoutState>(state) }; | ||
let image_cache = unsafe { core::mem::transmute::<usize, &ImageCache>(image_cache) }; | ||
self.inner.render(state, image_cache); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.