Skip to content

Commit

Permalink
update: 更新接口为Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan Heng committed Jul 25, 2023
1 parent 2a9f07a commit a978b7b
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { BaseService } from '@pictode/utils';
import { fabric } from 'fabric';

import { MouseService } from './services/mouse';
import { AppOption, ControlsOption, EventArgs, Plugin, ToolStrategy } from './types';
import { AppOption, ControlsOption, EventArgs, Plugin, Tool } from './types';
import { DEFAULT_APP_OPTION } from './utils';

export class App extends BaseService<EventArgs> {
public canvas: fabric.Canvas;
public mouseService: MouseService;
public currentTool: ToolStrategy | null = null;
public currentTool: Tool | null = null;

private option: AppOption & { controls: ControlsOption };
private installedPlugins: Map<string, Plugin> = new Map();
Expand Down Expand Up @@ -55,7 +55,7 @@ export class App extends BaseService<EventArgs> {
this.render(true);
}

public setTool(tool: ToolStrategy): void {
public setTool(tool: Tool): void {
this.currentTool = tool;
this.canvas.discardActiveObject();
this.render();
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tools/ellipse-tool.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { fabric } from 'fabric';

import { Ellipse } from '../customs/ellipse';
import { AppMouseEvent, ToolStrategy } from '../types';
import { AppMouseEvent, Tool } from '../types';

import { selectTool } from './select-tool';

class EllipseTool implements ToolStrategy {
class EllipseTool implements Tool {
public name: string = 'ellipseTool';
public drawable: boolean = true;
private startPointer: fabric.Point = new fabric.Point(0, 0);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tools/polyline-tool.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { fabric } from 'fabric';

import { Polyline } from '../customs/polyline';
import { AppMouseEvent, ToolStrategy } from '../types';
import { AppMouseEvent, Tool } from '../types';

import { selectTool } from './select-tool';

class PolylineTool implements ToolStrategy {
class PolylineTool implements Tool {
public name: string = 'polylineTool';
public drawable: boolean = true;
private points: fabric.Point[] = [];
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tools/rect-tool.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { fabric } from 'fabric';

import { Rect } from '../customs/rect';
import { AppMouseEvent, ToolStrategy } from '../types';
import { AppMouseEvent, Tool } from '../types';

import { selectTool } from './select-tool';

class RectTool implements ToolStrategy {
class RectTool implements Tool {
public name: string = 'rectTool';
public drawable: boolean = true;
private startPointer: fabric.Point = new fabric.Point(0, 0);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tools/select-tool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppMouseEvent, ToolStrategy } from '../types';
import { AppMouseEvent, Tool } from '../types';

class SelectTool implements ToolStrategy {
class SelectTool implements Tool {
public name: string = 'selectTool';
public drawable: boolean = false;

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tools/triangle-tool.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { fabric } from 'fabric';

import { Triangle } from '../customs/triangle';
import { AppMouseEvent, ToolStrategy } from '../types';
import { AppMouseEvent, Tool } from '../types';

import { selectTool } from './select-tool';

class TriangleTool implements ToolStrategy {
class TriangleTool implements Tool {
public name: string = 'triangleTool';
public drawable: boolean = true;
private startPointer: fabric.Point = new fabric.Point(0, 0);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface AppMouseEvent {
app: App;
}

export interface ToolStrategy {
export interface Tool {
name: string;
drawable: boolean;
onMouseDown?: (event: AppMouseEvent) => void;
Expand Down

0 comments on commit a978b7b

Please sign in to comment.