rt-sim-training-client/src/jmap/transformHandle.js

71 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-07-05 00:40:53 +08:00
2019-07-25 10:32:29 +08:00
import {createTransform, createBoundingRect} from './utils/parser';
2019-07-07 22:56:09 +08:00
2019-07-18 17:21:18 +08:00
class TransformHandle {
2019-11-06 18:37:32 +08:00
constructor(painter) {
this.$painter = painter;
2019-07-05 00:40:53 +08:00
2019-11-06 18:37:32 +08:00
this.parentLevel = painter.getParentLevel();
2019-07-19 15:17:58 +08:00
2019-11-06 18:37:32 +08:00
this.rect = { x: 0, y: 0, width: 0, height: 0 };
2019-07-19 18:32:19 +08:00
2019-11-06 18:37:32 +08:00
this.transform = createTransform({ scaleRate: 1, offsetX: 0, offsetY: 0 });
}
2019-07-09 09:24:54 +08:00
2019-11-06 18:37:32 +08:00
checkVisible(view) {
return createBoundingRect(view).intersect(this.rect);
}
2019-07-05 00:40:53 +08:00
2019-11-06 18:37:32 +08:00
revisibleView(view) {
if (this.checkVisible(view)) {
view.show();
} else {
view.hide();
}
2019-07-19 13:54:23 +08:00
2019-11-06 18:37:32 +08:00
view.dirty();
}
2019-07-09 09:24:54 +08:00
2019-11-06 18:37:32 +08:00
// 视图进行缩放/平移
transformView(view) {
if (view) {
view.transform = this.transform;
view.decomposeTransform();
this.revisibleView(view);
}
}
2019-07-09 09:24:54 +08:00
2019-11-06 18:37:32 +08:00
// 处理所有视图缩放/平移
transformAll() {
this.traverse(this.transformView, this);
}
2019-07-05 00:40:53 +08:00
2019-11-06 18:37:32 +08:00
// 重新计算显示图形
revisibleAll() {
this.traverse(this.revisibleView, this);
}
2019-07-09 09:24:54 +08:00
2019-11-06 18:37:32 +08:00
// 更新偏移量
updateTransform(opts) {
this.transform = createTransform(opts);
this.transformAll();
}
2019-07-19 11:11:34 +08:00
2019-11-06 18:37:32 +08:00
// 更新画布尺寸
updateZrSize(opts) {
this.rect = { x: 0, y: 0, width: opts.width, height: opts.height };
this.revisibleAll();
}
2019-07-21 20:20:41 +08:00
2019-11-06 18:37:32 +08:00
// 遍历group执行回调
traverse(cb, context) {
this.parentLevel.eachChild(level => {
level.eachChild((view) => {
cb.call(context, view);
}, context);
}, context);
}
2019-07-05 00:40:53 +08:00
}
2019-07-18 17:21:18 +08:00
export default TransformHandle;