@@ -21,17 +21,56 @@ export default class Inserter {
2121 this . main . clearBackground ( ) ;
2222 this . ctx . putImageData ( tmpData , 0 , 0 ) ;
2323 this . main . adjustSizeFull ( ) ;
24- this . worklog . captureState ( ) ;
2524 if ( img . naturalWidth < oldW ) {
2625 const offset = Math . round ( ( oldW - img . naturalWidth ) / 2 ) ;
2726 this . main . select . placeAt ( offset , oldH , offset , 0 , img ) ;
2827 } else {
2928 this . main . select . placeAt ( 0 , oldH , 0 , 0 , img ) ;
3029 }
30+ this . worklog . captureState ( ) ;
31+ } ,
32+ } ,
33+ extend_right : {
34+ handle : ( img ) => {
35+ this . tmpImg = img ;
36+ const oldH = this . main . size . h ;
37+ const oldW = this . main . size . w ;
38+ const newW = oldW + img . naturalWidth ;
39+ const newH = Math . max ( oldH , img . naturalHeight ) ;
40+ const tmpData = this . ctx . getImageData ( 0 , 0 , this . main . size . w , this . main . size . h ) ;
41+ this . main . resize ( newW , newH ) ;
42+ this . main . clearBackground ( ) ;
43+ this . ctx . putImageData ( tmpData , 0 , 0 ) ;
44+ this . main . adjustSizeFull ( ) ;
45+ if ( img . naturalHeight < oldH ) {
46+ const offset = Math . round ( ( oldH - img . naturalHeight ) / 2 ) ;
47+ this . main . select . placeAt ( oldW , offset , 0 , offset , img ) ;
48+ } else {
49+ this . main . select . placeAt ( oldW , 0 , 0 , 0 , img ) ;
50+ }
51+ this . worklog . captureState ( ) ;
52+ } ,
53+ } ,
54+ over : {
55+ handle : ( img ) => {
56+ this . tmpImg = img ;
57+ const oldH = this . main . size . h ;
58+ const oldW = this . main . size . w ;
59+ if ( img . naturalHeight <= oldH && img . naturalWidth <= oldW ) {
60+ this . main . select . placeAt (
61+ 0 , 0 ,
62+ oldW - img . naturalWidth ,
63+ oldH - img . naturalHeight , img ) ;
64+ } else if ( img . naturalWidth / img . naturalHeight > oldW / oldH ) {
65+ const newH = oldW * ( img . naturalHeight / img . naturalWidth ) ;
66+ this . main . select . placeAt ( 0 , 0 , 0 , oldH - newH , img ) ;
67+ } else {
68+ const newW = oldH * ( img . naturalWidth / img . naturalHeight ) ;
69+ this . main . select . placeAt ( 0 , 0 , oldW - newW , 0 , img ) ;
70+ }
71+ this . worklog . captureState ( ) ;
3172 } ,
3273 } ,
33- extend_right : { } ,
34- over : { } ,
3574 } ;
3675 }
3776
@@ -58,8 +97,8 @@ export default class Inserter {
5897 }
5998
6099 insert ( x , y , w , h ) {
61- console . log ( "inserting " , this . tmpImg , x , y , w , h ) ;
62100 this . main . ctx . drawImage ( this . tmpImg , x , y , w , h ) ;
101+ this . main . worklog . reCaptureState ( ) ;
63102 }
64103
65104 loaded ( img ) {
0 commit comments