@@ -161,8 +161,8 @@ window.onload = function () {
161161 messagefolder . add ( options , "ui_message_text" ) . name ( "Message Text" ) . onChange ( updateMask ) ;
162162 messagefolder . add ( options , "ui_message_scale" ) . min ( 0 ) . max ( 10 ) . step ( 1 ) . name ( "Scale" ) . onChange ( updateMask ) ;
163163 const messagePositionFolder = messagefolder . addFolder ( "Position" ) ;
164- messagePositionFolder . add ( options , "ui_message_positionX" ) . min ( 0 ) . max ( 200 ) . step ( 1 ) . name ( "X" ) . onChange ( updateMask ) ;
165- messagePositionFolder . add ( options , "ui_message_positionY" ) . min ( 0 ) . max ( 200 ) . step ( 1 ) . name ( "Y" ) . onChange ( updateMask ) ;
164+ messagePositionFolder . add ( options , "ui_message_positionX" ) . min ( - 100 ) . max ( 100 ) . step ( 1 ) . name ( "X" ) . onChange ( updateMask ) ;
165+ messagePositionFolder . add ( options , "ui_message_positionY" ) . min ( - 100 ) . max ( 100 ) . step ( 1 ) . name ( "Y" ) . onChange ( updateMask ) ;
166166
167167 const otherFolder = gui . addFolder ( "Other" ) ;
168168 otherFolder . add ( options , 'ui_other_codesCommaSeparated' ) . name ( 'Codes (Comma separated)' ) . onChange ( ( ) => {
@@ -432,11 +432,14 @@ window.onload = function () {
432432 }
433433
434434 if ( options . ui_message_message ) {
435+ let bb = getTextBoundingBox ( options . ui_message_text ) ;
435436 if ( options . ui_message_scale > 0 ) {
436- let position = [ 0 , 5 * options . ui_message_scale ] ;
437- drawTextOnMask ( options . ui_message_text , position [ 0 ] + options . ui_message_positionX , position [ 1 ] + options . ui_message_positionY , options . ui_message_scale ) ;
438- } else
439- drawTextOnMatrix ( options . ui_message_text , options . ui_message_positionX , options . ui_message_positionY ) ;
437+ let center = [ Math . floor ( ( columns - bb [ 0 ] * 4 * options . ui_message_scale ) / 2 ) , Math . floor ( ( rows - bb [ 1 ] * 6 * options . ui_message_scale ) / 2 ) ] ;
438+ drawTextOnMask ( options . ui_message_text , center [ 0 ] + options . ui_message_positionX , center [ 1 ] + options . ui_message_positionY , options . ui_message_scale ) ;
439+ } else {
440+ let center = [ Math . floor ( ( columns - bb [ 0 ] ) / 2 ) , Math . floor ( ( rows - bb [ 1 ] ) / 2 ) ] ;
441+ drawTextOnMatrix ( options . ui_message_text , center [ 0 ] + options . ui_message_positionX , center [ 1 ] + options . ui_message_positionY ) ;
442+ }
440443 }
441444 }
442445
@@ -453,9 +456,16 @@ window.onload = function () {
453456 y = clamp ( 0 , rows - lines . length , y ) ;
454457
455458 for ( let i = 0 ; i < lines . length ; i ++ ) {
456- mask . fillRect ( x * options . ui_font_size - font_offset_x , ( y + i ) * options . ui_font_size + font_offset_y , lines [ i ] . length * options . ui_font_size , options . ui_font_size ) ;
459+
460+ let sections = lines [ i ] . split ( " " ) , currentCharIndex = 0 ;
461+ for ( let j = 0 ; j < sections . length ; j ++ ) {
462+ if ( sections [ j ] . length > 0 )
463+ mask . fillRect ( ( x + currentCharIndex ) * options . ui_font_size - font_offset_x , ( y + i ) * options . ui_font_size + font_offset_y , sections [ j ] . length * options . ui_font_size , options . ui_font_size ) ;
464+ currentCharIndex += sections [ j ] . length + 1 ;
465+ }
466+
457467 for ( let j = 0 ; j < lines [ i ] . length ; j ++ )
458- staticChars [ x + j ] [ y + i + 1 ] = lines [ i ] [ j ] ;
468+ staticChars [ x + j ] [ y + i + 1 ] = lines [ i ] [ j ] != " " ? lines [ i ] [ j ] : null ;
459469 }
460470 }
461471
@@ -464,7 +474,16 @@ window.onload = function () {
464474 mask . fillStyle = "#FFF" ;
465475 lines = text . split ( "\\n" ) ;
466476 for ( let i = 0 ; i < lines . length ; i ++ )
467- mask . fillText ( lines [ i ] , options . ui_font_size * x - font_offset_x , options . ui_font_size * y + font_offset_y + ( 6 * i * options . ui_font_size * scale ) ) ;
477+ mask . fillText ( lines [ i ] , options . ui_font_size * x - font_offset_x , options . ui_font_size * ( y + ( 6 * ( i + 1 ) * scale ) ) + font_offset_y ) ;
478+ }
479+
480+ function getTextBoundingBox ( text ) {
481+ lines = text . split ( "\\n" ) ;
482+ var maxChars = 0 ;
483+ for ( let i = 0 ; i < lines . length ; i ++ )
484+ if ( lines [ i ] . length > maxChars )
485+ maxChars = lines [ i ] . length ;
486+ return [ maxChars , lines . length ] ;
468487 }
469488
470489 function drawMask ( ) {
@@ -508,8 +527,8 @@ window.onload = function () {
508527
509528 //MARK: Grid
510529 function updateGrid ( ) {
511- columns = neoMatrixDom . width / options . ui_font_size ;
512- rows = neoMatrixDom . height / options . ui_font_size ;
530+ columns = Math . floor ( neoMatrixDom . width / options . ui_font_size ) ;
531+ rows = Math . floor ( neoMatrixDom . height / options . ui_font_size ) ;
513532 column_hue = Math . floor ( 360 / columns ) ;
514533 row_hue = Math . floor ( 360 / rows ) ;
515534 column_frequency = frequencyArrayLength / ( columns * 2 ) ;
0 commit comments