添加画布接口,调整相关引入

This commit is contained in:
walker 2023-08-31 15:30:08 +08:00
parent 7c32c51462
commit b327c6b4c4
9 changed files with 54 additions and 22 deletions

View File

@ -1,19 +1,19 @@
import { GraphicData, JlGraphic } from '../core';
import { JlOperation } from '../operation';
import { ICanvasProperties, IGraphicApp, JlCanvas } from './JlGraphicApp';
import { ICanvasProperties, IGraphicApp, IJlCanvas } from './JlGraphicApp';
/**
*
*/
export class UpdateCanvasOperation extends JlOperation {
obj: JlCanvas;
obj: IJlCanvas;
old: ICanvasProperties;
data: ICanvasProperties;
description = '';
constructor(
app: IGraphicApp,
obj: JlCanvas,
obj: IJlCanvas,
old: ICanvasProperties,
data: ICanvasProperties
) {

View File

@ -32,7 +32,7 @@ import {
GraphicAppOptions,
ICanvasProperties,
IGraphicApp,
JlCanvas,
IJlCanvas,
} from './JlGraphicApp';
/**
@ -76,7 +76,7 @@ export abstract class GraphicDrawAssistant<
this.app.registerGraphicTemplates(this.graphicTemplate);
}
public get canvas(): JlCanvas {
public get canvas(): IJlCanvas {
return this.app.canvas;
}

View File

@ -114,7 +114,37 @@ export class CanvasData implements ICanvasProperties {
}
}
export class JlCanvas extends Container {
export interface IJlCanvas extends Container {
/**
*
*/
get properties(): ICanvasProperties;
/**
*
*/
get scene(): IGraphicScene;
/**
*
* @param properties
*/
update(properties: ICanvasProperties): void;
/**
*
* @param appends
*/
addAssistantAppends(...appends: DisplayObject[]): void;
/**
*
* @param appends
*/
removeAssistantAppends(...appends: DisplayObject[]): void;
/**
*
*/
saveData(): ICanvasProperties;
}
export class JlCanvas extends Container implements IJlCanvas {
__JlCanvas = true;
type = 'Canvas';
scene: IGraphicScene;
@ -382,7 +412,7 @@ export interface IGraphicScene extends EventEmitter<GraphicAppEvents> {
/**
*
*/
get canvas(): JlCanvas;
get canvas(): IJlCanvas;
/**
* dom
*/
@ -1034,6 +1064,8 @@ abstract class GraphicSceneBase
*/
destroy(): void {
console.debug('场景销毁', this);
this.unbindDom();
if (this.wsMsgBroker) {
this.wsMsgBroker.close();
}
@ -1044,7 +1076,6 @@ abstract class GraphicSceneBase
this.canvas.destroy(true);
this.viewport.destroy();
this.pixi.destroy(true, true);
this.unbindDom();
}
}

View File

@ -14,6 +14,7 @@ import {
GraphicAppOptions,
IGraphicApp,
IGraphicStorage,
IJlCanvas,
} from './JlGraphicApp';
/**
@ -34,10 +35,11 @@ export function newDrawApp(options: DrawAppOptions): IDrawApp {
return new JlDrawApp(options);
}
export { AppConsts, JlCanvas, GraphicDrawAssistant };
export { AppConsts, GraphicDrawAssistant };
export type {
ICanvasProperties,
IGraphicScene,
IJlCanvas,
IGraphicApp,
IGraphicStorage,
IDrawApp,

View File

@ -10,7 +10,7 @@ import {
Point,
Rectangle,
} from 'pixi.js';
import { AppConsts, JlCanvas } from '../app';
import { AppConsts, IJlCanvas } from '../app';
import {
convertRectangleToPolygonPoints,
recursiveChildren,
@ -277,7 +277,7 @@ DisplayObject.prototype.getCanvas = function getCanvas() {
graphic = graphic.parent;
}
if (graphic) {
return graphic as JlCanvas;
return graphic as IJlCanvas;
}
throw new Error(`图形${this.name}不在画布中`);
};

View File

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
declare namespace GlobalMixins {
type JlCanvasType = import('./app').JlCanvas;
type JlCanvasType = import('./app').IJlCanvas;
type CanvasProperties = import('./app').ICanvasProperties;
type GraphicApp = import('./app').IGraphicApp;
type JlGraphicType = import('./core').JlGraphic;

View File

@ -1,5 +1,5 @@
import { DisplayObject, FederatedMouseEvent, Graphics, Point } from 'pixi.js';
import { IGraphicScene, JlCanvas } from '../app';
import { IGraphicScene } from '../app';
import { JlGraphic } from '../core';
import {
AppDragEvent,
@ -173,8 +173,9 @@ export class CommonMouseTool extends AppInteractionPlugin {
}
setCursor(e: FederatedMouseEvent) {
this.rightTarget = e.target as DisplayObject;
if (e.target instanceof JlCanvas && this.app.pixi.view.style) {
const target = e.target as DisplayObject;
this.rightTarget = target;
if (target.isCanvas() && this.app.pixi.view.style) {
this.app.pixi.view.style.cursor = 'grab';
}
}
@ -182,7 +183,7 @@ export class CommonMouseTool extends AppInteractionPlugin {
resumeCursor() {
if (
this.rightTarget &&
this.rightTarget instanceof JlCanvas &&
this.rightTarget.isCanvas() &&
this.app.pixi.view.style
) {
this.app.pixi.view.style.cursor = 'inherit';
@ -248,7 +249,7 @@ export class CommonMouseTool extends AppInteractionPlugin {
}
} else {
// 非多选
if (e.target instanceof JlCanvas) {
if ((e.target as DisplayObject).isCanvas()) {
this.app.updateSelected();
} else {
if (

View File

@ -122,9 +122,6 @@
<script setup lang="ts">
import { useQuasar } from 'quasar';
import DrawProperties from 'src/components/draw-app/DrawProperties.vue';
import { getDrawApp, loadDrawDatas } from 'src/examples/app';
import { getWebsocketUrl } from 'src/examples/app/configs/UrlManage';
import { ClientEngine } from 'src/jlgraphic';
import { useDrawStore } from 'src/stores/draw-store';
import { onMounted, onUnmounted, ref } from 'vue';
import { useRouter } from 'vue-router';

View File

@ -1,6 +1,7 @@
import { defineStore } from 'pinia';
import { destroyDrawApp, getDrawApp, initDrawApp } from 'src/examples/app';
import { DrawAssistant, JlCanvas, IDrawApp, JlGraphic } from 'src/jlgraphic';
import { DrawAssistant, IDrawApp, JlGraphic } from 'src/jlgraphic';
import { IJlCanvas } from 'src/jlgraphic/app/JlGraphicApp';
export const useDrawStore = defineStore('draw', {
state: () => ({
@ -48,7 +49,7 @@ export const useDrawStore = defineStore('draw', {
}
return app;
},
getJlCanvas(): JlCanvas {
getJlCanvas(): IJlCanvas {
return this.getDrawApp().canvas;
},
initDrawApp() {