Partial fix to lock mode on resize.

And add more human readable identifiers to
shape resize handlers.
This commit is contained in:
Andrey Antukh 2016-05-28 12:45:31 +03:00
parent 17790256ec
commit 4693722f40
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
2 changed files with 51 additions and 54 deletions

View file

@ -63,50 +63,50 @@
:style {:stroke "#333" :fill "transparent" :stroke-opacity "1"}}] :style {:stroke "#333" :fill "transparent" :stroke-opacity "1"}}]
[:circle.top [:circle.top
(merge +circle-props+ (merge +circle-props+
{:on-mouse-up #(on-mouse-up 5 %) {:on-mouse-up #(on-mouse-up :top %)
:on-mouse-down #(on-mouse-down 5 %) :on-mouse-down #(on-mouse-down :top %)
:cx (+ x (/ width 2)) :cx (+ x (/ width 2))
:cy (- y 2)})] :cy (- y 2)})]
[:circle.right [:circle.right
(merge +circle-props+ (merge +circle-props+
{:on-mouse-up #(on-mouse-up 6 %) {:on-mouse-up #(on-mouse-up :right %)
:on-mouse-down #(on-mouse-down 6 %) :on-mouse-down #(on-mouse-down :right %)
:cy (+ y (/ height 2)) :cy (+ y (/ height 2))
:cx (+ x width 1)})] :cx (+ x width 1)})]
[:circle.bottom [:circle.bottom
(merge +circle-props+ (merge +circle-props+
{:on-mouse-up #(on-mouse-up 7 %) {:on-mouse-up #(on-mouse-up :bottom %)
:on-mouse-down #(on-mouse-down 7 %) :on-mouse-down #(on-mouse-down :bottom %)
:cx (+ x (/ width 2)) :cx (+ x (/ width 2))
:cy (+ y height 2)})] :cy (+ y height 2)})]
[:circle.left [:circle.left
(merge +circle-props+ (merge +circle-props+
{:on-mouse-up #(on-mouse-up 8 %) {:on-mouse-up #(on-mouse-up :left %)
:on-mouse-down #(on-mouse-down 8 %) :on-mouse-down #(on-mouse-down :left %)
:cy (+ y (/ height 2)) :cy (+ y (/ height 2))
:cx (- x 3)})] :cx (- x 3)})]
[:circle.top-left [:circle.top-left
(merge +circle-props+ (merge +circle-props+
{:on-mouse-up #(on-mouse-up 1 %) {:on-mouse-up #(on-mouse-up :top-left %)
:on-mouse-down #(on-mouse-down 1 %) :on-mouse-down #(on-mouse-down :top-left %)
:cx x :cx x
:cy y})] :cy y})]
[:circle.top-right [:circle.top-right
(merge +circle-props+ (merge +circle-props+
{:on-mouse-up #(on-mouse-up 2 %) {:on-mouse-up #(on-mouse-up :top-right %)
:on-mouse-down #(on-mouse-down 2 %) :on-mouse-down #(on-mouse-down :top-right %)
:cx (+ x width) :cx (+ x width)
:cy y})] :cy y})]
[:circle.bottom-left [:circle.bottom-left
(merge +circle-props+ (merge +circle-props+
{:on-mouse-up #(on-mouse-up 3 %) {:on-mouse-up #(on-mouse-up :bottom-left %)
:on-mouse-down #(on-mouse-down 3 %) :on-mouse-down #(on-mouse-down :bottom-left %)
:cx x :cx x
:cy (+ y height)})] :cy (+ y height)})]
[:circle.bottom-right [:circle.bottom-right
(merge +circle-props+ (merge +circle-props+
{:on-mouse-up #(on-mouse-up 4 %) {:on-mouse-up #(on-mouse-up :bottom-right %)
:on-mouse-down #(on-mouse-down 4 %) :on-mouse-down #(on-mouse-down :bottom-right %)
:cx (+ x width) :cx (+ x width)
:cy (+ y height)})]])))) :cy (+ y height)})]]))))

View file

