Skip to content

Commit 497a46d

Browse files
authored
Merge branch 'master' into Versioning-and-History
2 parents 4f4aaed + 6554b34 commit 497a46d

14 files changed

Lines changed: 151 additions & 8 deletions

src/features/cseMachine/CseMachineConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ export const Config = Object.freeze({
6666
PrintStrokeColor: '#777',
6767
PrintStrokeColorFaded: '#ccc',
6868
ArrowHighlightedColor: '#ffffff',
69+
ArrowDeadHighlightedColor: '#787777',
6970

7071
// Colors of different states
7172
ActiveColor: '#030fff',
7273
PrintActiveColor: '#3d5afe',
7374
DangerColor: '#ff1744',
7475
PrintDangerColor: '#f44336',
7576
HoverColor: '#25c225',
77+
HoverDeadColor: '#127a12',
7678
PrintHoverColor: '#0dbf0d',
7779

7880
// Colors for text hover background

src/features/cseMachine/CseMachineTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export interface IVisible extends Drawable {
4040
height(): number;
4141

4242
ref?: React.RefObject<any>;
43+
setArrowSourceHighlightedStyle?(): void;
44+
setArrowSourceNormalStyle?(): void;
4345
}
4446

4547
/** unassigned is internally represented as a symbol */

src/features/cseMachine/components/ArrayUnit.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ export class ArrayUnit extends Visible {
6060
if (!CseMachine.getPrintableMode()) this.indexRef.current?.hide();
6161
}
6262

63+
setArrowSourceHighlightedStyle(): void {
64+
if (this.parent.isLive()) {
65+
this.ref.current?.stroke(Config.HoverColor);
66+
} else {
67+
this.ref.current?.stroke(Config.HoverDeadColor);
68+
}
69+
}
70+
71+
setArrowSourceNormalStyle(): void {
72+
this.ref.current?.stroke(
73+
this.parent.isReferenced() && this.parent.isEnclosingFrameLive()
74+
? defaultStrokeColor()
75+
: fadedStrokeColor()
76+
);
77+
}
78+
6379
draw(): React.ReactNode {
6480
if (this.isDrawn()) return null;
6581
this._isDrawn = true;

src/features/cseMachine/components/ControlItemComponent.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ export class ControlItemComponent extends Visible implements IHoverable {
9292
this.ref.current.zIndex(this.zIndex);
9393
};
9494

95+
setArrowSourceHighlightedStyle(): void {
96+
this.tag?.stroke(Config.HoverColor);
97+
this.secItem?.fill(Config.HoverColor);
98+
}
99+
100+
setArrowSourceNormalStyle(): void {
101+
this.tag?.stroke(this.topItem ? defaultActiveColor() : defaultStrokeColor());
102+
this.secItem?.fill(defaultTextColor());
103+
}
104+
95105
destroy() {
96106
this.ref.current.destroyChildren();
97107
}

src/features/cseMachine/components/Frame.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Rect as KonvaRect } from 'konva/lib/shapes/Rect';
12
import React from 'react';
23
import { Group, Rect } from 'react-konva';
34

@@ -59,6 +60,7 @@ export class Frame extends Visible implements IHoverable {
5960
readonly bindings: Binding[] = [];
6061
/** name of this frame to display */
6162
private _name!: Text; // removed readonly to allow reassignment for fixed layout
63+
private readonly rectRef = React.createRef<KonvaRect | null>();
6264
/** the level in which this frame resides */
6365
readonly level: Level | undefined;
6466
/** environment associated with this frame */
@@ -260,13 +262,34 @@ export class Frame extends Visible implements IHoverable {
260262

261263
onMouseLeave = () => {};
262264

265+
setArrowSourceHighlightedStyle(): void {
266+
if (this.isLive) {
267+
this.rectRef.current?.stroke(Config.HoverColor);
268+
} else {
269+
this.rectRef.current?.stroke(Config.HoverDeadColor);
270+
}
271+
this.name.setArrowSourceHighlightedStyle();
272+
}
273+
274+
setArrowSourceNormalStyle(): void {
275+
this.rectRef.current?.stroke(
276+
CseMachine.getCurrentEnvId() === this.environment?.id
277+
? defaultActiveColor()
278+
: this.isLive
279+
? defaultStrokeColor()
280+
: fadedStrokeColor()
281+
);
282+
this.name.setArrowSourceNormalStyle();
283+
}
284+
263285
draw(): React.ReactNode {
264286
return (
265287
<Group ref={this.ref} key={Layout.key++}>
266288
{this.name.draw()}
267289

268290
<Rect
269291
{...ShapeDefaultProps}
292+
ref={this.rectRef}
270293
x={this.x()}
271294
y={this.y()}
272295
width={this.width()}

src/features/cseMachine/components/StashItemComponent.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ export class StashItemComponent extends Visible implements IHoverable {
106106
this.ref.current.zIndex(this.zIndex);
107107
};
108108

109+
setArrowSourceHighlightedStyle(): void {
110+
this.tag?.stroke(Config.HoverColor);
111+
this.secItem?.fill(Config.HoverColor);
112+
}
113+
114+
setArrowSourceNormalStyle(): void {
115+
this.tag?.stroke(isStashItemInDanger(this.index) ? defaultDangerColor() : defaultStrokeColor());
116+
this.secItem?.fill(defaultTextColor());
117+
}
118+
109119
destroy() {
110120
this.ref.current.destroyChildren();
111121
}

src/features/cseMachine/components/Text.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ export class Text extends Visible implements IHoverable {
9595
currentTarget.getLayer()?.draw();
9696
};
9797

98+
setArrowSourceHighlightedStyle(): void {
99+
if (this.options.faded) {
100+
this.ref.current?.fill(Config.HoverDeadColor);
101+
} else {
102+
this.ref.current?.fill(Config.HoverColor);
103+
}
104+
}
105+
106+
setArrowSourceNormalStyle(): void {
107+
this.ref.current?.fill(this.options.faded ? fadedTextColor() : defaultTextColor());
108+
}
109+
98110
draw(): React.ReactNode {
99111
const props = {
100112
fontFamily: this.options.fontFamily,

src/features/cseMachine/components/Visible.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Konva from 'konva';
12
import React from 'react';
23
import { RefObject } from 'react';
34

@@ -30,6 +31,27 @@ export abstract class Visible implements IVisible {
3031
reset(): void {
3132
this._isDrawn = false;
3233
}
34+
setShapesStyle(color: string): void {
35+
const shapes = this.ref.current?.getChildren?.() ?? [];
36+
shapes.forEach((shape: Konva.Node) => {
37+
if (shape instanceof Konva.Shape) {
38+
if (shape.attrs.stroke) {
39+
shape.stroke(color);
40+
}
41+
if (shape.attrs.fill) {
42+
shape.fill(color);
43+
}
44+
}
45+
});
46+
}
3347
public ref: RefObject<any> = React.createRef();
48+
protected get tag() {
49+
return this.ref.current?.getChildren?.()[0];
50+
}
51+
protected get secItem() {
52+
return this.ref.current?.getChildren?.()[1];
53+
}
54+
setArrowSourceHighlightedStyle(): void {}
55+
setArrowSourceNormalStyle(): void {}
3456
abstract draw(key?: number): React.ReactNode;
3557
}

src/features/cseMachine/components/arrows/ArrowSelection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class ArrowSelectionManager {
1616
clearSelection(): GenericArrow<IVisible, IVisible> | null {
1717
const oldArrow = this.selectedArrow;
1818
this.selectedArrow = null;
19+
oldArrow?.setNormalStyle();
1920
return oldArrow;
2021
}
2122

src/features/cseMachine/components/arrows/GenericArrow.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export class GenericArrow<Source extends IVisible, Target extends IVisible>
146146
* Subclasses can override this to provide custom hover colors.
147147
*/
148148
protected getHighlightedColor(): string {
149-
return Config.ArrowHighlightedColor;
149+
return this.isLive ? Config.ArrowHighlightedColor : Config.ArrowDeadHighlightedColor;
150150
}
151151

152152
onMouseEnter = (e: KonvaEventObject<MouseEvent>) => {
@@ -189,8 +189,9 @@ export class GenericArrow<Source extends IVisible, Target extends IVisible>
189189
this.arrowHeadRef.current.pointerWidth(Config.ArrowHoveredHeadSize);
190190
this.arrowHeadRef.current.pointerLength(Config.ArrowHoveredHeadSize);
191191
}
192+
this.source.setArrowSourceHighlightedStyle?.();
193+
this.target?.setArrowSourceHighlightedStyle?.();
192194
}
193-
194195
public setNormalStyle() {
195196
const color = this.isLive ? defaultStrokeColor() : fadedStrokeColor();
196197
if (this.pathRef.current) {
@@ -202,19 +203,16 @@ export class GenericArrow<Source extends IVisible, Target extends IVisible>
202203
this.arrowHeadRef.current.pointerWidth(Config.ArrowHeadSize);
203204
this.arrowHeadRef.current.pointerLength(Config.ArrowHeadSize);
204205
}
206+
this.source.setArrowSourceNormalStyle?.();
207+
this.target?.setArrowSourceNormalStyle?.();
205208
}
206209

207210
onClick = (e: KonvaEventObject<MouseEvent>) => {
208211
e.cancelBubble = true;
209212

210213
// Toggle selection - clear first, then select if it wasn't already selected
211214
const wasSelected = this.isSelected();
212-
const oldArrow = arrowSelection.clearSelection();
213-
214-
// Update old arrow's visual state
215-
if (oldArrow && oldArrow !== this) {
216-
oldArrow.setNormalStyle();
217-
}
215+
arrowSelection.clearSelection();
218216

219217
if (!wasSelected) {
220218
this.select();

0 commit comments

Comments
 (0)