mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 01:58:27 +00:00
feat: implement rotation of element
This commit is contained in:
parent
516292a136
commit
ca3f83668d
10 changed files with 207 additions and 31 deletions
|
|
@ -6,3 +6,5 @@ export const CURSOR_RESIZE =
|
|||
export const CURSOR_DRAG_DEFAULT = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAApCAYAAABHomvIAAAEvUlEQVRYhc2Y20/cVRDHP8v+uKzAWkpDCtZq8BYhJkq8PBoJxgj7I2m0ryaSyFN9IT74pI8+8WJiggRj/APApFkSTGRJ+qKGUiyxbGPEWsUSuVhYC12Wy8+HmeMeYPe3d3WSye/k/M7le+bMzJkZ+J9ToEJreGVYN+vihcytstjQocUlAw0WCSoIVCv3Ae8CXwIt+u8XHVeOG8qLqgAHqAFCQCNwGugCthBJGd7S/tM6LqTzHI5KuqzgaoAHgEvAtwrkG2AG8FzXvep5nue67lX9N6P/PR1/SefXlBtkFXKNDUA/RyX1D9uUbYzOb9D1ygbSQU7eDMxhSSsSiVz3AxiJRK57nuf19/fPad8coqONFCBJPyUOIKc1OvcbgiY9ICDT8+0DHge2gR0gBeyTtviM5HeKAGlrrfMZVwhdAVaAr4F3KNF4gkA9cBbowOc68+3LwDn1Mhdy4/OcYk54nPr6+m54nofruvPa9SFQ6wfQTweNgTwInAGuQWk6mEUvHwb+Au4Dexx7ffK9+0q+CHWIBIOZ9skHYKWfK9tQ8gZoLDjIyWCg3ORY+2T8aYOyg4EaRIFrkCs4QU1NTSvabC20zyIDzuyfkYzEahHX8jHwE/LwXwHeJ4P7KIVIu5ouxFDC+HgLAy4MfEF2v1UpgOezATSiNVf6EvAWsD01NXVtdnb2bk9Pz81sp/q3KIi8t83Ae4DX0tJy0z7t8PDwD4FAYIX/WILVwKMAzc3Nu/agoaGhzmg0ugcsV0hIvlSNoH8IuIiebHJycrls4sotwaxGYvueAPAjEg3jum79yMjIr5WUjFLOxMpBIopWoBN4GfhOJ+4NDg4ulVt6i4uL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80lFMB/t/+V/sPGZfTmtMFR4EAAAAASUVORK5CYII=`;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type { UtilEventEmitter, CoreEvent } from '@idraw/types';
|
||||
import { limitAngle, loadImage, parseAngleToRadian } from '@idraw/util';
|
||||
import { CURSOR, CURSOR_RESIZE, CURSOR_DRAG_DEFAULT, CURSOR_DRAG_ACTIVE } from './cursor-image';
|
||||
import { CURSOR, CURSOR_RESIZE, CURSOR_DRAG_DEFAULT, CURSOR_DRAG_ACTIVE, CURSOR_RESIZE_ROTATE } from './cursor-image';
|
||||
|
||||
export class Cursor {
|
||||
#eventHub: UtilEventEmitter<CoreEvent>;
|
||||
|
|
@ -11,7 +11,8 @@ export class Cursor {
|
|||
auto: CURSOR,
|
||||
'drag-default': CURSOR_DRAG_DEFAULT,
|
||||
'drag-active': CURSOR_DRAG_ACTIVE,
|
||||
'rotate-0': CURSOR_RESIZE
|
||||
'rotate-0': CURSOR_RESIZE,
|
||||
rotate: CURSOR_RESIZE_ROTATE
|
||||
};
|
||||
constructor(
|
||||
container: HTMLDivElement,
|
||||
|
|
@ -31,6 +32,8 @@ export class Cursor {
|
|||
eventHub.on('cursor', (e) => {
|
||||
if (e.type === 'over-element' || !e.type) {
|
||||
this.#resetCursor('auto');
|
||||
} else if (e.type === 'resize-rotate') {
|
||||
this.#resetCursor('rotate');
|
||||
} else if (typeof e.type === 'string' && e.type?.startsWith('resize-')) {
|
||||
this.#setCursorResize(e);
|
||||
} else if (e.type === 'drag-default') {
|
||||
|
|
@ -64,6 +67,9 @@ export class Cursor {
|
|||
if (cursorKey.startsWith('rotate-') && this.#cursorImageMap[this.#cursorType]) {
|
||||
offsetX = 10;
|
||||
offsetY = 10;
|
||||
} else if (cursorKey === 'rotate') {
|
||||
offsetX = 10;
|
||||
offsetY = 10;
|
||||
}
|
||||
if (cursorKey === 'default') {
|
||||
this.#container.style.cursor = 'default';
|
||||
|
|
|
|||
|
|
@ -26,4 +26,6 @@ export const areaBorderWidth = 1;
|
|||
export const wrapperColor = '#1973ba';
|
||||
|
||||
export const lockColor = '#5b5959b5';
|
||||
|
||||
export const controllerSize = 10;
|
||||
// export const wrapperColor = '#1890ff';
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ import type {
|
|||
ViewSizeInfo,
|
||||
ElementSizeController
|
||||
} from '@idraw/types';
|
||||
import { rotateElementVertexes, calcViewVertexes } from '@idraw/util';
|
||||
import { rotateElementVertexes, calcViewPointSize, calcViewVertexes } from '@idraw/util';
|
||||
import type { AreaSize } from './types';
|
||||
|
||||
import { resizeControllerBorderWidth, areaBorderWidth, wrapperColor, selectWrapperBorderWidth, lockColor } from './config';
|
||||
import { resizeControllerBorderWidth, areaBorderWidth, wrapperColor, selectWrapperBorderWidth, lockColor, controllerSize } from './config';
|
||||
|
||||
function drawVertexes(
|
||||
ctx: ViewContext2D,
|
||||
|
|
@ -36,6 +36,69 @@ function drawVertexes(
|
|||
ctx.fill();
|
||||
}
|
||||
|
||||
function drawLine(ctx: ViewContext2D, start: PointSize, end: PointSize, opts: { borderColor: string; borderWidth: number; lineDash: number[] }) {
|
||||
const { borderColor, borderWidth, lineDash } = opts;
|
||||
ctx.setLineDash([]);
|
||||
ctx.lineWidth = borderWidth;
|
||||
ctx.strokeStyle = borderColor;
|
||||
ctx.setLineDash(lineDash);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(start.x, start.y);
|
||||
ctx.lineTo(end.x, end.y);
|
||||
ctx.closePath();
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
function drawCircleController(
|
||||
ctx: ViewContext2D,
|
||||
circleCenter: PointSize,
|
||||
opts: { borderColor: string; borderWidth: number; background: string; lineDash: number[]; size: number }
|
||||
) {
|
||||
const { size, borderColor, borderWidth, background } = opts;
|
||||
const center = circleCenter;
|
||||
const r = size / 2;
|
||||
|
||||
const a = r;
|
||||
const b = r;
|
||||
// 'content-box'
|
||||
|
||||
if (a >= 0 && b >= 0) {
|
||||
// draw border
|
||||
if (typeof borderWidth === 'number' && borderWidth > 0) {
|
||||
const ba = borderWidth / 2 + a;
|
||||
const bb = borderWidth / 2 + b;
|
||||
ctx.beginPath();
|
||||
ctx.strokeStyle = borderColor;
|
||||
ctx.lineWidth = borderWidth;
|
||||
ctx.circle(center.x, center.y, ba, bb, 0, 0, 2 * Math.PI);
|
||||
ctx.closePath();
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// draw content
|
||||
ctx.beginPath();
|
||||
ctx.fillStyle = background;
|
||||
ctx.circle(center.x, center.y, a, b, 0, 0, 2 * Math.PI);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
// ctx.setLineDash([]);
|
||||
// ctx.lineWidth = borderWidth;
|
||||
// ctx.strokeStyle = borderColor;
|
||||
// ctx.fillStyle = background;
|
||||
// ctx.setLineDash(lineDash);
|
||||
// ctx.beginPath();
|
||||
// ctx.moveTo(vertexes[0].x, vertexes[0].y);
|
||||
// ctx.lineTo(vertexes[1].x, vertexes[1].y);
|
||||
// ctx.lineTo(vertexes[2].x, vertexes[2].y);
|
||||
// ctx.lineTo(vertexes[3].x, vertexes[3].y);
|
||||
// ctx.lineTo(vertexes[0].x, vertexes[0].y);
|
||||
// ctx.closePath();
|
||||
// ctx.stroke();
|
||||
// ctx.fill();
|
||||
}
|
||||
|
||||
export function drawHoverVertexesWrapper(
|
||||
ctx: ViewContext2D,
|
||||
vertexes: ViewRectVertexes | null,
|
||||
|
|
@ -114,10 +177,11 @@ export function drawSelectedElementControllersVertexes(
|
|||
if (!controller) {
|
||||
return;
|
||||
}
|
||||
const { elementWrapper, topLeft, topRight, bottomLeft, bottomRight } = controller;
|
||||
const { elementWrapper, topLeft, topRight, bottomLeft, bottomRight, top, rotate } = controller;
|
||||
const wrapperOpts = { borderColor: wrapperColor, borderWidth: selectWrapperBorderWidth, background: 'transparent', lineDash: [] };
|
||||
const ctrlOpts = { ...wrapperOpts, borderWidth: resizeControllerBorderWidth, background: '#FFFFFF' };
|
||||
|
||||
drawLine(ctx, calcViewPointSize(top.center, opts), calcViewPointSize(rotate.center, opts), { ...ctrlOpts, borderWidth: 2 });
|
||||
drawVertexes(ctx, calcViewVertexes(elementWrapper, opts), wrapperOpts);
|
||||
// drawVertexes(ctx, calcViewVertexes(left.vertexes, opts), ctrlOpts);
|
||||
// drawVertexes(ctx, calcViewVertexes(right.vertexes, opts), ctrlOpts);
|
||||
|
|
@ -127,6 +191,7 @@ export function drawSelectedElementControllersVertexes(
|
|||
drawVertexes(ctx, calcViewVertexes(topRight.vertexes, opts), ctrlOpts);
|
||||
drawVertexes(ctx, calcViewVertexes(bottomLeft.vertexes, opts), ctrlOpts);
|
||||
drawVertexes(ctx, calcViewVertexes(bottomRight.vertexes, opts), ctrlOpts);
|
||||
drawCircleController(ctx, calcViewPointSize(rotate.center, opts), { ...ctrlOpts, size: controllerSize, borderWidth: 2 });
|
||||
}
|
||||
|
||||
export function drawElementListShadows(ctx: ViewContext2D, elements: Element<ElementType>[], opts?: Omit<RendererDrawElementOptions, 'loader'>) {
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@ import {
|
|||
calcElementVertexesInGroup,
|
||||
calcElementQueueVertexesQueueInGroup,
|
||||
calcElementSizeController,
|
||||
calcElementCenterFromVertexes,
|
||||
rotatePointInGroup,
|
||||
getGroupQueueFromList,
|
||||
findElementsFromList,
|
||||
findElementsFromListByPositions,
|
||||
deepResizeGroupElement
|
||||
} from '@idraw/util';
|
||||
import type { ViewRectVertexes, CoreEvent, ElementPosition } from '@idraw/types';
|
||||
import type { ViewRectVertexes, CoreEvent, ElementPosition, ViewScaleInfo, ViewSizeInfo, ElementSizeController } from '@idraw/types';
|
||||
import type {
|
||||
Point,
|
||||
PointSize,
|
||||
|
|
@ -33,6 +34,7 @@ import {
|
|||
import {
|
||||
getPointTarget,
|
||||
resizeElement,
|
||||
rotateElement,
|
||||
getSelectedListArea,
|
||||
calcSelectedElementsArea,
|
||||
isElementInGroup,
|
||||
|
|
@ -50,7 +52,8 @@ import {
|
|||
keyHoverElementVertexes,
|
||||
keySelectedElementList,
|
||||
keySelectedElementListVertexes,
|
||||
keySelectedElementController
|
||||
keySelectedElementController,
|
||||
controllerSize
|
||||
// keyDebugElemCenter,
|
||||
// keyDebugEnd0,
|
||||
// keyDebugEndHorizontal,
|
||||
|
|
@ -112,7 +115,7 @@ export const MiddlewareSelector: BoardMiddleware<DeepSelectorSharedStorage, Core
|
|||
if (list.length === 1) {
|
||||
const controller = calcElementSizeController(list[0], {
|
||||
groupQueue: sharer.getSharedStorage(keyGroupQueue),
|
||||
controllerSize: 10,
|
||||
controllerSize,
|
||||
viewScaleInfo: sharer.getActiveViewScaleInfo()
|
||||
});
|
||||
sharer.setSharedStorage(keySelectedElementController, controller);
|
||||
|
|
@ -389,6 +392,8 @@ export const MiddlewareSelector: BoardMiddleware<DeepSelectorSharedStorage, Core
|
|||
const data = sharer.getActiveStorage('data');
|
||||
const elems = getActiveElements();
|
||||
const scale = sharer.getActiveStorage('scale') || 1;
|
||||
const viewScaleInfo: ViewScaleInfo = sharer.getActiveViewScaleInfo() as unknown as ViewScaleInfo;
|
||||
const viewSizeInfo: ViewSizeInfo = sharer.getActiveViewSizeInfo() as unknown as ViewSizeInfo;
|
||||
const start = prevPoint;
|
||||
const end = e.point;
|
||||
const resizeType = sharer.getSharedStorage(keyResizeType);
|
||||
|
|
@ -432,26 +437,51 @@ export const MiddlewareSelector: BoardMiddleware<DeepSelectorSharedStorage, Core
|
|||
angle: 0 - angle
|
||||
} as Element<'group'>);
|
||||
});
|
||||
|
||||
let resizeStart: PointSize = start;
|
||||
let resizeEnd: PointSize = end;
|
||||
|
||||
if (groupQueue.length > 0) {
|
||||
resizeStart = rotatePointInGroup(start, pointGroupQueue);
|
||||
resizeEnd = rotatePointInGroup(end, pointGroupQueue);
|
||||
}
|
||||
const resizedElemSize = resizeElement(elems[0], { scale, start: resizeStart, end: resizeEnd, resizeType, sharer });
|
||||
elems[0].x = resizedElemSize.x;
|
||||
elems[0].y = resizedElemSize.y;
|
||||
if (elems[0].type === 'group' && elems[0].operations?.deepResize === true) {
|
||||
// TODO
|
||||
// elems[0].w = resizedElemSize.w;
|
||||
// elems[0].h = resizedElemSize.h;
|
||||
deepResizeGroupElement(elems[0] as Element<'group'>, {
|
||||
w: resizedElemSize.w,
|
||||
h: resizedElemSize.h
|
||||
if (resizeType === 'resize-rotate') {
|
||||
const controller: ElementSizeController = sharer.getSharedStorage(keySelectedElementController) as ElementSizeController;
|
||||
const viewVertexes: ViewRectVertexes = [
|
||||
controller.topLeft.center,
|
||||
controller.topRight.center,
|
||||
controller.bottomLeft.center,
|
||||
controller.bottomRight.center
|
||||
];
|
||||
|
||||
const viewCenter: PointSize = calcElementCenterFromVertexes(viewVertexes);
|
||||
const resizedElemSize = rotateElement(elems[0], {
|
||||
center: viewCenter,
|
||||
viewScaleInfo,
|
||||
viewSizeInfo,
|
||||
start,
|
||||
end,
|
||||
resizeType,
|
||||
sharer
|
||||
});
|
||||
|
||||
elems[0].angle = resizedElemSize.angle;
|
||||
} else {
|
||||
elems[0].w = resizedElemSize.w;
|
||||
elems[0].h = resizedElemSize.h;
|
||||
const resizedElemSize = resizeElement(elems[0], { scale, start: resizeStart, end: resizeEnd, resizeType, sharer });
|
||||
elems[0].x = resizedElemSize.x;
|
||||
elems[0].y = resizedElemSize.y;
|
||||
if (elems[0].type === 'group' && elems[0].operations?.deepResize === true) {
|
||||
// TODO
|
||||
// elems[0].w = resizedElemSize.w;
|
||||
// elems[0].h = resizedElemSize.h;
|
||||
deepResizeGroupElement(elems[0] as Element<'group'>, {
|
||||
w: resizedElemSize.w,
|
||||
h: resizedElemSize.h
|
||||
});
|
||||
} else {
|
||||
elems[0].w = resizedElemSize.w;
|
||||
elems[0].h = resizedElemSize.h;
|
||||
}
|
||||
}
|
||||
|
||||
updateSelectedElementList([elems[0]]);
|
||||
|
|
|
|||
|
|
@ -66,7 +66,8 @@ export type ResizeType =
|
|||
| 'resize-top-left'
|
||||
| 'resize-top-right'
|
||||
| 'resize-bottom-left'
|
||||
| 'resize-bottom-right';
|
||||
| 'resize-bottom-right'
|
||||
| 'resize-rotate';
|
||||
|
||||
export type PointTargetType = null | ResizeType | 'list-area' | 'over-element';
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@ import {
|
|||
rotatePointInGroup,
|
||||
rotatePoint,
|
||||
parseAngleToRadian,
|
||||
limitAngle
|
||||
parseRadianToAngle,
|
||||
limitAngle,
|
||||
calcRadian
|
||||
} from '@idraw/util';
|
||||
import type { ViewRectVertexes, ElementSizeController, StoreSharer } from '@idraw/types';
|
||||
import type { ViewRectVertexes, ElementSizeController, StoreSharer, ViewScaleInfo, ViewSizeInfo } from '@idraw/types';
|
||||
import type {
|
||||
Data,
|
||||
Element,
|
||||
|
|
@ -18,13 +20,11 @@ import type {
|
|||
PointSize,
|
||||
PointTarget,
|
||||
PointTargetType,
|
||||
ViewScaleInfo,
|
||||
ViewCalculator,
|
||||
ElementType,
|
||||
ElementSize,
|
||||
ResizeType,
|
||||
AreaSize,
|
||||
ViewSizeInfo
|
||||
AreaSize
|
||||
} from './types';
|
||||
// import { keyDebugElemCenter, keyDebugEnd0, keyDebugEndHorizontal, keyDebugEndVertical, keyDebugStartHorizontal, keyDebugStartVertical } from './config';
|
||||
|
||||
|
|
@ -104,8 +104,8 @@ export function getPointTarget(
|
|||
|
||||
// resize
|
||||
if (selectedElementController) {
|
||||
const { left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight } = selectedElementController;
|
||||
const ctrls = [left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight];
|
||||
const { left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight, rotate } = selectedElementController;
|
||||
const ctrls = [left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight, rotate];
|
||||
for (let i = 0; i < ctrls.length; i++) {
|
||||
const ctrl = ctrls[i];
|
||||
if (isPointInViewActiveVertexes(p, { ctx, vertexes: ctrl.vertexes, viewSizeInfo, viewScaleInfo })) {
|
||||
|
|
@ -819,6 +819,37 @@ export function resizeElement(
|
|||
return { x, y, w, h, angle: elem.angle };
|
||||
}
|
||||
|
||||
export function rotateElement(
|
||||
elem: Element<ElementType>,
|
||||
opts: {
|
||||
center: PointSize;
|
||||
start: PointSize;
|
||||
end: PointSize;
|
||||
resizeType: ResizeType;
|
||||
viewScaleInfo: ViewScaleInfo;
|
||||
viewSizeInfo: ViewSizeInfo;
|
||||
sharer: StoreSharer; // TODO
|
||||
}
|
||||
): ElementSize {
|
||||
const { x, y, w, h, angle = 0 } = elem;
|
||||
const { center, start, end, viewScaleInfo, viewSizeInfo } = opts;
|
||||
const elemCenter = calcViewPointSize(center, {
|
||||
viewScaleInfo,
|
||||
viewSizeInfo
|
||||
});
|
||||
const startAngle = limitAngle(angle);
|
||||
const changedRadian = calcRadian(elemCenter, start, end);
|
||||
const endAngle = startAngle + parseRadianToAngle(changedRadian);
|
||||
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
w,
|
||||
h,
|
||||
angle: endAngle
|
||||
};
|
||||
}
|
||||
|
||||
export function getSelectedListArea(
|
||||
data: Data,
|
||||
opts: {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ export type ElementSizeControllerType =
|
|||
| 'left-middle'
|
||||
| 'right-middle'
|
||||
| 'top-middle'
|
||||
| 'bottom-middle';
|
||||
| 'bottom-middle'
|
||||
| 'rotate';
|
||||
|
||||
export interface ElementSizeControllerItem {
|
||||
type: ElementSizeControllerType;
|
||||
|
|
@ -31,9 +32,9 @@ export interface ElementSizeController {
|
|||
topRight: ElementSizeControllerItem;
|
||||
bottomLeft: ElementSizeControllerItem;
|
||||
bottomRight: ElementSizeControllerItem;
|
||||
|
||||
topMiddle: ElementSizeControllerItem;
|
||||
bottomMiddle: ElementSizeControllerItem;
|
||||
leftMiddle: ElementSizeControllerItem;
|
||||
rightMiddle: ElementSizeControllerItem;
|
||||
rotate: ElementSizeControllerItem;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ export {
|
|||
calcElementCenter,
|
||||
calcElementCenterFromVertexes,
|
||||
rotatePointInGroup,
|
||||
limitAngle
|
||||
limitAngle,
|
||||
calcRadian
|
||||
} from './lib/rotate';
|
||||
export {
|
||||
getSelectedElementUUIDs,
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ export function calcElementSizeController(
|
|||
|
||||
const ctrlSize = (controllerSize && controllerSize > 0 ? controllerSize : 8) / viewScaleInfo.scale;
|
||||
const { x, y, w, h, angle = 0 } = elemSize;
|
||||
|
||||
const ctrlGroupQueue = [
|
||||
...[
|
||||
{
|
||||
|
|
@ -48,6 +49,17 @@ export function calcElementSizeController(
|
|||
});
|
||||
|
||||
const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue }) as ViewRectVertexes;
|
||||
const rotateElemVertexes = calcElementVertexesInGroup(
|
||||
{
|
||||
x: x - ctrlSize * 2,
|
||||
y: y - ctrlSize * 2,
|
||||
h: h + ctrlSize * 4,
|
||||
w: w + ctrlSize * 4,
|
||||
angle
|
||||
},
|
||||
{ groupQueue: [...groupQueue] }
|
||||
) as ViewRectVertexes;
|
||||
|
||||
const topCenter = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
|
||||
const rightCenter = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
|
||||
const bottomCenter = getCenterFromTwoPoints(vertexes[2], vertexes[3]);
|
||||
|
|
@ -83,6 +95,26 @@ export function calcElementSizeController(
|
|||
const bottomMiddleVertexes = calcElementVertexes(bottomMiddleSize);
|
||||
const leftMiddleVertexes = calcElementVertexes(leftMiddleSize);
|
||||
|
||||
// const originRotateCenter: PointSize = {
|
||||
// x: x + w / 2,
|
||||
// y: y - ctrlSize * 4
|
||||
// };
|
||||
|
||||
// const rotateCenter = topCenter;
|
||||
const rotateCenter = getCenterFromTwoPoints(rotateElemVertexes[0], rotateElemVertexes[1]);
|
||||
const rotateSize = createControllerElementSizeFromCenter(rotateCenter, { size: ctrlSize, angle: totalAngle });
|
||||
const rotateVertexes = calcElementVertexes(rotateSize);
|
||||
|
||||
// const rotateCtrlElem: ElementSize = {
|
||||
// x: originRotateCenter.x - ctrlSize / 2,
|
||||
// y: originRotateCenter.x - ctrlSize / 2,
|
||||
// w: ctrlSize,
|
||||
// h: ctrlSize,
|
||||
// angle
|
||||
// };
|
||||
// const rotateVertexes = calcElementVertexesInGroup(rotateCtrlElem, { groupQueue }) as ViewRectVertexes;
|
||||
// const rotateCenter = getCenterFromTwoPoints(rotateVertexes[0], rotateVertexes[2]);
|
||||
|
||||
const sizeController: ElementSizeController = {
|
||||
elementWrapper: vertexes,
|
||||
left: {
|
||||
|
|
@ -144,6 +176,11 @@ export function calcElementSizeController(
|
|||
type: 'bottom-middle',
|
||||
vertexes: bottomMiddleVertexes,
|
||||
center: bottomCenter
|
||||
},
|
||||
rotate: {
|
||||
type: 'rotate',
|
||||
vertexes: rotateVertexes,
|
||||
center: rotateCenter
|
||||
}
|
||||
};
|
||||
return sizeController;
|
||||
|
|
|
|||
Loading…
Reference in a new issue