@ -181,29 +181,26 @@
(defn- move-rect-vertex (defn- move-rect-vertex
"A specialized function for vertex movement "A specialized function for vertex movement
for rect-like shapes." for rect-like shapes."
[shape vid {dx :x dy :y}] [shape vid {dx :x dy :y lock? :lock}]
(let [{:keys [x1 x2 y1 y2]} shape] (let [{:keys [x1 x2 y1 y2]} shape
dy (if lock? dx dy)]
(case vid (case vid
1 (assoc shape :top-left (assoc shape
:x1 (min x2 (+ x1 dx)) :x1 (min x2 (+ x1 dx))
:y1 (min y2 (+ y1 dy))) :y1 (min y2 (+ y1 dy)))
2 (assoc shape :top-right (assoc shape
:x2 (max x1 (+ x2 dx)) :x2 (max x1 (+ x2 dx))
:y1 (min y2 (+ y1 dy))) :y1 (min y2 (+ y1 dy)))
3 (assoc shape :bottom-left (assoc shape
:x1 (min x2 (+ x1 dx)) :x1 (min x2 (+ x1 dx))
:y2 (max y1 (+ y2 dy))) :y2 (max y1 (+ y2 dy)))
4 (assoc shape :bottom-right (assoc shape
:x2 (max x1 (+ x2 dx)) :x2 (max x1 (+ x2 dx))
:y2 (max y1 (+ y2 dy))) :y2 (max y1 (+ y2 dy)))
5 (assoc shape :top (assoc shape :y1 (min y2 (+ y1 dy)))
:y1 (min y2 (+ y1 dy))) :right (assoc shape :x2 (max x1 (+ x2 dx)))
6 (assoc shape :bottom (assoc shape :y2 (max y1 (+ y2 dy)))
:x2 (max x1 (+ x2 dx))) :left (assoc shape :x1 (min x2 (+ x1 dx))))))
7 (assoc shape
:y2 (max y1 (+ y2 dy)))
8 (assoc shape
:x1 (min x2 (+ x1 dx))))))
(defn- move-circle-vertex (defn- move-circle-vertex
"A specialized function for vertex movement "A specialized function for vertex movement
@ -211,22 +208,22 @@
[shape vid {dx :x dy :y lock :lock}] [shape vid {dx :x dy :y lock :lock}]
(let [[dx dy] (if lock [dx dx] [dx dy])] (let [[dx dy] (if lock [dx dx] [dx dy])]
(case vid (case vid
1 (assoc shape :top-left (assoc shape
:rx (max 0 (- (:rx shape) dx)) :rx (max 0 (- (:rx shape) dx))
:ry (max 0 (- (:ry shape) dy))) :ry (max 0 (- (:ry shape) dy)))
2 (assoc shape :top-right (assoc shape
:rx (max 0 (+ (:rx shape) dx)) :rx (max 0 (+ (:rx shape) dx))
:ry (max 0 (- (:ry shape) dy))) :ry (max 0 (- (:ry shape) dy)))
3 (assoc shape :bottom-left (assoc shape
:rx (max 0 (- (:rx shape) dx)) :rx (max 0 (- (:rx shape) dx))
:ry (max 0 (+ (:ry shape) dy))) :ry (max 0 (+ (:ry shape) dy)))
4 (assoc shape :bottom-right (assoc shape
:rx (max 0 (+ (:rx shape) dx)) :rx (max 0 (+ (:rx shape) dx))
:ry (max 0 (+ (:ry shape) dy))) :ry (max 0 (+ (:ry shape) dy)))
5 (assoc shape :ry (max 0 (- (:ry shape) dy))) :top (assoc shape :ry (max 0 (- (:ry shape) dy)))
6 (assoc shape :rx (max 0 (+ (:rx shape) dx))) :right (assoc shape :rx (max 0 (+ (:rx shape) dx)))
7 (assoc shape :ry (max 0 (+ (:ry shape) dy))) :bottom (assoc shape :ry (max 0 (+ (:ry shape) dy)))
8 (assoc shape :rx (max 0 (+ (:rx shape) dx)))))) :left (assoc shape :rx (max 0 (+ (:rx shape) dx))))))
;; --- Resize (Absolute) ;; --- Resize (Absolute)