-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
73 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,35 @@ | ||
import { Observable } from '@daign/observable'; | ||
|
||
import { SelectionManager } from './selectionManager'; | ||
import { ControlLayer } from './controlLayer'; | ||
import { Viewport } from './viewport'; | ||
|
||
// Observable implementation with a public invoke method. | ||
class EventSource extends Observable { | ||
public constructor() { | ||
super(); | ||
} | ||
public invoke(): void { | ||
this.notifyObservers(); | ||
} | ||
} | ||
import { EventEmitter, UnicastEventEmitter } from '@daign/observable'; | ||
|
||
/** | ||
* Class that manages update and change notifications between components. | ||
* Class that manages the steps to update and redraw the graphic. | ||
*/ | ||
export class UpdateManager { | ||
// Subscribe to know when the graphic data has changes. | ||
public dataChangeEvent: EventSource = new EventSource(); | ||
// Incoming signal to run the update and redraw cycle. | ||
public redrawSignal: UnicastEventEmitter = new UnicastEventEmitter(); | ||
|
||
// Subscribe to know when the selection changes. | ||
public selectionChangeEvent: EventSource = new EventSource(); | ||
// Components that want to update when the graphic was changed subscribe to this event. | ||
public graphicUpdateEvent: EventEmitter = new EventEmitter(); | ||
|
||
// Subscribe to know when the graphic needs to be redrawn. | ||
public redrawEvent: EventSource = new EventSource(); | ||
// The control layer subscribes to this event to know when to redraw the controls. | ||
public redrawControlsSignal: UnicastEventEmitter = new UnicastEventEmitter(); | ||
|
||
// Subscribe to know when the viewport has changed. | ||
public viewportInputEvent: EventSource = new EventSource(); | ||
// Subscribe your render function to this event. | ||
public renderSignal: UnicastEventEmitter = new UnicastEventEmitter(); | ||
|
||
/** | ||
* Constructor. | ||
* @param selectionManager - The selection manager. | ||
* @param controlLayer - The control layer. | ||
* @param drawingLayer - The drawing layer. | ||
*/ | ||
public constructor( | ||
private selectionManager: SelectionManager, | ||
private controlLayer: ControlLayer | null, | ||
private drawingLayer: Viewport | ||
) { | ||
// Actions to take when the selection manager has changes. | ||
this.selectionManager.subscribeToChanges( (): void => { | ||
this.selectionChangeEvent.invoke(); | ||
this.createControls(); | ||
this.redrawEvent.invoke(); | ||
} ); | ||
public constructor() { | ||
// Run the update and redraw cycle on incoming signal. | ||
this.redrawSignal.setObserver( (): void => { | ||
// Notify components that want to update when the graphic was changed. | ||
this.graphicUpdateEvent.emit(); | ||
|
||
// Actions to take when the drawing layer has changes. | ||
this.drawingLayer.subscribeToChanges( (): void => { | ||
this.dataChangeEvent.invoke(); | ||
this.createControls(); | ||
this.redrawEvent.invoke(); | ||
} ); | ||
// Redraw the controls. | ||
this.redrawControlsSignal.emit(); | ||
|
||
// Actions to take when the viewport has changed. | ||
this.viewportInputEvent.subscribeToChanges( (): void => { | ||
this.createControls(); | ||
this.redrawEvent.invoke(); | ||
// Render the graphic. | ||
this.renderSignal.emit(); | ||
} ); | ||
} | ||
|
||
/** | ||
* Let the control layer create the controls for the currently selected object. | ||
*/ | ||
public createControls(): void { | ||
if ( this.controlLayer ) { | ||
this.controlLayer.createControls(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.