From 1f8fe2dc4c63c8c46a0a08b91558c6a047292d9f Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 3 Oct 2024 08:00:32 +0200 Subject: [PATCH] WIP: basic color support --- frontend/render_v2/rs/src/main.rs | 6 +++++- frontend/src/app/render_v2/rs.cljs | 6 ++++-- frontend/src/app/render_v2/rs.js | 32 +++++++++++++++--------------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/frontend/render_v2/rs/src/main.rs b/frontend/render_v2/rs/src/main.rs index 50e49e990..03c0c3ce4 100644 --- a/frontend/render_v2/rs/src/main.rs +++ b/frontend/render_v2/rs/src/main.rs @@ -116,11 +116,15 @@ pub unsafe extern "C" fn draw_rect( top: i32, right: i32, bottom: i32, + r: u8, + g: u8, + b: u8, ) { let state = unsafe { state.as_mut() }.expect("got an invalid state pointer"); let rect = Rect::new(left as f32, top as f32, right as f32, bottom as f32); + let color = Color::from_rgb(r, g, b); - render_rect(&mut state.surface, rect, Color::BLACK); + render_rect(&mut state.surface, rect, color); state .gpu_state .context diff --git a/frontend/src/app/render_v2/rs.cljs b/frontend/src/app/render_v2/rs.cljs index 1f06a71d9..bfa20d6dd 100644 --- a/frontend/src/app/render_v2/rs.cljs +++ b/frontend/src/app/render_v2/rs.cljs @@ -7,6 +7,7 @@ (ns app.render-v2.rs (:require ["./rs.js" :as render-v2] + [app.common.colors :as cc] [app.config :as cf] [beicon.v2.core :as rx] [goog.object :as gobj] @@ -28,9 +29,10 @@ (scale gpu-state zoom zoom) (translate gpu-state (- (:x vbox)) (- (:y vbox))) (doseq [shape supported-shapes] - (let [sr (:selrect shape)] + (let [sr (:selrect shape) + [r g b] (cc/hex->rgb (-> shape :fills first :fill-color))] ;; (js/console.log (clj->js shape)) - (draw-rect gpu-state (:x1 sr) (:y1 sr) (:x2 sr) (:y2 sr))))))) + (draw-rect gpu-state (:x1 sr) (:y1 sr) (:x2 sr) (:y2 sr) r g b)))))) (defn set-canvas [canvas vbox zoom objects] diff --git a/frontend/src/app/render_v2/rs.js b/frontend/src/app/render_v2/rs.js index 38bfc19f1..019d22e53 100644 --- a/frontend/src/app/render_v2/rs.js +++ b/frontend/src/app/render_v2/rs.js @@ -8563,7 +8563,7 @@ var wasmExports = createWasm(); var ___wasm_call_ctors = createExportWrapper('__wasm_call_ctors', 0); var _init = Module['_init'] = createExportWrapper('init', 2); var _resize_surface = Module['_resize_surface'] = createExportWrapper('resize_surface', 3); -var _draw_rect = Module['_draw_rect'] = createExportWrapper('draw_rect', 5); +var _draw_rect = Module['_draw_rect'] = createExportWrapper('draw_rect', 8); var _translate = Module['_translate'] = createExportWrapper('translate', 3); var _scale = Module['_scale'] = createExportWrapper('scale', 3); var _reset_canvas = Module['_reset_canvas'] = createExportWrapper('reset_canvas', 1); @@ -8612,10 +8612,10 @@ var dynCall_iiiiij = Module['dynCall_iiiiij'] = createExportWrapper('dynCall_iii var dynCall_iiiiijj = Module['dynCall_iiiiijj'] = createExportWrapper('dynCall_iiiiijj', 9); var dynCall_iiiiiijj = Module['dynCall_iiiiiijj'] = createExportWrapper('dynCall_iiiiiijj', 10); -function invoke_iii(index,a1,a2) { +function invoke_vii(index,a1,a2) { var sp = stackSave(); try { - return getWasmTableEntry(index)(a1,a2); + getWasmTableEntry(index)(a1,a2); } catch(e) { stackRestore(sp); if (!(e instanceof EmscriptenEH)) throw e; @@ -8634,17 +8634,6 @@ function invoke_ii(index,a1) { } } -function invoke_vii(index,a1,a2) { - var sp = stackSave(); - try { - getWasmTableEntry(index)(a1,a2); - } catch(e) { - stackRestore(sp); - if (!(e instanceof EmscriptenEH)) throw e; - _setThrew(1, 0); - } -} - function invoke_viii(index,a1,a2,a3) { var sp = stackSave(); try { @@ -8667,10 +8656,10 @@ function invoke_vi(index,a1) { } } -function invoke_iiii(index,a1,a2,a3) { +function invoke_iii(index,a1,a2) { var sp = stackSave(); try { - return getWasmTableEntry(index)(a1,a2,a3); + return getWasmTableEntry(index)(a1,a2); } catch(e) { stackRestore(sp); if (!(e instanceof EmscriptenEH)) throw e; @@ -8700,6 +8689,17 @@ function invoke_iiiiiii(index,a1,a2,a3,a4,a5,a6) { } } +function invoke_iiii(index,a1,a2,a3) { + var sp = stackSave(); + try { + return getWasmTableEntry(index)(a1,a2,a3); + } catch(e) { + stackRestore(sp); + if (!(e instanceof EmscriptenEH)) throw e; + _setThrew(1, 0); + } +} + function invoke_iiiii(index,a1,a2,a3,a4) { var sp = stackSave(); try {