Media editor minor improvements
This commit is contained in:
parent
38cdb9b289
commit
dccd3fbf73
4 changed files with 27 additions and 7 deletions
|
@ -399,6 +399,7 @@ export const MediaEditor = ({
|
||||||
|
|
||||||
const [canRedo, setCanRedo] = useState(false);
|
const [canRedo, setCanRedo] = useState(false);
|
||||||
const [canUndo, setCanUndo] = useState(false);
|
const [canUndo, setCanUndo] = useState(false);
|
||||||
|
const [canCrop, setCanCrop] = useState(false);
|
||||||
const [cropAspectRatioLock, setcropAspectRatioLock] = useState(false);
|
const [cropAspectRatioLock, setcropAspectRatioLock] = useState(false);
|
||||||
const [drawTool, setDrawTool] = useState<DrawTool>(DrawTool.Pen);
|
const [drawTool, setDrawTool] = useState<DrawTool>(DrawTool.Pen);
|
||||||
const [drawWidth, setDrawWidth] = useState<DrawWidth>(DrawWidth.Regular);
|
const [drawWidth, setDrawWidth] = useState<DrawWidth>(DrawWidth.Regular);
|
||||||
|
@ -572,6 +573,13 @@ export const MediaEditor = ({
|
||||||
width,
|
width,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
rect.on('modified', () => {
|
||||||
|
const { height: currHeight, width: currWidth } =
|
||||||
|
rect.getBoundingRect(true);
|
||||||
|
|
||||||
|
setCanCrop(currHeight < height || currWidth < width);
|
||||||
|
});
|
||||||
|
|
||||||
rect.on('deselected', () => {
|
rect.on('deselected', () => {
|
||||||
setEditMode(undefined);
|
setEditMode(undefined);
|
||||||
});
|
});
|
||||||
|
@ -589,6 +597,8 @@ export const MediaEditor = ({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCanCrop(false);
|
||||||
}, [editMode, fabricCanvas, imageState.height, imageState.width, zoom]);
|
}, [editMode, fabricCanvas, imageState.height, imageState.width, zoom]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -857,6 +867,7 @@ export const MediaEditor = ({
|
||||||
<button
|
<button
|
||||||
aria-label={i18n('MediaEditor__crop--crop')}
|
aria-label={i18n('MediaEditor__crop--crop')}
|
||||||
className="MediaEditor__crop-toolbar--button MediaEditor__crop-toolbar--crop"
|
className="MediaEditor__crop-toolbar--button MediaEditor__crop-toolbar--crop"
|
||||||
|
disabled={!canCrop}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!fabricCanvas) {
|
if (!fabricCanvas) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -85,6 +85,7 @@ MediaEditorFabricCropRect.prototype.controls = {
|
||||||
x: -0.5,
|
x: -0.5,
|
||||||
y: -0.5,
|
y: -0.5,
|
||||||
actionHandler: fabric.controlsUtils.scalingEqually,
|
actionHandler: fabric.controlsUtils.scalingEqually,
|
||||||
|
cursorStyle: 'nwse-resize',
|
||||||
render: (
|
render: (
|
||||||
ctx: CanvasRenderingContext2D,
|
ctx: CanvasRenderingContext2D,
|
||||||
left: number,
|
left: number,
|
||||||
|
@ -111,6 +112,7 @@ MediaEditorFabricCropRect.prototype.controls = {
|
||||||
x: 0.5,
|
x: 0.5,
|
||||||
y: -0.5,
|
y: -0.5,
|
||||||
actionHandler: fabric.controlsUtils.scalingEqually,
|
actionHandler: fabric.controlsUtils.scalingEqually,
|
||||||
|
cursorStyle: 'nesw-resize',
|
||||||
render: (
|
render: (
|
||||||
ctx: CanvasRenderingContext2D,
|
ctx: CanvasRenderingContext2D,
|
||||||
left: number,
|
left: number,
|
||||||
|
@ -137,6 +139,7 @@ MediaEditorFabricCropRect.prototype.controls = {
|
||||||
x: -0.5,
|
x: -0.5,
|
||||||
y: 0.5,
|
y: 0.5,
|
||||||
actionHandler: fabric.controlsUtils.scalingEqually,
|
actionHandler: fabric.controlsUtils.scalingEqually,
|
||||||
|
cursorStyle: 'nesw-resize',
|
||||||
render: (
|
render: (
|
||||||
ctx: CanvasRenderingContext2D,
|
ctx: CanvasRenderingContext2D,
|
||||||
left: number,
|
left: number,
|
||||||
|
@ -163,6 +166,7 @@ MediaEditorFabricCropRect.prototype.controls = {
|
||||||
x: 0.5,
|
x: 0.5,
|
||||||
y: 0.5,
|
y: 0.5,
|
||||||
actionHandler: fabric.controlsUtils.scalingEqually,
|
actionHandler: fabric.controlsUtils.scalingEqually,
|
||||||
|
cursorStyle: 'nwse-resize',
|
||||||
render: (
|
render: (
|
||||||
ctx: CanvasRenderingContext2D,
|
ctx: CanvasRenderingContext2D,
|
||||||
left: number,
|
left: number,
|
||||||
|
|
|
@ -2,14 +2,20 @@
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { fabric } from 'fabric';
|
import { fabric } from 'fabric';
|
||||||
import { customFabricObjectControls } from './util/customFabricObjectControls';
|
|
||||||
|
|
||||||
export class MediaEditorFabricPath extends fabric.Path {
|
export class MediaEditorFabricPath extends fabric.Path {
|
||||||
constructor(
|
constructor(
|
||||||
path?: string | Array<fabric.Point>,
|
path?: string | Array<fabric.Point>,
|
||||||
options?: fabric.IPathOptions
|
options?: fabric.IPathOptions
|
||||||
) {
|
) {
|
||||||
super(path, { fill: undefined, lockScalingFlip: true, ...(options || {}) });
|
super(path, {
|
||||||
|
evented: false,
|
||||||
|
fill: undefined,
|
||||||
|
hasControls: false,
|
||||||
|
lockScalingFlip: true,
|
||||||
|
selectable: false,
|
||||||
|
...(options || {}),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static override fromObject(
|
static override fromObject(
|
||||||
|
@ -26,4 +32,3 @@ export class MediaEditorFabricPath extends fabric.Path {
|
||||||
|
|
||||||
MediaEditorFabricPath.prototype.type = 'MediaEditorFabricPath';
|
MediaEditorFabricPath.prototype.type = 'MediaEditorFabricPath';
|
||||||
MediaEditorFabricPath.prototype.borderColor = '#ffffff';
|
MediaEditorFabricPath.prototype.borderColor = '#ffffff';
|
||||||
MediaEditorFabricPath.prototype.controls = customFabricObjectControls;
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ const resizeControl = new fabric.Control({
|
||||||
cursorStyleHandler: () => 'se-resize',
|
cursorStyleHandler: () => 'se-resize',
|
||||||
render: (ctx: CanvasRenderingContext2D, left: number, top: number) => {
|
render: (ctx: CanvasRenderingContext2D, left: number, top: number) => {
|
||||||
// circle
|
// circle
|
||||||
const size = 9;
|
const size = 12;
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.fillStyle = '#fff';
|
ctx.fillStyle = '#fff';
|
||||||
ctx.strokeStyle = '#fff';
|
ctx.strokeStyle = '#fff';
|
||||||
|
@ -18,7 +18,7 @@ const resizeControl = new fabric.Control({
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
|
|
||||||
// arrows NW & SE
|
// arrows NW & SE
|
||||||
const arrowSize = 4;
|
const arrowSize = 5;
|
||||||
ctx.fillStyle = '#3b3b3b';
|
ctx.fillStyle = '#3b3b3b';
|
||||||
ctx.strokeStyle = '#3b3b3b';
|
ctx.strokeStyle = '#3b3b3b';
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
|
@ -96,7 +96,7 @@ const deleteControl = new fabric.Control({
|
||||||
},
|
},
|
||||||
render: (ctx: CanvasRenderingContext2D, left: number, top: number) => {
|
render: (ctx: CanvasRenderingContext2D, left: number, top: number) => {
|
||||||
// circle
|
// circle
|
||||||
const size = 9;
|
const size = 12;
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.fillStyle = '#000';
|
ctx.fillStyle = '#000';
|
||||||
ctx.strokeStyle = '#000';
|
ctx.strokeStyle = '#000';
|
||||||
|
@ -106,7 +106,7 @@ const deleteControl = new fabric.Control({
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
|
|
||||||
// x
|
// x
|
||||||
const xSize = 3;
|
const xSize = 4;
|
||||||
ctx.fillStyle = '#fff';
|
ctx.fillStyle = '#fff';
|
||||||
ctx.strokeStyle = '#fff';
|
ctx.strokeStyle = '#fff';
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
|
|
Loading…
Add table
Reference in a new issue