Public Vars

Back

ratio? (clj)

(source)

function

(ratio? n)
Returns true if n is a Ratio

Examples

re-path/studio
(ns renderer.tools.page
  (:require
   [clojure.core.matrix :as mat]
   [clojure.string :as str]
   [goog.string :as g.str]
   [re-frame.core :as rf]
   [reagent.dom.server :as dom]
   [renderer.element.handlers :as element.h]
   [renderer.tools.base :as tools]
   [renderer.utils.pointer :as pointer]
   [renderer.utils.units :as units]))

(defmethod tools/drag :page
  [{:keys [adjusted-pointer-pos adjusted-pointer-offset] :as db} e]
  (let [[offset-x offset-y] adjusted-pointer-offset
        [pos-x pos-y] adjusted-pointer-pos
        lock-ratio? (contains? (:modifiers e) :ctrl)
        width (abs (- pos-x offset-x))
        height (abs (- pos-y offset-y))
        attrs {:x (min pos-x offset-x)
               :y (min pos-y offset-y)
               :width (if lock-ratio? (min width height) width)
               :height (if lock-ratio? (min width height) height)
               :fill "#ffffff"}]
    (element.h/set-temp db {:tag :page
                            :type :element
                            :name "Page"
                            :attrs attrs})))
re-path/studio
(ns renderer.tools.ellipse
  "https://www.w3.org/TR/SVG/shapes.html#EllipseElement"
  (:require
   [clojure.core.matrix :as mat]
   [clojure.string :as str]
   [re-frame.core :as rf]
   [renderer.attribute.hierarchy :as hierarchy]
   [renderer.element.handlers :as element.h]
   [renderer.overlay :as overlay]
   [renderer.tools.base :as tools]
   [renderer.utils.units :as units]
   [renderer.utils.bounds :as bounds]))

(defmethod tools/drag :ellipse
  [{:keys [adjusted-pointer-offset active-document adjusted-pointer-pos] :as db} e]
  (let [{:keys [stroke fill]} (get-in db [:documents active-document])
        [offset-x offset-y] adjusted-pointer-offset
        [pos-x pos-y] adjusted-pointer-pos
        lock-ratio? (contains? (:modifiers e) :ctrl)
        rx (abs (- pos-x offset-x))
        ry (abs (- pos-y offset-y))
        attrs {:cx offset-x
               :cy offset-y
               :fill fill
               :stroke stroke
               :rx (if lock-ratio? (min rx ry) rx)
               :ry (if lock-ratio? (min rx ry) ry)}]
    (element.h/set-temp db {:type :element
                            :tag :ellipse
                            :attrs attrs})))