@@ -2,6 +2,8 @@ import { DEFAULT_SHAPE_COLOR, HOVERED_SHAPE_COLOR, CLICKED_SHAPE_COLOR, SELECTED
22import { hslToArray , colorHsl } from "./colors"
33import { Hatching } from "./styles"
44import { DataInterface } from "./dataInterfaces"
5+ import { highlightShape } from "./interactions"
6+
57
68export class Vertex {
79 constructor ( public x : number = 0 , public y : number = 0 ) { }
@@ -82,16 +84,51 @@ export class InteractiveObject {
8284
8385 public mouseClick : Vertex = null ;
8486
85- public isHovered : boolean = false ;
86- public isClicked : boolean = false ;
87+ private _isHovered : boolean = false ;
88+ private _isClicked : boolean = false ;
8789 public isSelected : boolean = false ;
8890 public isScaled : boolean = true ;
8991 public isFilled : boolean = true ;
9092 public visible : boolean = true ;
9193 public inFrame : boolean = true ; // TODO: remove it
9294
95+ public referencePath : string = "#" ;
96+
9397 constructor ( ) { } ;
9498
99+ public get isHovered ( ) : boolean {
100+ return this . _isHovered ;
101+ } ;
102+ set isHovered ( hovered : boolean ) {
103+ if ( hovered !== this . _isHovered && this . referencePath !== "#" ) {
104+ // The first check is important, otherwise we fire the event every mouse move.
105+ // The second is for dev purpose, should we keep it ?
106+ const highlightData = {
107+ referencePath : this . referencePath ,
108+ highlight : hovered ,
109+ select : false
110+ }
111+ highlightShape . next ( highlightData ) ;
112+ }
113+ this . _isHovered = hovered ;
114+ }
115+
116+ public get isClicked ( ) : boolean {
117+ return this . _isClicked ;
118+ }
119+ set isClicked ( clicked : boolean ) {
120+ if ( clicked != this . _isClicked && this . referencePath !== "#" ) {
121+ // Same than isHovered
122+ const highlightData = {
123+ referencePath : this . referencePath ,
124+ highlight : clicked ,
125+ select : true
126+ }
127+ highlightShape . next ( highlightData ) ;
128+ }
129+ this . _isClicked = clicked ;
130+ }
131+
95132 public getBounds ( ) : [ Vertex , Vertex ] { return [ new Vertex ( 0 , 1 ) , new Vertex ( 0 , 1 ) ] }
96133
97134 protected updateTooltipOrigin ( matrix : DOMMatrix ) : void { }
@@ -161,7 +198,9 @@ export class InteractiveObject {
161198
162199 public mouseDown ( mouseDown : Vertex ) { if ( this . isHovered ) this . mouseClick = mouseDown . copy ( ) }
163200
164- public mouseMove ( context : CanvasRenderingContext2D , mouseCoords : Vertex ) : void { this . isHovered = this . isPointInShape ( context , mouseCoords ) }
201+ public mouseMove ( context : CanvasRenderingContext2D , mouseCoords : Vertex ) : void {
202+ this . isHovered = this . isPointInShape ( context , mouseCoords ) ;
203+ }
165204
166205 public mouseUp ( keepState : boolean ) : void {
167206 this . isClicked = this . isHovered ? ! this . isClicked : ( keepState ? this . isClicked : false ) ;
0 commit comments