Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

feat: overlays for dark/light effect with crop

httpjamesmcc6519bb0940
diff --git a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx b/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
index b3d8b68763..f3bd801fbf 100644
--- a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
+++ b/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx
@@ -592,67 +592,139 @@ const ImageEditorOverlay = (props: IProps) => {
onMouseMove={isDragging ? handleDrag : null}
onMouseDown={handleDragStart}>
<Box
- height="90%"
- width="100%"
- ref={parentRef}
- display="flex"
- alignItems="center"
- justifyContent="center"
- position="relative">
- {(fileURL === null || canvasLoading) && (
- <CircularProgress />
- )}
-
- <canvas
- ref={canvasRef}
- style={{
- objectFit: 'contain',
- display:
- fileURL === null || canvasLoading
- ? 'none'
- : 'block',
- position: 'absolute',
- }}
- />
- <canvas
- ref={originalSizeCanvasRef}
- style={{
- display: 'none',
- }}
- />
- <div
- style={{
- display:
- currentTab === 'crop' ? 'grid' : 'none',
- position: 'absolute',
- left: cropBox.x + 'px',
- top: cropBox.y + 'px',
- width: cropBox.width + 'px',
- height: cropBox.height + 'px',
- backgroundColor: 'rgba(0,0,0,0.5)',
- border: '1px solid white',
- gridTemplateColumns: '1fr 1fr 1fr',
- gridTemplateRows: '1fr 1fr 1fr',
- gap: '0px',
- }}
- ref={cropBoxRef}>
- {Array.from({ length: 9 }).map((_, index) => (
- <div
- key={index}
- style={{
- border: '1px solid white',
- boxSizing: 'border-box',
- pointerEvents: 'none',
- }}></div>
- ))}
-
- <div
- style={seHandleStyle}
- onMouseDown={(e) => {
- e.preventDefault();
- setIsDragging(true);
- }}></div>
- </div>
+ style={{
+ position: 'relative',
+ width: '100%',
+ height: '100%',
+ }}>
+ <Box
+ height="90%"
+ width="100%"
+ ref={parentRef}
+ display="flex"
+ alignItems="center"
+ justifyContent="center"
+ position="relative">
+ {(fileURL === null || canvasLoading) && (
+ <CircularProgress />
+ )}
+
+ <canvas
+ ref={canvasRef}
+ style={{
+ objectFit: 'contain',
+ display:
+ fileURL === null || canvasLoading
+ ? 'none'
+ : 'block',
+ position: 'absolute',
+ }}
+ />
+ <canvas
+ ref={originalSizeCanvasRef}
+ style={{
+ display: 'none',
+ }}
+ />
+
+ {currentTab === 'crop' && (
+ <>
+ {/* Top overlay */}
+ <div
+ style={{
+ position: 'absolute',
+ top: 0,
+ left: 0,
+ right: 0,
+ height: cropBox.y + 'px', // height up to the top of the crop box
+ backgroundColor:
+ 'rgba(0,0,0,0.5)',
+ pointerEvents: 'none',
+ }}></div>
+
+ {/* Bottom overlay */}
+ <div
+ style={{
+ position: 'absolute',
+ bottom: 0,
+ left: 0,
+ right: 0,
+ height: `calc(100% - ${
+ cropBox.y + cropBox.height
+ }px)`, // height from the bottom of the crop box to the bottom of the canvas
+ backgroundColor:
+ 'rgba(0,0,0,0.5)',
+ pointerEvents: 'none',
+ }}></div>
+
+ {/* Left overlay */}
+ <div
+ style={{
+ position: 'absolute',
+ top: cropBox.y + 'px',
+ left: 0,
+ width: cropBox.x + 'px', // width up to the left side of the crop box
+ height: cropBox.height + 'px', // same height as the crop box
+ backgroundColor:
+ 'rgba(0,0,0,0.5)',
+ pointerEvents: 'none',
+ }}></div>
+
+ {/* Right overlay */}
+ <div
+ style={{
+ position: 'absolute',
+ top: cropBox.y + 'px',
+ right: 0,
+ width: `calc(100% - ${
+ cropBox.x + cropBox.width
+ }px)`, // width from the right side of the crop box to the right side of the canvas
+ height: cropBox.height + 'px', // same height as the crop box
+ backgroundColor:
+ 'rgba(0,0,0,0.5)',
+ pointerEvents: 'none',
+ }}></div>
+
+ <div
+ style={{
+ display: 'grid',
+ position: 'absolute',
+ left: cropBox.x + 'px',
+ top: cropBox.y + 'px',
+ width: cropBox.width + 'px',
+ height: cropBox.height + 'px',
+ border: '1px solid white',
+ gridTemplateColumns:
+ '1fr 1fr 1fr',
+ gridTemplateRows: '1fr 1fr 1fr',
+ gap: '0px',
+ zIndex: 30, // make sure the crop box is above the overlays
+ }}
+ ref={cropBoxRef}>
+ {Array.from({ length: 9 }).map(
+ (_, index) => (
+ <div
+ key={index}
+ style={{
+ border: '1px solid white',
+ boxSizing:
+ 'border-box',
+ pointerEvents:
+ 'none',
+ }}></div>
+ )
+ )}
+
+ <div
+ style={seHandleStyle}
+ onMouseDown={(e) => {
+ e.preventDefault();
+ setIsDragging(true);
+ }}></div>
+ </div>
+ </>
+ )}
+ </Box>
</Box>
</Box>
</Box>