mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 14:39:45 -05:00
draw shapes with zoom (rust)
This commit is contained in:
parent
26ab39a45d
commit
80bbfe7a6f
3 changed files with 12 additions and 13 deletions
|
@ -273,17 +273,17 @@
|
|||
(when (render-v2/is-enabled?)
|
||||
;; set up canvas and first render
|
||||
(mf/with-effect
|
||||
[canvas-ref vbox' @canvas-set? base-objects]
|
||||
[canvas-ref vbox' @canvas-set? base-objects zoom]
|
||||
(let [canvas (mf/ref-val canvas-ref)]
|
||||
(when (and (some? vbox') (not @canvas-set?))
|
||||
(p/then (render-v2/init) (fn []
|
||||
(render-v2/set-canvas canvas vbox' base-objects)
|
||||
(render-v2/set-canvas canvas vbox' zoom base-objects)
|
||||
(swap! canvas-set? true))))))
|
||||
;; redraw when vbox or shapes change
|
||||
(mf/with-effect
|
||||
[vbox' base-objects canvas-set?]
|
||||
[vbox' base-objects canvas-set? zoom]
|
||||
(when @canvas-set?
|
||||
(render-v2/draw-canvas vbox' base-objects))))
|
||||
(render-v2/draw-canvas vbox' zoom base-objects))))
|
||||
|
||||
(hooks/setup-dom-events zoom disable-paste in-viewport? workspace-read-only? drawing-tool drawing-path?)
|
||||
(hooks/setup-viewport-size vport viewport-ref)
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
(render-v2-rs/init)))
|
||||
|
||||
(defn set-canvas
|
||||
[canvas vbox base-objects]
|
||||
[canvas vbox zoom base-objects]
|
||||
(cond
|
||||
;; CPP
|
||||
(contains? cf/flags :render-v2-cpp)
|
||||
|
@ -35,10 +35,10 @@
|
|||
|
||||
;; Rust
|
||||
(contains? cf/flags :render-v2-rs)
|
||||
(render-v2-rs/set-canvas canvas vbox base-objects)))
|
||||
(render-v2-rs/set-canvas canvas vbox zoom base-objects)))
|
||||
|
||||
(defn draw-canvas [vbox base-objects]
|
||||
(defn draw-canvas [vbox zoom base-objects]
|
||||
(cond
|
||||
;; Rust
|
||||
(contains? cf/flags :render-v2-rs)
|
||||
(render-v2-rs/draw-canvas vbox base-objects)))
|
||||
(render-v2-rs/draw-canvas vbox zoom base-objects)))
|
||||
|
|
|
@ -16,13 +16,14 @@
|
|||
(defonce ^:dynamic internal-module #js {})
|
||||
(defonce ^:dynamic gpu-state #js {})
|
||||
|
||||
(defn draw-canvas [vbox objects]
|
||||
(defn draw-canvas [vbox zoom objects]
|
||||
(let [draw-rect (gobj/get ^js internal-module "_draw_rect")
|
||||
translate (gobj/get ^js internal-module "_translate")
|
||||
reset-canvas (gobj/get ^js internal-module "_reset_canvas")
|
||||
scale (gobj/get ^js internal-module "_scale")]
|
||||
|
||||
(reset-canvas gpu-state)
|
||||
(scale gpu-state zoom zoom)
|
||||
(translate gpu-state (- (:x vbox)) (- (:y vbox)))
|
||||
(doseq [shape (vals objects)]
|
||||
(let [sr (:selrect shape)]
|
||||
|
@ -30,7 +31,7 @@
|
|||
(draw-rect gpu-state (:x1 sr) (:y1 sr) (:x2 sr) (:y2 sr))))))
|
||||
|
||||
(defn set-canvas
|
||||
[canvas vbox objects]
|
||||
[canvas vbox zoom objects]
|
||||
(let [gl (gobj/get ^js internal-module "GL")
|
||||
context (.getContext canvas "webgl2" {"antialias" true
|
||||
"depth" true
|
||||
|
@ -50,13 +51,11 @@
|
|||
(set! (.-height canvas) (.-clientHeight canvas))
|
||||
(set! gpu-state state)
|
||||
|
||||
(draw-canvas vbox objects)
|
||||
(draw-canvas vbox zoom objects)
|
||||
|
||||
#_(draw_rect state 100 100 500 500)
|
||||
(println "set-canvas ok" (.-width canvas) (.-height canvas))))
|
||||
|
||||
|
||||
|
||||
(defn on-init
|
||||
[module']
|
||||
(set! internal-module module')
|
||||
|
|
Loading…
Add table
Reference in a new issue