Browse Source

[完善] 文档注释

develop
徐振升 5 years ago
parent
commit
b72a9c5510
  1. 172
      src/app/working-area/working-area.component.ts

172
src/app/working-area/working-area.component.ts

@ -104,9 +104,15 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
// this.lineIconShadow.lineTo(100, 100);
});
}
/// <summary>
/// 创建单点图标
/// <summary>
/**
*
* @param source
* @param x
* @param y
* @param width
* @param height
* @param alpha
*/
private createSinglePointIcon(source: PIXI.Texture, x: number, y: number, width: number, height: number, alpha: number): PIXI.Sprite {
const singlePointIcon = new PIXI.Sprite(source);
singlePointIcon.x = x;
@ -245,14 +251,18 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
}
});
}
// 测试创建
/**
*
* @param texture
* @param points
*/
private createLineIconTest(texture: PIXI.Texture, points: PIXI.Point[]) {
const icon = new MultipointIcon(texture, points);
this.backgroundImage.addChild(icon);
}
/// <summary>
/// 创建背景图
/// <summary>
/**
*
*/
private createBackgroundImage(): void {
this.backgroundImage = PIXI.Sprite.from('assets/images/noImg.png');
this.backgroundImage.anchor.set(0.5);
@ -324,10 +334,11 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
});
this.app.stage.addChild(this.backgroundImage);
}
/// <summary>
/// 替换背景图
/// 参数{source:string} 可以是一个url地址,也可以是本地assets下的一个图片路径
/// <summary>
/**
*
* @param imageUri url地址,assets下的一个图片路径
* @param imageAngle
*/
public changeBackgroundImage(imageUri: string, imageAngle: number): void {
this.backgroundImage.texture = PIXI.Texture.from(imageUri);
this.backgroundImage.angle = imageAngle;
@ -335,13 +346,14 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
}
/**
*
* @param imageAngle
*/
public setBackgroundAngle(imageAngle: number) {
this.backgroundImage.angle = imageAngle;
}
/// <summary>
/// 创建单点图标影子
/// <summary>
/**
*
*/
private createSinglePointIconShadow(): void {
this.singlePointIconShadow = PIXI.Sprite.from('assets/images/noImg.png');
this.singlePointIconShadow.width = 32;
@ -351,43 +363,50 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
this.singlePointIconShadow.visible = false;
this.app.stage.addChild(this.singlePointIconShadow);
}
/// <summary>
/// 改变单点图标影子
/// <summary>
private changeSinglePointIconShadow(source: string): void {
this.singlePointIconShadow.texture = PIXI.Texture.from(source);
/**
*
* @param uri
*/
private changeSinglePointIconShadow(uri: string): void {
this.singlePointIconShadow.texture = PIXI.Texture.from(uri);
this.singlePointIconShadow.visible = true;
}
/// <>
/// 创建线图标影子
/// <>
/**
* 线
*/
private createLineIconShadow() {
this.app.stage.addChild(this.lineIconShadow);
}
/// <summary>
/// 开始绘画单点图标
/// <summary>
public beginPaintSinglePointIcon(source: string): void {
/**
*
* @param imageUri
*/
public beginPaintSinglePointIcon(imageUri: string): void {
this.cancelPaint();
this.paintMode = PaintMode.SinglePointIcon;
this.changeSinglePointIconShadow(source);
this.changeSinglePointIconShadow(imageUri);
}
// 开始绘画多边形
public beginPaintPolygonIcon(source: string): void {
/**
*
*/
public beginPaintPolygonIcon(): void {
this.cancelPaint();
this.paintMode = PaintMode.PolygonIcon;
}
// 开始绘画线
public beginPaintLineIcon(source: string): void {
/**
*
* @param imageUri
*/
public beginPaintLineIcon(imageUri: string): void {
this.cancelPaint();
this.paintMode = PaintMode.LineIcon;
this.changeSinglePointIconShadow(source);
this.changeSinglePointIconShadow(imageUri);
// this.lineIconShadow.lineStyle(1, 0xffd900, 1);
}
/// <summary>
/// 取消绘画
/// <summary>
/**
*
*/
private cancelPaint(): void {
switch (this.paintMode) {
case PaintMode.PaintEnd:
@ -405,24 +424,25 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
break;
}
}
/// <summary>
/// 画圆
/// <summary>
/**
*
* @param x
*/
paintShadowCircle(x: number): void {
this.circleShadow.beginFill(0xFFCC5A);
this.circleShadow.drawCircle(0, 0, x);
this.app.stage.addChild(this.circleShadow);
}
/// <summary>
/// 取消画圆
/// <summary>
/**
*
*/
cancelPaintShadowCircle(): void {
this.app.stage.removeChild(this.circleShadow);
}
}
/// <summary>
/// 绘制模式
/// <summary>
/**
*
*/
enum PaintMode {
SinglePointIcon,
LineIcon,
@ -431,17 +451,21 @@ enum PaintMode {
PaintEnd,
}
/// 多点图标
/**
* 线
*/
class MultipointIcon extends PIXI.Container {
public pointsData: PIXI.Point[];
public pointsGraphics: PIXI.Graphics[] = [];
public iconsTilingSprite: PIXI.TilingSprite[] = [];
/**
*
*
* @param texture
* @param points
*/
constructor(texture: PIXI.Texture, data: PIXI.Point[]) {
constructor(texture: PIXI.Texture, points: PIXI.Point[]) {
super();
this.pointsData = data;
this.pointsData = points;
// 画线图标
for (let i = 0, count = this.pointsData.length - 1; i < count; i++) {
const pointA = this.pointsData[i];
@ -584,8 +608,8 @@ class MultipointIcon extends PIXI.Container {
});
}
/**
*
* value: Boolean
*
* @param value
*/
public setPointVisiable(value: boolean) {
this.pointsGraphics.forEach((item) => {
@ -593,3 +617,51 @@ class MultipointIcon extends PIXI.Container {
});
}
}
interface IEventData {
// 事件唯一ID
uuid: number;
callback: (data: any) => void;
}
/**
*
*/
export default class Event {
public static eventUuid = 0;
public static eventList: { [eventName: string]: IEventData[] } = {};
public static register(eventName: string, callback: (data: any) => void): number {
this.eventUuid = this.eventUuid + 1;
if (this.eventList[eventName] === undefined) {
this.eventList[eventName] = [];
}
this.eventList[eventName][this.eventUuid] = { uuid: this.eventUuid, callback };
return this.eventUuid;
}
public static unregister(eventName: string, tag: number) {
if (tag == null) {
this.eventList[eventName] = undefined;
} else {
if (this.eventList[eventName] !== undefined && this.eventList[eventName][tag] !== undefined) {
this.eventList[eventName][tag] = undefined;
}
}
}
public static dispatch(eventName: string, data: any) {
const eventList: IEventData[] = this.eventList[eventName];
if (eventList !== undefined) {
for (const key in eventList) {
if (eventList[key].callback !== undefined) {
eventList[key].callback(data);
}
}
}
}
}

Loading…
Cancel
Save