Skip to content

Commit

Permalink
friendlier zoom; allow hitfunc clicks on entire stage
Browse files Browse the repository at this point in the history
  • Loading branch information
bobnik committed Sep 27, 2023
1 parent f69fa80 commit 5cfa806
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
4 changes: 3 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
- selectLayersByGroupId - some kind of compound parent key "[a]-[b]"
- big thunk which just changes layer dimensions
- if it has effects, can render those via selector
- store pattern name and other desired attribution (?) in exported file and display it in preview window if provided
- store pattern name and other desired attribution (?) in exported file and display it somewhere (either stats tab or in the preview window)
- show pattern start/end type (e.g., 1-0) if start/end if specified
- new fine tuning setting: when backtracking at end, optionally ignore border if enabled

## NEW IN 1.0.0

Expand Down
1 change: 0 additions & 1 deletion src/features/effects/FineTuning.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ export default class FineTuning extends Effect {

drawBorder(vertices, effect) {
let hull = convexHull(cloneVertices(vertices))
const start = vertices[0]
const last = vertices[vertices.length - 1]
const closestVertex = closest(hull, last)
const index = hull.indexOf(closestVertex)
Expand Down
26 changes: 13 additions & 13 deletions src/features/preview/PreviewWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const PreviewWindow = () => {
const selectedLayer = useSelector(selectSelectedLayer, isEqual)
const layerIds = useSelector(selectVisibleLayerIds, isEqual)
const zoom = useSelector(selectPreviewZoom)
const stageZoom = zoom > 1 ? zoom : 1
const offsetZoom = zoom > 1 ? 1 : zoom
const remainingLayerIds = layerIds.filter((id) => id !== selectedLayer?.id)
const layerRef = useRef()
const stagePadding = 22
Expand Down Expand Up @@ -68,33 +70,31 @@ const PreviewWindow = () => {

// add hidden debugging option to toggle the hit canvas on the layer when the user
// clicks on the layer while pressing the Alt key
const handleLayerClick = (e) => {
const handleStageClick = (e) => {
dispatch(setCurrentLayer(null))
if (e.evt.altKey && layerRef.current) {
layerRef.current.toggleHitCanvas()
e.cancelBubble = true
}
}

const handleStageClick = (e) => {
dispatch(setCurrentLayer(null))
}

// some awkward rendering to put the current layer as the last child in the layer to ensure
// transformer rotation works; this is a Konva restriction.
return (
<Stage
scaleX={scale * zoom}
scaleY={scale * zoom}
height={height * scaleHeight * zoom + stagePadding}
width={width * scaleWidth * zoom + stagePadding}
offsetX={(-width * (scaleWidth / scale) - stagePadding * 0.5) / 2}
offsetY={(-height * (scaleHeight / scale) - stagePadding * 0.5) / 2}
height={height * scaleHeight * stageZoom + stagePadding}
width={width * scaleWidth * stageZoom + stagePadding}
offsetX={
(-width * (scaleWidth / scale / offsetZoom) - stagePadding * 0.5) / 2
}
offsetY={
(-height * (scaleHeight / scale / offsetZoom) - stagePadding * 0.5) / 2
}
onClick={handleStageClick}
>
<Layer
ref={layerRef}
onClick={handleLayerClick}
>
<Layer ref={layerRef}>
{machine.type === "polar" && (
<Circle
x={0}
Expand Down

0 comments on commit 5cfa806

Please sign in to comment.