|
@@ -12,16 +12,16 @@
|
|
|
<script lang="ts">
|
|
|
import { SMouseEvent, SUndoStack } from "@saga-web/base";
|
|
|
import { SColor, SPainter, SRect } from "@saga-web/draw";
|
|
|
- import { SGraphyItem, SGraphyScene, SGraphyView } from "@saga-web/graphy";
|
|
|
- import {SGraphyCommand} from "@saga-web/graphy/lib";
|
|
|
+ import { SGraphItem, SGraphScene, SGraphView } from "@saga-web/graph";
|
|
|
+ import {SGraphCommand} from "@saga-web/graph/lib";
|
|
|
import {SUndoCommand} from "@saga-web/base/lib";
|
|
|
import {SPoint} from "@saga-web/draw/lib";
|
|
|
|
|
|
- class RectItem extends SGraphyItem {
|
|
|
+ class RectItem extends SGraphItem {
|
|
|
width = 100;
|
|
|
height = 100;
|
|
|
|
|
|
- constructor(parent: SGraphyItem | null) {
|
|
|
+ constructor(parent: SGraphItem | null) {
|
|
|
super(parent);
|
|
|
this.moveable = true;
|
|
|
this.selectable = true;
|
|
@@ -40,10 +40,10 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- class CircleItem extends SGraphyItem {
|
|
|
+ class CircleItem extends SGraphItem {
|
|
|
r = 50;
|
|
|
|
|
|
- constructor(parent: SGraphyItem | null) {
|
|
|
+ constructor(parent: SGraphItem | null) {
|
|
|
super(parent);
|
|
|
this.moveable = true;
|
|
|
this.selectable = true;
|
|
@@ -61,7 +61,7 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- class SScene extends SGraphyScene {
|
|
|
+ class SScene extends SGraphScene {
|
|
|
undoStack = new SUndoStack();
|
|
|
/** 定义命令 */
|
|
|
cmd = 0;
|
|
@@ -71,7 +71,7 @@
|
|
|
}
|
|
|
|
|
|
|
|
|
- onMouseUp(event: SMouseEvent): void {
|
|
|
+ onMouseUp(event: SMouseEvent): boolean {
|
|
|
switch(this.cmd) {
|
|
|
case 1:
|
|
|
this.addCircle(event.x, event.y);
|
|
@@ -83,40 +83,41 @@
|
|
|
super.onMouseUp(event);
|
|
|
}
|
|
|
this.cmd = 0;
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
private addCircle(x: number, y: number): void {
|
|
|
- let item = new CircleItem();
|
|
|
+ let item = new CircleItem(null);
|
|
|
item.moveTo(x - 50, y - 50);
|
|
|
this.addItem(item);
|
|
|
- this.undoStack.push(new SGraphyAddCommand(this, item));
|
|
|
+ this.undoStack.push(new SGraphAddCommand(this, item));
|
|
|
item.connect("onMove", this, this.onItemMove.bind(this));
|
|
|
}
|
|
|
|
|
|
private addRect(x: number, y: number): void {
|
|
|
- let item = new RectItem();
|
|
|
+ let item = new RectItem(null);
|
|
|
item.moveTo(x - 50, y - 50);
|
|
|
this.addItem(item);
|
|
|
- this.undoStack.push(new SGraphyAddCommand(this, item));
|
|
|
+ this.undoStack.push(new SGraphAddCommand(this, item));
|
|
|
item.connect("onMove", this, this.onItemMove.bind(this));
|
|
|
}
|
|
|
|
|
|
- onItemMove(item: SGraphyItem, ...arg: any): void {
|
|
|
- this.undoStack.push(new SGraphyMoveCommand(this, item, arg[0][0] as SPoint, arg[0][1] as SPoint));
|
|
|
+ onItemMove(item: SGraphItem, ...arg: any): void {
|
|
|
+ this.undoStack.push(new SGraphMoveCommand(this, item, arg[0][0] as SPoint, arg[0][1] as SPoint));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- class TestView extends SGraphyView {
|
|
|
+ class TestView extends SGraphView {
|
|
|
constructor() {
|
|
|
super("undoFrame");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- class SGraphyAddCommand extends SGraphyCommand {
|
|
|
- item: SGraphyItem;
|
|
|
- parent: SGraphyItem | null;
|
|
|
+ class SGraphAddCommand extends SGraphCommand {
|
|
|
+ item: SGraphItem;
|
|
|
+ parent: SGraphItem | null;
|
|
|
|
|
|
- constructor(scene: SGraphyScene, item: SGraphyItem) {
|
|
|
+ constructor(scene: SGraphScene, item: SGraphItem) {
|
|
|
super(scene);
|
|
|
this.item = item;
|
|
|
this.parent = item.parent;
|
|
@@ -136,7 +137,7 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- class SGraphyDeleteCommand extends SGraphyCommand {
|
|
|
+ class SGraphDeleteCommand extends SGraphCommand {
|
|
|
mergeWith(command: SUndoCommand): boolean {
|
|
|
return false;
|
|
|
}
|
|
@@ -148,19 +149,19 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- class SGraphyMoveCommand extends SGraphyCommand {
|
|
|
- item: SGraphyItem;
|
|
|
+ class SGraphMoveCommand extends SGraphCommand {
|
|
|
+ item: SGraphItem;
|
|
|
old: SPoint;
|
|
|
pos: SPoint;
|
|
|
|
|
|
- constructor(scene: SGraphyScene, item: SGraphyItem, old: SPoint, pos: SPoint) {
|
|
|
+ constructor(scene: SGraphScene, item: SGraphItem, old: SPoint, pos: SPoint) {
|
|
|
super(scene);
|
|
|
this.item = item;
|
|
|
this.old = old;
|
|
|
this.pos = pos;
|
|
|
}
|
|
|
mergeWith(command: SUndoCommand): boolean {
|
|
|
- if (command instanceof SGraphyMoveCommand && command.item == this.item) {
|
|
|
+ if (command instanceof SGraphMoveCommand && command.item == this.item) {
|
|
|
command.pos = this.pos;
|
|
|
return true;
|
|
|
}
|
|
@@ -211,4 +212,4 @@
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
-</style>
|
|
|
+</style>
|