ContainerRefPoint.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {Point, ViewTool} from './UIUtils';
  2. /**
  3. * 容器边界上的参考点
  4. * @author zhaoyk
  5. */
  6. export class ContainerRefPoint {
  7. static TL = "TL";
  8. static TR = "TR";
  9. static BR = "BR";
  10. static BL = "BL";
  11. containerId: string;
  12. name: string;
  13. location: Point;
  14. constructor(containerId:string, name:string){
  15. this.containerId = containerId;
  16. this.name = name;
  17. }
  18. static getRefPoints(containerId:string, conLocation: Point, conSize: Point): Array<ContainerRefPoint> {
  19. const points = new Array<ContainerRefPoint>();
  20. ContainerRefPoint.addPoint(containerId, ContainerRefPoint.TL, new Point(conLocation.x, conLocation.y), points);
  21. ContainerRefPoint.addPoint(containerId, ContainerRefPoint.TR, new Point(conLocation.x + conSize.x, conLocation.y), points);
  22. ContainerRefPoint.addPoint(containerId, ContainerRefPoint.BR, new Point(conLocation.x + conSize.x, conLocation.y + conSize.y), points);
  23. ContainerRefPoint.addPoint(containerId, ContainerRefPoint.BL, new Point(conLocation.x, conLocation.y + conSize.y), points);
  24. var len = conSize.x / 4;
  25. for (var i = 1; i <= 3; i++) {
  26. ContainerRefPoint.addPoint(containerId, "T" + i, new Point(conLocation.x + len * i, conLocation.y), points);
  27. ContainerRefPoint.addPoint(containerId, "B" + i, new Point(conLocation.x + len * i, conLocation.y + conSize.y), points);
  28. }
  29. len = conSize.y / 4;
  30. for (var i = 1; i <= 3; i++) {
  31. ContainerRefPoint.addPoint(containerId, "L" + i, new Point(conLocation.x, conLocation.y + len * i), points);
  32. ContainerRefPoint.addPoint(containerId, "R" + i, new Point(conLocation.x + conSize.x, conLocation.y + len * i), points);
  33. }
  34. return points;
  35. }
  36. static addPoint(containerId: string, name: string, location: Point, points: Array<ContainerRefPoint>): void{
  37. const refPoint = new ContainerRefPoint(containerId, name);
  38. refPoint.location = location;
  39. points.push(refPoint);
  40. }
  41. static getRefPoint(containerId:string, conLocation: Point, conSize: Point, refName: string) : ContainerRefPoint{
  42. const list = ContainerRefPoint.getRefPoints(containerId, conLocation, conSize);
  43. for(const p of list) {
  44. if(p.name.toLowerCase() == refName.toLowerCase())
  45. return p;
  46. }
  47. return null;
  48. }
  49. }