@@ -4,6 +4,7 @@ import PgPoco from '../../poco';
44import { demos } from './examples' ;
55
66import template from './basic.html' ;
7+ import { mockMyFont , mockMyFontBMP } from './myFont' ;
78
89function extractBody ( fn ) {
910 const src = fn . toString ( ) ;
@@ -44,44 +45,47 @@ export default class XPgPocoBasic extends HTMLElement {
4445 this . $code . value = extractBody ( demos [ 0 ] . run ) ;
4546 this . $run . addEventListener ( 'click' , this . handleRun . bind ( this ) ) ;
4647 this . $error . style . display = 'none' ;
47- // Load testing resources
48- this . $poco . setResource ( 'colorBitmap.bmp' , 40 , 40 , ( ctx , w , h ) => {
48+ // Resources
49+ this . $poco . setResourceBMPCanvas ( 'colorBitmap.bmp' , 40 , 40 , ( ctx , w , h ) => {
4950 ctx . fillStyle = "#fff" ; ctx . fillRect ( 0 , 0 , w , h ) ;
5051 ctx . fillStyle = "#000" ; ctx . fillRect ( 4 , 4 , 32 , 32 ) ;
5152 ctx . fillStyle = "#fff" ; ctx . fillRect ( 8 , 8 , 24 , 24 ) ;
5253 ctx . fillStyle = "#000" ; ctx . fillRect ( 12 , 12 , 16 , 16 ) ;
5354 ctx . fillStyle = "#fff" ; ctx . fillRect ( 16 , 16 , 8 , 8 ) ;
5455 } ) ;
55- this . $poco . setResource ( 'monoBitmap.bmp' , 32 , 32 , ( ctx , w , h ) => {
56+ this . $poco . setResourceBMPCanvas ( 'monoBitmap.bmp' , 32 , 32 , ( ctx , w , h ) => {
5657 ctx . fillStyle = "#fff" ; ctx . fillRect ( 0 , 0 , w , h ) ;
5758 ctx . strokeStyle = "#000" ; ctx . lineWidth = 1 ;
5859 ctx . strokeRect ( 0.5 , 0.5 , w - 1 , h - 1 ) ;
5960 ctx . beginPath ( ) ; ctx . moveTo ( 0 , 0 ) ; ctx . lineTo ( w / 2 , h / 2 ) ; ctx . lineTo ( w , 0 ) ; ctx . stroke ( ) ;
6061 ctx . beginPath ( ) ; ctx . moveTo ( 0 , h ) ; ctx . lineTo ( w / 2 , h / 2 ) ; ctx . lineTo ( w , h ) ; ctx . stroke ( ) ;
6162 } ) ;
62- this . $poco . setResource ( 'grayBitmap.bmp' , 32 , 32 , ( ctx , w , h ) => {
63+ this . $poco . setResourceBMPCanvas ( 'grayBitmap.bmp' , 32 , 32 , ( ctx , w , h ) => {
6364 const grad = ctx . createRadialGradient ( w / 2 , h / 2 , 2 , w / 2 , h / 2 , w / 2 ) ;
6465 grad . addColorStop ( 0 , "#fff" ) ;
6566 grad . addColorStop ( 1 , "#000" ) ;
6667 ctx . fillStyle = grad ;
6768 ctx . fillRect ( 0 , 0 , w , h ) ;
6869 } ) ;
69- this . $poco . setResource ( 'circleMask.bmp' , 40 , 40 , ( ctx , w , h ) => {
70+ this . $poco . setResourceBMPCanvas ( 'circleMask.bmp' , 40 , 40 , ( ctx , w , h ) => {
7071 ctx . fillStyle = "#000" ; ctx . fillRect ( 0 , 0 , w , h ) ;
7172 const grad = ctx . createRadialGradient ( w / 2 , h / 2 , 0 , w / 2 , h / 2 , w / 2 ) ;
7273 grad . addColorStop ( 0 , "#fff" ) ;
7374 grad . addColorStop ( 1 , "#000" ) ;
7475 ctx . fillStyle = grad ;
7576 ctx . beginPath ( ) ; ctx . arc ( w / 2 , h / 2 , w / 2 , 0 , Math . PI * 2 ) ; ctx . fill ( ) ;
7677 } ) ;
77- this . $poco . setResource ( 'patternBitmap.bmp' , 30 , 30 , ( ctx , w , h ) => {
78+ this . $poco . setResourceBMPCanvas ( 'patternBitmap.bmp' , 30 , 30 , ( ctx , w , h ) => {
7879 const size = 10 ;
7980 for ( let r = 0 ; r < h ; r += size )
8081 for ( let c = 0 ; c < w ; c += size ) {
8182 ctx . fillStyle = ( ( r + c ) / size % 2 === 0 ) ? "#000" : "#fff" ;
8283 ctx . fillRect ( c , r , size , size ) ;
8384 }
8485 } ) ;
86+ // Resources - Font
87+ this . $poco . setResourceBMP ( 'myFont.bmp' , mockMyFontBMP ) ;
88+ this . $poco . setResourceBMFJSON ( 'myFont.fnt' , mockMyFont ) ;
8589 }
8690
8791 handleRun ( ) {
@@ -110,6 +114,7 @@ export default class XPgPocoBasic extends HTMLElement {
110114 } catch ( e : any ) {
111115 this . $error . textContent = e . message ;
112116 this . $error . style . display = "block" ;
117+ throw e ;
113118 }
114119 }
115120}
0 commit comments