+ rImage.drawGraphics( *m_pImage,
+ inter.x - pPos->getLeft(),
+ inter.y - pPos->getTop(),
+ inter.x, inter.y,
+ inter.width, inter.height );
+ }
+ else if( m_resizeMethod == kMosaic )
+ {
+ int xDest0 = pPos->getLeft();
+ int yDest0 = pPos->getTop();
+
+ // Use mosaic method
+ while( width > 0 )
+ {
+ int curWidth = __MIN( width, m_pImage->getWidth() );
+ height = pPos->getHeight();
+ int curYDest = yDest0;
+ while( height > 0 )
+ {
+ int curHeight = __MIN( height, m_pImage->getHeight() );
+ rect region1( xDest0, curYDest, curWidth, curHeight );
+ rect inter1;
+ if( rect::intersect( region1, clip, &inter1 ) )
+ {
+ rImage.drawGraphics( *m_pImage,
+ inter1.x - region1.x,
+ inter1.y - region1.y,
+ inter1.x, inter1.y,
+ inter1.width, inter1.height );
+ }
+ curYDest += curHeight;
+ height -= m_pImage->getHeight();
+ }
+ xDest0 += curWidth;
+ width -= m_pImage->getWidth();
+ }
+ }
+ else if( m_resizeMethod == kScaleAndRatioPreserved )
+ {
+ int w0 = m_pBitmap->getWidth();
+ int h0 = m_pBitmap->getHeight();
+
+ int scaled_height = width * h0 / w0;
+ int scaled_width = height * w0 / h0;
+
+ // new image scaled with aspect ratio preserved
+ // and centered inside the control boundaries
+ int w, h;
+ if( scaled_height > height )
+ {
+ w = scaled_width;
+ h = height;
+ m_x = ( width - w ) / 2;
+ m_y = 0;
+ }
+ else
+ {
+ w = width;
+ h = scaled_height;
+ m_x = 0;
+ m_y = ( height - h ) / 2;
+ }
+
+ // rescale the image if size changed
+ if( w != m_pImage->getWidth() ||
+ h != m_pImage->getHeight() )
+ {
+ OSFactory *pOsFactory = OSFactory::instance( getIntf() );
+ ScaledBitmap bmp( getIntf(), *m_pBitmap, w, h );
+ delete m_pImage;
+ m_pImage = pOsFactory->createOSGraphics( w, h );
+ m_pImage->drawBitmap( bmp, 0, 0 );
+ }
+
+ // draw the scaled image at offset (m_x, m_y) from control origin
+ rect region1( pPos->getLeft() + m_x, pPos->getTop() + m_y, w, h );
+ rect inter1;
+ if( rect::intersect( region1, inter, &inter1 ) )
+ {
+ rImage.drawGraphics( *m_pImage,
+ inter1.x - pPos->getLeft() - m_x,
+ inter1.y - pPos->getTop() - m_y,
+ inter1.x, inter1.y,
+ inter1.width, inter1.height );
+ }