]> git.sesse.net Git - vlc/commitdiff
* skins2: new "xkeepratio" and "ykeepratio" attributes, common to all the
authorOlivier Teulière <ipkiss@videolan.org>
Sat, 5 Aug 2006 13:37:06 +0000 (13:37 +0000)
committerOlivier Teulière <ipkiss@videolan.org>
Sat, 5 Aug 2006 13:37:06 +0000 (13:37 +0000)
   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.

doc/skins/skins2-howto.xml
modules/gui/skins2/parser/builder.cpp
modules/gui/skins2/parser/builder.hpp
modules/gui/skins2/parser/builder_data.def
modules/gui/skins2/parser/builder_data.hpp
modules/gui/skins2/parser/skin_parser.cpp
modules/gui/skins2/utils/position.cpp
modules/gui/skins2/utils/position.hpp
share/skins2/skin.dtd

index 5e94fbb00b0651c0748d0327208d6bdeadb45929..2612d5e1ef7b3b7ce8dedff593eae2d3a20baa72 100644 (file)
@@ -398,7 +398,7 @@ difficulty to understand how VLC skins work.</para>
   </sect4>
   <sect4 id="anchorrange">
     <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>
   </sect4>
 </sect3>
@@ -406,7 +406,7 @@ difficulty to understand how VLC skins work.</para>
 
 <sect3 id="commattr">
   <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">
     <title>id</title>
     <para>Identifiant of the control. Currently unused.</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>Default value: lefttop</para>
   </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">
     <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>
index 9eba9dc3631a66102dd926ea5bf4f76088599163..569010e4d8e8358fd2facd5198bf52eecc34bc4f 100644 (file)
@@ -430,7 +430,8 @@ void Builder::addButton( const BuilderData::Button &rData )
     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
                                        rData.m_xPos, rData.m_yPos,
                                        pBmpUp->getWidth(),
-                                       pBmpUp->getHeight(), *pLayout );
+                                       pBmpUp->getHeight(), *pLayout,
+                                       rData.m_xKeepRatio, rData.m_yKeepRatio );
 
     pLayout->addControl( pButton, pos, rData.m_layer );
 
@@ -505,7 +506,8 @@ void Builder::addCheckbox( const BuilderData::Checkbox &rData )
     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
                                        rData.m_xPos, rData.m_yPos,
                                        pBmpUp1->getWidth(),
-                                       pBmpUp1->getHeight(), *pLayout );
+                                       pBmpUp1->getHeight(), *pLayout,
+                                       rData.m_xKeepRatio, rData.m_yKeepRatio );
 
     pLayout->addControl( pCheckbox, pos, rData.m_layer );
 
@@ -551,9 +553,10 @@ void Builder::addImage( const BuilderData::Image &rData )
 
     // Compute the position of the control
     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
-                                       rData.m_xPos,
-                                       rData.m_yPos, pBmp->getWidth(),
-                                       pBmp->getHeight(), *pLayout );
+                                       rData.m_xPos, rData.m_yPos,
+                                       pBmp->getWidth(), pBmp->getHeight(),
+                                       *pLayout, rData.m_xKeepRatio,
+                                       rData.m_yKeepRatio );
 
     // XXX: test to be changed! XXX
     if( rData.m_actionId == "move" )
@@ -660,8 +663,8 @@ void Builder::addText( const BuilderData::Text &rData )
     // Compute the position of the control
     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
                                        rData.m_xPos, rData.m_yPos,
-                                       rData.m_width, height,
-                                       *pLayout );
+                                       rData.m_width, height, *pLayout,
+                                       rData.m_xKeepRatio, rData.m_yKeepRatio );
 
     pLayout->addControl( pText, pos, rData.m_layer );
 
@@ -708,10 +711,12 @@ void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
 
     // XXX: resizing is not supported
     // Compute the position of the control
-    const Position pos =
-        makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos,
-                      rData.m_yPos, pSeq->getWidth(),
-                      pSeq->getHeight() / rData.m_nbImages, *pLayout );
+    const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
+                                       rData.m_xPos, rData.m_yPos,
+                                       pSeq->getWidth(),
+                                       pSeq->getHeight() / rData.m_nbImages,
+                                       *pLayout,
+                                       rData.m_xKeepRatio, rData.m_yKeepRatio );
 
     pLayout->addControl( pRadial, pos, rData.m_layer );
 
@@ -772,7 +777,8 @@ void Builder::addSlider( const BuilderData::Slider &rData )
     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
                                        rData.m_xPos, rData.m_yPos,
                                        pCurve->getWidth(), pCurve->getHeight(),
-                                       *pLayout );
+                                       *pLayout,
+                                       rData.m_xKeepRatio, rData.m_yKeepRatio );
 
     pLayout->addControl( pBackground, pos, rData.m_layer );
 
@@ -852,7 +858,8 @@ void Builder::addList( const BuilderData::List &rData )
     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
                                        rData.m_xPos, rData.m_yPos,
                                        rData.m_width, rData.m_height,
-                                       *pLayout );
+                                       *pLayout,
+                                       rData.m_xKeepRatio, rData.m_yKeepRatio );
 
     pLayout->addControl( pList, pos, rData.m_layer );
 
@@ -916,7 +923,8 @@ void Builder::addTree( const BuilderData::Tree &rData )
     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
                                        rData.m_xPos, rData.m_yPos,
                                        rData.m_width, rData.m_height,
-                                       *pLayout );
+                                       *pLayout,
+                                       rData.m_xKeepRatio, rData.m_yKeepRatio );
 
     pLayout->addControl( pTree, pos, rData.m_layer );
 
@@ -945,7 +953,8 @@ void Builder::addVideo( const BuilderData::Video &rData )
     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
                                        rData.m_xPos, rData.m_yPos,
                                        rData.m_width, rData.m_height,
-                                       *pLayout );
+                                       *pLayout,
+                                       rData.m_xKeepRatio, rData.m_yKeepRatio );
 
     pLayout->addControl( pVideo, pos, rData.m_layer );
 
@@ -956,7 +965,8 @@ void Builder::addVideo( const BuilderData::Video &rData )
 const Position Builder::makePosition( const string &rLeftTop,
                                       const string &rRightBottom,
                                       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;
     Position::Ref_t refLeftTop = Position::kLeftTop;
@@ -1018,7 +1028,7 @@ const Position Builder::makePosition( const string &rLeftTop,
     }
 
     return Position( left, top, right, bottom, rBox, refLeftTop,
-                     refRightBottom );
+                     refRightBottom, xKeepRatio, yKeepRatio );
 }
 
 
