[vlc-commits] skins2: extend xoffset and yoffset parameters
Erwan Tulou
git at videolan.org
Sat Jun 22 15:38:15 CEST 2013
vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Sat Jun 22 14:05:46 2013 +0200| [31dafe28c46f1952a564958f1036de5cfe0f06ea] | committer: Erwan Tulou
skins2: extend xoffset and yoffset parameters
Till now, these two parameters only had a meaning for geographical positioning.
As explained at http://forum.videolan.org/viewtopic.php?f=26&t=111572,
extending xoffset and yoffset for the general case would help a lot skin
developpers easily position an object of unknown size around a given point :
for instance,
x="50%" xoffset="-50%" would center an object horizontally.
x="100%" xoffset="-100%" would set an object to the East
This patch doesn't modify the existing behaviour. It just implements a new
feature for the case where it was a silent no op.
x,y, width, height percentages are computed against the parent container
xoffset and yoffset percentages are computed against the current object
TODO: this approach could be generalized to all objects (need to extend the dtd)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=31dafe28c46f1952a564958f1036de5cfe0f06ea
---
modules/gui/skins2/parser/skin_parser.cpp | 64 +++++++++++++++++------------
1 file changed, 38 insertions(+), 26 deletions(-)
diff --git a/modules/gui/skins2/parser/skin_parser.cpp b/modules/gui/skins2/parser/skin_parser.cpp
index f0937e4..a96771b 100644
--- a/modules/gui/skins2/parser/skin_parser.cpp
+++ b/modules/gui/skins2/parser/skin_parser.cpp
@@ -959,33 +959,45 @@ void SkinParser::convertPosition( string position, string xOffset,
int refWidth, int refHeight, int* p_x, int* p_y )
{
int iPosition = getPosition( position );
- if( iPosition == POS_UNDEF )
- return;
+ if( iPosition != POS_UNDEF )
+ {
+ // compute offset against the parent object size
+ // for backward compatibility
+ int i_xOffset = getDimension( xOffset, refWidth );
+ int i_yOffset = getDimension( yOffset, refHeight );
+ int i_xMargin = getDimension( xMargin, refWidth );
+ int i_yMargin = getDimension( yMargin, refHeight );
+
+ // compute *p_x
+ if( iPosition & POS_LEFT )
+ *p_x = i_xMargin;
+ else if( iPosition & POS_RIGHT )
+ *p_x = refWidth - width - i_xMargin;
+ else
+ *p_x = ( refWidth - width ) / 2;
+
+ // compute *p_y
+ if( iPosition & POS_TOP )
+ *p_y = i_yMargin;
+ else if( iPosition & POS_BOTTOM )
+ *p_y = refHeight - height - i_yMargin;
+ else
+ *p_y = ( refHeight - height ) / 2;
+
+ // add offset
+ *p_x += i_xOffset;
+ *p_y += i_yOffset;
+ }
+ else
+ {
+ // compute offset against the current object size
+ int i_xOffset = getDimension( xOffset, width );
+ int i_yOffset = getDimension( yOffset, height );
- int i_xOffset = getDimension( xOffset, refWidth );
- int i_yOffset = getDimension( yOffset, refHeight );
- int i_xMargin = getDimension( xMargin, refWidth );
- int i_yMargin = getDimension( yMargin, refHeight );
-
- // compute *p_x
- if( iPosition & POS_LEFT )
- *p_x = i_xMargin;
- else if( iPosition & POS_RIGHT )
- *p_x = refWidth - width - i_xMargin;
- else
- *p_x = ( refWidth - width ) / 2;
-
- // compute *p_y
- if( iPosition & POS_TOP )
- *p_y = i_yMargin;
- else if( iPosition & POS_BOTTOM )
- *p_y = refHeight - height - i_yMargin;
- else
- *p_y = ( refHeight - height ) / 2;
-
- // add offset
- *p_x += i_xOffset;
- *p_y += i_yOffset;
+ // add offset
+ *p_x += i_xOffset;
+ *p_y += i_yOffset;
+ }
}
More information about the vlc-commits
mailing list