我正在制作图形编辑器,现在我必须添加边界框,但是我不知道该怎么做,我正在寻找并且找不到任何东西,实际上该应用程序已经相当高级了,也就是说我仍然需要做的一件事,是感谢帮助。
可以在https://github.com/OSarmient/Graphic-Editor
中找到该项目这些是我必须实现边界框的示例类:
import { Tool } from './tool';
import { App } from '../controller/app';
export class SelectionTool extends Tool {
protected handleMouseReleased(): void {
const equals: boolean = !!this.ptpressed
&& !!this.ptReleased
&& this.ptpressed.offsetX === this.ptReleased.offsetX
&& this.ptpressed.offsetY === this.ptReleased.offsetY;
if ( equals ) {
// point selection
App.getInstance()
.selectPoint(
this.ptReleased
);
}
else {
// bound box selection
// 1. create bbox
// 2. normalize bbox
// 3. => App
}
};
}
export interface Position {
x: number;
y: number;
}
export interface Dimension {
w: number;
h: number;
}
export interface Color {
r: number;
g: number;
b: number;
a: number;
}
export abstract class Figure {
abstract doPaint(
context: CanvasRenderingContext2D ): void;
protected selected: boolean = false;
constructor(
protected position: Position,protected size: Dimension,protected color: Color ) {
}
protected setColor(
context: CanvasRenderingContext2D,color: string ): void {
context.strokeStyle = color;
}
// template method
paint(
context: CanvasRenderingContext2D ): void {
// 1. compose color
const color: string = 'rgba('
+ this.color.r
+ ','
+ this.color.g
+ ','
+ this.color.b
+ ','
+ this.color.a
+ ')';
// 2. set color
this.setColor(
context,color
);
// 3. call abstract paint
this.doPaint(
context
);
// 4. if selected => draw bbox
if ( this.selected ) {
// this.bbox
}
}
}