|
@@ -168,11 +168,14 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
* @param item 当前选中的 item
|
|
|
*/
|
|
|
addItem(item: SGraphItem): void {
|
|
|
+ // 遍历已选中的 item 的列表
|
|
|
for (let i = 0; i < this.itemList.length; i++) {
|
|
|
+ // 已存在不处理
|
|
|
if (this.itemList[i] == item) {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
+ // item 可选且可见
|
|
|
if (item.selectable && item.visible) {
|
|
|
item.selected = true;
|
|
|
this.itemList.push(item);
|
|
@@ -186,10 +189,12 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
* @param item 当前选中的 item
|
|
|
*/
|
|
|
setItem(item: SGraphItem): void {
|
|
|
+ // 重置所有已选中 item
|
|
|
this.itemList.forEach((t: SGraphItem): void => {
|
|
|
t.selected = false;
|
|
|
});
|
|
|
this.itemList.length = 0;
|
|
|
+ // 可选且可见
|
|
|
if (item.selectable && item.visible) {
|
|
|
item.selected = true;
|
|
|
this.itemList.push(item);
|
|
@@ -201,6 +206,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
* 清空选择对象
|
|
|
*/
|
|
|
clear(): void {
|
|
|
+ // 重置所有选中 item
|
|
|
this.itemList.forEach((t: SGraphItem): void => {
|
|
|
t.selected = false;
|
|
|
});
|
|
@@ -214,7 +220,9 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
* @param item 当前选中的 item
|
|
|
*/
|
|
|
toggleItem(item: SGraphItem): void {
|
|
|
+ // 遍历已选中列表
|
|
|
for (let i = 0; i < this.itemList.length; i++) {
|
|
|
+ // 已选中则反选
|
|
|
if (this.itemList[i] == item) {
|
|
|
this.itemList[i].selected = false;
|
|
|
this.itemList.splice(i, 1);
|
|
@@ -228,6 +236,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
+ // 可选且可见
|
|
|
if (item.selectable && item.visible) {
|
|
|
item.selected = true;
|
|
|
this.itemList.push(item);
|
|
@@ -241,31 +250,40 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
* @param type 对齐方式
|
|
|
*/
|
|
|
layout(type: SGraphLayoutType): void {
|
|
|
+ // 已选中列表少于2项
|
|
|
if (this.itemList.length < 2) {
|
|
|
return;
|
|
|
}
|
|
|
switch (type) {
|
|
|
+ // 左对齐
|
|
|
case SGraphLayoutType.Left:
|
|
|
this.alignLeft();
|
|
|
break;
|
|
|
+ // 底对齐
|
|
|
case SGraphLayoutType.Bottom:
|
|
|
this.alignBottom();
|
|
|
break;
|
|
|
+ // 水平居中
|
|
|
case SGraphLayoutType.Center:
|
|
|
this.alignCenter();
|
|
|
break;
|
|
|
+ // 垂直分布
|
|
|
case SGraphLayoutType.Horizontal:
|
|
|
this.alignHorizontal();
|
|
|
break;
|
|
|
+ // 垂直居中
|
|
|
case SGraphLayoutType.Middle:
|
|
|
this.alignMiddle();
|
|
|
break;
|
|
|
+ // 右对齐
|
|
|
case SGraphLayoutType.Right:
|
|
|
this.alignRight();
|
|
|
break;
|
|
|
+ // 顶对齐
|
|
|
case SGraphLayoutType.Top:
|
|
|
this.alignTop();
|
|
|
break;
|
|
|
+ // 垂直分布
|
|
|
case SGraphLayoutType.Vertical:
|
|
|
this.alignVertical();
|
|
|
break;
|
|
@@ -281,19 +299,24 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
* @param type 操作类型
|
|
|
*/
|
|
|
setOrder(type: SOrderSetType): void {
|
|
|
+ // 已选中列表少于1项
|
|
|
if (this.itemList.length < 1) {
|
|
|
return;
|
|
|
}
|
|
|
switch (type) {
|
|
|
+ // 置顶
|
|
|
case SOrderSetType.Top:
|
|
|
this.setTop();
|
|
|
break;
|
|
|
+ // 置底
|
|
|
case SOrderSetType.Bottom:
|
|
|
this.setBottom();
|
|
|
break;
|
|
|
+ // 上移一层
|
|
|
case SOrderSetType.After:
|
|
|
this.setAfter();
|
|
|
break;
|
|
|
+ // 下移一层
|
|
|
case SOrderSetType.Before:
|
|
|
this.setBefore();
|
|
|
break;
|
|
@@ -313,8 +336,10 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
standardItem.boundingRect().x,
|
|
|
standardItem.boundingRect().y
|
|
|
);
|
|
|
+ // 遍历已选中列表
|
|
|
for (let i = 1; i < this.itemList.length; i++) {
|
|
|
let curItem = this.itemList[i];
|
|
|
+ // 可移动
|
|
|
if (curItem.moveable) {
|
|
|
// 将 p 转换为当前 item 中的坐标
|
|
|
let p1 = curItem.mapFromScene(p.x, p.y);
|
|
@@ -335,8 +360,10 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
standardItem.boundingRect().x,
|
|
|
standardItem.boundingRect().y
|
|
|
);
|
|
|
+ // 遍历已选中列表
|
|
|
for (let i = 1; i < this.itemList.length; i++) {
|
|
|
let curItem = this.itemList[i];
|
|
|
+ // 可移动
|
|
|
if (curItem.moveable) {
|
|
|
let p1 = curItem.mapFromScene(p.x, p.y);
|
|
|
curItem.y =
|
|
@@ -355,8 +382,10 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
standardItem.boundingRect().right,
|
|
|
standardItem.boundingRect().bottom
|
|
|
);
|
|
|
+ // 遍历已选中列表
|
|
|
for (let i = 1; i < this.itemList.length; i++) {
|
|
|
let curItem = this.itemList[i];
|
|
|
+ // 可移动
|
|
|
if (curItem.moveable) {
|
|
|
let p1 = curItem.mapFromScene(p.x, p.y);
|
|
|
curItem.x =
|
|
@@ -376,8 +405,10 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
standardItem.boundingRect().right,
|
|
|
standardItem.boundingRect().bottom
|
|
|
);
|
|
|
+ // 遍历已选中列表
|
|
|
for (let i = 1; i < this.itemList.length; i++) {
|
|
|
let curItem = this.itemList[i];
|
|
|
+ // 可移动
|
|
|
if (curItem.moveable) {
|
|
|
let p1 = curItem.mapFromScene(p.x, p.y);
|
|
|
curItem.y =
|
|
@@ -398,8 +429,10 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
let center = standardItem.boundingRect().center();
|
|
|
// 中心点转换为场景坐标
|
|
|
let p = standardItem.mapToScene(center.x, center.y);
|
|
|
+ // 遍历已选中列表
|
|
|
for (let i = 1; i < this.itemList.length; i++) {
|
|
|
let curItem = this.itemList[i];
|
|
|
+ // 可移动
|
|
|
if (curItem.moveable) {
|
|
|
let p1 = curItem.mapFromScene(p.x, p.y);
|
|
|
// 根据等式差值相等 newcenterx - oldcenterx = newposx - oldposx => newposx = newcenterx - oldcenterx + oldposx
|
|
@@ -421,8 +454,10 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
let center = standardItem.boundingRect().center();
|
|
|
// 中心点转换为场景坐标
|
|
|
let p = standardItem.mapToScene(center.x, center.y);
|
|
|
+ // 遍历已选中列表
|
|
|
for (let i = 1; i < this.itemList.length; i++) {
|
|
|
let curItem = this.itemList[i];
|
|
|
+ // 可移动
|
|
|
if (curItem.moveable) {
|
|
|
let p1 = curItem.mapFromScene(p.x, p.y);
|
|
|
curItem.y =
|
|
@@ -437,9 +472,11 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
* 垂直分布
|
|
|
*/
|
|
|
private alignVertical(): void {
|
|
|
+ // 已选中列表不足3项
|
|
|
if (this.itemList.length < 3) {
|
|
|
return;
|
|
|
}
|
|
|
+ // 遍历选中列表
|
|
|
for (let i = 0; i < this.itemList.length - 1; i++) {
|
|
|
for (let j = 0; j < this.itemList.length - 1 - i; j++) {
|
|
|
let curItemCenter = this.itemList[j].boundingRect().center();
|
|
@@ -472,7 +509,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
bottom.mapToScene(bottomCenter.x, bottomCenter.y).y -
|
|
|
top.mapToScene(topCenter.x, topCenter.y).y;
|
|
|
let average = leftToRight / (this.itemList.length - 1);
|
|
|
-
|
|
|
+ // 遍历选中列表
|
|
|
for (let k = 1; k < this.itemList.length - 1; k++) {
|
|
|
let curItem = this.itemList[k];
|
|
|
if (curItem.moveable) {
|
|
@@ -493,9 +530,11 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
* 水平分布
|
|
|
*/
|
|
|
private alignHorizontal(): void {
|
|
|
+ // 已选中列表不足3项
|
|
|
if (this.itemList.length < 3) {
|
|
|
return;
|
|
|
}
|
|
|
+ // 遍历选中列表
|
|
|
for (let i = 0; i < this.itemList.length - 1; i++) {
|
|
|
for (let j = 0; j < this.itemList.length - 1 - i; j++) {
|
|
|
let curItemCenter = this.itemList[j].boundingRect().center();
|
|
@@ -529,6 +568,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
left.mapToScene(leftCenter.x, leftCenter.y).x;
|
|
|
let average = leftToRight / (this.itemList.length - 1);
|
|
|
|
|
|
+ // 遍历选中列表
|
|
|
for (let k = 1; k < this.itemList.length - 1; k++) {
|
|
|
let curItem = this.itemList[k];
|
|
|
if (curItem.moveable) {
|
|
@@ -601,6 +641,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
*/
|
|
|
private setBefore(): void {
|
|
|
const arr: SGraphItem[] = this.sortItemList(this.itemList, false);
|
|
|
+ // 按顺序 zOrder 减小
|
|
|
arr.forEach((it): void => {
|
|
|
if (it.parent) {
|
|
|
const min = it.zOrder;
|
|
@@ -635,6 +676,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
*/
|
|
|
private setAfter(): void {
|
|
|
const arr: SGraphItem[] = this.sortItemList(this.itemList, false);
|
|
|
+ // 按顺序 zOrder 增加
|
|
|
arr.forEach((it): void => {
|
|
|
if (it.parent) {
|
|
|
const max = it.zOrder;
|
|
@@ -742,6 +784,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
if (this.itemList.length) {
|
|
|
const fir = this.itemList[0];
|
|
|
let rect = fir.boundingRect().adjusted(fir.pos.x, fir.pos.y, 0, 0);
|
|
|
+ // 遍历选中列表
|
|
|
for (let i = 1; i < this.itemList.length; i++) {
|
|
|
const cur = this.itemList[i];
|
|
|
rect = rect.unioned(
|
|
@@ -785,6 +828,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
getNearestPoint(p: SPoint): void {
|
|
|
let len = this.sceneDis;
|
|
|
this.curIndex = -1;
|
|
|
+ // 遍历 8 个控制点
|
|
|
for (let i = 0; i < this.pointList.length; i++) {
|
|
|
let dis = SMathUtil.pointDistance(
|
|
|
p.x,
|
|
@@ -805,6 +849,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
* @return 对象边界区域
|
|
|
*/
|
|
|
boundingRect(): SRect {
|
|
|
+ // 可见
|
|
|
if (this.visible) {
|
|
|
return new SRect(
|
|
|
-this.sceneDis,
|
|
@@ -840,12 +885,15 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
* @return 是否处理事件
|
|
|
*/
|
|
|
onMouseDown(event: SMouseEvent): boolean {
|
|
|
+ // 鼠标左键
|
|
|
if (event.buttons == 1) {
|
|
|
this.getNearestPoint(new SPoint(event.x, event.y));
|
|
|
+ // 未店家到控制点
|
|
|
if (this.curIndex < 0) {
|
|
|
this.curPoint = undefined;
|
|
|
return super.onMouseDown(event);
|
|
|
} else {
|
|
|
+ // 否则
|
|
|
const cur = this.pointList[this.curIndex];
|
|
|
this.curPoint = new SPoint(cur.x, cur.y);
|
|
|
this.oldWidth = this.width;
|
|
@@ -866,6 +914,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
*/
|
|
|
onMouseMove(event: SMouseEvent): boolean {
|
|
|
this.setCursor(9);
|
|
|
+ // 点击到控制点且有选中的 item ,item 可以改变大小
|
|
|
if (
|
|
|
this.curIndex > -1 &&
|
|
|
this.count == 1 &&
|
|
@@ -880,6 +929,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
const oldSize = new SSize(this.width, this.height);
|
|
|
let resultX, resultY;
|
|
|
switch (this.curIndex) {
|
|
|
+ // 左上角
|
|
|
case 0:
|
|
|
resultX = this.width - difX;
|
|
|
resultY = this.height - difY;
|
|
@@ -892,6 +942,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
this.y = this.y + mp.y;
|
|
|
}
|
|
|
break;
|
|
|
+ // 中上
|
|
|
case 1:
|
|
|
resultY = this.height - difY;
|
|
|
if (resultY > this.minHeight && resultY < this.maxHeight) {
|
|
@@ -899,6 +950,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
this.y = this.y + mp.y;
|
|
|
}
|
|
|
break;
|
|
|
+ // 右上
|
|
|
case 2:
|
|
|
resultX = this.oldWidth + difX;
|
|
|
resultY = this.height - difY;
|
|
@@ -910,12 +962,14 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
this.y = this.y + mp.y;
|
|
|
}
|
|
|
break;
|
|
|
+ // 右中
|
|
|
case 3:
|
|
|
resultX = this.oldWidth + difX;
|
|
|
if (resultX > this.minWidth && resultX < this.maxWidth) {
|
|
|
this.width = resultX;
|
|
|
}
|
|
|
break;
|
|
|
+ // 右下
|
|
|
case 4:
|
|
|
resultX = this.oldWidth + difX;
|
|
|
resultY = this.oldHeight + difY;
|
|
@@ -926,12 +980,14 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
this.height = resultY;
|
|
|
}
|
|
|
break;
|
|
|
+ // 中下
|
|
|
case 5:
|
|
|
resultY = this.oldHeight + difY;
|
|
|
if (resultY > this.minHeight && resultY < this.maxHeight) {
|
|
|
this.height = resultY;
|
|
|
}
|
|
|
break;
|
|
|
+ // 左下
|
|
|
case 6:
|
|
|
resultX = this.width - difX;
|
|
|
resultY = this.oldHeight + difY;
|
|
@@ -943,6 +999,7 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
this.height = resultY;
|
|
|
}
|
|
|
break;
|
|
|
+ // 左中
|
|
|
case 7:
|
|
|
resultX = this.width - difX;
|
|
|
if (resultX > this.minWidth && resultX < this.maxWidth) {
|
|
@@ -958,11 +1015,13 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
this.calExtreme();
|
|
|
} else {
|
|
|
let flag = true;
|
|
|
+ // 所有选中的均可移动
|
|
|
for (let v of this.itemList) {
|
|
|
if (!v.moveable) {
|
|
|
flag = false;
|
|
|
}
|
|
|
}
|
|
|
+ // 所有均可移动
|
|
|
if (flag) {
|
|
|
super.onMouseMove(event);
|
|
|
this.setCursor(8);
|
|
@@ -1031,10 +1090,13 @@ export class SGraphSelectContainer extends SGraphItem {
|
|
|
|
|
|
const r = painter.toPx(this.radius);
|
|
|
painter.pen.lineDash = [];
|
|
|
+ // 遍历控制点
|
|
|
this.pointList.forEach((t, i): void => {
|
|
|
if (i == this.curIndex) {
|
|
|
+ // 是按下的项
|
|
|
painter.brush.color = this.fillColor;
|
|
|
} else {
|
|
|
+ // 否则
|
|
|
painter.brush.color = SColor.White;
|
|
|
}
|
|
|
painter.drawCircle(t.x, t.y, r);
|