From c4664ab7f93c0594300f497729c54c3c9f6ae7cf Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 1 Jun 2020 08:22:21 +0200 Subject: [PATCH 1/3] :tada: Custom cursors files --- frontend/resources/images/cursors/create-artboard.svg | 4 ++++ frontend/resources/images/cursors/create-ellipse.svg | 6 ++++++ frontend/resources/images/cursors/create-polygon.svg | 6 ++++++ frontend/resources/images/cursors/create-reclangle.svg | 6 ++++++ frontend/resources/images/cursors/create-shape.svg | 5 +++++ frontend/resources/images/cursors/duplicate.svg | 6 ++++++ frontend/resources/images/cursors/hand.svg | 1 + frontend/resources/images/cursors/move-pointer.svg | 5 +++++ frontend/resources/images/cursors/pen.svg | 8 ++++++++ frontend/resources/images/cursors/pencil.svg | 1 + frontend/resources/images/cursors/pointer-inner.svg | 5 +++++ frontend/resources/images/cursors/resize-alt.svg | 5 +++++ frontend/resources/images/cursors/resize-diagonal.svg | 5 +++++ frontend/resources/images/cursors/resize-h.svg | 1 + frontend/resources/images/cursors/rotate.svg | 6 ++++++ frontend/resources/images/cursors/text.svg | 1 + 16 files changed, 71 insertions(+) create mode 100644 frontend/resources/images/cursors/create-artboard.svg create mode 100644 frontend/resources/images/cursors/create-ellipse.svg create mode 100644 frontend/resources/images/cursors/create-polygon.svg create mode 100644 frontend/resources/images/cursors/create-reclangle.svg create mode 100644 frontend/resources/images/cursors/create-shape.svg create mode 100644 frontend/resources/images/cursors/duplicate.svg create mode 100644 frontend/resources/images/cursors/hand.svg create mode 100644 frontend/resources/images/cursors/move-pointer.svg create mode 100644 frontend/resources/images/cursors/pen.svg create mode 100644 frontend/resources/images/cursors/pencil.svg create mode 100644 frontend/resources/images/cursors/pointer-inner.svg create mode 100644 frontend/resources/images/cursors/resize-alt.svg create mode 100644 frontend/resources/images/cursors/resize-diagonal.svg create mode 100644 frontend/resources/images/cursors/resize-h.svg create mode 100644 frontend/resources/images/cursors/rotate.svg create mode 100644 frontend/resources/images/cursors/text.svg diff --git a/frontend/resources/images/cursors/create-artboard.svg b/frontend/resources/images/cursors/create-artboard.svg new file mode 100644 index 000000000..636becc5b --- /dev/null +++ b/frontend/resources/images/cursors/create-artboard.svg @@ -0,0 +1,4 @@ + + + + diff --git a/frontend/resources/images/cursors/create-ellipse.svg b/frontend/resources/images/cursors/create-ellipse.svg new file mode 100644 index 000000000..8be94f60d --- /dev/null +++ b/frontend/resources/images/cursors/create-ellipse.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/frontend/resources/images/cursors/create-polygon.svg b/frontend/resources/images/cursors/create-polygon.svg new file mode 100644 index 000000000..d3115e65f --- /dev/null +++ b/frontend/resources/images/cursors/create-polygon.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/frontend/resources/images/cursors/create-reclangle.svg b/frontend/resources/images/cursors/create-reclangle.svg new file mode 100644 index 000000000..aa40add04 --- /dev/null +++ b/frontend/resources/images/cursors/create-reclangle.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/frontend/resources/images/cursors/create-shape.svg b/frontend/resources/images/cursors/create-shape.svg new file mode 100644 index 000000000..9d0699e82 --- /dev/null +++ b/frontend/resources/images/cursors/create-shape.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/frontend/resources/images/cursors/duplicate.svg b/frontend/resources/images/cursors/duplicate.svg new file mode 100644 index 000000000..4938b2bfa --- /dev/null +++ b/frontend/resources/images/cursors/duplicate.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/frontend/resources/images/cursors/hand.svg b/frontend/resources/images/cursors/hand.svg new file mode 100644 index 000000000..2e935f3c5 --- /dev/null +++ b/frontend/resources/images/cursors/hand.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/resources/images/cursors/move-pointer.svg b/frontend/resources/images/cursors/move-pointer.svg new file mode 100644 index 000000000..1c8fa8d04 --- /dev/null +++ b/frontend/resources/images/cursors/move-pointer.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/frontend/resources/images/cursors/pen.svg b/frontend/resources/images/cursors/pen.svg new file mode 100644 index 000000000..a4ddc9a6f --- /dev/null +++ b/frontend/resources/images/cursors/pen.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/frontend/resources/images/cursors/pencil.svg b/frontend/resources/images/cursors/pencil.svg new file mode 100644 index 000000000..5cc93a9c4 --- /dev/null +++ b/frontend/resources/images/cursors/pencil.svg @@ -0,0 +1 @@ + diff --git a/frontend/resources/images/cursors/pointer-inner.svg b/frontend/resources/images/cursors/pointer-inner.svg new file mode 100644 index 000000000..f5239e09a --- /dev/null +++ b/frontend/resources/images/cursors/pointer-inner.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/frontend/resources/images/cursors/resize-alt.svg b/frontend/resources/images/cursors/resize-alt.svg new file mode 100644 index 000000000..9e712e862 --- /dev/null +++ b/frontend/resources/images/cursors/resize-alt.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/frontend/resources/images/cursors/resize-diagonal.svg b/frontend/resources/images/cursors/resize-diagonal.svg new file mode 100644 index 000000000..00ee0d028 --- /dev/null +++ b/frontend/resources/images/cursors/resize-diagonal.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/frontend/resources/images/cursors/resize-h.svg b/frontend/resources/images/cursors/resize-h.svg new file mode 100644 index 000000000..afda462b0 --- /dev/null +++ b/frontend/resources/images/cursors/resize-h.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/resources/images/cursors/rotate.svg b/frontend/resources/images/cursors/rotate.svg new file mode 100644 index 000000000..e075f4c27 --- /dev/null +++ b/frontend/resources/images/cursors/rotate.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/frontend/resources/images/cursors/text.svg b/frontend/resources/images/cursors/text.svg new file mode 100644 index 000000000..09860fd8b --- /dev/null +++ b/frontend/resources/images/cursors/text.svg @@ -0,0 +1 @@ + \ No newline at end of file From b3237524bd142a009ec83952eae857d5a89af1bf Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 1 Jun 2020 14:57:39 +0200 Subject: [PATCH 2/3] :tada: Adds infrastructure to add cursors --- frontend/deps.edn | 3 + .../main/partials/debug-icons-preview.scss | 12 ++- frontend/src/uxbox/main/ui.cljs | 8 +- frontend/src/uxbox/main/ui/cursors.clj | 75 +++++++++++++++++++ frontend/src/uxbox/main/ui/cursors.cljs | 61 +++++++++++++++ 5 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 frontend/src/uxbox/main/ui/cursors.clj create mode 100644 frontend/src/uxbox/main/ui/cursors.cljs diff --git a/frontend/deps.edn b/frontend/deps.edn index 55ea41dfb..eb597d0eb 100644 --- a/frontend/deps.edn +++ b/frontend/deps.edn @@ -33,6 +33,9 @@ thheller/shadow-cljs {:mvn/version "2.8.110"} + lambdaisland/uri {:mvn/version "1.3.45" + :exclusions [org.clojure/data.json]} + ;; i18n parsing carocad/parcera {:mvn/version "0.11.0"} org.antlr/antlr4-runtime {:mvn/version "4.7"}}} diff --git a/frontend/resources/styles/main/partials/debug-icons-preview.scss b/frontend/resources/styles/main/partials/debug-icons-preview.scss index ed8e7054d..5e56fc0a4 100644 --- a/frontend/resources/styles/main/partials/debug-icons-preview.scss +++ b/frontend/resources/styles/main/partials/debug-icons-preview.scss @@ -1,9 +1,14 @@ +.debug-preview { + max-height: 100vh; + display: flex; + flex-direction: column; + overflow: scroll; +} .debug-icons-preview { display: flex; flex-wrap: wrap; - overflow: scroll; - .icon-item { + .icon-item, .cursor-item { padding: 10px; display: flex; flex-direction: column; @@ -17,4 +22,7 @@ height: 100%; } } + .cursor-item { + height: auto; + } } diff --git a/frontend/src/uxbox/main/ui.cljs b/frontend/src/uxbox/main/ui.cljs index 84f30e87e..3c9b9b553 100644 --- a/frontend/src/uxbox/main/ui.cljs +++ b/frontend/src/uxbox/main/ui.cljs @@ -23,6 +23,7 @@ [uxbox.main.ui.auth :refer [auth verify-token]] [uxbox.main.ui.dashboard :refer [dashboard]] [uxbox.main.ui.icons :as i] + [uxbox.main.ui.cursors :as c] [uxbox.main.ui.messages :as msgs] [uxbox.main.ui.settings :as settings] [uxbox.main.ui.static :refer [not-found-page not-authorized-page]] @@ -106,7 +107,12 @@ :debug-icons-preview (when *assert* - [:& i/debug-icons-preview]) + [:div.debug-preview + [:h1 "Cursors"] + [:& c/debug-preview] + [:h1 "Icons"] + [:& i/debug-icons-preview] + ]) (:dashboard-search :dashboard-team diff --git a/frontend/src/uxbox/main/ui/cursors.clj b/frontend/src/uxbox/main/ui/cursors.clj new file mode 100644 index 000000000..8ef5e672e --- /dev/null +++ b/frontend/src/uxbox/main/ui/cursors.clj @@ -0,0 +1,75 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; This Source Code Form is "Incompatible With Secondary Licenses", as +;; defined by the Mozilla Public License, v. 2.0. +;; +;; Copyright (c) 2020 UXBOX Labs SL + +(ns uxbox.main.ui.cursors + (:import java.net.URLEncoder) + (:require [rumext.alpha] + [clojure.java.io :as io] + [lambdaisland.uri.normalize :as uri] + [cuerdas.core :as str])) + +(def cursor-folder "images/cursors") + +(def default-hotspot-x 12) +(def default-hotspot-y 12) +(def default-rotation 0) + +(defn parse-svg [svg-data] + (-> svg-data + ;; Remove the header + (str/replace #"(?i)<\?xml[^\?]*\?>", "") + + ;; Remove comments + (str/replace #"<\!\-\-(.*?(?=\-\->))\-\->" "") + + ;; Remofe end of line + (str/replace #"\r?\n|\r" " ") + + ;; Replace double quotes for single + (str/replace #"\"" "'") + + ;; Remove the svg root tag + (str/replace #"(?i)" "") + + ;; And the closing tag + (str/replace #"(?i)<\/svg>" "") + + ;; Remove some defs that can be redundant + (str/replace #"" "") + + ;; Unifies the spaces into single space + (str/replace #"\s+" " ") + + ;; Remove spaces at the beginning of the svg + (str/replace #"^\s+" "") + + ;; Remove spaces at the end + (str/replace #"\s+$" ""))) + +(defn encode-svg-cursor + [id rotation x y] + (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='24px' height='24px'~A%3E~A%3C/svg%3E\") ~A ~A, auto" + transform data x y)] + data)) + +(defmacro cursor-ref + ([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))) + +(defmacro cursor-fn + [id initial] + (let [cursor (encode-svg-cursor id "{{rotation}}" default-hotspot-x default-hotspot-y)] + `(fn [rot#] + (str/replace ~cursor "{{rotation}}" (+ ~initial rot#))))) diff --git a/frontend/src/uxbox/main/ui/cursors.cljs b/frontend/src/uxbox/main/ui/cursors.cljs new file mode 100644 index 000000000..4fd68072f --- /dev/null +++ b/frontend/src/uxbox/main/ui/cursors.cljs @@ -0,0 +1,61 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; This Source Code Form is "Incompatible With Secondary Licenses", as +;; defined by the Mozilla Public License, v. 2.0. +;; +;; Copyright (c) 2020 UXBOX Labs SL + +(ns uxbox.main.ui.cursors + (:require-macros [uxbox.main.ui.cursors :refer [cursor-ref + cursor-fn]]) + (:require [rumext.alpha :as mf] + [cuerdas.core :as str] + [uxbox.util.timers :as ts])) + +(def create-artboard (cursor-ref :create-artboard)) +(def create-ellipse (cursor-ref :create-ellipse)) +(def create-polygon (cursor-ref :create-polygon)) +(def create-rectangle (cursor-ref :create-reclangle)) +(def create-shape (cursor-ref :create-shape)) +(def duplicate (cursor-ref :duplicate 0 0 0)) +(def hand (cursor-ref :hand)) +(def move-pointer (cursor-ref :move-pointer)) +(def pencil (cursor-ref :pencil 0 0 24)) +(def pen (cursor-ref :pen 0 0 0)) +(def pointer-inner (cursor-ref :pointer-inner 0 0 0)) +(def resize-alt (cursor-ref :resize-alt)) + +#_(def resize-nesw (cursor-fn :resize-diagonal 90)) +#_(def resize-nwse (cursor-fn :resize-diagonal 0)) +(def resize-nesw (cursor-fn :resize-h 45)) +(def resize-nwse (cursor-fn :resize-h 135)) + +(def resize-ew (cursor-fn :resize-h 0)) +(def resize-ns (cursor-fn :resize-h 90)) + +(def rotate (cursor-fn :rotate 90)) +(def text (cursor-ref :text)) + +(mf/defc debug-preview + {::mf/wrap-props false} + [props] + (let [rotation (mf/use-state 0)] + (mf/use-effect (fn [] (ts/interval 100 #(reset! rotation inc)))) + + [:section.debug-icons-preview + (for [[key val] (sort-by first (ns-publics 'uxbox.main.ui.cursors))] + (when (not= key 'debug-icons-preview) + (let [value (deref val) + value (if (fn? value) (value @rotation) value)] + [:div.cursor-item {:key key} + [:div {:style {:width "100px" + :height "100px" + :background-image (-> value (str/replace #"(url\(.*\)).*" "$1")) + :background-size "cover" + :cursor value}}] + + [:span {:style {:white-space "nowrap" + :margin-right "1rem"}} (pr-str key)]])))])) + From bedd244f44768ebeecf34d2e439acba0be91104e Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 2 Jun 2020 10:44:32 +0200 Subject: [PATCH 3/3] :tada: New cursors in viewport --- .../styles/main/partials/workspace.scss | 9 ----- frontend/src/uxbox/main/data/workspace.cljs | 8 +++++ .../uxbox/main/data/workspace/transforms.cljs | 2 +- frontend/src/uxbox/main/ui/cursors.clj | 2 ++ frontend/src/uxbox/main/ui/cursors.cljs | 5 --- .../uxbox/main/ui/workspace/selection.cljs | 33 ++++++++++--------- .../main/ui/workspace/shapes/common.cljs | 1 + .../uxbox/main/ui/workspace/shapes/text.cljs | 2 ++ .../src/uxbox/main/ui/workspace/viewport.cljs | 20 +++++++++-- frontend/src/uxbox/worker/selection.cljs | 1 + 10 files changed, 49 insertions(+), 34 deletions(-) diff --git a/frontend/resources/styles/main/partials/workspace.scss b/frontend/resources/styles/main/partials/workspace.scss index 56494be88..39751a6be 100644 --- a/frontend/resources/styles/main/partials/workspace.scss +++ b/frontend/resources/styles/main/partials/workspace.scss @@ -145,15 +145,6 @@ g.controls { rect.main { pointer-events: none; } - circle.rotate { cursor: ns-resize; } // TODO - .top-left { cursor: nwse-resize; } - .bottom-right { cursor: nwse-resize; } - .top-right { cursor: nesw-resize; } - .bottom-left { cursor: nesw-resize; } - .top { cursor: ns-resize; } - .bottom { cursor: ns-resize; } - .left { cursor: ew-resize; } - .right { cursor: ew-resize; } } } diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index 4bc6885a3..20f5556e5 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -315,6 +315,14 @@ (reduce reduce-fn state groups-to-adjust))))) +(defn start-pan [state] + (-> state + (assoc-in [:workspace-local :panning] true))) + +(defn finish-pan [state] + (-> state + (update :workspace-local dissoc :panning))) + ;; --- Toggle layout flag diff --git a/frontend/src/uxbox/main/data/workspace/transforms.cljs b/frontend/src/uxbox/main/data/workspace/transforms.cljs index 4141c9026..42d093602 100644 --- a/frontend/src/uxbox/main/data/workspace/transforms.cljs +++ b/frontend/src/uxbox/main/data/workspace/transforms.cljs @@ -204,7 +204,7 @@ (rx/take-until stopper) (rx/map #(gpt/to-vec initial %)) (rx/map #(gpt/length %)) - (rx/filter #(> % 0.5)) + (rx/filter #(> % 1)) (rx/take 1) (rx/map #(start-move initial selected))))))) diff --git a/frontend/src/uxbox/main/ui/cursors.clj b/frontend/src/uxbox/main/ui/cursors.clj index 8ef5e672e..46270d37f 100644 --- a/frontend/src/uxbox/main/ui/cursors.clj +++ b/frontend/src/uxbox/main/ui/cursors.clj @@ -64,11 +64,13 @@ 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))) (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)] `(fn [rot#] diff --git a/frontend/src/uxbox/main/ui/cursors.cljs b/frontend/src/uxbox/main/ui/cursors.cljs index 4fd68072f..f02d31951 100644 --- a/frontend/src/uxbox/main/ui/cursors.cljs +++ b/frontend/src/uxbox/main/ui/cursors.cljs @@ -26,15 +26,10 @@ (def pen (cursor-ref :pen 0 0 0)) (def pointer-inner (cursor-ref :pointer-inner 0 0 0)) (def resize-alt (cursor-ref :resize-alt)) - -#_(def resize-nesw (cursor-fn :resize-diagonal 90)) -#_(def resize-nwse (cursor-fn :resize-diagonal 0)) (def resize-nesw (cursor-fn :resize-h 45)) (def resize-nwse (cursor-fn :resize-h 135)) - (def resize-ew (cursor-fn :resize-h 0)) (def resize-ns (cursor-fn :resize-h 90)) - (def rotate (cursor-fn :rotate 90)) (def text (cursor-ref :text)) diff --git a/frontend/src/uxbox/main/ui/workspace/selection.cljs b/frontend/src/uxbox/main/ui/workspace/selection.cljs index b0a41512c..645203487 100644 --- a/frontend/src/uxbox/main/ui/workspace/selection.cljs +++ b/frontend/src/uxbox/main/ui/workspace/selection.cljs @@ -19,6 +19,7 @@ [uxbox.main.refs :as refs] [uxbox.main.store :as st] [uxbox.main.streams :as ms] + [uxbox.main.ui.cursors :as cur] [uxbox.util.dom :as dom] [uxbox.util.object :as obj] [uxbox.common.geom.shapes :as geom] @@ -26,8 +27,6 @@ [uxbox.common.geom.matrix :as gmt] [uxbox.util.debug :refer [debug?]])) -(defn rotation-cursor [angle] - (str "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20px' height='20px' transform='rotate(" angle ")' viewBox='0 0 132.292 132.006'%3E%3Cpath d='M85.225 3.48c.034 4.989-.093 9.852-.533 14.78-29.218 5.971-54.975 27.9-63.682 56.683-1.51 2.923-1.431 7.632-3.617 9.546-5.825.472-11.544.5-17.393.45 11.047 15.332 20.241 32.328 32.296 46.725 5.632 1.855 7.155-5.529 10.066-8.533 8.12-12.425 17.252-24.318 24.269-37.482-6.25-.86-12.564-.88-18.857-1.057 5.068-17.605 19.763-31.81 37.091-37.122.181 6.402.206 12.825 1.065 19.184 15.838-9.05 30.899-19.617 45.601-30.257 2.985-4.77-3.574-7.681-6.592-9.791C111.753 17.676 98.475 8.889 85.23.046l-.005 3.435z'/%3E%3Cpath fill='%23fff' d='M92.478 23.995s-1.143.906-6.714 1.923c-29.356 5.924-54.352 30.23-59.717 59.973-.605 3.728-1.09 5.49-1.09 5.49l-11.483-.002s7.84 10.845 10.438 15.486c3.333 4.988 6.674 9.971 10.076 14.912a2266.92 2266.92 0 0019.723-29.326c-5.175-.16-10.35-.343-15.522-.572 3.584-27.315 26.742-50.186 53.91-54.096.306 5.297.472 10.628.631 15.91a2206.462 2206.462 0 0029.333-19.726c-9.75-6.7-19.63-13.524-29.483-20.12z'/%3E%3C/svg%3E\") 10 10, auto")) (def rotation-handler-size 25) (def resize-point-radius 4) @@ -115,7 +114,7 @@ :top-right 90 :bottom-right 180 :bottom-left 270)] - [:rect {:style {:cursor (rotation-cursor (+ rotation angle))} + [:rect {:style {:cursor (cur/rotate (+ rotation angle))} :x x :y y :width size @@ -124,7 +123,7 @@ :transform transform :on-mouse-down on-rotate}])) -(mf/defc resize-point-handler [{:keys [cx cy zoom position on-resize transform]}] +(mf/defc resize-point-handler [{:keys [cx cy zoom position on-resize transform rotation]}] (let [{cx' :x cy' :y} (gpt/transform (gpt/point cx cy) transform) rot-square (case position :top-left 0 @@ -132,34 +131,36 @@ :bottom-right 180 :bottom-left 270)] [:g.resize-handler - [:circle {:class (name position) - :r (/ resize-point-radius zoom) + [:circle {:r (/ resize-point-radius zoom) :style {:fillOpacity "1" :strokeWidth "1px" - :vectorEffect "non-scaling-stroke"} + :vectorEffect "non-scaling-stroke" + } :fill "#FFFFFF" :stroke "#1FDEA7" :cx cx' :cy cy'}] - [:rect {:class (name position) - :x cx + [:rect {:x cx :y cy :width (/ resize-point-rect-size zoom) :height (/ resize-point-rect-size zoom) :fill (if (debug? :resize-handler) "red" "transparent") :on-mouse-down on-resize + :style {:cursor (if (#{:top-left :bottom-right} position) + (cur/resize-nesw rotation) (cur/resize-nwse rotation))} :transform (gmt/multiply transform (gmt/rotate-matrix rot-square (gpt/point cx cy)))}] - [:circle {:class (name position) - :on-mouse-down on-resize + [:circle {:on-mouse-down on-resize :r (/ resize-point-circle-radius zoom) :fill (if (debug? :resize-handler) "red" "transparent") :cx cx' - :cy cy'}] + :cy cy' + :style {:cursor (if (#{:top-left :bottom-right} position) + (cur/resize-nesw rotation) (cur/resize-nwse rotation))}}] ])) -(mf/defc resize-side-handler [{:keys [x y length angle zoom position transform on-resize]}] +(mf/defc resize-side-handler [{:keys [x y length angle zoom position rotation transform on-resize]}] [:rect {:x (+ x (/ resize-point-rect-size zoom)) :y (- y (/ resize-side-height 2 zoom)) :width (max 0 (- length (/ (* resize-point-rect-size 2) zoom))) @@ -169,8 +170,8 @@ :on-mouse-down on-resize :style {:fill (if (debug? :resize-handler) "yellow" "transparent") :cursor (if (#{:left :right} position) - "ew-resize" - "ns-resize") }}]) + (cur/resize-ew rotation) + (cur/resize-ns rotation)) }}]) (mf/defc controls {::mf/wrap-props false} @@ -244,7 +245,7 @@ :on-mouse-down #(on-mouse-down % index) :fill "#ffffff" :stroke "#1FDEA7" - :style {:cursor "pointer"}}]))]))) + :style {:cursor cur/move-pointer}}]))]))) ;; TODO: add specs for clarity diff --git a/frontend/src/uxbox/main/ui/workspace/shapes/common.cljs b/frontend/src/uxbox/main/ui/workspace/shapes/common.cljs index 1385967e1..60b630f8e 100644 --- a/frontend/src/uxbox/main/ui/workspace/shapes/common.cljs +++ b/frontend/src/uxbox/main/ui/workspace/shapes/common.cljs @@ -48,6 +48,7 @@ (when-not (or (empty? selected) (kbd/shift? event)) (st/emit! dw/deselect-all)) (st/emit! (dw/select-shape id)))) + (st/emit! (dw/start-move-selected))))))) (defn on-context-menu diff --git a/frontend/src/uxbox/main/ui/workspace/shapes/text.cljs b/frontend/src/uxbox/main/ui/workspace/shapes/text.cljs index 77b9890e8..0e2478d33 100644 --- a/frontend/src/uxbox/main/ui/workspace/shapes/text.cljs +++ b/frontend/src/uxbox/main/ui/workspace/shapes/text.cljs @@ -18,6 +18,7 @@ [uxbox.main.data.workspace.texts :as dwt] [uxbox.main.refs :as refs] [uxbox.main.store :as st] + [uxbox.main.ui.cursors :as cur] [uxbox.main.ui.workspace.shapes.common :as common] [uxbox.main.ui.shapes.text :as text] [uxbox.main.ui.keyboard :as kbd] @@ -301,6 +302,7 @@ :spell-check "false" :on-focus on-focus :class "rich-text" + :style {:cursor cur/text} :render-element render-element :render-leaf render-text :on-mouse-up on-mouse-up diff --git a/frontend/src/uxbox/main/ui/workspace/viewport.cljs b/frontend/src/uxbox/main/ui/workspace/viewport.cljs index 370f31219..ae5b8f162 100644 --- a/frontend/src/uxbox/main/ui/workspace/viewport.cljs +++ b/frontend/src/uxbox/main/ui/workspace/viewport.cljs @@ -15,6 +15,7 @@ [potok.core :as ptk] [rumext.alpha :as mf] [uxbox.main.ui.icons :as i] + [uxbox.main.ui.cursors :as cur] [uxbox.common.data :as d] [uxbox.main.constants :as c] [uxbox.main.data.workspace :as dw] @@ -96,6 +97,7 @@ stream (->> ms/mouse-position-delta (rx/take-until stoper))] + (st/emit! dw/start-pan) (rx/subscribe stream (fn [delta] (let [vbox (.. ^js node -viewBox -baseVal) @@ -136,7 +138,8 @@ vbox edition tooltip - selected]} local + selected + panning]} local viewport-ref (mf/use-ref nil) last-position (mf/use-var nil) @@ -185,7 +188,8 @@ (st/emit! (ms/->MouseEvent :up ctrl? shift?)) (when (= 2 (.-which event)) - (st/emit! ::finish-positioning))))) + (st/emit! dw/finish-pan + ::finish-positioning))))) on-pointer-down (mf/use-callback @@ -251,7 +255,8 @@ :shift? shift? :ctrl? ctrl?}] (when (kbd/space? event) - (st/emit! ::finish-positioning)) + (st/emit! dw/finish-pan + ::finish-positioning)) (st/emit! (ms/->KeyboardEvent :up key ctrl? shift?))))) translate-point-to-viewport @@ -365,6 +370,15 @@ (:height vbox 0)]) :ref viewport-ref :class (when drawing-tool "drawing") + :style {:cursor (cond + panning cur/hand + (= drawing-tool :frame) cur/create-artboard + (= drawing-tool :rect) cur/create-rectangle + (= drawing-tool :circle) cur/create-ellipse + (= drawing-tool :path) cur/pen + (= drawing-tool :curve)cur/pencil + drawing-tool cur/create-shape + :else cur/pointer-inner)} :on-context-menu on-context-menu :on-click on-click :on-double-click on-double-click diff --git a/frontend/src/uxbox/worker/selection.cljs b/frontend/src/uxbox/worker/selection.cljs index 603d17b2d..9a285bf5a 100644 --- a/frontend/src/uxbox/worker/selection.cljs +++ b/frontend/src/uxbox/worker/selection.cljs @@ -71,3 +71,4 @@ [index {:keys [id x y width height] :as obj}] (let [rect #js {:x x :y y :width width :height height}] (qdt/insert index rect obj))) +