Skip to content

Commit

Permalink
fix a bug in the 'draw' event
Browse files Browse the repository at this point in the history
  • Loading branch information
emilefokkema committed Mar 15, 2024
1 parent 8d9e351 commit a0e29c3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/animation-frame-drawing-iteration-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {DrawingIterationProvider} from "./interfaces/drawing-iteration-provider"

export class AnimationFrameDrawingIterationProvider implements DrawingIterationProvider{
private animationFrameRequested: boolean = false;
public provideDrawingIteration(draw: () => void): void {
public provideDrawingIteration(draw: () => boolean): void {
if(this.animationFrameRequested){
return;
}
Expand Down
9 changes: 6 additions & 3 deletions src/drawing-iteration-provider-with-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ export class DrawingIterationProviderWithCallback implements DrawingIterationPro
constructor(private readonly drawingIterationProvider: DrawingIterationProvider){

}
public provideDrawingIteration(draw: () => void): void{
public provideDrawingIteration(draw: () => boolean): void{
this.drawingIterationProvider.provideDrawingIteration(() => {
draw();
this._drawHappened.dispatch();
const didDraw = draw();
if(didDraw){
this._drawHappened.dispatch();
}
return didDraw;
});
}
}
3 changes: 2 additions & 1 deletion src/infinite-canvas-viewbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ export class InfiniteCanvasViewBox implements ViewBox{
this.rectangleManager.measure();
}
if(!this.rectangleManager.rectangle){
return;
return false;
}
this.context.restore();
this.context.save();
this.context.clearRect(0, 0, this.width, this.height);
this.setInitialTransformation();
this.instructionSet.execute(this.context, this.rectangleManager.rectangle);
return true;
});
}
private setInitialTransformation(): void{
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/drawing-iteration-provider.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface DrawingIterationProvider{
provideDrawingIteration(draw: () => void): void;
provideDrawingIteration(draw: () => boolean): void;
}
4 changes: 2 additions & 2 deletions src/lockable-drawing-iteration-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DrawingIterationProvider } from "./interfaces/drawing-iteration-provide
import { DrawingLock } from "./drawing-lock";

export class LockableDrawingIterationProvider implements DrawingIterationProvider{
private _draw: () => void;
private _draw: () => boolean;
private _locks: DrawingLock[] = [];
constructor(private readonly drawingIterationProvider: DrawingIterationProvider){

Expand All @@ -14,7 +14,7 @@ export class LockableDrawingIterationProvider implements DrawingIterationProvide
this.drawingIterationProvider.provideDrawingIteration(this._draw);
}
}
public provideDrawingIteration(draw: () => void): void{
public provideDrawingIteration(draw: () => boolean): void{
if(this._locks.length){
this._draw = draw;
}else{
Expand Down

0 comments on commit a0e29c3

Please sign in to comment.