Fix the visual glitches with FocusRangeCurtains

This commit is contained in:
Aria Minaei 2022-05-05 15:17:35 +02:00
parent c6a7c40339
commit a38201a835
3 changed files with 69 additions and 28 deletions

View file

@ -11,12 +11,11 @@ const divWidth = 1000
const Curtain = styled.div<{enabled: boolean}>` const Curtain = styled.div<{enabled: boolean}>`
position: absolute; position: absolute;
top: ${topStripHeight}px;
left: 0; left: 0;
opacity: 0.15; opacity: 0.15;
top: ${topStripHeight}px;
width: ${divWidth}px; width: ${divWidth}px;
transform-origin: top left; transform-origin: top left;
z-index: 20;
pointer-events: none; pointer-events: none;
background-color: ${(props) => (props.enabled ? '#000000' : 'transparent')}; background-color: ${(props) => (props.enabled ? '#000000' : 'transparent')};
` `
@ -44,36 +43,78 @@ const FocusRangeCurtains: React.FC<{
const {range} = existingRange const {range} = existingRange
const height = val(layoutP.rightDims.height) const height = val(layoutP.rightDims.height) - topStripHeight
const unitSpaceToClippedSpace = val(layoutP.clippedSpace.fromUnitSpace) const unitSpaceToClippedSpace = val(layoutP.clippedSpace.fromUnitSpace)
const clippedSpaceWidth = val(layoutP.clippedSpace.width)
const els = [ const els: Array<{translateX: number; scaleX: number}> = []
[-1000, range.start],
[range.end, val(layoutP.clippedSpace.range.end)],
].map(([start, end], i) => {
const startPosInClippedSpace = unitSpaceToClippedSpace(start)
const endPosInClippedSpace = unitSpaceToClippedSpace(end) {
const desiredWidth = endPosInClippedSpace - startPosInClippedSpace // the left (start) curtain
// starts from 0px
let startX = 0
// ends in the start of the range
let endX = unitSpaceToClippedSpace(existingRange.range.start)
let scaleX: number, translateX: number
// hide the curtain if:
if (
// endX would be larger than startX, which means the curtain is to the left of the RightOverlay
startX > endX
) {
// fully hide it then with scaleX = 0
translateX = 0
scaleX = 0
} else {
// clip the end of the curtain if it's going over the right side of RightOverlay
if (endX > clippedSpaceWidth) {
//
endX = clippedSpaceWidth
}
translateX = startX
scaleX = (endX - startX) / divWidth
}
els.push({translateX, scaleX})
}
{
// the right (end) curtain
// starts at the end of the range
let startX = unitSpaceToClippedSpace(existingRange.range.end)
// and ends at the right edge of RightOverlay (which is clippedSpaceWidth)
let endX = clippedSpaceWidth
let scaleX: number, translateX: number
// if the whole curtain falls to the right of RightOverlay, hide it
if (startX > endX) {
translateX = 0
scaleX = 0
} else {
// if the left of the curtain falls on the left of RightOverlay, clip it
if (startX < 0) {
startX = 0
}
translateX = startX
scaleX = (endX - startX) / divWidth
}
els.push({translateX, scaleX})
}
return ( return (
<>
{els.map(({translateX, scaleX}, i) => (
<Curtain <Curtain
key={`curtain-${i}`} key={`curtain-${i}`}
enabled={true} enabled={true}
style={{ style={{
height: `${height}px`, height: `${height}px`,
transform: `translateX(${ transform: `translateX(${translateX}px) scaleX(${scaleX})`,
val(layoutP.scaledSpace.leftPadding) +
startPosInClippedSpace -
unitSpaceToClippedSpace(0)
}px) scaleX(${desiredWidth / divWidth})`,
}} }}
/> />
))}
</>
) )
})
return <>{els}</>
}, [layoutP, existingRangeD]) }, [layoutP, existingRangeD])
} }

View file

@ -10,7 +10,6 @@ import {zIndexes} from '@theatre/studio/panels/SequenceEditorPanel/SequenceEdito
import DopeSheetSelectionView from './DopeSheetSelectionView' import DopeSheetSelectionView from './DopeSheetSelectionView'
import HorizontallyScrollableArea from './HorizontallyScrollableArea' import HorizontallyScrollableArea from './HorizontallyScrollableArea'
import SheetRow from './SheetRow' import SheetRow from './SheetRow'
import FocusRangeCurtains from './FocusRangeCurtains'
export const contentWidth = 1000000 export const contentWidth = 1000000
@ -49,7 +48,6 @@ const Right: React.FC<{
return ( return (
<> <>
<HorizontallyScrollableArea layoutP={layoutP} height={height}> <HorizontallyScrollableArea layoutP={layoutP} height={height}>
<FocusRangeCurtains layoutP={layoutP} />
<DopeSheetSelectionView layoutP={layoutP}> <DopeSheetSelectionView layoutP={layoutP}>
<ListContainer style={{top: tree.top + 'px'}}> <ListContainer style={{top: tree.top + 'px'}}>
<SheetRow leaf={tree} layoutP={layoutP} /> <SheetRow leaf={tree} layoutP={layoutP} />

View file

@ -10,6 +10,7 @@ import FrameStamp from './FrameStamp'
import HorizontalScrollbar from './HorizontalScrollbar' import HorizontalScrollbar from './HorizontalScrollbar'
import Playhead from './Playhead' import Playhead from './Playhead'
import TopStrip from './TopStrip' import TopStrip from './TopStrip'
import FocusRangeCurtains from '@theatre/studio/panels/SequenceEditorPanel/DopeSheet/Right/FocusRangeCurtains'
const Container = styled.div` const Container = styled.div`
position: absolute; position: absolute;
@ -34,6 +35,7 @@ const RightOverlay: React.FC<{
<FrameStamp layoutP={layoutP} /> <FrameStamp layoutP={layoutP} />
<TopStrip layoutP={layoutP} /> <TopStrip layoutP={layoutP} />
<LengthIndicator layoutP={layoutP} /> <LengthIndicator layoutP={layoutP} />
<FocusRangeCurtains layoutP={layoutP} />
</Container> </Container>
) )
}, [layoutP]) }, [layoutP])