2015-12-17 12:51:36 +02:00
|
|
|
(ns uxbox.ui.workspace.workarea
|
|
|
|
(:require [sablono.core :as html :refer-macros [html]]
|
|
|
|
[rum.core :as rum]
|
|
|
|
[uxbox.router :as r]
|
|
|
|
[uxbox.rstore :as rs]
|
|
|
|
[uxbox.state :as s]
|
2015-12-18 19:14:57 +02:00
|
|
|
[uxbox.ui.mixins :as mx]
|
|
|
|
[uxbox.ui.util :as util]
|
2015-12-28 16:33:14 +02:00
|
|
|
[uxbox.data.workspace :as dw]
|
2015-12-28 15:24:24 +02:00
|
|
|
[uxbox.ui.workspace.canvas :refer (canvas)]
|
|
|
|
[uxbox.ui.workspace.grid :refer (grid)]
|
2015-12-28 15:20:16 +02:00
|
|
|
[uxbox.ui.workspace.base :as wb]))
|
2015-12-17 12:51:36 +02:00
|
|
|
|
2015-12-28 16:33:14 +02:00
|
|
|
;; TODO: implement as streams
|
|
|
|
|
|
|
|
(defn- on-click
|
|
|
|
[event wstate]
|
|
|
|
(let [mousepos @wb/mouse-position
|
|
|
|
shape (:drawing wstate)]
|
|
|
|
(when shape
|
|
|
|
(let [props {:x (first mousepos)
|
|
|
|
:y (second mousepos)
|
|
|
|
:width 100
|
|
|
|
:height 100}]
|
|
|
|
(rs/emit!
|
|
|
|
(dw/add-shape shape props)
|
|
|
|
(dw/select-for-drawing nil))))))
|
|
|
|
|
2015-12-17 15:44:05 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2015-12-28 16:33:14 +02:00
|
|
|
;; Viewport Component
|
2015-12-17 15:44:05 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(defn viewport-render
|
2015-12-28 16:33:14 +02:00
|
|
|
[own]
|
2015-12-17 15:44:05 +02:00
|
|
|
(let [workspace (rum/react wb/workspace-state)
|
2015-12-28 14:32:05 +02:00
|
|
|
drawing? (:drawing workspace)
|
2015-12-17 15:44:05 +02:00
|
|
|
zoom 1]
|
|
|
|
(html
|
2015-12-28 14:32:05 +02:00
|
|
|
[:svg.viewport {:width wb/viewport-height
|
|
|
|
:height wb/viewport-width
|
2015-12-28 16:33:14 +02:00
|
|
|
:on-click #(on-click % workspace)
|
2015-12-28 14:32:05 +02:00
|
|
|
:class (when drawing? "drawing")}
|
|
|
|
[:g.zoom {:transform (str "scale(" zoom ", " zoom ")")}
|
2015-12-28 15:24:24 +02:00
|
|
|
(canvas)
|
2015-12-29 14:23:41 +02:00
|
|
|
#_(grid zoom)]])))
|
2015-12-17 15:44:05 +02:00
|
|
|
|
|
|
|
(def viewport
|
|
|
|
(util/component
|
|
|
|
{:render viewport-render
|
|
|
|
:name "viewport"
|
|
|
|
:mixins [rum/reactive]}))
|