@@ -232,6 +232,10 @@ var CCLScripting = function(workerUrl){
232232 } ) ;
233233 this . addListener ( "Player::action" , function ( msg ) {
234234 try {
235+ if ( self . getPlayer ( ) == null ) {
236+ self . getLogger ( ) . warn ( "Player not initialized!" ) ;
237+ return ;
238+ } ;
235239 switch ( msg . action ) {
236240 default :return ;
237241 case "play" : self . getPlayer ( ) . play ( ) ; break ;
@@ -292,37 +296,69 @@ var CCLScripting = function(workerUrl){
292296 /** Define some unpackers **/
293297 var ScriptingContext = CCLScripting . prototype . ScriptingContext ;
294298 ScriptingContext . prototype . Unpack . Comment = function ( stage , data , ctx ) {
295- this . DOM = _ ( "div" , { } ) ;
296- /** Load the text format **/
299+ this . DOM = _ ( "div" , {
300+ "style" :{
301+ "position" :"absolute" ,
302+ } ,
303+ "className" :"cmt"
304+ } ) ;
305+ /** Load the text **/
297306 this . DOM . appendChild ( document . createTextNode ( data . text ) ) ;
298- this . DOM . style . fontFamily = data . textFormat . font ;
299- this . DOM . style . fontSize = data . textFormat . size + "px" ;
300- this . DOM . style . color = "#" + data . textFormat . color . toString ( 16 ) ;
301- if ( data . textFormat . bold )
302- this . DOM . style . fontWeight = "bold" ;
303- if ( data . textFormat . underline )
304- this . DOM . style . textDecoration = "underline" ;
305- if ( data . textFormat . italic )
306- this . DOM . style . fontStyle = "italic" ;
307- this . DOM . style . margin = data . textFormat . margin ;
307+ var getColor = function ( c ) {
308+ var color = c . toString ( 16 ) ;
309+ while ( color . length < 6 ) {
310+ color = "0" + color ;
311+ }
312+ return "#" + color ;
313+ } ;
314+ this . setTextFormat = function ( textFormat ) {
315+ this . DOM . style . fontFamily = textFormat . font ;
316+ this . DOM . style . fontSize = textFormat . size + "px" ;
317+ this . DOM . style . color = getColor ( textFormat . color ) ;
318+ if ( textFormat . color <= 16 ) {
319+ this . DOM . style . textShadow = "0 0 1px #fff" ;
320+ } ;
321+ if ( textFormat . bold )
322+ this . DOM . style . fontWeight = "bold" ;
323+ if ( textFormat . underline )
324+ this . DOM . style . textDecoration = "underline" ;
325+ if ( textFormat . italic )
326+ this . DOM . style . fontStyle = "italic" ;
327+ this . DOM . style . margin = textFormat . margin ;
328+ } ;
329+ /** Load the text format **/
330+ this . setTextFormat ( data . textFormat ) ;
331+
332+ this . setX = function ( x ) {
333+ data . x = x ;
334+ this . DOM . style . left = data . x + "px" ;
335+ } ;
336+
337+ this . setY = function ( y ) {
338+ data . y = y ;
339+ this . DOM . style . top = data . y + "px" ;
340+ } ;
341+ /** Load x,y **/
342+ this . setX ( data . x ) ;
343+ this . setY ( data . y ) ;
308344
309345 this . setFilters = function ( params ) {
310346 for ( var i = 0 ; i < params [ 0 ] . length ; i ++ ) {
311347 var filter = params [ 0 ] [ i ] ;
312348 if ( filter . type === "blur" ) {
313349 this . DOM . style . color = "transparent" ;
314- this . DOM . style . textShadow = [ - filter . params . blurX + "px" ,
315- - filter . params . blurY + "px" , Math . max (
350+ this . DOM . style . textShadow = [ 0 , 0 , Math . max (
316351 filter . params . blurX , filter . params . blurY ) +
317352 "px" ] . join ( " " ) ;
318353 } else if ( filter . type === "glow" ) {
319- this . DOM . style . textShadow = [ - filter . params . blurX + "px" ,
320- - filter . params . blurY + "px" , Math . max (
354+ this . DOM . style . textShadow = [ 0 , 0 , Math . max (
321355 filter . params . blurX , filter . params . blurY ) +
322- "px" , "#" + filter . params . color . toString ( 16 ) ] . join ( " " ) ;
356+ "px" , getColor ( filter . params . color ) ] . join ( " " ) ;
323357 }
324358 } ;
325359 } ;
360+
361+ /** Common **/
326362 this . unload = function ( ) {
327363 try {
328364 stage . removeChild ( this . DOM ) ;
@@ -343,8 +379,8 @@ var CCLScripting = function(workerUrl){
343379 "width" :"100%" ,
344380 "height" :"100%"
345381 } } ) ;
346- this . x = data . x ;
347- this . y = data . y ;
382+ this . x = data . x ? data . x : 0 ;
383+ this . y = data . y ? data . y : 0 ;
348384 this . alpha = data . alpha ? data . alpha : 1 ;
349385 // Helpers
350386 var __ = function ( e , attr ) {
@@ -362,12 +398,15 @@ var CCLScripting = function(workerUrl){
362398 return elem ;
363399 } ;
364400 var defaultEffects = __ ( "defs" ) ;
365- var defaultGroup = __ ( "g" , { "x" :this . x , "y" :this . y , "opacity" :this . alpha } ) ;
401+ var defaultGroup = __ ( "g" , {
402+ "transform" :"translate(" + this . x + "," + this . y + ")" ,
403+ "opacity" :this . alpha ,
404+ } ) ;
366405 this . DOM . appendChild ( defaultEffects ) ;
367406 this . DOM . appendChild ( defaultGroup ) ;
368407
369408 this . line = {
370- width :1 ,
409+ width :0 ,
371410 color :"#ffffff" ,
372411 alpha :1
373412 } ;
@@ -404,10 +443,20 @@ var CCLScripting = function(workerUrl){
404443
405444 /** Public methods **/
406445 this . setX = function ( x ) {
407- __ ( defaultGroup , { "x" :x } ) ;
446+ if ( ! x )
447+ return ;
448+ this . x = x ;
449+ __ ( defaultGroup , {
450+ "transform" :"translate(" + this . x + "," + this . y + ")"
451+ } ) ;
408452 } ;
409453 this . setY = function ( y ) {
410- __ ( defaultGroup , { "y" :y } ) ;
454+ if ( ! y )
455+ return ;
456+ this . y = y ;
457+ __ ( defaultGroup , {
458+ "transform" :"translate(" + this . x + "," + this . y + ")"
459+ } ) ;
411460 } ;
412461 this . moveTo = function ( params ) {
413462 var p = __ ( "path" , {
@@ -528,10 +577,10 @@ var CCLScripting = function(workerUrl){
528577 var filter = filters [ i ] ;
529578 var dFilter = __ ( "filter" , {
530579 "id" :"fe" + filter . type + i ,
531- "x" :"-50 %" ,
532- "y" :"-50 %" ,
533- "width" :"200 %" ,
534- "height" :"200 %"
580+ "x" :"-100 %" ,
581+ "y" :"-100 %" ,
582+ "width" :"400 %" ,
583+ "height" :"400 %"
535584 } ) ;
536585 switch ( filter . type ) {
537586 default :break ;
0 commit comments