index d0831b68ab2d16bb05a38b3e8be52f086dc75cd5..49f4b365fd86d3b6378f67e95b34f1064cf7f936 100644 (file)
@@ -90,7 +90,8 @@ class Builder: public SkinObject
         const Position makePosition( const string &rLeftTop,
                                      const string &rRightBottom,
                                      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
         string getFilePath( const string &fileName ) const;
index 7c673bd5adfe3bbb89f4410fe84a25a63a023e21..eebde0e2656ae7fb8f73889733f9e273100c909d 100644 (file)
@@ -9,13 +9,13 @@ MenuSeparator pos:int popupId:string
 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
 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
-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 action2Id:string resize: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 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 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
-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
-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 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
-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
-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
+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 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 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 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 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 xKeepRatio:bool yKeepRatio:bool visible:string autoResize:bool help:string layer:int windowId:string layoutId:string
index 61ed07b99bb1441c72d618c4131ac8dc4a9a43bb..d0c6ec08f00c8f388e884dab0735b3ebf21ed3a4 100644 (file)
@@ -203,14 +203,16 @@ m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_range( range ), m_priori
     /// Type definition
     struct Button
     {
-        Button( const string & id, int xPos, int yPos, const string & leftTop, const string & rightBottom, const string & visible, const string & upId, const string & downId, const string & overId, const string & actionId, const string & tooltip, 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_upId( upId ), m_downId( downId ), m_overId( overId ), m_actionId( actionId ), m_tooltip( tooltip ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
+        Button( const string & id, int xPos, int yPos, const string & leftTop, const string & rightBottom, bool xKeepRatio, bool yKeepRatio, const string & visible, const string & upId, const string & downId, const string & overId, const string & actionId, const string & tooltip, 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_xKeepRatio( xKeepRatio ), m_yKeepRatio( yKeepRatio ), m_visible( visible ), m_upId( upId ), m_downId( downId ), m_overId( overId ), m_actionId( actionId ), m_tooltip( tooltip ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
 
         string m_id;
         int m_xPos;
         int m_yPos;
         string m_leftTop;
         string m_rightBottom;
+        bool m_xKeepRatio;
+        bool m_yKeepRatio;
         string m_visible;
         string m_upId;
         string m_downId;
@@ -228,14 +230,16 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom(
     /// Type definition
     struct Checkbox
     {
-        Checkbox( const string & id, int xPos, int yPos, const string & leftTop, const string & rightBottom, const string & visible, const string & up1Id, const string & down1Id, const string & over1Id, const string & up2Id, const string & down2Id, const string & over2Id, const string & state, const string & action1, const string & action2, const string & tooltip1, const string & tooltip2, 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_up1Id( up1Id ), m_down1Id( down1Id ), m_over1Id( over1Id ), m_up2Id( up2Id ), m_down2Id( down2Id ), m_over2Id( over2Id ), m_state( state ), m_action1( action1 ), m_action2( action2 ), m_tooltip1( tooltip1 ), m_tooltip2( tooltip2 ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
+        Checkbox( const string & id, int xPos, int yPos, const string & leftTop, const string & rightBottom, bool xKeepRatio, bool yKeepRatio, const string & visible, const string & up1Id, const string & down1Id, const string & over1Id, const string & up2Id, const string & down2Id, const string & over2Id, const string & state, const string & action1, const string & action2, const string & tooltip1, const string & tooltip2, 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_xKeepRatio( xKeepRatio ), m_yKeepRatio( yKeepRatio ), m_visible( visible ), m_up1Id( up1Id ), m_down1Id( down1Id ), m_over1Id( over1Id ), m_up2Id( up2Id ), m_down2Id( down2Id ), m_over2Id( over2Id ), m_state( state ), m_action1( action1 ), m_action2( action2 ), m_tooltip1( tooltip1 ), m_tooltip2( tooltip2 ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
 
         string m_id;
         int m_xPos;
         int m_yPos;
         string m_leftTop;
         string m_rightBottom;
+        bool m_xKeepRatio;
+        bool m_yKeepRatio;
         string m_visible;
         string m_up1Id;
         string m_down1Id;
@@ -259,14 +263,16 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom(
     /// Type definition
     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 & action2Id, 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_action2Id( action2Id ), m_resize( resize ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
+        Image( const string & id, int xPos, int yPos, const string & leftTop, const string & rightBottom, bool xKeepRatio, bool yKeepRatio, const string & visible, const string & bmpId, const string & actionId, const string & action2Id, 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_xKeepRatio( xKeepRatio ), m_yKeepRatio( yKeepRatio ), m_visible( visible ), m_bmpId( bmpId ), m_actionId( actionId ), m_action2Id( action2Id ), m_resize( resize ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
 
         string m_id;
         int m_xPos;
         int m_yPos;
         string m_leftTop;
         string m_rightBottom;
+        bool m_xKeepRatio;
+        bool m_yKeepRatio;
         string m_visible;
         string m_bmpId;
         string m_actionId;
@@ -295,8 +301,8 @@ m_id( id ), m_file( file ) {}
     /// Type definition
     struct Text
     {
-        Text( const string & id, int xPos, int yPos, const string & visible, const string & fontId, const string & text, int width, const string & leftTop, const string & rightBottom, uint32_t color, const string & scrolling, const string & alignment, const string & help, int layer, const string & windowId, const string & layoutId ):
-m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_fontId( fontId ), m_text( text ), m_width( width ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_color( color ), m_scrolling( scrolling ), m_alignment( alignment ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
+        Text( const string & id, int xPos, int yPos, const string & visible, const string & fontId, const string & text, int width, const string & leftTop, const string & rightBottom, bool xKeepRatio, bool yKeepRatio, uint32_t color, const string & scrolling, const string & alignment, const string & help, int layer, const string & windowId, const string & layoutId ):
+m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_fontId( fontId ), m_text( text ), m_width( width ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_xKeepRatio( xKeepRatio ), m_yKeepRatio( yKeepRatio ), m_color( color ), m_scrolling( scrolling ), m_alignment( alignment ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
 
         string m_id;
         int m_xPos;
@@ -307,6 +313,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_fontId( font
         int m_width;
         string m_leftTop;
         string m_rightBottom;
+        bool m_xKeepRatio;
+        bool m_yKeepRatio;
         uint32_t m_color;
         string m_scrolling;
         string m_alignment;
@@ -321,8 +329,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_fontId( font
     /// Type definition
     struct RadialSlider
     {
-        RadialSlider( const string & id, const string & visible, int xPos, int yPos, const string & leftTop, const string & rightBottom, const string & sequence, int nbImages, float minAngle, float maxAngle, const string & value, const string & tooltip, const string & help, int layer, const string & windowId, const string & layoutId ):
-m_id( id ), m_visible( visible ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_sequence( sequence ), m_nbImages( nbImages ), m_minAngle( minAngle ), m_maxAngle( maxAngle ), m_value( value ), m_tooltip( tooltip ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
+        RadialSlider( const string & id, const string & visible, int xPos, int yPos, const string & leftTop, const string & rightBottom, bool xKeepRatio, bool yKeepRatio, const string & sequence, int nbImages, float minAngle, float maxAngle, const string & value, const string & tooltip, const string & help, int layer, const string & windowId, const string & layoutId ):
+m_id( id ), m_visible( visible ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_xKeepRatio( xKeepRatio ), m_yKeepRatio( yKeepRatio ), m_sequence( sequence ), m_nbImages( nbImages ), m_minAngle( minAngle ), m_maxAngle( maxAngle ), m_value( value ), m_tooltip( tooltip ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
 
         string m_id;
         string m_visible;
@@ -330,6 +338,8 @@ m_id( id ), m_visible( visible ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( lef
         int m_yPos;
         string m_leftTop;
         string m_rightBottom;
+        bool m_xKeepRatio;
+        bool m_yKeepRatio;
         string m_sequence;
         int m_nbImages;
         float m_minAngle;
@@ -347,8 +357,8 @@ m_id( id ), m_visible( visible ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( lef
     /// Type definition
     struct Slider
     {
-        Slider( const string & id, const string & visible, int xPos, int yPos, const string & leftTop, const string & rightBottom, const string & upId, const string & downId, const string & overId, const string & points, int thickness, const string & value, const string & imageId, int nbHoriz, int nbVert, int padHoriz, int padVert, const string & tooltip, const string & help, int layer, const string & windowId, const string & layoutId ):
-m_id( id ), m_visible( visible ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_upId( upId ), m_downId( downId ), m_overId( overId ), m_points( points ), m_thickness( thickness ), m_value( value ), m_imageId( imageId ), m_nbHoriz( nbHoriz ), m_nbVert( nbVert ), m_padHoriz( padHoriz ), m_padVert( padVert ), m_tooltip( tooltip ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
+        Slider( const string & id, const string & visible, int xPos, int yPos, const string & leftTop, const string & rightBottom, bool xKeepRatio, bool yKeepRatio, const string & upId, const string & downId, const string & overId, const string & points, int thickness, const string & value, const string & imageId, int nbHoriz, int nbVert, int padHoriz, int padVert, const string & tooltip, const string & help, int layer, const string & windowId, const string & layoutId ):
+m_id( id ), m_visible( visible ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_xKeepRatio( xKeepRatio ), m_yKeepRatio( yKeepRatio ), m_upId( upId ), m_downId( downId ), m_overId( overId ), m_points( points ), m_thickness( thickness ), m_value( value ), m_imageId( imageId ), m_nbHoriz( nbHoriz ), m_nbVert( nbVert ), m_padHoriz( padHoriz ), m_padVert( padVert ), m_tooltip( tooltip ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
 
         string m_id;
         string m_visible;
@@ -356,6 +366,8 @@ m_id( id ), m_visible( visible ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( lef
         int m_yPos;
         string m_leftTop;
         string m_rightBottom;
+        bool m_xKeepRatio;
+        bool m_yKeepRatio;
         string m_upId;
         string m_downId;
         string m_overId;
@@ -379,8 +391,8 @@ m_id( id ), m_visible( visible ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( lef
     /// Type definition
     struct List
     {
-        List( const string & id, int xPos, int yPos, const string & visible, int width, int height, const string & leftTop, const string & rightBottom, const string & fontId, const string & var, const string & bgImageId, const string & fgColor, const string & playColor, const string & bgColor1, const string & bgColor2, const string & selColor, const string & help, int layer, const string & windowId, const string & layoutId ):
-m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_width( width ), m_height( height ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_fontId( fontId ), m_var( var ), m_bgImageId( bgImageId ), m_fgColor( fgColor ), m_playColor( playColor ), m_bgColor1( bgColor1 ), m_bgColor2( bgColor2 ), m_selColor( selColor ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
+        List( const string & id, int xPos, int yPos, const string & visible, int width, int height, const string & leftTop, const string & rightBottom, bool xKeepRatio, bool yKeepRatio, const string & fontId, const string & var, const string & bgImageId, const string & fgColor, const string & playColor, const string & bgColor1, const string & bgColor2, const string & selColor, const string & help, int layer, const string & windowId, const string & layoutId ):
+m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_width( width ), m_height( height ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_xKeepRatio( xKeepRatio ), m_yKeepRatio( yKeepRatio ), m_fontId( fontId ), m_var( var ), m_bgImageId( bgImageId ), m_fgColor( fgColor ), m_playColor( playColor ), m_bgColor1( bgColor1 ), m_bgColor2( bgColor2 ), m_selColor( selColor ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
 
         string m_id;
         int m_xPos;
@@ -390,6 +402,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_width( width
         int m_height;
         string m_leftTop;
         string m_rightBottom;
+        bool m_xKeepRatio;
+        bool m_yKeepRatio;
         string m_fontId;
         string m_var;
         string m_bgImageId;
@@ -409,8 +423,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_width( width
     /// Type definition
     struct Tree
     {
-        Tree( const string & id, int xPos, int yPos, const string & visible, const string & flat, int width, int height, const string & leftTop, const string & rightBottom, const string & fontId, const string & var, const string & bgImageId, const string & itemImageId, const string & openImageId, const string & closedImageId, const string & fgColor, const string & playColor, const string & bgColor1, const string & bgColor2, const string & selColor, const string & help, int layer, const string & windowId, const string & layoutId ):
-m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_flat( flat ), m_width( width ), m_height( height ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_fontId( fontId ), m_var( var ), m_bgImageId( bgImageId ), m_itemImageId( itemImageId ), m_openImageId( openImageId ), m_closedImageId( closedImageId ), m_fgColor( fgColor ), m_playColor( playColor ), m_bgColor1( bgColor1 ), m_bgColor2( bgColor2 ), m_selColor( selColor ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
+        Tree( const string & id, int xPos, int yPos, const string & visible, const string & flat, int width, int height, const string & leftTop, const string & rightBottom, bool xKeepRatio, bool yKeepRatio, const string & fontId, const string & var, const string & bgImageId, const string & itemImageId, const string & openImageId, const string & closedImageId, const string & fgColor, const string & playColor, const string & bgColor1, const string & bgColor2, const string & selColor, const string & help, int layer, const string & windowId, const string & layoutId ):
+m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_flat( flat ), m_width( width ), m_height( height ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_xKeepRatio( xKeepRatio ), m_yKeepRatio( yKeepRatio ), m_fontId( fontId ), m_var( var ), m_bgImageId( bgImageId ), m_itemImageId( itemImageId ), m_openImageId( openImageId ), m_closedImageId( closedImageId ), m_fgColor( fgColor ), m_playColor( playColor ), m_bgColor1( bgColor1 ), m_bgColor2( bgColor2 ), m_selColor( selColor ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
 
         string m_id;
         int m_xPos;
@@ -421,6 +435,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_flat( flat )
         int m_height;
         string m_leftTop;
         string m_rightBottom;
+        bool m_xKeepRatio;
+        bool m_yKeepRatio;
         string m_fontId;
         string m_var;
         string m_bgImageId;
@@ -443,8 +459,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_flat( flat )
     /// Type definition
     struct Video
     {
-        Video( const string & id, int xPos, int yPos, int width, int height, const string & leftTop, const string & rightBottom, const string & visible, bool autoResize, const string & help, int layer, const string & windowId, const string & layoutId ):
-m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_width( width ), m_height( height ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_visible( visible ), m_autoResize( autoResize ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
+        Video( const string & id, int xPos, int yPos, int width, int height, const string & leftTop, const string & rightBottom, bool xKeepRatio, bool yKeepRatio, const string & visible, bool autoResize, const string & help, int layer, const string & windowId, const string & layoutId ):
+m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_width( width ), m_height( height ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_xKeepRatio( xKeepRatio ), m_yKeepRatio( yKeepRatio ), m_visible( visible ), m_autoResize( autoResize ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
 
         string m_id;
         int m_xPos;
@@ -453,6 +469,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_width( width ), m_height( height )
         int m_height;
         string m_leftTop;
         string m_rightBottom;
+        bool m_xKeepRatio;
+        bool m_yKeepRatio;
         string m_visible;
         bool m_autoResize;
         string m_help;
index 4c994406934b0471c0f69ec0e58311a7b1870f1c..bd6384b724cc612a7176038a5074cfa40f4592a7 100644 (file)
@@ -181,6 +181,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         CheckDefault( "y", "0" );
         CheckDefault( "lefttop", "lefttop" );
         CheckDefault( "rightbottom", "lefttop" );
+        CheckDefault( "xkeepratio", "false" );
+        CheckDefault( "ykeepratio", "false" );
         CheckDefault( "down", "none" );
         CheckDefault( "over", "none" );
         CheckDefault( "action", "none" );
@@ -189,7 +191,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
 
         const BuilderData::Button button( uniqueId( attr["id"] ),
                 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["tooltiptext"], attr["help"],
                 m_curLayer, m_curWindowId, m_curLayoutId );
@@ -208,6 +212,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         CheckDefault( "y", "0" );
         CheckDefault( "lefttop", "lefttop" );
         CheckDefault( "rightbottom", "lefttop" );
+        CheckDefault( "xkeepratio", "false" );
+        CheckDefault( "ykeepratio", "false" );
         CheckDefault( "down1", "none" );
         CheckDefault( "over1", "none" );
         CheckDefault( "down2", "none" );
@@ -220,7 +226,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
 
         const BuilderData::Checkbox checkbox( uniqueId( attr["id"] ),
                 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["up2"], attr["down2"], attr["over2"], attr["state"],
                 attr["action1"], attr["action2"], attr["tooltiptext1"],
@@ -261,6 +269,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         CheckDefault( "y", "0" );
         CheckDefault( "lefttop", "lefttop" );
         CheckDefault( "rightbottom", "lefttop" );
+        CheckDefault( "xkeepratio", "false" );
+        CheckDefault( "ykeepratio", "false" );
         CheckDefault( "action", "none" );
         CheckDefault( "action2", "none" );
         CheckDefault( "resize", "mosaic" );
@@ -268,7 +278,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
 
         const BuilderData::Image imageData( uniqueId( attr["id"] ),
                 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["help"], m_curLayer, m_curWindowId, m_curLayoutId );
         m_curLayer++;
@@ -305,6 +317,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         CheckDefault( "height", "0" );
         CheckDefault( "lefttop", "lefttop" );
         CheckDefault( "rightbottom", "lefttop" );
+        CheckDefault( "xkeepratio", "false" );
+        CheckDefault( "ykeepratio", "false" );
         CheckDefault( "bgimage", "none" );
         CheckDefault( "itemimage", "none" );
         CheckDefault( "openimage", "none" );
@@ -321,6 +335,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
                 attr["flat"],
                 atoi( attr["width"]), atoi( attr["height"] ),
                 attr["lefttop"], attr["rightbottom"],
+                convertBoolean( attr["xkeepratio"] ),
+                convertBoolean( attr["ykeepratio"] ),
                 attr["font"], "playtree",
                 attr["bgimage"], attr["itemimage"],
                 attr["openimage"], attr["closedimage"],
@@ -345,6 +361,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         CheckDefault( "height", "0" );
         CheckDefault( "lefttop", "lefttop" );
         CheckDefault( "rightbottom", "lefttop" );
+        CheckDefault( "xkeepratio", "false" );
+        CheckDefault( "ykeepratio", "false" );
         CheckDefault( "bgimage", "none" );
         CheckDefault( "itemimage", "none" );
         CheckDefault( "openimage", "none" );
@@ -362,6 +380,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
                 attr["flat"],
                 atoi( attr["width"]), atoi( attr["height"] ),
                 attr["lefttop"], attr["rightbottom"],
+                convertBoolean( attr["xkeepratio"] ),
+                convertBoolean( attr["ykeepratio"] ),
                 attr["font"], "playtree",
                 attr["bgimage"], attr["itemimage"],
                 attr["openimage"], attr["closedimage"],
@@ -383,6 +403,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         CheckDefault( "y", "0" );
         CheckDefault( "lefttop", "lefttop" );
         CheckDefault( "rightbottom", "lefttop" );
+        CheckDefault( "xkeepratio", "false" );
+        CheckDefault( "ykeepratio", "false" );
         CheckDefault( "minangle", "0" );
         CheckDefault( "maxangle", "360" );
         CheckDefault( "value", "none" );
@@ -392,7 +414,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         const BuilderData::RadialSlider radial( uniqueId( attr["id"] ),
                 attr["visible"],
                 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,
                 atof( attr["maxAngle"] ) * M_PI / 180, attr["value"],
                 attr["tooltiptext"], attr["help"], m_curLayer, m_curWindowId,
@@ -413,6 +437,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         CheckDefault( "height", "0" );
         CheckDefault( "lefttop", "lefttop" );
         CheckDefault( "rightbottom", "lefttop" );
+        CheckDefault( "xkeepratio", "false" );
+        CheckDefault( "ykeepratio", "false" );
         CheckDefault( "down", "none" );
         CheckDefault( "over", "none" );
         CheckDefault( "thickness", "10" );
@@ -429,7 +455,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         const BuilderData::Slider slider( uniqueId( attr["id"] ),
                 attr["visible"], atoi( attr["x"] ) + m_xOffset,
                 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"] ),
                 newValue, "none", 0, 0, 0, 0, attr["tooltiptext"],
                 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
@@ -469,6 +496,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         CheckDefault( "width", "0" );
         CheckDefault( "lefttop", "lefttop" );
         CheckDefault( "rightbottom", "lefttop" );
+        CheckDefault( "xkeepratio", "false" );
+        CheckDefault( "ykeepratio", "false" );
         CheckDefault( "help", "" );
 
         const BuilderData::Text textData( uniqueId( attr["id"] ),
@@ -476,6 +505,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
                 attr["visible"], attr["font"],
                 attr["text"], atoi( attr["width"] ),
                 attr["lefttop"], attr["rightbottom"],
+                convertBoolean( attr["xkeepratio"] ),
+                convertBoolean( attr["ykeepratio"] ),
                 convertColor( attr["color"] ),
                 attr["scrolling"], attr["alignment"],
                 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
@@ -522,6 +553,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         CheckDefault( "height", "0" );
         CheckDefault( "lefttop", "lefttop" );
         CheckDefault( "rightbottom", "lefttop" );
+        CheckDefault( "xkeepratio", "false" );
+        CheckDefault( "ykeepratio", "false" );
         CheckDefault( "autoresize", "false" );
         CheckDefault( "help", "" );
 
@@ -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["width"] ), atoi( attr["height" ]),
                 attr["lefttop"], attr["rightbottom"],
+                convertBoolean( attr["xkeepratio"] ),
+                convertBoolean( attr["ykeepratio"] ),
                 attr["visible"], convertBoolean( attr["autoresize"] ),
                 attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
         m_curLayer++;
index 87b1cc4dd13e665a86d28fe3a0c37deddd929a33..5529fc7b5cb224edab9f8ad61b1ebed699034115 100644 (file)
@@ -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,
-                    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_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
 {
-    switch( m_refLeftTop )
+    if( m_xKeepRatio )
     {
-        case kLeftTop:
-        case kLeftBottom:
-            return m_left;
-            break;
-        case kRightTop:
-        case kRightBottom:
-            return m_rBox.getWidth() + m_left - 1;
-            break;
+        // Ratio mode
+        // First compute the width of the box minus the width of the control
+        int freeSpace = m_rBox.getWidth() - (m_right - m_left);
+        return (int)(m_xRatio * freeSpace);
+    }
+    else
+    {
+        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
 {
-    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:
-        case kRightTop:
-            return m_top;
-            break;
-        case kRightBottom:
-        case kLeftBottom:
-            return m_rBox.getHeight() + m_top - 1;
-            break;
+        switch( m_refLeftTop )
+        {
+            case kLeftTop:
+            case kRightTop:
+                return m_top;
+                break;
+            case kRightBottom:
+            case kLeftBottom:
+                return m_rBox.getHeight() + m_top - 1;
+                break;
+        }
+        // Avoid a warning
+        return 0;
     }
-    // Avoid a warning
-    return 0;
 }
 
 
 int Position::getRight() const
 {
-    switch( m_refRighBottom )
+    if( m_xKeepRatio )
     {
-        case kLeftTop:
-        case kLeftBottom:
-            return m_right;
-            break;
-        case kRightTop:
-        case kRightBottom:
-            return m_rBox.getWidth() + m_right - 1;
-            break;
+        // Ratio mode
+        // The width of the control being constant, we can use the result of
+        // getLeft() (this will avoid rounding issues).
+        return getLeft() + m_right - m_left;
+    }
+    else
+    {
+        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
 {
-    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:
-        case kRightTop:
-            return m_bottom;
-            break;
-        case kLeftBottom:
-        case kRightBottom:
-            return m_rBox.getHeight() + m_bottom - 1;
-            break;
+        switch( m_refRighBottom )
+        {
+            case kLeftTop:
+            case kRightTop:
+                return m_bottom;
+                break;
+            case kLeftBottom:
+            case kRightBottom:
+                return m_rBox.getHeight() + m_bottom - 1;
+                break;
+        }
+        // Avoid a warning
+        return 0;
     }
-    // Avoid a warning
-    return 0;
 }
 
 
index 10ed3e5c1cf0fad86a86675c95806a08d5590aa6..efd20c0754ee93edf0504f56c08ce0af188d1025 100644 (file)
@@ -82,8 +82,8 @@ class Position
 
         /// Create a new position relative to the given box
         Position( int left, int top, int right, int bottom, const Box &rBox,
-                  Ref_t refLeftTop = kLeftTop,
-                  Ref_t refRightBottom = kLeftTop );
+                  Ref_t refLeftTop, Ref_t refRightBottom,
+                  bool xKeepRatio, bool yKeepRatio );
 
         ~Position() {}
 
@@ -108,6 +108,13 @@ class Position
         const Box &m_rBox;
         Ref_t m_refLeftTop;
         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;
 };
 
 
index f39ea28080a35ad02787a49baf7f52d1b8ebd661..e04bd635b0b698296e928fff1dd75ef156520ad0 100644 (file)
         y           CDATA   "0"
         lefttop     CDATA   "lefttop"
         rightbottom CDATA   "lefttop"
+        xkeepratio  CDATA   "false"
+        ykeepratio  CDATA   "false"
         image       CDATA   #REQUIRED
         action      CDATA   "none"
         action2     CDATA   "none"
         y           CDATA   "0"
         lefttop     CDATA   "lefttop"
         rightbottom CDATA   "lefttop"
+        xkeepratio  CDATA   "false"
+        ykeepratio  CDATA   "false"
         up          CDATA   #REQUIRED
         down        CDATA   "none"
         over        CDATA   "none"
         y            CDATA   "0"
         lefttop      CDATA   "lefttop"
         rightbottom  CDATA   "lefttop"
+        xkeepratio  CDATA   "false"
+        ykeepratio  CDATA   "false"
         up1          CDATA   #REQUIRED
         down1        CDATA   "none"
         over1        CDATA   "none"
         y           CDATA   "0"
         lefttop     CDATA   "lefttop"
         rightbottom CDATA   "lefttop"
+        xkeepratio  CDATA   "false"
+        ykeepratio  CDATA   "false"
         up          CDATA   #REQUIRED
         down        CDATA   "none"
         over        CDATA   "none"
         y           CDATA   "0"
         lefttop     CDATA   "lefttop"
         rightbottom CDATA   "lefttop"
+        xkeepratio  CDATA   "false"
+        ykeepratio  CDATA   "false"
         sequence    CDATA   #REQUIRED
         nbimages    CDATA   #REQUIRED
         minangle    CDATA   "0"
         width       CDATA   "0"
         lefttop     CDATA   "lefttop"
         rightbottom CDATA   "lefttop"
+        xkeepratio  CDATA   "false"
+        ykeepratio  CDATA   "false"
         text        CDATA   ""
         font        CDATA   #REQUIRED
         color       CDATA   "#000000"
         height      CDATA   "0"
         lefttop     CDATA   "lefttop"
         rightbottom CDATA   "lefttop"
+        xkeepratio  CDATA   "false"
+        ykeepratio  CDATA   "false"
         font        CDATA   #REQUIRED
         bgimage     CDATA   "none"
         fgcolor     CDATA   "#000000"
         height      CDATA   "0"
         lefttop     CDATA   "lefttop"
         rightbottom CDATA   "lefttop"
+        xkeepratio  CDATA   "false"
+        ykeepratio  CDATA   "false"
         font        CDATA   #REQUIRED
         bgimage     CDATA   "none"
         itemimage   CDATA   "none"
         height      CDATA   "0"
         lefttop     CDATA   "lefttop"
         rightbottom CDATA   "lefttop"
+        xkeepratio  CDATA   "false"
+        ykeepratio  CDATA   "false"
         autoresize  CDATA   "true"
         help        CDATA   ""
     >