|
@@ -5,6 +5,7 @@ import { CompObject } from "../SelectCtrl/compObj";
|
|
import { ObjsContainer } from "../SelectCtrl/ObjsContainer";
|
|
import { ObjsContainer } from "../SelectCtrl/ObjsContainer";
|
|
import { Matrix } from "../SelectCtrl/matrix";
|
|
import { Matrix } from "../SelectCtrl/matrix";
|
|
import { TransformCtrl } from "../TransformCtrl";
|
|
import { TransformCtrl } from "../TransformCtrl";
|
|
|
|
+import { CreateTransform } from "../../components/CompUI/basicUI/Transfer/transform";
|
|
|
|
|
|
function createImage(url:string) :Promise<HTMLImageElement> {
|
|
function createImage(url:string) :Promise<HTMLImageElement> {
|
|
return new Promise((r)=>{
|
|
return new Promise((r)=>{
|
|
@@ -46,14 +47,15 @@ export class ImageCropperCtrl extends ModuleControl<EditorModule> {
|
|
const initW = this.initValue.w;
|
|
const initW = this.initValue.w;
|
|
const initH = this.initValue.h;
|
|
const initH = this.initValue.h;
|
|
const initMtrx = this.initValue.matrix;
|
|
const initMtrx = this.initValue.matrix;
|
|
-
|
|
|
|
|
|
+
|
|
if (name == "Cross") { //取消操作
|
|
if (name == "Cross") { //取消操作
|
|
const compId = this.state.compId
|
|
const compId = this.state.compId
|
|
const imgComp = this.store.compMap[compId];
|
|
const imgComp = this.store.compMap[compId];
|
|
imgComp.value.matrix = initMtrx;
|
|
imgComp.value.matrix = initMtrx;
|
|
imgComp.value.w = initW;
|
|
imgComp.value.w = initW;
|
|
imgComp.value.h = initH;
|
|
imgComp.value.h = initH;
|
|
- this.state.compId = "";
|
|
|
|
|
|
+ this.close();
|
|
|
|
+
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
//确定操作
|
|
//确定操作
|
|
@@ -77,22 +79,23 @@ export class ImageCropperCtrl extends ModuleControl<EditorModule> {
|
|
imgComp.value.h = lastH;
|
|
imgComp.value.h = lastH;
|
|
}
|
|
}
|
|
} as any)
|
|
} as any)
|
|
|
|
+
|
|
|
|
+ this.close();
|
|
})
|
|
})
|
|
|
|
|
|
let tmpM = new Matrix();
|
|
let tmpM = new Matrix();
|
|
let tmpM2 = new Matrix();
|
|
let tmpM2 = new Matrix();
|
|
|
|
|
|
this.modifyCtrl.on("change", (dtx:number, dty:number)=>{
|
|
this.modifyCtrl.on("change", (dtx:number, dty:number)=>{
|
|
-
|
|
|
|
const imgComp = this.store.compMap[this.state.compId];
|
|
const imgComp = this.store.compMap[this.state.compId];
|
|
|
|
|
|
tmpM.copyFrom(this.modifyCtrl.objContainer.parent.worldTransform);
|
|
tmpM.copyFrom(this.modifyCtrl.objContainer.parent.worldTransform);
|
|
|
|
|
|
- const comp = new CompObject(imgComp);
|
|
|
|
|
|
+ // const comp = new CompObject(imgComp);
|
|
|
|
+ // tmpM2.copyFrom(comp.worldTransform)
|
|
|
|
+ // tmpM2.invert()
|
|
|
|
+ // tmpM.prepend(tmpM2)
|
|
|
|
|
|
- tmpM2.copyFrom(comp.worldTransform)
|
|
|
|
- tmpM2.invert()
|
|
|
|
- tmpM.prepend(tmpM2)
|
|
|
|
|
|
|
|
this.lastValue.w = this.modifyCtrl.objContainer.width;
|
|
this.lastValue.w = this.modifyCtrl.objContainer.width;
|
|
this.lastValue.h = this.modifyCtrl.objContainer.height;
|
|
this.lastValue.h = this.modifyCtrl.objContainer.height;
|
|
@@ -103,34 +106,53 @@ export class ImageCropperCtrl extends ModuleControl<EditorModule> {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ cancelTransform: ()=>void = ()=>{console.log("not cropper!!")};
|
|
|
|
+
|
|
|
|
+ async croppImage(id:string) {
|
|
|
|
|
|
- async croppImage(id :string) {
|
|
|
|
const imgComp = this.store.compMap[id]
|
|
const imgComp = this.store.compMap[id]
|
|
if (imgComp.compKey != "Image") return;
|
|
if (imgComp.compKey != "Image") return;
|
|
|
|
|
|
this.state.compId = id;
|
|
this.state.compId = id;
|
|
this.state.visible = true;
|
|
this.state.visible = true;
|
|
-
|
|
|
|
this.controls.historyCtrl.state.enable = false;
|
|
this.controls.historyCtrl.state.enable = false;
|
|
|
|
+ this.modifyCtrl.state.toolbarNames = ["Right", "Cross"];
|
|
|
|
+
|
|
|
|
+ const cardBox = this.controls.selectCtrl.getCurrCardBox();
|
|
|
|
+ this.modifyCtrl.baseBox.x = cardBox.left;
|
|
|
|
+ this.modifyCtrl.baseBox.y = cardBox.top;
|
|
|
|
+ this.modifyCtrl.baseBox.w = cardBox.width;
|
|
|
|
+ this.modifyCtrl.baseBox.h = cardBox.height;
|
|
|
|
+
|
|
|
|
+ const isChild = this.helper.isStreamCardChild(id)
|
|
|
|
+ if (isChild) {
|
|
|
|
+ await this.croppImageImpl(id, true);
|
|
|
|
+ } else {
|
|
|
|
+ await this.croppImageImpl(id, false);
|
|
|
|
+ }
|
|
|
|
+ const vm = CreateTransform(this.modifyCtrl);
|
|
|
|
+
|
|
|
|
+ const editLayer = this.helper.createEditElement(id)
|
|
|
|
+ if (!editLayer) return;
|
|
|
|
+
|
|
|
|
+ vm.mount(editLayer.dom);
|
|
|
|
+
|
|
|
|
+ this.cancelTransform = ()=>{
|
|
|
|
+ vm.unmount()
|
|
|
|
+ editLayer.destroy();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ async croppImageImpl(id :string, isChild= true) {
|
|
|
|
+
|
|
|
|
+ const imgComp = this.store.compMap[id]
|
|
const obj = new CompObject(imgComp);
|
|
const obj = new CompObject(imgComp);
|
|
const w = obj.width, h = obj.height; //图片的宽高
|
|
const w = obj.width, h = obj.height; //图片的宽高
|
|
const r1 = h / w;
|
|
const r1 = h / w;
|
|
const imgObj = await createImage(imgComp.value.url)
|
|
const imgObj = await createImage(imgComp.value.url)
|
|
const r2 = imgObj.height / imgObj.width;
|
|
const r2 = imgObj.height / imgObj.width;
|
|
|
|
|
|
- const selecCtrl = this.controls.selectCtrl;
|
|
|
|
- const cardBox = selecCtrl.getCurrCardBox();
|
|
|
|
- const pageBox = selecCtrl.getPageBox();
|
|
|
|
-
|
|
|
|
- const yoff = cardBox.top - pageBox.top;
|
|
|
|
- this.modifyCtrl.state.baseTop = yoff;
|
|
|
|
- this.modifyCtrl.baseBox.x = cardBox.left;
|
|
|
|
- this.modifyCtrl.baseBox.y = cardBox.top;
|
|
|
|
- this.modifyCtrl.baseBox.w = cardBox.width;
|
|
|
|
- this.modifyCtrl.baseBox.h = cardBox.height;
|
|
|
|
- this.modifyCtrl.state.toolbarNames = ["Right", "Cross"];
|
|
|
|
-
|
|
|
|
|
|
+ this.modifyCtrl.state.baseTop = 0;
|
|
const defaultScale = imgComp.value.s == undefined || (imgComp.value.s == 1 && imgComp.value.x == 0 && imgComp.value.y == 0);
|
|
const defaultScale = imgComp.value.s == undefined || (imgComp.value.s == 1 && imgComp.value.x == 0 && imgComp.value.y == 0);
|
|
let scale = 1;
|
|
let scale = 1;
|
|
let offsetX = 0;
|
|
let offsetX = 0;
|
|
@@ -181,11 +203,14 @@ export class ImageCropperCtrl extends ModuleControl<EditorModule> {
|
|
this.initValue.w = srcWidth;
|
|
this.initValue.w = srcWidth;
|
|
this.initValue.h = srcHeight;
|
|
this.initValue.h = srcHeight;
|
|
|
|
|
|
- //获取obj的image图片的世界大小
|
|
|
|
- const paths = this.helper.getCompTrees(id);
|
|
|
|
- const objC = new ObjsContainer([new CompObject(paths[2])]) //当前对象作为容器
|
|
|
|
- m.prepend(objC.parent.worldTransform);
|
|
|
|
-
|
|
|
|
|
|
+ //获取obj的image图片的世界大小
|
|
|
|
+ // const paths = this.helper.getCompTrees(id);
|
|
|
|
+ // const objC = new ObjsContainer([new CompObject(paths[2])]) //当前对象作为容器
|
|
|
|
+ // const wmx = new Matrix();
|
|
|
|
+ // wmx.copyFrom(objC.parent.worldTransform)
|
|
|
|
+ // wmx.tx = 0;
|
|
|
|
+ // wmx.ty = 0;
|
|
|
|
+ // m.prepend(wmx);
|
|
if (this.controls.selectCtrl.assistMagnet) {
|
|
if (this.controls.selectCtrl.assistMagnet) {
|
|
this.controls.selectCtrl.assistMagnet.enable = false;
|
|
this.controls.selectCtrl.assistMagnet.enable = false;
|
|
}
|
|
}
|
|
@@ -204,7 +229,8 @@ export class ImageCropperCtrl extends ModuleControl<EditorModule> {
|
|
}
|
|
}
|
|
|
|
|
|
close(): void {
|
|
close(): void {
|
|
- if ( !this.state.visible ) return;
|
|
|
|
|
|
+ this.cancelTransform();
|
|
|
|
+ this.cancelTransform = ()=>{console.log("empty")};
|
|
|
|
|
|
const compId = this.state.compId
|
|
const compId = this.state.compId
|
|
const imgComp = this.store.compMap[compId];
|
|
const imgComp = this.store.compMap[compId];
|