Commit f07020df authored by Cyril Deguet's avatar Cyril Deguet

* skin.dtd: added an attribute "resize" in the "Image" element, to define

  the method used to resize the image, which can be "mosaic" (the default)
  or "scale". Note that the previous behaviour was always "scale" before,
  but mosaic is much much faster, so use scale method only for fun ;)
* skins2/*: support of the new mosaic method; playlist resize with this
  method is significantly faster!
parent a110441d
...@@ -32,8 +32,10 @@ ...@@ -32,8 +32,10 @@
CtrlImage::CtrlImage( intf_thread_t *pIntf, const GenericBitmap &rBitmap, CtrlImage::CtrlImage( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
const UString &rHelp, VarBool *pVisible ): resize_t resizeMethod, const UString &rHelp,
CtrlFlat( pIntf, rHelp, pVisible ), m_rBitmap( rBitmap ) VarBool *pVisible ):
CtrlFlat( pIntf, rHelp, pVisible ), m_rBitmap( rBitmap ),
m_resizeMethod( resizeMethod )
{ {
OSFactory *pOsFactory = OSFactory::instance( pIntf ); OSFactory *pOsFactory = OSFactory::instance( pIntf );
// Create an initial unscaled image in the buffer // Create an initial unscaled image in the buffer
...@@ -79,16 +81,42 @@ void CtrlImage::draw( OSGraphics &rImage, int xDest, int yDest ) ...@@ -79,16 +81,42 @@ void CtrlImage::draw( OSGraphics &rImage, int xDest, int yDest )
{ {
int width = pPos->getWidth(); int width = pPos->getWidth();
int height = pPos->getHeight(); int height = pPos->getHeight();
if( width != m_pImage->getWidth() || height != m_pImage->getHeight() )
if( m_resizeMethod == kScale )
{
// Use scaling method
if( width != m_pImage->getWidth() ||
height != m_pImage->getHeight() )
{
OSFactory *pOsFactory = OSFactory::instance( getIntf() );
// Rescale the image with the actual size of the control
ScaledBitmap bmp( getIntf(), m_rBitmap, width, height );
SKINS_DELETE( m_pImage );
m_pImage = pOsFactory->createOSGraphics( width, height );
m_pImage->drawBitmap( bmp, 0, 0 );
}
rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest );
}
else
{ {
OSFactory *pOsFactory = OSFactory::instance( getIntf() ); // Use mosaic method
// Rescale the image with the actual size of the control while( width > 0 )
ScaledBitmap bmp( getIntf(), m_rBitmap, width, height ); {
SKINS_DELETE( m_pImage ); int curWidth = __MIN( width, m_pImage->getWidth() );
m_pImage = pOsFactory->createOSGraphics( width, height ); height = pPos->getHeight();
m_pImage->drawBitmap( bmp, 0, 0 ); int curYDest = yDest;
while( height > 0 )
{
int curHeight = __MIN( height, m_pImage->getHeight() );
rImage.drawGraphics( *m_pImage, 0, 0, xDest, curYDest,
curWidth, curHeight );
curYDest += curHeight;
height -= m_pImage->getHeight();
}
xDest += curWidth;
width -= m_pImage->getWidth();
}
} }
rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest );
} }
} }
...@@ -36,9 +36,17 @@ class OSGraphics; ...@@ -36,9 +36,17 @@ class OSGraphics;
class CtrlImage: public CtrlFlat class CtrlImage: public CtrlFlat
{ {
public: public:
/// Resize methods
typedef enum
{
kMosaic, // Repeat the base image in a mosaic
kScale // Scale the base image
} resize_t;
// Create an image with the given bitmap (which is NOT copied) // Create an image with the given bitmap (which is NOT copied)
CtrlImage( intf_thread_t *pIntf, const GenericBitmap &rBitmap, CtrlImage( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
const UString &rHelp, VarBool *pVisible ); resize_t resizeMethod, const UString &rHelp,
VarBool *pVisible );
virtual ~CtrlImage(); virtual ~CtrlImage();
/// Handle an event on the control /// Handle an event on the control
...@@ -58,6 +66,8 @@ class CtrlImage: public CtrlFlat ...@@ -58,6 +66,8 @@ class CtrlImage: public CtrlFlat
const GenericBitmap &m_rBitmap; const GenericBitmap &m_rBitmap;
/// Buffer to stored the rendered bitmap /// Buffer to stored the rendered bitmap
OSGraphics *m_pImage; OSGraphics *m_pImage;
/// Resize method
resize_t m_resizeMethod;
}; };
#endif #endif
...@@ -389,7 +389,9 @@ void Builder::addImage( const BuilderData::Image &rData ) ...@@ -389,7 +389,9 @@ void Builder::addImage( const BuilderData::Image &rData )
Interpreter *pInterpreter = Interpreter::instance( getIntf() ); Interpreter *pInterpreter = Interpreter::instance( getIntf() );
VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme ); VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp, CtrlImage::resize_t resizeMethod =
(rData.m_resize == "scale" ? CtrlImage::kScale : CtrlImage::kMosaic);
CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp, resizeMethod,
UString( getIntf(), rData.m_help.c_str() ), pVisible ); UString( getIntf(), rData.m_help.c_str() ), pVisible );
// Compute the position of the control // Compute the position of the control
......
...@@ -7,7 +7,7 @@ Layout id:string width:int height:int minWidth:int maxWidth:int minHeight:int ma ...@@ -7,7 +7,7 @@ Layout id:string width:int height:int minWidth:int maxWidth:int minHeight:int ma
Anchor xPos:int yPos:int range:int priority:int points:string layoutId:string Anchor xPos:int yPos:int range:int priority:int points:string layoutId:string
Button id:string xPos:int yPos:int leftTop:string rightBottom:string visible:string upId:string downId:string overId:string actionId:string tooltip:string help:string layer:int windowId:string layoutId:string Button id:string xPos:int yPos:int leftTop:string rightBottom:string visible:string upId:string downId:string overId:string actionId:string tooltip:string help:string layer:int windowId:string layoutId:string
Checkbox id:string xPos:int yPos:int leftTop:string rightBottom:string visible:string up1Id:string down1Id:string over1Id:string up2Id:string down2Id:string over2Id:string state:string action1:string action2:string tooltip1:string tooltip2:string help:string layer:int windowId:string layoutId:string Checkbox id:string xPos:int yPos:int leftTop:string rightBottom:string visible:string up1Id:string down1Id:string over1Id:string up2Id:string down2Id:string over2Id:string state:string action1:string action2:string tooltip1:string tooltip2:string help:string layer:int windowId:string layoutId:string
Image id:string xPos:int yPos:int leftTop:string rightBottom:string visible:string bmpId:string actionId:string help:string layer:int windowId:string layoutId:string Image id:string xPos:int yPos:int leftTop:string rightBottom:string visible:string bmpId:string actionId:string resize:string help:string layer:int windowId:string layoutId:string
Text id:string xPos:int yPos:int visible:string fontId:string text:string width:int leftTop:string rightBottom:string color:uint32_t help:string layer:int windowId:string layoutId:string Text id:string xPos:int yPos:int visible:string fontId:string text:string width:int leftTop:string rightBottom:string color:uint32_t help:string layer:int windowId:string layoutId:string
RadialSlider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string sequence:string nbImages:int minAngle:float maxAngle:float value:string tooltip:string help:string layer:int windowId:string layoutId:string RadialSlider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string sequence:string nbImages:int minAngle:float maxAngle:float value:string tooltip:string help:string layer:int windowId:string layoutId:string
Slider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string upId:string downId:string overId:string points:string thickness:int value:string tooltip:string help:string layer:int windowId:string layoutId:string Slider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string upId:string downId:string overId:string points:string thickness:int value:string tooltip:string help:string layer:int windowId:string layoutId:string
......
...@@ -201,8 +201,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom( ...@@ -201,8 +201,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom(
/// Type definition /// Type definition
struct Image struct Image
{ {
Image( const string & id, int xPos, int yPos, const string & leftTop, const string & rightBottom, const string & visible, const string & bmpId, const string & actionId, const string & help, int layer, const string & windowId, const string & layoutId ): Image( const string & id, int xPos, int yPos, const string & leftTop, const string & rightBottom, const string & visible, const string & bmpId, const string & actionId, const string & resize, const string & help, int layer, const string & windowId, const string & layoutId ):
m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_visible( visible ), m_bmpId( bmpId ), m_actionId( actionId ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {} m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_visible( visible ), m_bmpId( bmpId ), m_actionId( actionId ), m_resize( resize ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
const string m_id; const string m_id;
int m_xPos; int m_xPos;
...@@ -212,6 +212,7 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom( ...@@ -212,6 +212,7 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom(
const string m_visible; const string m_visible;
const string m_bmpId; const string m_bmpId;
const string m_actionId; const string m_actionId;
const string m_resize;
const string m_help; const string m_help;
int m_layer; int m_layer;
const string m_windowId; const string m_windowId;
......
...@@ -173,13 +173,14 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -173,13 +173,14 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
CheckDefault( "lefttop", "lefttop" ); CheckDefault( "lefttop", "lefttop" );
CheckDefault( "rightbottom", "lefttop" ); CheckDefault( "rightbottom", "lefttop" );
CheckDefault( "action", "none" ); CheckDefault( "action", "none" );
CheckDefault( "resize", "mosaic" );
CheckDefault( "help", "" ); CheckDefault( "help", "" );
const BuilderData::Image imageData( uniqueId( attr["id"] ), const BuilderData::Image imageData( uniqueId( attr["id"] ),
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset, atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
attr["lefttop"], attr["rightbottom"], attr["visible"], attr["lefttop"], attr["rightbottom"], attr["visible"],
attr["image"], attr["action"], attr["help"], m_curLayer, attr["image"], attr["action"], attr["resize"], attr["help"],
m_curWindowId, m_curLayoutId ); m_curLayer, m_curWindowId, m_curLayoutId );
m_curLayer++; m_curLayer++;
m_data.m_listImage.push_back( imageData ); m_data.m_listImage.push_back( imageData );
} }
......
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
rightbottom CDATA "lefttop" rightbottom CDATA "lefttop"
image CDATA #REQUIRED image CDATA #REQUIRED
action CDATA "none" action CDATA "none"
resize CDATA "mosaic"
help CDATA "" help CDATA ""
> >
<!ELEMENT Button EMPTY> <!ELEMENT Button EMPTY>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment