Improves selection

This commit is contained in:
Steve Ruiz 2021-06-08 12:27:47 +01:00
parent b27c487147
commit 9943bdd420
3 changed files with 17 additions and 9 deletions

View file

@ -70,6 +70,7 @@ export default function BoundsBg() {
rotate(${(bounds.rotation || 0) * (180 / Math.PI)}, 0, 0)`} rotate(${(bounds.rotation || 0) * (180 / Math.PI)}, 0, 0)`}
onPointerDown={handlePointerDown} onPointerDown={handlePointerDown}
onPointerUp={handlePointerUp} onPointerUp={handlePointerUp}
pointerEvents="all"
/> />
) )
} }

View file

@ -174,14 +174,14 @@ export default function useKeyboardEvents() {
if (metaKey(e)) { if (metaKey(e)) {
state.send('COPIED', getKeyboardEventInfo(e)) state.send('COPIED', getKeyboardEventInfo(e))
} else { } else {
state.send('SELECTED_CIRCLE_TOOL', getKeyboardEventInfo(e)) state.send('SELECTED_ELLIPSE_TOOL', getKeyboardEventInfo(e))
} }
break break
} }
case 'i': { case 'i': {
if (metaKey(e)) { if (metaKey(e)) {
} else { } else {
state.send('SELECTED_ELLIPSE_TOOL', getKeyboardEventInfo(e)) state.send('SELECTED_CIRCLE_TOOL', getKeyboardEventInfo(e))
} }
break break
} }

View file

@ -9,7 +9,6 @@ import storage from './storage'
import * as Sessions from './sessions' import * as Sessions from './sessions'
import commands from './commands' import commands from './commands'
import { import {
clamp,
getChildren, getChildren,
getCommonBounds, getCommonBounds,
getCurrent, getCurrent,
@ -46,8 +45,12 @@ import {
DashStyle, DashStyle,
SizeStyle, SizeStyle,
ColorStyle, ColorStyle,
Bounds,
} from 'types' } from 'types'
import session from './session' import session from './session'
import { pointInBounds } from 'utils/bounds'
let currentBounds: Bounds
const initialData: Data = { const initialData: Data = {
isReadOnly: false, isReadOnly: false,
@ -239,6 +242,7 @@ const state = createState({
to: 'brushSelecting', to: 'brushSelecting',
}, },
'setPointedId', 'setPointedId',
{ if: 'pointInSelectionBounds', to: 'pointingBounds' },
{ {
unless: 'isPointedShapeSelected', unless: 'isPointedShapeSelected',
then: { then: {
@ -758,7 +762,13 @@ const state = createState({
shapeIsHovered(data, payload: { target: string }) { shapeIsHovered(data, payload: { target: string }) {
return data.hoveredId === payload.target return data.hoveredId === payload.target
}, },
pointHitsShape(data, payload: { target: string; point: number[] }) { pointInSelectionBounds(data, payload: PointerInfo) {
return (
currentBounds &&
pointInBounds(screenToWorld(payload.point, data), currentBounds)
)
},
pointHitsShape(data, payload: PointerInfo) {
const shape = getShape(data, payload.target) const shape = getShape(data, payload.target)
return getShapeUtils(shape).hitTest( return getShapeUtils(shape).hitTest(
@ -1499,14 +1509,11 @@ const state = createState({
const bounds = getShapeUtils(shape).getRotatedBounds(shape) const bounds = getShapeUtils(shape).getRotatedBounds(shape)
return bounds return bounds
return translateBounds(
rotateBounds(bounds, getBoundsCenter(bounds), parentRotation),
vec.neg(parentOffset)
)
}) })
) )
currentBounds = commonBounds
return commonBounds return commonBounds
}, },
selectedStyle(data) { selectedStyle(data) {