瀏覽代碼

Improves hover appearance

main
Steve Ruiz 4 年之前
父節點
當前提交
39ef1cf317
共有 5 個檔案被更改,包括 69 行新增28 行删除
  1. 13
    4
      components/canvas/shape.tsx
  2. 7
    3
      components/toolbar.tsx
  3. 12
    10
      lib/shape-utils/draw.tsx
  4. 27
    0
      state/state.ts
  5. 10
    11
      styles/stitches.config.ts

+ 13
- 4
components/canvas/shape.tsx 查看文件

36
       transform={transform}
36
       transform={transform}
37
       {...events}
37
       {...events}
38
     >
38
     >
39
-      {isSelecting && <HoverIndicator as="use" href={'#' + id} />}
39
+      {isSelecting && (
40
+        <HoverIndicator
41
+          as="use"
42
+          href={'#' + id}
43
+          strokeWidth={+shape.style.strokeWidth + 8}
44
+        />
45
+      )}
40
       <StyledShape id={id} style={shape.style} />
46
       <StyledShape id={id} style={shape.style} />
41
       {/* 
47
       {/* 
42
       <text
48
       <text
102
         [`& ${HoverIndicator}`]: {
108
         [`& ${HoverIndicator}`]: {
103
           opacity: '1',
109
           opacity: '1',
104
           stroke: '$hint',
110
           stroke: '$hint',
105
-          zStrokeWidth: [8, 4],
111
+          fill: '$hint',
112
+          // zStrokeWidth: [8, 4],
106
         },
113
         },
107
       },
114
       },
108
     },
115
     },
113
         [`& ${HoverIndicator}`]: {
120
         [`& ${HoverIndicator}`]: {
114
           opacity: '1',
121
           opacity: '1',
115
           stroke: '$hint',
122
           stroke: '$hint',
116
-          zStrokeWidth: [6, 3],
123
+          fill: '$hint',
124
+          // zStrokeWidth: [6, 3],
117
         },
125
         },
118
       },
126
       },
119
     },
127
     },
124
         [`& ${HoverIndicator}`]: {
132
         [`& ${HoverIndicator}`]: {
125
           opacity: '1',
133
           opacity: '1',
126
           stroke: '$hint',
134
           stroke: '$hint',
127
-          zStrokeWidth: [8, 4],
135
+          fill: '$hint',
136
+          // zStrokeWidth: [8, 4],
128
         },
137
         },
129
       },
138
       },
130
     },
139
     },

+ 7
- 3
components/toolbar.tsx 查看文件

1
 import state, { useSelector } from 'state'
1
 import state, { useSelector } from 'state'
2
 import styled from 'styles'
2
 import styled from 'styles'
3
-import { Lock, Menu, Unlock } from 'react-feather'
3
+import { Lock, Menu, RotateCcw, RotateCw, Unlock } from 'react-feather'
4
 import { IconButton } from './shared'
4
 import { IconButton } from './shared'
5
 
5
 
6
 export default function Toolbar() {
6
 export default function Toolbar() {
86
         <Button onClick={() => state.send('RESET_CAMERA')}>Reset Camera</Button>
86
         <Button onClick={() => state.send('RESET_CAMERA')}>Reset Camera</Button>
87
       </Section>
87
       </Section>
88
       <Section>
88
       <Section>
89
-        <Button onClick={() => state.send('UNDO')}>Undo</Button>
90
-        <Button onClick={() => state.send('REDO')}>Redo</Button>
89
+        <Button title="Undo" onClick={() => state.send('UNDO')}>
90
+          <RotateCcw />
91
+        </Button>
92
+        <Button title="Redo" onClick={() => state.send('REDO')}>
93
+          <RotateCw />
94
+        </Button>
91
       </Section>
95
       </Section>
92
     </ToolbarContainer>
96
     </ToolbarContainer>
93
   )
97
   )

+ 12
- 10
lib/shape-utils/draw.tsx 查看文件

12
   translateBounds,
12
   translateBounds,
13
 } from 'utils/utils'
13
 } from 'utils/utils'
14
 
14
 
15
-const pathCache = new WeakMap<number[][], string>([])
15
+const pathCache = new WeakMap<DrawShape, string>([])
16
 
16
 
17
 const draw = registerShapeUtils<DrawShape>({
17
 const draw = registerShapeUtils<DrawShape>({
18
   boundsCache: new WeakMap([]),
18
   boundsCache: new WeakMap([]),
40
   },
40
   },
41
 
41
 
42
   render(shape) {
42
   render(shape) {
43
-    const { id, point, points, style } = shape
43
+    const { id, points, style } = shape
44
 
44
 
45
-    if (!pathCache.has(points)) {
45
+    if (!pathCache.has(shape)) {
46
       if (points.length < 2) {
46
       if (points.length < 2) {
47
-        const left = vec.add(point, [6, 0])
47
+        const left = [+style.strokeWidth, 0]
48
         let d: number[][] = []
48
         let d: number[][] = []
49
         for (let i = 0; i < 10; i++) {
49
         for (let i = 0; i < 10; i++) {
50
-          d.push(vec.rotWith(left, point, i * ((Math.PI * 2) / 8)))
50
+          d.push(vec.rotWith(left, [0, 0], i * ((Math.PI * 2) / 8)))
51
         }
51
         }
52
-        pathCache.set(points, getSvgPathFromStroke(d))
52
+        pathCache.set(shape, getSvgPathFromStroke(d))
53
       } else {
53
       } else {
54
         pathCache.set(
54
         pathCache.set(
55
-          points,
55
+          shape,
56
           getSvgPathFromStroke(
56
           getSvgPathFromStroke(
57
-            getStroke(points, { size: Number(style.strokeWidth) * 2 })
57
+            getStroke(points, { size: +style.strokeWidth * 2 })
58
           )
58
           )
59
         )
59
         )
60
       }
60
       }
61
     }
61
     }
62
 
62
 
63
-    return <path id={id} d={pathCache.get(points)} />
63
+    return <path id={id} d={pathCache.get(shape)} />
64
   },
64
   },
65
 
65
 
66
   applyStyles(shape, style) {
66
   applyStyles(shape, style) {
95
 
95
 
96
     for (let i = 1; i < shape.points.length; i++) {
96
     for (let i = 1; i < shape.points.length; i++) {
97
       let curr = shape.points[i]
97
       let curr = shape.points[i]
98
-      if (vec.distanceToLineSegment(prev, curr, pt) < 4) {
98
+      if (
99
+        vec.distanceToLineSegment(prev, curr, pt) < +shape.style.strokeWidth
100
+      ) {
99
         return true
101
         return true
100
       }
102
       }
101
       prev = curr
103
       prev = curr

+ 27
- 0
state/state.ts 查看文件

274
         },
274
         },
275
         usingTool: {
275
         usingTool: {
276
           initial: 'draw',
276
           initial: 'draw',
277
+          onEnter: 'clearSelectedIds',
277
           states: {
278
           states: {
278
             draw: {
279
             draw: {
279
               initial: 'creating',
280
               initial: 'creating',
281
                 creating: {
282
                 creating: {
282
                   on: {
283
                   on: {
283
                     CANCELLED: { to: 'selecting' },
284
                     CANCELLED: { to: 'selecting' },
285
+                    POINTED_SHAPE: {
286
+                      get: 'newDraw',
287
+                      do: 'createShape',
288
+                      to: 'draw.editing',
289
+                    },
284
                     POINTED_CANVAS: {
290
                     POINTED_CANVAS: {
285
                       get: 'newDraw',
291
                       get: 'newDraw',
286
                       do: 'createShape',
292
                       do: 'createShape',
313
                 creating: {
319
                 creating: {
314
                   on: {
320
                   on: {
315
                     CANCELLED: { to: 'selecting' },
321
                     CANCELLED: { to: 'selecting' },
322
+                    POINTED_SHAPE: {
323
+                      get: 'newDot',
324
+                      do: 'createShape',
325
+                      to: 'dot.editing',
326
+                    },
316
                     POINTED_CANVAS: {
327
                     POINTED_CANVAS: {
317
                       get: 'newDot',
328
                       get: 'newDot',
318
                       do: 'createShape',
329
                       do: 'createShape',
364
                 creating: {
375
                 creating: {
365
                   on: {
376
                   on: {
366
                     CANCELLED: { to: 'selecting' },
377
                     CANCELLED: { to: 'selecting' },
378
+                    POINTED_SHAPE: {
379
+                      to: 'circle.editing',
380
+                    },
367
                     POINTED_CANVAS: {
381
                     POINTED_CANVAS: {
368
                       to: 'circle.editing',
382
                       to: 'circle.editing',
369
                     },
383
                     },
418
                 creating: {
432
                 creating: {
419
                   on: {
433
                   on: {
420
                     CANCELLED: { to: 'selecting' },
434
                     CANCELLED: { to: 'selecting' },
435
+                    POINTED_SHAPE: {
436
+                      to: 'rectangle.editing',
437
+                    },
421
                     POINTED_CANVAS: {
438
                     POINTED_CANVAS: {
422
                       to: 'rectangle.editing',
439
                       to: 'rectangle.editing',
423
                     },
440
                     },
445
                 creating: {
462
                 creating: {
446
                   on: {
463
                   on: {
447
                     CANCELLED: { to: 'selecting' },
464
                     CANCELLED: { to: 'selecting' },
465
+                    POINTED_SHAPE: {
466
+                      get: 'newRay',
467
+                      do: 'createShape',
468
+                      to: 'ray.editing',
469
+                    },
448
                     POINTED_CANVAS: {
470
                     POINTED_CANVAS: {
449
                       get: 'newRay',
471
                       get: 'newRay',
450
                       do: 'createShape',
472
                       do: 'createShape',
470
                 creating: {
492
                 creating: {
471
                   on: {
493
                   on: {
472
                     CANCELLED: { to: 'selecting' },
494
                     CANCELLED: { to: 'selecting' },
495
+                    POINTED_SHAPE: {
496
+                      get: 'newLine',
497
+                      do: 'createShape',
498
+                      to: 'line.editing',
499
+                    },
473
                     POINTED_CANVAS: {
500
                     POINTED_CANVAS: {
474
                       get: 'newLine',
501
                       get: 'newLine',
475
                       do: 'createShape',
502
                       do: 'createShape',

+ 10
- 11
styles/stitches.config.ts 查看文件

45
   utils: {
45
   utils: {
46
     zStrokeWidth: () => (value: number | number[]) => {
46
     zStrokeWidth: () => (value: number | number[]) => {
47
       if (Array.isArray(value)) {
47
       if (Array.isArray(value)) {
48
+        // const [val, min, max] = value
49
+        // return {
50
+        //   strokeWidth:
51
+        //     min !== undefined && max !== undefined
52
+        //       ? `clamp(${min}px, (calc(${val}px / var(--camera-zoom))), ${max}px)`
53
+        //       : min !== undefined
54
+        //       ? `min(${min}px, calc(${val}px / var(--camera-zoom)))`
55
+        //       : `calc(${val}px / var(--camera-zoom))`,
56
+        // }
57
+
48
         return {
58
         return {
49
           strokeWidth: `calc(${value[0]}px / var(--camera-zoom))`,
59
           strokeWidth: `calc(${value[0]}px / var(--camera-zoom))`,
50
         }
60
         }
51
       }
61
       }
52
 
62
 
53
-      // const [val, min, max] = value
54
-      // return {
55
-      //   strokeWidth:
56
-      //     min !== undefined && max !== undefined
57
-      //       ? `clamp(${min}, ${val} / var(--camera-zoom), ${max})`
58
-      //       : min !== undefined
59
-      //       ? `min(${min}, ${val} / var(--camera-zoom))`
60
-      //       : `calc(${val} / var(--camera-zoom))`,
61
-      // }
62
-      // }
63
-
64
       return {
63
       return {
65
         strokeWidth: `calc(${value}px / var(--camera-zoom))`,
64
         strokeWidth: `calc(${value}px / var(--camera-zoom))`,
66
       }
65
       }

Loading…
取消
儲存