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-25 22:21:05 +02:00
|
|
|
[uxbox.shapes :as shapes]
|
|
|
|
[uxbox.library.icons :as _icons]
|
2015-12-18 19:14:57 +02:00
|
|
|
[uxbox.ui.mixins :as mx]
|
|
|
|
[uxbox.ui.util :as util]
|
2015-12-17 12:51:36 +02:00
|
|
|
[uxbox.data.projects :as dp]
|
2015-12-28 11:28:01 +02:00
|
|
|
[uxbox.ui.workspace.canvas :as wc]
|
2015-12-17 12:51:36 +02:00
|
|
|
[uxbox.ui.workspace.base :as wb]
|
2015-12-17 16:43:58 +02:00
|
|
|
[uxbox.ui.workspace.rules :as wr]
|
2015-12-27 15:28:57 +02:00
|
|
|
[uxbox.ui.workspace.toolboxes :as toolboxes]))
|
2015-12-17 12:51:36 +02:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Coordinates Debug
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2015-12-22 20:25:38 +02:00
|
|
|
(defn- coordenates-render
|
|
|
|
[own]
|
2015-12-18 11:18:00 +02:00
|
|
|
(let [[x y] (rum/react wb/mouse-position)]
|
2015-12-17 12:51:36 +02:00
|
|
|
(html
|
2015-12-22 20:25:38 +02:00
|
|
|
[:div {:style {:position "absolute" :left "80px" :top "20px"}}
|
2015-12-17 12:51:36 +02:00
|
|
|
[:table
|
2015-12-17 15:44:05 +02:00
|
|
|
[:tbody
|
2015-12-22 20:25:38 +02:00
|
|
|
[:tr [:td "X:"] [:td x]]
|
|
|
|
[:tr [:td "Y:"] [:td y]]]]])))
|
2015-12-17 12:51:36 +02:00
|
|
|
|
|
|
|
(def coordinates
|
|
|
|
(util/component
|
|
|
|
{:render coordenates-render
|
|
|
|
:name "coordenates"
|
|
|
|
:mixins [rum/reactive]}))
|
|
|
|
|
2015-12-17 15:44:05 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Grid
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(def ^:static grid-color "#cccccc")
|
|
|
|
|
|
|
|
(defn grid-render
|
2015-12-28 14:32:05 +02:00
|
|
|
[own zoom]
|
2015-12-17 15:44:05 +02:00
|
|
|
(letfn [(vertical-line [position value padding]
|
|
|
|
(let [ticks-mod (/ 100 zoom)
|
|
|
|
step-size (/ 10 zoom)]
|
|
|
|
(if (< (mod value ticks-mod) step-size)
|
|
|
|
(html [:line {:key position
|
|
|
|
:y1 padding
|
2015-12-18 11:24:41 +02:00
|
|
|
:y2 wb/viewport-width
|
2015-12-17 15:44:05 +02:00
|
|
|
:x1 position
|
|
|
|
:x2 position
|
|
|
|
:stroke grid-color
|
|
|
|
:stroke-width (/ 0.5 zoom)
|
|
|
|
:opacity 0.75}])
|
|
|
|
(html [:line {:key position
|
|
|
|
:y1 padding
|
2015-12-18 11:24:41 +02:00
|
|
|
:y2 wb/viewport-width
|
2015-12-17 15:44:05 +02:00
|
|
|
:x1 position
|
|
|
|
:x2 position
|
|
|
|
:stroke grid-color
|
|
|
|
:stroke-width (/ 0.5 zoom)
|
|
|
|
:opacity 0.25}]))))
|
|
|
|
(horizontal-line [position value padding]
|
|
|
|
(let [ticks-mod (/ 100 zoom)
|
|
|
|
step-size (/ 10 zoom)]
|
|
|
|
(if (< (mod value ticks-mod) step-size)
|
|
|
|
(html [:line {:key position
|
|
|
|
:y1 position
|
|
|
|
:y2 position
|
|
|
|
:x1 padding
|
2015-12-18 11:24:41 +02:00
|
|
|
:x2 wb/viewport-height
|
2015-12-17 15:44:05 +02:00
|
|
|
:stroke grid-color
|
|
|
|
:stroke-width (/ 0.5 zoom)
|
|
|
|
:opacity 0.75}])
|
|
|
|
(html [:line {:key position
|
|
|
|
:y1 position
|
|
|
|
:y2 position
|
|
|
|
:x1 padding
|
2015-12-18 11:24:41 +02:00
|
|
|
:x2 wb/viewport-height
|
2015-12-17 15:44:05 +02:00
|
|
|
:stroke grid-color
|
|
|
|
:stroke-width (/ 0.5 zoom)
|
|
|
|
:opacity 0.25}]))))]
|
|
|
|
(let [padding (* 20 zoom)
|
|
|
|
ticks-mod (/ 100 zoom)
|
|
|
|
step-size (/ 10 zoom)
|
2015-12-28 14:32:05 +02:00
|
|
|
workspace (rum/react wb/workspace-state)
|
|
|
|
enabled? (:grid-enabled workspace false)
|
2015-12-18 11:24:41 +02:00
|
|
|
vertical-ticks (range (- padding wb/document-start-y)
|
|
|
|
(- wb/viewport-height wb/document-start-y padding)
|
|
|
|
step-size)
|
|
|
|
horizontal-ticks (range (- padding wb/document-start-x)
|
|
|
|
(- wb/viewport-width wb/document-start-x padding)
|
|
|
|
step-size)]
|
2015-12-17 15:44:05 +02:00
|
|
|
(html
|
|
|
|
[:g.grid
|
|
|
|
{:style {:display (if enabled? "block" "none")}}
|
|
|
|
(for [tick vertical-ticks]
|
2015-12-18 11:24:41 +02:00
|
|
|
(let [position (+ tick wb/document-start-x)
|
2015-12-17 15:44:05 +02:00
|
|
|
line (vertical-line position tick padding)]
|
|
|
|
(rum/with-key line (str "tick-" tick))))
|
|
|
|
(for [tick horizontal-ticks]
|
2015-12-18 11:24:41 +02:00
|
|
|
(let [position (+ tick wb/document-start-y)
|
2015-12-17 15:44:05 +02:00
|
|
|
line (horizontal-line position tick padding)]
|
|
|
|
(rum/with-key line (str "tick-" tick))))]))))
|
|
|
|
|
|
|
|
(def grid
|
|
|
|
(util/component
|
|
|
|
{:render grid-render
|
|
|
|
:name "grid"
|
2015-12-28 14:32:05 +02:00
|
|
|
:mixins [mx/static rum/reactive]}))
|
2015-12-17 15:44:05 +02:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Viewport
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(defn viewport-render
|
|
|
|
[]
|
|
|
|
(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
|
|
|
|
:class (when drawing? "drawing")}
|
|
|
|
[:g.zoom {:transform (str "scale(" zoom ", " zoom ")")}
|
2015-12-28 11:28:01 +02:00
|
|
|
(wc/canvas)
|
2015-12-28 14:32:05 +02:00
|
|
|
(grid zoom)]])))
|
2015-12-17 15:44:05 +02:00
|
|
|
|
|
|
|
(def viewport
|
|
|
|
(util/component
|
|
|
|
{:render viewport-render
|
|
|
|
:name "viewport"
|
|
|
|
:mixins [rum/reactive]}))
|
2015-12-17 12:51:36 +02:00
|
|
|
|
2015-12-18 17:50:34 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Aside
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(defn aside-render
|
|
|
|
[own]
|
|
|
|
(let [workspace (rum/react wb/workspace-state)]
|
2015-12-18 19:14:57 +02:00
|
|
|
(html
|
|
|
|
[:aside#settings-bar.settings-bar
|
|
|
|
[:div.settings-bar-inside
|
|
|
|
(when (:draw-toolbox-enabled workspace false)
|
2015-12-27 15:28:57 +02:00
|
|
|
(toolboxes/draw-tools))
|
|
|
|
(when (:icons-toolbox-enabled workspace false)
|
|
|
|
(toolboxes/icons))
|
2015-12-18 19:31:29 +02:00
|
|
|
(when (:layers-toolbox-enabled workspace false)
|
2015-12-27 15:28:57 +02:00
|
|
|
(toolboxes/layers))]])))
|
2015-12-18 17:50:34 +02:00
|
|
|
|
|
|
|
(def aside
|
|
|
|
(util/component
|
|
|
|
{:render aside-render
|
|
|
|
:name "aside"
|
|
|
|
:mixins [rum/reactive]}))
|
|
|
|
|
2015-12-17 12:51:36 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Work Area
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(defn working-area-render
|
|
|
|
[own]
|
2015-12-18 17:50:34 +02:00
|
|
|
(let [workspace (rum/react wb/workspace-state)]
|
|
|
|
(html
|
|
|
|
[:section.workspace-canvas
|
|
|
|
{:class (when (empty? (:toolboxes workspace)) "no-tool-bar")
|
|
|
|
:on-scroll (constantly nil)}
|
|
|
|
|
|
|
|
#_(when (:selected page)
|
|
|
|
(element-options conn
|
|
|
|
page-cursor
|
|
|
|
project-cursor
|
|
|
|
zoom-cursor
|
|
|
|
shapes-cursor))
|
|
|
|
(coordinates)
|
|
|
|
(viewport)])))
|
2015-12-17 12:51:36 +02:00
|
|
|
|
2015-12-17 15:44:05 +02:00
|
|
|
(def workarea
|
2015-12-17 12:51:36 +02:00
|
|
|
(util/component
|
|
|
|
{:render working-area-render
|
2015-12-17 15:44:05 +02:00
|
|
|
:name "workarea"
|
2015-12-18 17:50:34 +02:00
|
|
|
:mixins [rum/reactive]}))
|
2015-12-17 12:51:36 +02:00
|
|
|
|