Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc committed Nov 18, 2024
1 parent 6799cfa commit fa50676
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 deletions.
10 changes: 5 additions & 5 deletions src/renderer/attribute/impl/clock.cljs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns renderer.attribute.impl.clock
"https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#clock-value")

(def units
{:ms 0.001
:s 1
:m 60
:h 3600})
#_(def units
{:ms 0.001
:s 1
:m 60
:h 3600})
38 changes: 19 additions & 19 deletions src/renderer/handle/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
[renderer.utils.bounds :as bounds :refer [Bounds]]
[renderer.utils.pointer :as pointer]))

(defn circle
[el & children]
(let [{:keys [x y id]} el
zoom @(rf/subscribe [::document.s/zoom])
clicked-element @(rf/subscribe [::app.s/clicked-element])
pointer-handler #(pointer/event-handler! % el)]
(into [:circle {:key id
:cx x
:cy y
:stroke theme.db/accent
:stroke-width (/ 1 zoom)
:fill (if (= (:key clicked-element) id)
theme.db/accent
theme.db/accent-inverted)
:r (/ 4 zoom)
:cursor "default"
:on-pointer-up pointer-handler
:on-pointer-down pointer-handler
:on-pointer-move pointer-handler}] children)))
#_(defn circle
[el & children]
(let [{:keys [x y id]} el
zoom @(rf/subscribe [::document.s/zoom])
clicked-element @(rf/subscribe [::app.s/clicked-element])
pointer-handler #(pointer/event-handler! % el)]
(into [:circle {:key id
:cx x
:cy y
:stroke theme.db/accent
:stroke-width (/ 1 zoom)
:fill (if (= (:key clicked-element) id)
theme.db/accent
theme.db/accent-inverted)
:r (/ 4 zoom)
:cursor "default"
:on-pointer-up pointer-handler
:on-pointer-down pointer-handler
:on-pointer-move pointer-handler}] children)))

(defn square
[el & children]
Expand Down
18 changes: 13 additions & 5 deletions src/renderer/tool/impl/base/transform.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[renderer.element.handlers :as element.h]
[renderer.element.hierarchy :as element.hierarchy]
[renderer.element.subs :as-alias element.s]
[renderer.handle.db :refer [Handle]]
[renderer.handle.views :as handle.v]
[renderer.history.handlers :as history.h]
[renderer.ruler.db :refer [Orientation]]
Expand Down Expand Up @@ -189,10 +190,17 @@
:bottom-right [[x y] [x1 y1]]
:bottom-left [[(- x) y] [x2 y1]])))

(m/=> scale [:-> App Vec2D map? App])
(def ScaleOptions
[:map
[:ratio-locked boolean?]
[:in-place boolean?]
[:recursive boolean?]])

(m/=> scale [:-> App Vec2D ScaleOptions App])
(defn scale
[db offset {:keys [ratio-locked in-place recursive]}]
(let [handle (-> db :clicked-element :id)
[db offset options]
(let [{:keys [ratio-locked in-place recursive]} options
handle (-> db :clicked-element :id)
bounds (element.h/bounds db)
[offset pivot-point] (delta->offset-with-pivot-point handle offset bounds)
pivot-point (if in-place (bounds/center bounds) pivot-point)
Expand All @@ -202,10 +210,10 @@
ratio (cond-> ratio ratio-locked (lock-ratio handle))
;; TODO: Handle negative ratio, and position on recursive scale.
ratio (mapv #(max % 0.01) ratio)]
(-> db
(assoc :pivot-point pivot-point)
(-> (assoc db :pivot-point pivot-point)
(element.h/scale ratio pivot-point recursive))))

(m/=> selectable? [:-> [:or Element Handle nil?] boolean?])
(defn selectable?
[clicked-element]
(and clicked-element
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/utils/system.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
(defonce mac?
(= platform "darwin"))

(defonce windows?
(= platform "win32"))
#_(defonce windows?
(= platform "win32"))

(defonce linux?
(= platform "linux"))
#_(defonce linux?
(= platform "linux"))

0 comments on commit fa50676

Please sign in to comment.