-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#183 new feature: colorize existing actions
- Loading branch information
Francois Schwarzentruber
committed
Mar 5, 2024
1 parent
abb2049
commit 10d37f1
Showing
6 changed files
with
95 additions
and
8 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,11 +1,16 @@ | ||
/** | ||
* An operation is performed by the user and can be undone/redone. | ||
* | ||
* | ||
* Examples of instantiation: | ||
* 1. draw a line will correspond to an operation of "adding an action that draws a line, at a particular timestep in the timeline" | ||
* 2. remove an action in the timeline | ||
* | ||
* /!\ do not confuse with an Action | ||
* | ||
*/ | ||
export abstract class Operation { | ||
abstract undo(): void; | ||
abstract redo(): void; | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { BoardManager } from "./boardManager"; | ||
import { Action } from "./Action"; | ||
import { Operation } from "./Operation"; | ||
import { ActionFreeDraw } from "./ActionFreeDraw"; | ||
import { AnimationToolBar } from "./AnimationToolBar"; | ||
|
||
|
||
|
||
/** | ||
* @description recolorize actions, i.e. change the color of the selected actions. If some actions have no color (like ActionErase) | ||
* this operation does nothing (technically it assigns a fake non-used property "color") | ||
*/ | ||
export class OperationColorizeSeveralActions extends Operation { | ||
private previousColors: string[]; | ||
|
||
/** | ||
* | ||
* @param indices the indices of the actions to be recolorized | ||
* @param newColor new color to assign to the actions | ||
*/ | ||
constructor(private indices: number[], private newColor: string) { | ||
super(); | ||
this.previousColors = this.indices.map(index => this.getColor(BoardManager.timeline.actions[index])); | ||
} | ||
|
||
/** | ||
* | ||
* @param action | ||
* @param color | ||
* @returns set the color of the action | ||
*/ | ||
private setColor(action: Action, color: string) { | ||
if (action instanceof ActionFreeDraw) | ||
action.setColor(color); | ||
else | ||
(<any>action).color = color; | ||
} | ||
|
||
/** | ||
* | ||
* @param action | ||
* @returns the color of the action | ||
* | ||
*/ | ||
private getColor(action: Action) { | ||
if (action instanceof ActionFreeDraw) | ||
return action.getMainColor(); | ||
else return (<any>action).color; | ||
} | ||
|
||
undo(): void { | ||
for (const i in this.indices) | ||
this.setColor(BoardManager.timeline.actions[this.indices[i]], this.previousColors[i]); | ||
BoardManager.timeline.resetAndUpdate(); | ||
AnimationToolBar.update(); | ||
} | ||
|
||
|
||
async redo(): Promise<void> { | ||
for (const i in this.indices) | ||
this.setColor(BoardManager.timeline.actions[this.indices[i]], this.newColor); | ||
BoardManager.timeline.resetAndUpdate(); | ||
AnimationToolBar.update(); | ||
} | ||
} |
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