Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/features/cseMachine/CseMachineTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export interface IVisible extends Drawable {
height(): number;

ref?: React.RefObject<any>;
setArrowSourceHighlightedStyle?(): void;
setArrowSourceNormalStyle?(): void;
}

/** unassigned is internally represented as a symbol */
Expand Down
12 changes: 12 additions & 0 deletions src/features/cseMachine/components/ArrayUnit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ export class ArrayUnit extends Visible {
if (!CseMachine.getPrintableMode()) this.indexRef.current?.hide();
}

setArrowSourceHighlightedStyle(): void {
this.ref.current?.stroke(Config.HoverColor);
}

setArrowSourceNormalStyle(): void {
this.ref.current?.stroke(
this.parent.isReferenced() && this.parent.isEnclosingFrameLive()
? defaultStrokeColor()
: fadedStrokeColor()
);
Comment thread
Akshay-2007-1 marked this conversation as resolved.
}

draw(): React.ReactNode {
if (this.isDrawn()) return null;
this._isDrawn = true;
Expand Down
12 changes: 12 additions & 0 deletions src/features/cseMachine/components/ControlItemComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ export class ControlItemComponent extends Visible implements IHoverable {
this.ref.current.zIndex(this.zIndex);
};

setArrowSourceHighlightedStyle(): void {
this.resetStyle();
this.tag?.stroke(Config.HoverColor);
this.secItem?.fill(Config.HoverColor);
}

setArrowSourceNormalStyle(): void {
this.resetStyle();
this.tag?.stroke(this.topItem ? defaultActiveColor() : defaultStrokeColor());
this.secItem?.fill(defaultTextColor());
}
Comment thread
Akshay-2007-1 marked this conversation as resolved.

destroy() {
this.ref.current.destroyChildren();
}
Expand Down
18 changes: 18 additions & 0 deletions src/features/cseMachine/components/Frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class Frame extends Visible implements IHoverable {
readonly bindings: Binding[] = [];
/** name of this frame to display */
private _name!: Text; // removed readonly to allow reassignment for fixed layout
private readonly rectRef = React.createRef<any>();
Comment thread
Akshay-2007-1 marked this conversation as resolved.
Outdated
/** the level in which this frame resides */
readonly level: Level | undefined;
/** environment associated with this frame */
Expand Down Expand Up @@ -260,13 +261,30 @@ export class Frame extends Visible implements IHoverable {

onMouseLeave = () => {};

setArrowSourceHighlightedStyle(): void {
this.rectRef.current?.stroke(Config.HoverColor);
this.name.setArrowSourceHighlightedStyle();
}

setArrowSourceNormalStyle(): void {
this.rectRef.current?.stroke(
CseMachine.getCurrentEnvId() === this.environment?.id
? defaultActiveColor()
: this.isLive
? defaultStrokeColor()
: fadedStrokeColor()
);
this.name.setArrowSourceNormalStyle();
}

draw(): React.ReactNode {
return (
<Group ref={this.ref} key={Layout.key++}>
{this.name.draw()}

<Rect
{...ShapeDefaultProps}
ref={this.rectRef}
x={this.x()}
y={this.y()}
width={this.width()}
Expand Down
12 changes: 12 additions & 0 deletions src/features/cseMachine/components/StashItemComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ export class StashItemComponent extends Visible implements IHoverable {
this.ref.current.zIndex(this.zIndex);
};

setArrowSourceHighlightedStyle(): void {
this.resetStyle();
this.tag?.stroke(Config.HoverColor);
this.secItem?.fill(Config.HoverColor);
}

setArrowSourceNormalStyle(): void {
this.resetStyle();
this.tag?.stroke(isStashItemInDanger(this.index) ? defaultDangerColor() : defaultStrokeColor());
this.secItem?.fill(defaultTextColor());
}
Comment thread
Akshay-2007-1 marked this conversation as resolved.

destroy() {
this.ref.current.destroyChildren();
}
Expand Down
8 changes: 8 additions & 0 deletions src/features/cseMachine/components/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ export class Text extends Visible implements IHoverable {
currentTarget.getLayer()?.draw();
};

setArrowSourceHighlightedStyle(): void {
this.ref.current?.fill(Config.HoverColor);
}

setArrowSourceNormalStyle(): void {
this.ref.current?.fill(this.options.faded ? fadedTextColor() : defaultTextColor());
}

draw(): React.ReactNode {
const props = {
fontFamily: this.options.fontFamily,
Expand Down
15 changes: 15 additions & 0 deletions src/features/cseMachine/components/Visible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ export abstract class Visible implements IVisible {
reset(): void {
this._isDrawn = false;
}
setShapesStyle(color: string) {
const shapes = this.ref.current?.getChildren?.() ?? [];
shapes.forEach((shape: any) => {
if (shape.attrs.stroke) shape.stroke(color);
if (shape.attrs.fill) shape.fill(color);
});
}
Comment thread
Akshay-2007-1 marked this conversation as resolved.
Outdated
Comment thread
Akshay-2007-1 marked this conversation as resolved.
public ref: RefObject<any> = React.createRef();
protected tag = this.ref.current?.getChildren?.()[0];
protected secItem = this.ref.current?.getChildren?.()[1];
Comment thread
Akshay-2007-1 marked this conversation as resolved.
Outdated
resetStyle(): void {
this.tag = this.ref.current?.getChildren?.()[0];
this.secItem = this.ref.current?.getChildren?.()[1];
Comment thread
Akshay-2007-1 marked this conversation as resolved.
Outdated
}
Comment thread
Akshay-2007-1 marked this conversation as resolved.
Outdated
setArrowSourceHighlightedStyle(): void {}
setArrowSourceNormalStyle(): void {}
abstract draw(key?: number): React.ReactNode;
}
5 changes: 5 additions & 0 deletions src/features/cseMachine/components/arrows/GenericArrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export class GenericArrow<Source extends IVisible, Target extends IVisible>
this.arrowHeadRef.current.pointerWidth(Config.ArrowHoveredHeadSize);
this.arrowHeadRef.current.pointerLength(Config.ArrowHoveredHeadSize);
}
this.source.setArrowSourceHighlightedStyle?.();
}

public setNormalStyle() {
Comment thread
Akshay-2007-1 marked this conversation as resolved.
Expand All @@ -202,6 +203,7 @@ export class GenericArrow<Source extends IVisible, Target extends IVisible>
this.arrowHeadRef.current.pointerWidth(Config.ArrowHeadSize);
this.arrowHeadRef.current.pointerLength(Config.ArrowHeadSize);
}
this.source.setArrowSourceNormalStyle?.();
}

onClick = (e: KonvaEventObject<MouseEvent>) => {
Expand All @@ -220,6 +222,9 @@ export class GenericArrow<Source extends IVisible, Target extends IVisible>
this.select();
// Update this arrow's visual state
this.setHighlightedStyle();
} else {
// If the arrow was already selected, deselect it and revert to normal style
this.setNormalStyle();
}
Comment thread
Akshay-2007-1 marked this conversation as resolved.
Outdated

// Force redraw entire layer to update all arrows
Expand Down
9 changes: 9 additions & 0 deletions src/features/cseMachine/components/values/ContValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ export class ContValue extends Value implements IHoverable {
this.labelRef.current?.hide();
};

setArrowSourceHighlightedStyle(): void {
this.setShapesStyle(Config.HoverColor);
}

setArrowSourceNormalStyle(): void {
const strokeColor = this.isLive() ? defaultStrokeColor() : fadedStrokeColor();
this.setShapesStyle(strokeColor);
}
Comment thread
Akshay-2007-1 marked this conversation as resolved.

draw(): React.ReactNode {
if (this.enclosingFrame) {
this._arrow = new ArrowFromFn(this).to(this.enclosingFrame) as ArrowFromFn;
Expand Down
9 changes: 9 additions & 0 deletions src/features/cseMachine/components/values/FnValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ export class FnValue extends Value implements IHoverable {
currentTarget.getLayer()?.batchDraw();
};

setArrowSourceHighlightedStyle(): void {
this.setShapesStyle(Config.HoverColor);
}

setArrowSourceNormalStyle(): void {
const strokeColor = this.isLive() ? defaultStrokeColor() : fadedStrokeColor();
this.setShapesStyle(strokeColor);
}
Comment thread
Akshay-2007-1 marked this conversation as resolved.

isLive(): boolean {
const id = (this.data as any).id;
return id ? Layout.liveObjectIDs.has(id) : false;
Expand Down
9 changes: 9 additions & 0 deletions src/features/cseMachine/components/values/GlobalFnValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ export class GlobalFnValue extends Value implements IHoverable {
currentTarget.getLayer()?.batchDraw();
};

setArrowSourceHighlightedStyle(): void {
this.setShapesStyle(Config.HoverColor);
}

setArrowSourceNormalStyle(): void {
const strokeColor = this.isReferenced() ? defaultStrokeColor() : fadedStrokeColor();
this.setShapesStyle(strokeColor);
}
Comment thread
Akshay-2007-1 marked this conversation as resolved.

draw(): React.ReactNode {
this._isDrawn = true;
if (Layout.globalEnvNode.frame) {
Expand Down
Loading