summaryrefslogtreecommitdiff
path: root/WebInterface/wasm/asm-paint/src/site.rs
diff options
context:
space:
mode:
Diffstat (limited to 'WebInterface/wasm/asm-paint/src/site.rs')
-rw-r--r--WebInterface/wasm/asm-paint/src/site.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/WebInterface/wasm/asm-paint/src/site.rs b/WebInterface/wasm/asm-paint/src/site.rs
new file mode 100644
index 0000000..4ae0237
--- /dev/null
+++ b/WebInterface/wasm/asm-paint/src/site.rs
@@ -0,0 +1,28 @@
+use web_sys;
+use crate::canvas::Canvas;
+
+pub struct Site {
+ window: web_sys::Window,
+ document: web_sys::Document,
+}
+
+impl Site {
+ pub fn from_current() -> Option<Self> {
+ let window = web_sys::window()
+ .or_else(|| {error!("unable to query window"); None})?;
+ let document = window.document()
+ .or_else(|| {error!("unable to query document"); None})?;
+ Some(Self {
+ window, document
+ })
+ }
+
+ pub fn create_canvas(&self) -> Option<Canvas> {
+ debug!("gain canvas element");
+ let element = self.document.get_element_by_id("canvas")
+ .or_else(|| {error!("could not gain canvas element"); None})?;
+ Canvas::new(element)
+ .or_else(|| {error!("could not create a webgl2 canvas.
+ Your browser doesn't seem to support webgl2"); None})
+ }
+}