From d727f6e769ae6f3210a57f32f6c198469efaa9b8 Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Sat, 25 May 2019 22:44:04 +0200 Subject: Run with lighttpd and remove deploy.py --- WebInterface/wasm/asm-paint/deploy | 4 ---- 1 file changed, 4 deletions(-) delete mode 100755 WebInterface/wasm/asm-paint/deploy (limited to 'WebInterface/wasm/asm-paint/deploy') diff --git a/WebInterface/wasm/asm-paint/deploy b/WebInterface/wasm/asm-paint/deploy deleted file mode 100755 index 9f7f823..0000000 --- a/WebInterface/wasm/asm-paint/deploy +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -./build.sh -./deploy.py -- cgit v1.2.3-70-g09d2 From 12dcfc7320b7fd2b9e72f34e7411a6632cc3e4e0 Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Sun, 26 May 2019 18:04:40 +0200 Subject: Create a canvas --- WebInterface/wasm/asm-paint/deploy | 2 ++ WebInterface/wasm/asm-paint/index.html | 10 +++++++++ WebInterface/wasm/asm-paint/src/app.rs | 2 ++ WebInterface/wasm/asm-paint/src/canvas.rs | 27 ++++++++++++++++++++++++ WebInterface/wasm/asm-paint/src/client_logger.rs | 18 +++++++++++++--- WebInterface/wasm/asm-paint/src/lib.rs | 1 + WebInterface/wasm/asm-paint/src/site.rs | 9 ++++++++ 7 files changed, 66 insertions(+), 3 deletions(-) create mode 100755 WebInterface/wasm/asm-paint/deploy create mode 100644 WebInterface/wasm/asm-paint/src/canvas.rs (limited to 'WebInterface/wasm/asm-paint/deploy') diff --git a/WebInterface/wasm/asm-paint/deploy b/WebInterface/wasm/asm-paint/deploy new file mode 100755 index 0000000..13d1d0a --- /dev/null +++ b/WebInterface/wasm/asm-paint/deploy @@ -0,0 +1,2 @@ +#!/bin/sh +lighttpd -f ./lighttpd.config diff --git a/WebInterface/wasm/asm-paint/index.html b/WebInterface/wasm/asm-paint/index.html index 631122d..5a221e3 100644 --- a/WebInterface/wasm/asm-paint/index.html +++ b/WebInterface/wasm/asm-paint/index.html @@ -4,6 +4,16 @@ Scribblio + diff --git a/WebInterface/wasm/asm-paint/src/app.rs b/WebInterface/wasm/asm-paint/src/app.rs index d5d0e45..003a2a1 100644 --- a/WebInterface/wasm/asm-paint/src/app.rs +++ b/WebInterface/wasm/asm-paint/src/app.rs @@ -12,5 +12,7 @@ impl App { } pub fn run(&self) { + let canvas = self.site.create_canvas().unwrap(); + canvas.render(); } } diff --git a/WebInterface/wasm/asm-paint/src/canvas.rs b/WebInterface/wasm/asm-paint/src/canvas.rs new file mode 100644 index 0000000..a1ef415 --- /dev/null +++ b/WebInterface/wasm/asm-paint/src/canvas.rs @@ -0,0 +1,27 @@ +use web_sys; +use web_sys::{WebGlProgram, WebGlRenderingContext, WebGlShader}; +use wasm_bindgen::JsCast; + +pub struct Canvas { + element: web_sys::HtmlCanvasElement, + ctx: WebGlRenderingContext, +} + +impl Canvas { + pub fn new(element: web_sys::Element) -> Option { + let element: web_sys::HtmlCanvasElement = + element.dyn_into::() + .ok()?; + debug!("create webgl2 context"); + error!("'{:#?}'", element.get_context("webgl2").ok()??.dyn_into::()); + let ctx = element.get_context("webgl2").ok()?? + .dyn_into::().ok()?; + Some(Self { + element, ctx + }) + } + + pub fn render(&self) { + info!("rich kidd"); + } +} diff --git a/WebInterface/wasm/asm-paint/src/client_logger.rs b/WebInterface/wasm/asm-paint/src/client_logger.rs index a8765c6..f71918f 100644 --- a/WebInterface/wasm/asm-paint/src/client_logger.rs +++ b/WebInterface/wasm/asm-paint/src/client_logger.rs @@ -2,12 +2,24 @@ use wasm_bindgen::prelude::*; #[wasm_bindgen] extern "C" { - #[wasm_bindgen(js_namespace=console, js_name=log)] - fn __console_log_colored2(f: &str, c1: &str, c2: &str); + #[wasm_bindgen(js_namespace=console, js_name=debug)] + fn __console_debug_colored2(f: &str, c1: &str, c2: &str); + #[wasm_bindgen(js_namespace=console, js_name=info)] + fn __console_info_colored2(f: &str, c1: &str, c2: &str); + #[wasm_bindgen(js_namespace=console, js_name=warn)] + fn __console_warn_colored2(f: &str, c1: &str, c2: &str); + #[wasm_bindgen(js_namespace=console, js_name=error)] + fn __console_error_colored2(f: &str, c1: &str, c2: &str); } fn log(rec: &log::Record) { - __console_log_colored2(&format!("{}", rec.args()), + let log_fn = match rec.level() { + log::Level::Trace | log::Level::Debug => __console_debug_colored2, + log::Level::Info => __console_info_colored2, + log::Level::Warn => __console_warn_colored2, + log::Level::Error => __console_error_colored2, + }; + log_fn(&format!("{}", rec.args()), &format!("color: {}", match rec.level() { log::Level::Trace => "violet", log::Level::Debug => "blue", diff --git a/WebInterface/wasm/asm-paint/src/lib.rs b/WebInterface/wasm/asm-paint/src/lib.rs index 037e8e9..8b0ee8f 100644 --- a/WebInterface/wasm/asm-paint/src/lib.rs +++ b/WebInterface/wasm/asm-paint/src/lib.rs @@ -1,4 +1,5 @@ mod client_logger; +mod canvas; mod site; mod app; diff --git a/WebInterface/wasm/asm-paint/src/site.rs b/WebInterface/wasm/asm-paint/src/site.rs index 740cb90..47afd19 100644 --- a/WebInterface/wasm/asm-paint/src/site.rs +++ b/WebInterface/wasm/asm-paint/src/site.rs @@ -1,4 +1,5 @@ use web_sys; +use crate::canvas::Canvas; pub struct Site { window: web_sys::Window, @@ -15,4 +16,12 @@ impl Site { window, document }) } + + pub fn create_canvas(&self) -> Option { + 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"); None}) + } } -- cgit v1.2.3-70-g09d2