@@ -158,6 +158,7 @@ AFRAME.registerComponent('gui-button', {
158158 schema : {
159159 on : { default : 'click' } ,
160160 toggle : { type : 'boolean' , default : false } ,
161+ toggleState : { type : 'boolean' , default : false } ,
161162 text : { type : 'string' , default : 'text' } ,
162163 fontSize : { type : 'string' , default : '150px' } ,
163164 fontFamily : { type : 'string' , default : 'Arial' } ,
@@ -166,6 +167,7 @@ AFRAME.registerComponent('gui-button', {
166167 backgroundColor : { type : 'string' , default : key_grey } ,
167168 hoverColor : { type : 'string' , default : key_grey_dark } ,
168169 activeColor : { type : 'string' , default : key_orange }
170+
169171 } ,
170172 init : function init ( ) {
171173
@@ -178,7 +180,6 @@ AFRAME.registerComponent('gui-button', {
178180 var multiplier = 512 ; // POT conversion
179181 var canvasWidth = guiItem . width * multiplier ;
180182 var canvasHeight = guiItem . height * multiplier ;
181- var toggleState = this . toggleState = data . toggle ;
182183
183184 var canvasContainer = document . createElement ( 'div' ) ;
184185 canvasContainer . setAttribute ( 'class' , 'visuallyhidden' ) ;
@@ -220,25 +221,30 @@ AFRAME.registerComponent('gui-button', {
220221
221222 el . addEventListener ( 'mouseenter' , function ( ) {
222223 buttonEntity . removeAttribute ( 'animation__leave' ) ;
223- buttonEntity . setAttribute ( 'animation__enter' , 'property: material.color; from: ' + data . backgroundColor + '; to:' + data . hoverColor + '; dur:200;' ) ;
224+ if ( ! data . toggle ) {
225+ buttonEntity . setAttribute ( 'animation__enter' , 'property: material.color; from: ' + data . backgroundColor + '; to:' + data . hoverColor + '; dur:200;' ) ;
226+ }
224227 } ) ;
225228 el . addEventListener ( 'mouseleave' , function ( ) {
226229 if ( ! data . toggle ) {
227230 buttonEntity . removeAttribute ( 'animation__click' ) ;
231+ buttonEntity . setAttribute ( 'animation__leave' , 'property: material.color; from: ' + data . hoverColor + '; to:' + data . backgroundColor + '; dur:200; easing: easeOutQuad;' ) ;
228232 }
229233 buttonEntity . removeAttribute ( 'animation__enter' ) ;
230- buttonEntity . setAttribute ( 'animation__leave' , 'property: material.color; from: ' + data . hoverColor + '; to:' + data . backgroundColor + '; dur:200; easing: easeOutQuad;' ) ;
231234 } ) ;
232235 el . addEventListener ( data . on , function ( ) {
233236 if ( ! data . toggle ) {
234237 // if not toggling flashing active state
235238 buttonEntity . setAttribute ( 'animation__click' , 'property: material.color; from: ' + data . activeColor + '; to:' + data . backgroundColor + '; dur:400; easing: easeOutQuad;' ) ;
236239 } else {
237- buttonEntity . setAttribute ( 'material' , 'color' , data . activeColor ) ;
240+ var guiButton = el . components [ 'gui-button' ] ;
241+ // console.log("about to toggle, current state: " + guiButton.data.toggleState);
242+ guiButton . setActiveState ( ! guiButton . data . toggleState ) ;
243+ // buttonEntity.setAttribute('material', 'color', data.activeColor);
238244 }
239245
240246 var clickActionFunctionName = guiInteractable . clickAction ;
241- console . log ( "in button, clickActionFunctionName: " + clickActionFunctionName ) ;
247+ // console.log("in button, clickActionFunctionName: "+ clickActionFunctionName);
242248 // find object
243249 var clickActionFunction = window [ clickActionFunctionName ] ;
244250 //console.log("clickActionFunction: "+clickActionFunction);
@@ -251,14 +257,18 @@ AFRAME.registerComponent('gui-button', {
251257 } ,
252258 play : function play ( ) { } ,
253259 update : function update ( oldData ) {
254- console . log ( "In button update, toggle: " + this . toggleState ) ;
260+ // console.log("In button update, toggle: "+ this.data .toggleState);
255261 } ,
256262 setActiveState : function setActiveState ( activeState ) {
257- console . log ( "in setActiveState function" ) ;
258- this . data . toggle = this . toggleState = activeState ;
263+ // console.log("in setActiveState function, new state: " + activeState );
264+ this . data . toggleState = activeState ;
259265 if ( ! activeState ) {
266+ console . log ( 'not active, about to set background color' ) ;
260267 this . buttonEntity . setAttribute ( 'material' , 'color' , this . data . backgroundColor ) ;
261- } else { }
268+ } else {
269+ console . log ( 'active, about to set active color' ) ;
270+ this . buttonEntity . setAttribute ( 'material' , 'color' , this . data . activeColor ) ;
271+ }
262272 } ,
263273 setText : function setText ( newText ) {
264274 drawText ( this . ctx , this . canvas , newText , this . data . fontSize , this . data . fontFamily , this . data . fontColor , 1 , 'center' , 'middle' ) ;
@@ -505,6 +515,18 @@ AFRAME.registerComponent('gui-circle-timer', {
505515 this . timerRing . setAttribute ( 'theta-length' , elapsed ) ; // this has to increase 0 to 360 when running the count_down
506516 //text doesn't update
507517 drawText ( this . ctx , this . canvas , left , data . fontSize , data . fontFamily , data . fontColor , 1 , 'center' , 'middle' ) ;
518+ if ( this . countDownLabel ) {
519+ el . removeChild ( this . countDownLabel ) ;
520+ }
521+ var guiItem = el . getAttribute ( "gui-item" ) ;
522+ var canvas = this . canvas ;
523+ var countDownLabel = document . createElement ( "a-entity" ) ;
524+ countDownLabel . setAttribute ( 'geometry' , 'primitive: plane; width: ' + guiItem . height / 1.5 + '; height: ' + guiItem . height / 1.5 + ';' ) ;
525+ countDownLabel . setAttribute ( 'material' , 'shader: flat; src: #' + canvas . id + '; transparent: true; opacity: 1; side:front;' ) ;
526+ countDownLabel . setAttribute ( 'position' , '0 0 0.022' ) ;
527+ el . appendChild ( countDownLabel ) ;
528+ this . countDownLabel = countDownLabel ;
529+
508530 if ( left == 1 ) {
509531 console . log ( 'fire callback on the last second' ) ;
510532 }
@@ -1720,7 +1742,9 @@ AFRAME.registerComponent('gui-label', {
17201742 var canvasHeight = guiItem . height * multiplier ;
17211743
17221744 var canvasContainer = document . createElement ( 'div' ) ;
1745+ this . canvasContainer = canvasContainer ;
17231746 canvasContainer . setAttribute ( 'class' , 'visuallyhidden' ) ;
1747+ canvasContainer . id = getUniqueId ( 'canvasContainer' ) ;
17241748 document . body . appendChild ( canvasContainer ) ;
17251749
17261750 var canvas = document . createElement ( "canvas" ) ;
@@ -1738,11 +1762,15 @@ AFRAME.registerComponent('gui-label', {
17381762
17391763 this . oldText = data . text ;
17401764
1741- drawText ( ctx , canvas , data . text , guiItem . fontSize + ' ' + data . fontFamily , data . fontColor , 1 ) ;
1765+ // drawText(ctx, canvas, data.text, guiItem.fontSize+ ' ' + data.fontFamily, data.fontColor, 1);
17421766
17431767 drawText ( ctx , canvas , data . text , data . fontSize , data . fontFamily , data . fontColor , 1 , 'center' , 'middle' ) ;
17441768
1769+ if ( this . textEntity ) {
1770+ el . removeChild ( this . textEntity ) ;
1771+ }
17451772 var textEntity = document . createElement ( "a-entity" ) ;
1773+ this . textEntity = textEntity ;
17461774 textEntity . setAttribute ( 'geometry' , 'primitive: plane; width: ' + guiItem . width / 1.05 + '; height: ' + guiItem . height / 1.05 + ';' ) ;
17471775 textEntity . setAttribute ( 'material' , 'shader: flat; src: #' + canvas . id + '; transparent: true; opacity: 1; side:front;' ) ;
17481776 textEntity . setAttribute ( 'position' , '0 0 0.001' ) ;
@@ -1760,7 +1788,10 @@ AFRAME.registerComponent('gui-label', {
17601788 } ,
17611789 tick : function tick ( ) {
17621790 if ( this . data . text !== this . oldText ) {
1763- drawText ( this . ctx , this . canvas , this . data . text , '100px ' + this . data . fontFamily , this . data . fontColor , 1 ) ;
1791+ // console.log('text was changed, about to draw text: ' + this.data.text);
1792+ this . oldText = this . data . text ;
1793+ // drawText(this.ctx, this.canvas, this.data.text, '100px ' + this.data.fontFamily, this.data.fontColor, 1);
1794+ drawText ( this . ctx , this . canvas , this . data . text , this . data . fontSize , this . data . fontFamily , this . data . fontColor , 1 , 'center' , 'middle' ) ;
17641795 }
17651796 }
17661797} ) ;
@@ -1774,10 +1805,10 @@ AFRAME.registerPrimitive('a-gui-label', {
17741805 'width' : 'gui-item.width' ,
17751806 'height' : 'gui-item.height' ,
17761807 'margin' : 'gui-item.margin' ,
1777- 'font-size' : 'gui-item.fontSize' ,
17781808 'on' : 'gui-button.on' ,
17791809 'value' : 'gui-label.text' ,
17801810 'label-for' : 'gui-label.labelFor' ,
1811+ 'font-size' : 'gui-label.fontSize' ,
17811812 'font-color' : 'gui-label.fontColor' ,
17821813 'font-family' : 'gui-label.fontFamily' ,
17831814 'background-color' : 'gui-label.backgroundColor'
0 commit comments