@@ -72,11 +72,20 @@ class Rect {
72
72
// Raphel rect element
73
73
this . $el = null ;
74
74
75
+ // lock unlock feature
75
76
this . locked = false ;
76
77
this . $lock_el = null ;
77
78
this . lock_el = null ;
78
79
this . lock_offset = 0 ;
79
80
81
+ //display label over rect
82
+ this . $label_el = null ;
83
+ this . label_el = null ;
84
+ this . label_offset = 0 ;
85
+
86
+ this . $label_background_el = null ;
87
+ this . label_background_el = null ;
88
+
80
89
// jQuer rect element
81
90
this . el = null ;
82
91
@@ -116,9 +125,9 @@ class Rect {
116
125
this . $el = this . $paper . rect ( 0 , 0 , this . $paper . width , this . $paper . height ) ;
117
126
this . el = this . $el . node ;
118
127
$ ( this . el ) . attr ( "id" , this . $el . id ) ;
119
-
128
+
120
129
var { scale} = this . getPlayerMetrics ( ) ;
121
-
130
+
122
131
this . $lock_el = this . $paper . text ( this . $paper . width / 2 , this . $paper . height / 2 , '\uf023' )
123
132
this . lock_el = this . $lock_el . node ;
124
133
$ ( this . lock_el ) . removeAttr ( 'style' ) ;
@@ -130,6 +139,21 @@ class Rect {
130
139
$ ( this . lock_el ) . addClass ( 'fas' ) ;
131
140
$ ( this . lock_el ) . css ( { visibility : "hidden" } ) ;
132
141
142
+ this . $label_el = this . $paper . text ( this . $paper . width / 2 , this . $paper . height / 2 , "" ) ;
143
+ this . label_el = this . $label_el . node ;
144
+ $ ( this . label_el ) . removeAttr ( 'style' ) ;
145
+ this . $label_el . attr ( {
146
+ fill : "white" ,
147
+ "font-size" : 15 / scale ,
148
+ } ) ;
149
+ this . label_offset = 8 / scale ;
150
+ $ ( this . label_el ) . css ( { visibility : "hidden" } ) ;
151
+
152
+ this . $label_background_el = this . $paper . rect ( 0 , 0 , 0 , 0 ) ;
153
+ this . label_background_el = this . $label_background_el . node ;
154
+ $ ( this . label_background_el ) . removeAttr ( 'style' ) ;
155
+ $ ( this . label_background_el ) . css ( { visibility : "hidden" } ) ;
156
+
133
157
//container
134
158
this . applyPreAttachedAppearance ( ) ;
135
159
this . setHandlers ( ) ;
@@ -161,13 +185,19 @@ class Rect {
161
185
162
186
appear ( { real, selected, singlekeyframe} ) {
163
187
this . setClassNameExts ( { real, selected, singlekeyframe} ) ;
164
-
188
+
165
189
if ( real ) {
190
+ this . $label_el . attr ( 'text' , this . _title ) ;
191
+ $ ( this . label_el ) . css ( { visibility : "visible" } ) ;
192
+ $ ( this . label_background_el ) . css ( { visibility : "visible" } ) ;
193
+ this . $label_el . toFront ( ) ;
166
194
if ( this . locked ) {
167
195
$ ( this . lock_el ) . css ( { visibility : "visible" } ) ;
168
196
}
169
197
} else {
170
198
$ ( this . lock_el ) . css ( { visibility : "hidden" } ) ;
199
+ $ ( this . label_el ) . css ( { visibility : "hidden" } ) ;
200
+ $ ( this . label_background_el ) . css ( { visibility : "hidden" } ) ;
171
201
}
172
202
173
203
if ( selected === true ) {
@@ -288,10 +318,21 @@ class Rect {
288
318
}
289
319
else {
290
320
this . $el . attr ( Bounds . toAttrs ( bounds ) ) ;
291
- this . $lock_el . attr ( { x : bounds . xMin + this . lock_offset ,
321
+ this . $lock_el . attr ( { x : bounds . xMin + this . lock_offset ,
292
322
y : bounds . yMin + this . lock_offset } ) ;
293
- }
323
+ this . $label_el . attr ( { x : ( bounds . xMax - ( bounds . xMax - bounds . xMin ) / 2 ) ,
324
+ y : bounds . yMax + this . label_offset } ) ;
325
+ var box = this . $label_el . getBBox ( ) ;
326
+ this . $label_background_el . attr ( {
327
+ x : box . x ,
328
+ y : box . y ,
329
+ width : box . width ,
330
+ height : box . height ,
331
+ fill : '#337ab7' ,
332
+ stroke : '#337ab7'
294
333
334
+ } ) ;
335
+ }
295
336
this . _bounds = bounds ;
296
337
297
338
// Trigger event
0 commit comments