Path create-edit workflow

This commit is contained in:
alonso.torres 2020-11-18 11:37:10 +01:00
parent 8db7078ce8
commit b1c786077b
18 changed files with 564 additions and 231 deletions

View file

@ -19,6 +19,7 @@
(def default-hotspot-x 12)
(def default-hotspot-y 12)
(def default-rotation 0)
(def default-height 20)
(defn parse-svg [svg-data]
(-> svg-data
@ -53,25 +54,27 @@
(str/replace #"\s+$" "")))
(defn encode-svg-cursor
[id rotation x y]
[id rotation x y height]
(let [svg-path (str cursor-folder "/" (name id) ".svg")
data (-> svg-path io/resource slurp parse-svg uri/percent-encode)
transform (if rotation (str " transform='rotate(" rotation ")'") "")
data (clojure.pprint/cl-format
nil
"url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' width='20px' height='20px'~A%3E~A%3C/svg%3E\") ~A ~A, auto"
transform data x y)]
"url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' width='20px' height='~Apx'~A%3E~A%3C/svg%3E\") ~A ~A, auto"
height transform data x y )]
data))
(defmacro cursor-ref
"Creates a static cursor given its name, rotation and x/y hotspot"
([id] (encode-svg-cursor id default-rotation default-hotspot-x default-hotspot-y))
([id rotation] (encode-svg-cursor id rotation default-hotspot-x default-hotspot-y))
([id rotation x y] (encode-svg-cursor id rotation x y)))
([id] (encode-svg-cursor id default-rotation default-hotspot-x default-hotspot-y default-height))
([id rotation] (encode-svg-cursor id rotation default-hotspot-x default-hotspot-y default-height))
([id rotation x y] (encode-svg-cursor id rotation x y default-height))
([id rotation x y height] (encode-svg-cursor id rotation x y height))
)
(defmacro cursor-fn
"Creates a dynamic cursor that can be rotated in runtime"
[id initial]
(let [cursor (encode-svg-cursor id "{{rotation}}" default-hotspot-x default-hotspot-y)]
(let [cursor (encode-svg-cursor id "{{rotation}}" default-hotspot-x default-hotspot-y default-height)]
`(fn [rot#]
(str/replace ~cursor "{{rotation}}" (+ ~initial rot#)))))