Commit dda858d4 authored by Olivier Teulière's avatar Olivier Teulière

* skins2: new "xkeepratio" and "ykeepratio" attributes, common to all the

   controls. When set to "true", the behaviour of the resizing is changed
   (cf. documentation). The main use for these attributes is to keep a
   a control centered in the layout (horizontally, vertically or both) without
   resizing the control.
parent 3d353c9e
...@@ -398,7 +398,7 @@ difficulty to understand how VLC skins work.</para> ...@@ -398,7 +398,7 @@ difficulty to understand how VLC skins work.</para>
</sect4> </sect4>
<sect4 id="anchorrange"> <sect4 id="anchorrange">
<title>range</title> <title>range</title>
<para>Range of action of the anchor, in pixels. Default is "10".</para> <para>Range of action of the anchor, in pixels.</para>
<para>Default value: 10</para> <para>Default value: 10</para>
</sect4> </sect4>
</sect3> </sect3>
...@@ -406,7 +406,7 @@ difficulty to understand how VLC skins work.</para> ...@@ -406,7 +406,7 @@ difficulty to understand how VLC skins work.</para>
<sect3 id="commattr"> <sect3 id="commattr">
<title>Attributes common to all the controls</title> <title>Attributes common to all the controls</title>
<para>The following attributes are common to all the controls (Image, Button, Checkbox, Text, Slider, RadialSlider, Playtree, Video)</para> <para>The following attributes are common to all the controls (Image, Button, Checkbox, Text, Slider, RadialSlider, Playlist, Playtree, Video)</para>
<sect4 id="attrid"> <sect4 id="attrid">
<title>id</title> <title>id</title>
<para>Identifiant of the control. Currently unused.</para> <para>Identifiant of the control. Currently unused.</para>
...@@ -437,6 +437,18 @@ difficulty to understand how VLC skins work.</para> ...@@ -437,6 +437,18 @@ difficulty to understand how VLC skins work.</para>
<para>Indicate to which corner of the Layout the bottom-right-hand corner of this control is attached, in case of resizing.</para> <para>Indicate to which corner of the Layout the bottom-right-hand corner of this control is attached, in case of resizing.</para>
<para>Default value: lefttop</para> <para>Default value: lefttop</para>
</sect4> </sect4>
<sect4 id="xkeepratio">
<title>xkeepratio</title>
<para>When set to true, the behaviour of the horizontal resizing is changed. Instead of taking into account the <link linkend="lefttop">lefttop</link> and <link linkend="rightbottom">rightbottom</link> attributes to determine how the control will be moved/resized, only its initial position inside the <link linkend="Layout">Layout</link> matters. For example, if initially the space to the left of the control is twice as big as the one to its right, this will stay the same during any horizontal resizing. The width of the control stays constant.</para>
<para>This attribute can be particularly useful to keep a control centered in the layout, without resizing it (to resize it, you would rather use the lefttop/rightbottom attributes).</para>
<para>Default value: false</para>
</sect4>
<sect4 id="ykeepratio">
<title>ykeepratio</title>
<para>When set to true, the behaviour of the vertical resizing is changed. Instead of taking into account the <link linkend="lefttop">lefttop</link> and <link linkend="rightbottom">rightbottom</link> attributes to determine how the control will be moved/resized, only its initial position inside the <link linkend="Layout">Layout</link> matters. For example, if initially the space to the top of the control is twice as big as the one to its bottom, this will stay the same during any vertical resizing. The height of the control stays constant.</para>
<para>This attribute can be particularly useful to keep a control centered in the layout, without resizing it (to resize it, you would rather use the lefttop/rightbottom attributes).</para>
<para>Default value: false</para>
</sect4>
<sect4 id="help"> <sect4 id="help">
<title>help</title> <title>help</title>
<para>Help text for the current control. The variable '$H' will be expanded to this value when the mouse hovers the current control (see <link linkend="textvars">Text variables</link>).</para> <para>Help text for the current control. The variable '$H' will be expanded to this value when the mouse hovers the current control (see <link linkend="textvars">Text variables</link>).</para>
......
...@@ -430,7 +430,8 @@ void Builder::addButton( const BuilderData::Button &rData ) ...@@ -430,7 +430,8 @@ void Builder::addButton( const BuilderData::Button &rData )
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
rData.m_xPos, rData.m_yPos, rData.m_xPos, rData.m_yPos,
pBmpUp->getWidth(), pBmpUp->getWidth(),
pBmpUp->getHeight(), *pLayout ); pBmpUp->getHeight(), *pLayout,
rData.m_xKeepRatio, rData.m_yKeepRatio );
pLayout->addControl( pButton, pos, rData.m_layer ); pLayout->addControl( pButton, pos, rData.m_layer );
...@@ -505,7 +506,8 @@ void Builder::addCheckbox( const BuilderData::Checkbox &rData ) ...@@ -505,7 +506,8 @@ void Builder::addCheckbox( const BuilderData::Checkbox &rData )
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
rData.m_xPos, rData.m_yPos, rData.m_xPos, rData.m_yPos,
pBmpUp1->getWidth(), pBmpUp1->getWidth(),
pBmpUp1->getHeight(), *pLayout ); pBmpUp1->getHeight(), *pLayout,
rData.m_xKeepRatio, rData.m_yKeepRatio );
pLayout->addControl( pCheckbox, pos, rData.m_layer ); pLayout->addControl( pCheckbox, pos, rData.m_layer );
...@@ -551,9 +553,10 @@ void Builder::addImage( const BuilderData::Image &rData ) ...@@ -551,9 +553,10 @@ void Builder::addImage( const BuilderData::Image &rData )
// Compute the position of the control // Compute the position of the control
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
rData.m_xPos, rData.m_xPos, rData.m_yPos,
rData.m_yPos, pBmp->getWidth(), pBmp->getWidth(), pBmp->getHeight(),
pBmp->getHeight(), *pLayout ); *pLayout, rData.m_xKeepRatio,
rData.m_yKeepRatio );
// XXX: test to be changed! XXX // XXX: test to be changed! XXX
if( rData.m_actionId == "move" ) if( rData.m_actionId == "move" )
...@@ -660,8 +663,8 @@ void Builder::addText( const BuilderData::Text &rData ) ...@@ -660,8 +663,8 @@ void Builder::addText( const BuilderData::Text &rData )
// Compute the position of the control // Compute the position of the control
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
rData.m_xPos, rData.m_yPos, rData.m_xPos, rData.m_yPos,
rData.m_width, height, rData.m_width, height, *pLayout,
*pLayout ); rData.m_xKeepRatio, rData.m_yKeepRatio );
pLayout->addControl( pText, pos, rData.m_layer ); pLayout->addControl( pText, pos, rData.m_layer );
...@@ -708,10 +711,12 @@ void Builder::addRadialSlider( const BuilderData::RadialSlider &rData ) ...@@ -708,10 +711,12 @@ void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
// XXX: resizing is not supported // XXX: resizing is not supported
// Compute the position of the control // Compute the position of the control
const Position pos = const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos, rData.m_xPos, rData.m_yPos,
rData.m_yPos, pSeq->getWidth(), pSeq->getWidth(),
pSeq->getHeight() / rData.m_nbImages, *pLayout ); pSeq->getHeight() / rData.m_nbImages,
*pLayout,
rData.m_xKeepRatio, rData.m_yKeepRatio );
pLayout->addControl( pRadial, pos, rData.m_layer ); pLayout->addControl( pRadial, pos, rData.m_layer );
...@@ -772,7 +777,8 @@ void Builder::addSlider( const BuilderData::Slider &rData ) ...@@ -772,7 +777,8 @@ void Builder::addSlider( const BuilderData::Slider &rData )
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
rData.m_xPos, rData.m_yPos, rData.m_xPos, rData.m_yPos,
pCurve->getWidth(), pCurve->getHeight(), pCurve->getWidth(), pCurve->getHeight(),
*pLayout ); *pLayout,
rData.m_xKeepRatio, rData.m_yKeepRatio );
pLayout->addControl( pBackground, pos, rData.m_layer ); pLayout->addControl( pBackground, pos, rData.m_layer );
...@@ -852,7 +858,8 @@ void Builder::addList( const BuilderData::List &rData ) ...@@ -852,7 +858,8 @@ void Builder::addList( const BuilderData::List &rData )
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
rData.m_xPos, rData.m_yPos, rData.m_xPos, rData.m_yPos,
rData.m_width, rData.m_height, rData.m_width, rData.m_height,
*pLayout ); *pLayout,
rData.m_xKeepRatio, rData.m_yKeepRatio );
pLayout->addControl( pList, pos, rData.m_layer ); pLayout->addControl( pList, pos, rData.m_layer );
...@@ -916,7 +923,8 @@ void Builder::addTree( const BuilderData::Tree &rData ) ...@@ -916,7 +923,8 @@ void Builder::addTree( const BuilderData::Tree &rData )
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
rData.m_xPos, rData.m_yPos, rData.m_xPos, rData.m_yPos,
rData.m_width, rData.m_height, rData.m_width, rData.m_height,
*pLayout ); *pLayout,
rData.m_xKeepRatio, rData.m_yKeepRatio );
pLayout->addControl( pTree, pos, rData.m_layer ); pLayout->addControl( pTree, pos, rData.m_layer );
...@@ -945,7 +953,8 @@ void Builder::addVideo( const BuilderData::Video &rData ) ...@@ -945,7 +953,8 @@ void Builder::addVideo( const BuilderData::Video &rData )
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
rData.m_xPos, rData.m_yPos, rData.m_xPos, rData.m_yPos,
rData.m_width, rData.m_height, rData.m_width, rData.m_height,
*pLayout ); *pLayout,
rData.m_xKeepRatio, rData.m_yKeepRatio );
pLayout->addControl( pVideo, pos, rData.m_layer ); pLayout->addControl( pVideo, pos, rData.m_layer );
...@@ -956,7 +965,8 @@ void Builder::addVideo( const BuilderData::Video &rData ) ...@@ -956,7 +965,8 @@ void Builder::addVideo( const BuilderData::Video &rData )
const Position Builder::makePosition( const string &rLeftTop, const Position Builder::makePosition( const string &rLeftTop,
const string &rRightBottom, const string &rRightBottom,
int xPos, int yPos, int width, int xPos, int yPos, int width,
int height, const Box &rBox ) const int height, const Box &rBox,
bool xKeepRatio, bool yKeepRatio ) const
{ {
int left = 0, top = 0, right = 0, bottom = 0; int left = 0, top = 0, right = 0, bottom = 0;
Position::Ref_t refLeftTop = Position::kLeftTop; Position::Ref_t refLeftTop = Position::kLeftTop;
...@@ -1018,7 +1028,7 @@ const Position Builder::makePosition( const string &rLeftTop, ...@@ -1018,7 +1028,7 @@ const Position Builder::makePosition( const string &rLeftTop,
} }
return Position( left, top, right, bottom, rBox, refLeftTop, return Position( left, top, right, bottom, rBox, refLeftTop,
refRightBottom ); refRightBottom, xKeepRatio, yKeepRatio );
} }
......
...@@ -90,7 +90,8 @@ class Builder: public SkinObject ...@@ -90,7 +90,8 @@ class Builder: public SkinObject
const Position makePosition( const string &rLeftTop, const Position makePosition( const string &rLeftTop,
const string &rRightBottom, const string &rRightBottom,
int xPos, int yPos, int width, int height, int xPos, int yPos, int width, int height,
const Box &rBox ) const; const Box &rBox, bool xKeepRatio = false,
bool yKeepRatio = false ) const;
// Build the full path of a file // Build the full path of a file
string getFilePath( const string &fileName ) const; string getFilePath( const string &fileName ) const;
......
...@@ -9,13 +9,13 @@ MenuSeparator pos:int popupId:string ...@@ -9,13 +9,13 @@ MenuSeparator pos:int popupId:string
Window id:string xPos:int yPos:int visible:bool dragDrop:bool playOnDrop:bool Window id:string xPos:int yPos:int visible:bool dragDrop:bool playOnDrop:bool
Layout id:string width:int height:int minWidth:int maxWidth:int minHeight:int maxHeight:int windowId:string Layout id:string width:int height:int minWidth:int maxWidth:int minHeight:int maxHeight:int windowId:string
Anchor xPos:int yPos:int leftTop:string range:int priority:int points:string layoutId:string Anchor xPos:int yPos:int leftTop:string 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 xKeepRatio:bool yKeepRatio:bool 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 xKeepRatio:bool yKeepRatio:bool 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 action2Id:string resize:string help:string layer:int windowId:string layoutId:string Image id:string xPos:int yPos:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool visible:string bmpId:string actionId:string action2Id:string resize:string help:string layer:int windowId:string layoutId:string
IniFile id:string file:string IniFile id:string file:string
Text id:string xPos:int yPos:int visible:string fontId:string text:string width:int leftTop:string rightBottom:string color:uint32_t scrolling:string alignment: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 xKeepRatio:bool yKeepRatio:bool color:uint32_t scrolling:string alignment: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 RadialSlider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool 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 imageId:string nbHoriz:int nbVert:int padHoriz:int padVert:int tooltip:string help:string layer:int windowId:string layoutId:string Slider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool upId:string downId:string overId:string points:string thickness:int value:string imageId:string nbHoriz:int nbVert:int padHoriz:int padVert:int tooltip:string help:string layer:int windowId:string layoutId:string
List id:string xPos:int yPos:int visible:string width:int height:int leftTop:string rightBottom:string fontId:string var:string bgImageId:string fgColor:string playColor:string bgColor1:string bgColor2:string selColor:string help:string layer:int windowId:string layoutId:string List id:string xPos:int yPos:int visible:string width:int height:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool fontId:string var:string bgImageId:string fgColor:string playColor:string bgColor1:string bgColor2:string selColor:string help:string layer:int windowId:string layoutId:string
Tree id:string xPos:int yPos:int visible:string flat:string width:int height:int leftTop:string rightBottom:string fontId:string var:string bgImageId:string itemImageId:string openImageId:string closedImageId:string fgColor:string playColor:string bgColor1:string bgColor2:string selColor:string help:string layer:int windowId:string layoutId:string Tree id:string xPos:int yPos:int visible:string flat:string width:int height:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool fontId:string var:string bgImageId:string itemImageId:string openImageId:string closedImageId:string fgColor:string playColor:string bgColor1:string bgColor2:string selColor:string help:string layer:int windowId:string layoutId:string
Video id:string xPos:int yPos:int width:int height:int leftTop:string rightBottom:string visible:string autoResize:bool help:string layer:int windowId:string layoutId:string Video id:string xPos:int yPos:int width:int height:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool visible:string autoResize:bool help:string layer:int windowId:string layoutId:string
This diff is collapsed.
...@@ -181,6 +181,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -181,6 +181,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
CheckDefault( "y", "0" ); CheckDefault( "y", "0" );
CheckDefault( "lefttop", "lefttop" ); CheckDefault( "lefttop", "lefttop" );
CheckDefault( "rightbottom", "lefttop" ); CheckDefault( "rightbottom", "lefttop" );
CheckDefault( "xkeepratio", "false" );
CheckDefault( "ykeepratio", "false" );
CheckDefault( "down", "none" ); CheckDefault( "down", "none" );
CheckDefault( "over", "none" ); CheckDefault( "over", "none" );
CheckDefault( "action", "none" ); CheckDefault( "action", "none" );
...@@ -189,7 +191,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -189,7 +191,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
const BuilderData::Button button( uniqueId( attr["id"] ), const BuilderData::Button button( 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"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ), attr["visible"],
attr["up"], attr["down"], attr["over"], attr["action"], attr["up"], attr["down"], attr["over"], attr["action"],
attr["tooltiptext"], attr["help"], attr["tooltiptext"], attr["help"],
m_curLayer, m_curWindowId, m_curLayoutId ); m_curLayer, m_curWindowId, m_curLayoutId );
...@@ -208,6 +212,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -208,6 +212,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
CheckDefault( "y", "0" ); CheckDefault( "y", "0" );
CheckDefault( "lefttop", "lefttop" ); CheckDefault( "lefttop", "lefttop" );
CheckDefault( "rightbottom", "lefttop" ); CheckDefault( "rightbottom", "lefttop" );
CheckDefault( "xkeepratio", "false" );
CheckDefault( "ykeepratio", "false" );
CheckDefault( "down1", "none" ); CheckDefault( "down1", "none" );
CheckDefault( "over1", "none" ); CheckDefault( "over1", "none" );
CheckDefault( "down2", "none" ); CheckDefault( "down2", "none" );
...@@ -220,7 +226,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -220,7 +226,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
const BuilderData::Checkbox checkbox( uniqueId( attr["id"] ), const BuilderData::Checkbox checkbox( 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"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ), attr["visible"],
attr["up1"], attr["down1"], attr["over1"], attr["up1"], attr["down1"], attr["over1"],
attr["up2"], attr["down2"], attr["over2"], attr["state"], attr["up2"], attr["down2"], attr["over2"], attr["state"],
attr["action1"], attr["action2"], attr["tooltiptext1"], attr["action1"], attr["action2"], attr["tooltiptext1"],
...@@ -261,6 +269,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -261,6 +269,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
CheckDefault( "y", "0" ); CheckDefault( "y", "0" );
CheckDefault( "lefttop", "lefttop" ); CheckDefault( "lefttop", "lefttop" );
CheckDefault( "rightbottom", "lefttop" ); CheckDefault( "rightbottom", "lefttop" );
CheckDefault( "xkeepratio", "false" );
CheckDefault( "ykeepratio", "false" );
CheckDefault( "action", "none" ); CheckDefault( "action", "none" );
CheckDefault( "action2", "none" ); CheckDefault( "action2", "none" );
CheckDefault( "resize", "mosaic" ); CheckDefault( "resize", "mosaic" );
...@@ -268,7 +278,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -268,7 +278,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
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"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ), attr["visible"],
attr["image"], attr["action"], attr["action2"], attr["resize"], attr["image"], attr["action"], attr["action2"], attr["resize"],
attr["help"], m_curLayer, m_curWindowId, m_curLayoutId ); attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
m_curLayer++; m_curLayer++;
...@@ -305,6 +317,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -305,6 +317,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
CheckDefault( "height", "0" ); CheckDefault( "height", "0" );
CheckDefault( "lefttop", "lefttop" ); CheckDefault( "lefttop", "lefttop" );
CheckDefault( "rightbottom", "lefttop" ); CheckDefault( "rightbottom", "lefttop" );
CheckDefault( "xkeepratio", "false" );
CheckDefault( "ykeepratio", "false" );
CheckDefault( "bgimage", "none" ); CheckDefault( "bgimage", "none" );
CheckDefault( "itemimage", "none" ); CheckDefault( "itemimage", "none" );
CheckDefault( "openimage", "none" ); CheckDefault( "openimage", "none" );
...@@ -321,6 +335,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -321,6 +335,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
attr["flat"], attr["flat"],
atoi( attr["width"]), atoi( attr["height"] ), atoi( attr["width"]), atoi( attr["height"] ),
attr["lefttop"], attr["rightbottom"], attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ),
attr["font"], "playtree", attr["font"], "playtree",
attr["bgimage"], attr["itemimage"], attr["bgimage"], attr["itemimage"],
attr["openimage"], attr["closedimage"], attr["openimage"], attr["closedimage"],
...@@ -345,6 +361,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -345,6 +361,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
CheckDefault( "height", "0" ); CheckDefault( "height", "0" );
CheckDefault( "lefttop", "lefttop" ); CheckDefault( "lefttop", "lefttop" );
CheckDefault( "rightbottom", "lefttop" ); CheckDefault( "rightbottom", "lefttop" );
CheckDefault( "xkeepratio", "false" );
CheckDefault( "ykeepratio", "false" );
CheckDefault( "bgimage", "none" ); CheckDefault( "bgimage", "none" );
CheckDefault( "itemimage", "none" ); CheckDefault( "itemimage", "none" );
CheckDefault( "openimage", "none" ); CheckDefault( "openimage", "none" );
...@@ -362,6 +380,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -362,6 +380,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
attr["flat"], attr["flat"],
atoi( attr["width"]), atoi( attr["height"] ), atoi( attr["width"]), atoi( attr["height"] ),
attr["lefttop"], attr["rightbottom"], attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ),
attr["font"], "playtree", attr["font"], "playtree",
attr["bgimage"], attr["itemimage"], attr["bgimage"], attr["itemimage"],
attr["openimage"], attr["closedimage"], attr["openimage"], attr["closedimage"],
...@@ -383,6 +403,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -383,6 +403,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
CheckDefault( "y", "0" ); CheckDefault( "y", "0" );
CheckDefault( "lefttop", "lefttop" ); CheckDefault( "lefttop", "lefttop" );
CheckDefault( "rightbottom", "lefttop" ); CheckDefault( "rightbottom", "lefttop" );
CheckDefault( "xkeepratio", "false" );
CheckDefault( "ykeepratio", "false" );
CheckDefault( "minangle", "0" ); CheckDefault( "minangle", "0" );
CheckDefault( "maxangle", "360" ); CheckDefault( "maxangle", "360" );
CheckDefault( "value", "none" ); CheckDefault( "value", "none" );
...@@ -392,7 +414,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -392,7 +414,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
const BuilderData::RadialSlider radial( uniqueId( attr["id"] ), const BuilderData::RadialSlider radial( uniqueId( attr["id"] ),
attr["visible"], attr["visible"],
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["sequence"], attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ), attr["sequence"],
atoi( attr["nbImages"] ), atof( attr["minAngle"] ) * M_PI /180, atoi( attr["nbImages"] ), atof( attr["minAngle"] ) * M_PI /180,
atof( attr["maxAngle"] ) * M_PI / 180, attr["value"], atof( attr["maxAngle"] ) * M_PI / 180, attr["value"],
attr["tooltiptext"], attr["help"], m_curLayer, m_curWindowId, attr["tooltiptext"], attr["help"], m_curLayer, m_curWindowId,
...@@ -413,6 +437,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -413,6 +437,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
CheckDefault( "height", "0" ); CheckDefault( "height", "0" );
CheckDefault( "lefttop", "lefttop" ); CheckDefault( "lefttop", "lefttop" );
CheckDefault( "rightbottom", "lefttop" ); CheckDefault( "rightbottom", "lefttop" );
CheckDefault( "xkeepratio", "false" );
CheckDefault( "ykeepratio", "false" );
CheckDefault( "down", "none" ); CheckDefault( "down", "none" );
CheckDefault( "over", "none" ); CheckDefault( "over", "none" );
CheckDefault( "thickness", "10" ); CheckDefault( "thickness", "10" );
...@@ -429,7 +455,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -429,7 +455,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
const BuilderData::Slider slider( uniqueId( attr["id"] ), const BuilderData::Slider slider( uniqueId( attr["id"] ),
attr["visible"], atoi( attr["x"] ) + m_xOffset, attr["visible"], atoi( attr["x"] ) + m_xOffset,
atoi( attr["y"] ) + m_yOffset, attr["lefttop"], atoi( attr["y"] ) + m_yOffset, attr["lefttop"],
attr["rightbottom"], attr["up"], attr["down"], attr["rightbottom"], convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ), attr["up"], attr["down"],
attr["over"], attr["points"], atoi( attr["thickness"] ), attr["over"], attr["points"], atoi( attr["thickness"] ),
newValue, "none", 0, 0, 0, 0, attr["tooltiptext"], newValue, "none", 0, 0, 0, 0, attr["tooltiptext"],
attr["help"], m_curLayer, m_curWindowId, m_curLayoutId ); attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
...@@ -469,6 +496,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -469,6 +496,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
CheckDefault( "width", "0" ); CheckDefault( "width", "0" );
CheckDefault( "lefttop", "lefttop" ); CheckDefault( "lefttop", "lefttop" );
CheckDefault( "rightbottom", "lefttop" ); CheckDefault( "rightbottom", "lefttop" );
CheckDefault( "xkeepratio", "false" );
CheckDefault( "ykeepratio", "false" );
CheckDefault( "help", "" ); CheckDefault( "help", "" );
const BuilderData::Text textData( uniqueId( attr["id"] ), const BuilderData::Text textData( uniqueId( attr["id"] ),
...@@ -476,6 +505,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -476,6 +505,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
attr["visible"], attr["font"], attr["visible"], attr["font"],
attr["text"], atoi( attr["width"] ), attr["text"], atoi( attr["width"] ),
attr["lefttop"], attr["rightbottom"], attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ),
convertColor( attr["color"] ), convertColor( attr["color"] ),
attr["scrolling"], attr["alignment"], attr["scrolling"], attr["alignment"],
attr["help"], m_curLayer, m_curWindowId, m_curLayoutId ); attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
...@@ -522,6 +553,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -522,6 +553,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
CheckDefault( "height", "0" ); CheckDefault( "height", "0" );
CheckDefault( "lefttop", "lefttop" ); CheckDefault( "lefttop", "lefttop" );
CheckDefault( "rightbottom", "lefttop" ); CheckDefault( "rightbottom", "lefttop" );
CheckDefault( "xkeepratio", "false" );
CheckDefault( "ykeepratio", "false" );
CheckDefault( "autoresize", "false" ); CheckDefault( "autoresize", "false" );
CheckDefault( "help", "" ); CheckDefault( "help", "" );
...@@ -529,6 +562,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -529,6 +562,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset, atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
atoi( attr["width"] ), atoi( attr["height" ]), atoi( attr["width"] ), atoi( attr["height" ]),
attr["lefttop"], attr["rightbottom"], attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ),
attr["visible"], convertBoolean( attr["autoresize"] ), attr["visible"], convertBoolean( attr["autoresize"] ),
attr["help"], m_curLayer, m_curWindowId, m_curLayoutId ); attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
m_curLayer++; m_curLayer++;
......
...@@ -35,83 +35,186 @@ Rect::Rect( int left, int top, int right, int bottom ): ...@@ -35,83 +35,186 @@ Rect::Rect( int left, int top, int right, int bottom ):
Position::Position( int left, int top, int right, int bottom, const Box &rBox, Position::Position( int left, int top, int right, int bottom, const Box &rBox,
Ref_t refLeftTop, Ref_t refRightBottom ): Ref_t refLeftTop, Ref_t refRightBottom, bool xKeepRatio,
bool yKeepRatio ):
m_left( left ), m_top( top ), m_right( right ), m_bottom( bottom ), m_left( left ), m_top( top ), m_right( right ), m_bottom( bottom ),
m_rBox( rBox ), m_refLeftTop( refLeftTop ), m_rBox( rBox ), m_refLeftTop( refLeftTop ),
m_refRighBottom( refRightBottom ) m_refRighBottom( refRightBottom ), m_xKeepRatio( xKeepRatio ),
m_yKeepRatio( yKeepRatio )
{ {
// Here is how the resizing algorithm works:
//
// - if we "keep the ratio" (xkeepratio="true" in the XML), the relative
// position of the control in the layout (i.e. the given rBox) is
// saved, and will be kept constant. The size of the control will not
// be changed, only its position may vary. To do that, we consider the
// part of the layout to the left of the control (for an horizontal
// resizing) and the part of the layout to the right of the control,
// and we make sure that the ratio between their widths is constant.
//
// - if we don't keep the ratio, the resizing algorithm is completely
// different. We consider that the top left hand corner of the control
// ("lefttop" attribute in the XML) is linked to one of the 4 corners
// of the layouts ("lefttop", "leftbottom", "righttop" and
// "rightbottom" values for the attribute). Same thing for the bottom
// right hand corner ("rightbottom" attribute). When resizing occurs,
// the linked corners will move together, and this will drive the
// moving/resizing of the control.
// Initialize the horizontal ratio
if( m_xKeepRatio )
{
// First compute the width of the box minus the width of the control
int freeSpace = m_rBox.getWidth() - (m_right - m_left);
// Instead of computing left/right, we compute left/(left+right),
// which is more convenient in my opinion.
if( freeSpace != 0 )
{
m_xRatio = (double)m_left / (double)freeSpace;
}
else
{
// If the control has the same size as the box, we can't compute
// the ratio in the same way (otherwise we would divide by zero).
// So we consider that the intent was to keep the control centered
// (if you are unhappy with this, go and fix your skin :))
m_xRatio = 0.5;
}
}
// Initial the vertical ratio
if( m_yKeepRatio )
{
// First compute the width of the box minus the width of the control
int freeSpace = m_rBox.getHeight() - (m_bottom - m_top);
// Instead of computing left/right, we compute left/(left+right),
// which is more convenient in my opinion.
if( freeSpace != 0 )
{
m_yRatio = (double)m_top / (double)freeSpace;
}
else
{
// If the control has the same size as the box, we can't compute
// the ratio in the same way (otherwise we would divide by zero).
// So we consider that the intent was to keep the control centered
// (if you are unhappy with this, go and fix your skin :))
m_yRatio = 0.5;
}
}
} }
int Position::getLeft() const int Position::getLeft() const
{ {
switch( m_refLeftTop ) if( m_xKeepRatio )
{ {
case kLeftTop: // Ratio mode
case kLeftBottom: // First compute the width of the box minus the width of the control
return m_left; int freeSpace = m_rBox.getWidth() - (m_right - m_left);
break; return (int)(m_xRatio * freeSpace);
case kRightTop: }
case kRightBottom: else
return m_rBox.getWidth() + m_left - 1; {
break; switch( m_refLeftTop )
{
case kLeftTop:
case kLeftBottom:
return m_left;
break;
case kRightTop:
case kRightBottom:
return m_rBox.getWidth() + m_left - 1;
break;
}
// Avoid a warning
return 0;
} }
// Avoid a warning
return 0;
} }
int Position::getTop() const int Position::getTop() const
{ {
switch( m_refLeftTop ) if( m_yKeepRatio )
{
// Ratio mode
// First compute the height of the box minus the height of the control
int freeSpace = m_rBox.getHeight() - (m_bottom - m_top);
return (int)(m_yRatio * freeSpace);
}
else
{ {
case kLeftTop: switch( m_refLeftTop )
case kRightTop: {
return m_top; case kLeftTop:
break; case kRightTop:
case kRightBottom: return m_top;
case kLeftBottom: break;
return m_rBox.getHeight() + m_top - 1; case kRightBottom:
break; case kLeftBottom:
return m_rBox.getHeight() + m_top - 1;
break;
}
// Avoid a warning
return 0;
} }
// Avoid a warning
return 0;
} }
int Position::getRight() const int Position::getRight() const
{ {
switch( m_refRighBottom ) if( m_xKeepRatio )
{ {
case kLeftTop: // Ratio mode
case kLeftBottom: // The width of the control being constant, we can use the result of
return m_right; // getLeft() (this will avoid rounding issues).
break; return getLeft() + m_right - m_left;
case kRightTop: }
case kRightBottom: else
return m_rBox.getWidth() + m_right - 1; {
break; switch( m_refRighBottom )
{
case kLeftTop:
case kLeftBottom:
return m_right;
break;
case kRightTop:
case kRightBottom:
return m_rBox.getWidth() + m_right - 1;
break;
}
// Avoid a warning
return 0;
} }
// Avoid a warning
return 0;
} }
int Position::getBottom() const int Position::getBottom() const
{ {
switch( m_refRighBottom ) if( m_yKeepRatio )
{
// Ratio mode
// The height of the control being constant, we can use the result of
// getTop() (this will avoid rounding issues).
return getTop() + m_bottom - m_top;
}
else
{ {
case kLeftTop: switch( m_refRighBottom )
case kRightTop: {
return m_bottom; case kLeftTop:
break; case kRightTop:
case kLeftBottom: return m_bottom;
case kRightBottom: break;
return m_rBox.getHeight() + m_bottom - 1; case kLeftBottom:
break; case kRightBottom:
return m_rBox.getHeight() + m_bottom - 1;
break;
}
// Avoid a warning
return 0;
} }
// Avoid a warning
return 0;
} }
......
...@@ -82,8 +82,8 @@ class Position ...@@ -82,8 +82,8 @@ class Position
/// Create a new position relative to the given box /// Create a new position relative to the given box
Position( int left, int top, int right, int bottom, const Box &rBox, Position( int left, int top, int right, int bottom, const Box &rBox,
Ref_t refLeftTop = kLeftTop, Ref_t refLeftTop, Ref_t refRightBottom,
Ref_t refRightBottom = kLeftTop ); bool xKeepRatio, bool yKeepRatio );
~Position() {} ~Position() {}
...@@ -108,6 +108,13 @@ class Position ...@@ -108,6 +108,13 @@ class Position
const Box &m_rBox; const Box &m_rBox;
Ref_t m_refLeftTop; Ref_t m_refLeftTop;
Ref_t m_refRighBottom; Ref_t m_refRighBottom;
/// "Keep ratio" mode
bool m_xKeepRatio;
bool m_yKeepRatio;
/// Initial width ratio (usually between 0 and 1)
double m_xRatio;
/// Initial height ratio (usually between 0 and 1)
double m_yRatio;
}; };
......
...@@ -114,6 +114,8 @@ ...@@ -114,6 +114,8 @@
y CDATA "0" y CDATA "0"
lefttop CDATA "lefttop" lefttop CDATA "lefttop"
rightbottom CDATA "lefttop" rightbottom CDATA "lefttop"
xkeepratio CDATA "false"
ykeepratio CDATA "false"
image CDATA #REQUIRED image CDATA #REQUIRED
action CDATA "none" action CDATA "none"
action2 CDATA "none" action2 CDATA "none"
...@@ -128,6 +130,8 @@ ...@@ -128,6 +130,8 @@
y CDATA "0" y CDATA "0"
lefttop CDATA "lefttop" lefttop CDATA "lefttop"
rightbottom CDATA "lefttop" rightbottom CDATA "lefttop"
xkeepratio CDATA "false"
ykeepratio CDATA "false"
up CDATA #REQUIRED up CDATA #REQUIRED
down CDATA "none" down CDATA "none"
over CDATA "none" over CDATA "none"
...@@ -143,6 +147,8 @@ ...@@ -143,6 +147,8 @@
y CDATA "0" y CDATA "0"
lefttop CDATA "lefttop" lefttop CDATA "lefttop"
rightbottom CDATA "lefttop" rightbottom CDATA "lefttop"
xkeepratio CDATA "false"
ykeepratio CDATA "false"
up1 CDATA #REQUIRED up1 CDATA #REQUIRED
down1 CDATA "none" down1 CDATA "none"
over1 CDATA "none" over1 CDATA "none"
...@@ -164,6 +170,8 @@ ...@@ -164,6 +170,8 @@
y CDATA "0" y CDATA "0"
lefttop CDATA "lefttop" lefttop CDATA "lefttop"
rightbottom CDATA "lefttop" rightbottom CDATA "lefttop"
xkeepratio CDATA "false"
ykeepratio CDATA "false"
up CDATA #REQUIRED up CDATA #REQUIRED
down CDATA "none" down CDATA "none"
over CDATA "none" over CDATA "none"
...@@ -191,6 +199,8 @@ ...@@ -191,6 +199,8 @@
y CDATA "0" y CDATA "0"
lefttop CDATA "lefttop" lefttop CDATA "lefttop"
rightbottom CDATA "lefttop" rightbottom CDATA "lefttop"
xkeepratio CDATA "false"
ykeepratio CDATA "false"
sequence CDATA #REQUIRED sequence CDATA #REQUIRED
nbimages CDATA #REQUIRED nbimages CDATA #REQUIRED
minangle CDATA "0" minangle CDATA "0"
...@@ -208,6 +218,8 @@ ...@@ -208,6 +218,8 @@
width CDATA "0" width CDATA "0"
lefttop CDATA "lefttop" lefttop CDATA "lefttop"
rightbottom CDATA "lefttop" rightbottom CDATA "lefttop"
xkeepratio CDATA "false"
ykeepratio CDATA "false"
text CDATA "" text CDATA ""
font CDATA #REQUIRED font CDATA #REQUIRED
color CDATA "#000000" color CDATA "#000000"
...@@ -225,6 +237,8 @@ ...@@ -225,6 +237,8 @@
height CDATA "0" height CDATA "0"
lefttop CDATA "lefttop" lefttop CDATA "lefttop"
rightbottom CDATA "lefttop" rightbottom CDATA "lefttop"
xkeepratio CDATA "false"
ykeepratio CDATA "false"
font CDATA #REQUIRED font CDATA #REQUIRED
bgimage CDATA "none" bgimage CDATA "none"
fgcolor CDATA "#000000" fgcolor CDATA "#000000"
...@@ -244,6 +258,8 @@ ...@@ -244,6 +258,8 @@
height CDATA "0" height CDATA "0"
lefttop CDATA "lefttop" lefttop CDATA "lefttop"
rightbottom CDATA "lefttop" rightbottom CDATA "lefttop"
xkeepratio CDATA "false"
ykeepratio CDATA "false"
font CDATA #REQUIRED font CDATA #REQUIRED
bgimage CDATA "none" bgimage CDATA "none"
itemimage CDATA "none" itemimage CDATA "none"
...@@ -267,6 +283,8 @@ ...@@ -267,6 +283,8 @@
height CDATA "0" height CDATA "0"
lefttop CDATA "lefttop" lefttop CDATA "lefttop"
rightbottom CDATA "lefttop" rightbottom CDATA "lefttop"
xkeepratio CDATA "false"
ykeepratio CDATA "false"
autoresize CDATA "true" autoresize CDATA "true"
help CDATA "" help CDATA ""
> >
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