Commit 6f772953 authored by Erwan Tulou's avatar Erwan Tulou

skins2: implement relative positioning

So far in skins2, all x, y, width and height were given in pixels, and
no reference to the screen resolution could be made.

This patch implements the following :
- all x, y, width, height can be given in pixels or in % of their container.
  For windows, the container is the screen. For widgets, it can be the
  layout or a panel.
- Five new tags eases up positioning
  - position : relative position given as "Center", "West", "NorthWest", ...
  - x/y-margin : margins to take into account (in px or %) wrt the borders.
  - x/y-offset : additional offset to apply (in px or %).
- the image control can now accept a width and a height parameters.
parent 5d7acec1
......@@ -598,10 +598,12 @@ void Builder::addImage( const BuilderData::Image &rData )
// Compute the position of the control
const GenericRect *pRect;
int width = (rData.m_width > 0) ? rData.m_width : pBmp->getWidth();
int height = (rData.m_height > 0) ? rData.m_height : pBmp->getHeight();
GET_BOX( pRect, rData.m_panelId , pLayout);
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
rData.m_xPos, rData.m_yPos,
pBmp->getWidth(), pBmp->getHeight(),
width, height,
*pRect, rData.m_xKeepRatio,
rData.m_yKeepRatio );
......
......@@ -6,12 +6,12 @@ Font id:string fontFile:string size:int
PopupMenu id:string
MenuItem label:string action:string pos:int popupId:string
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 position:string xOffset:string yOffset:string xMargin:string yMargin:string 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 xKeepRatio:bool yKeepRatio:bool visible:string upId:string downId:string overId:string actionId:string tooltip:string help:string layer:int windowId:string layoutId:string panelId: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 panelId: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 art:bool layer:int windowId:string layoutId:string panelId:string
Image id:string xPos:int yPos:int width:int height:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool visible:string bmpId:string actionId:string action2Id:string resize:string help:string art:bool layer:int windowId:string layoutId:string panelId:string
IniFile id:string file:string
Panel id:string xPos:int yPos:int leftTop:string rightBottom:string xKeepRatio:bool yKeepRatio:bool width:int height:int layer:int windowId:string layoutId:string panelId: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 panelId:string
......
......@@ -154,12 +154,17 @@ m_pos( pos ), m_popupId( popupId ) {}
/// Type definition
struct Window
{
Window( const string & id, int xPos, int yPos, bool visible, bool dragDrop, bool playOnDrop ):
m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_dragDrop( dragDrop ), m_playOnDrop( playOnDrop ) {}
Window( const string & id, int xPos, int yPos, const string & position, const string & xOffset, const string & yOffset, const string & xMargin, const string & yMargin, bool visible, bool dragDrop, bool playOnDrop ):
m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_position( position ), m_xOffset( xOffset ), m_yOffset( yOffset ), m_xMargin( xMargin ), m_yMargin( yMargin ), m_visible( visible ), m_dragDrop( dragDrop ), m_playOnDrop( playOnDrop ) {}
string m_id;
int m_xPos;
int m_yPos;
string m_position;
string m_xOffset;
string m_yOffset;
string m_xMargin;
string m_yMargin;
bool m_visible;
bool m_dragDrop;
bool m_playOnDrop;
......@@ -267,12 +272,14 @@ 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, bool xKeepRatio, bool yKeepRatio, const string & visible, const string & bmpId, const string & actionId, const string & action2Id, const string & resize, const string & help, bool art, int layer, const string & windowId, const string & layoutId, const string & panelId ):
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_art( art ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ), m_panelId( panelId ) {}
Image( const string & id, int xPos, int yPos, int width, int height, 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, bool art, int layer, const string & windowId, const string & layoutId, const string & panelId ):
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_bmpId( bmpId ), m_actionId( actionId ), m_action2Id( action2Id ), m_resize( resize ), m_help( help ), m_art( art ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ), m_panelId( panelId ) {}
string m_id;
int m_xPos;
int m_yPos;
int m_width;
int m_height;
string m_leftTop;
string m_rightBottom;
bool m_xKeepRatio;
......@@ -283,7 +290,7 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom(
string m_action2Id;
string m_resize;
string m_help;
bool m_art;
bool m_art;
int m_layer;
string m_windowId;
string m_layoutId;
......
......@@ -101,8 +101,12 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "points", "(0,0)" );
DefaultAttr( attr, "range", "10" );
const BuilderData::Anchor anchor( atoi( attr["x"] ) + m_xOffset,
atoi( attr["y"] ) + m_yOffset, attr["lefttop"],
int refWidth = getRefWidth( false );
int refHeight = getRefHeight( false );
int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight );
const BuilderData::Anchor anchor( x + m_xOffset,
y + m_yOffset, attr["lefttop"],
atoi( attr["range"] ), atoi( attr["priority"] ),
attr["points"], m_curLayoutId );
m_pData->m_listAnchor.push_back( anchor );
......@@ -202,8 +206,12 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "tooltiptext", "" );
DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false );
int refHeight = getRefHeight( false );
int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight );
const BuilderData::Button button( uniqueId( attr["id"] ),
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
x + m_xOffset, y + m_yOffset,
attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ), attr["visible"],
......@@ -237,8 +245,12 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "tooltiptext2", "" );
DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false );
int refHeight = getRefHeight( false );
int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight );
const BuilderData::Checkbox checkbox( uniqueId( attr["id"] ),
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
x + m_xOffset, y + m_yOffset,
attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ), attr["visible"],
......@@ -280,6 +292,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "visible", "true" );
DefaultAttr( attr, "x", "0" );
DefaultAttr( attr, "y", "0" );
DefaultAttr( attr, "width", "-1" );
DefaultAttr( attr, "height", "-1" );
DefaultAttr( attr, "lefttop", "lefttop" );
DefaultAttr( attr, "rightbottom", "lefttop" );
DefaultAttr( attr, "xkeepratio", "false" );
......@@ -290,8 +304,14 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "help", "" );
DefaultAttr( attr, "art", "false" );
int refWidth = getRefWidth( false );
int refHeight = getRefHeight( false );
int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight );
int width = getDimension( attr["width"], refWidth );
int height = getDimension( attr["height"], refHeight );
const BuilderData::Image imageData( uniqueId( attr["id"] ),
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
x + m_xOffset, y + m_yOffset, width, height,
attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ), attr["visible"],
......@@ -313,11 +333,21 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "minheight", "-1" );
DefaultAttr( attr, "maxheight", "-1" );
int refWidth = getRefWidth( true );
int refHeight = getRefHeight( true );
int width = getDimension( attr["width"], refWidth );
int height = getDimension( attr["height"], refHeight );
m_curLayoutId = uniqueId( attr["id"] );
const BuilderData::Layout layout( m_curLayoutId, atoi( attr["width"] ),
atoi( attr["height"] ), atoi( attr["minwidth"] ),
atoi( attr["maxwidth"] ), atoi( attr["minheight"] ),
atoi( attr["maxheight"] ), m_curWindowId );
const BuilderData::Layout layout( m_curLayoutId,
width, height,
getDimension( attr["minwidth"], refWidth ),
getDimension( attr["maxwidth"], refWidth ),
getDimension( attr["minheight"], refHeight ),
getDimension( attr["maxheight"], refHeight ),
m_curWindowId );
updateWindowPos( width, height );
m_pData->m_listLayout.push_back( layout );
m_curLayer = 0;
}
......@@ -332,14 +362,31 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "ykeepratio", "false" );
RequireAttr( attr, rName, "width" );
RequireAttr( attr, rName, "height" );
DefaultAttr( attr, "position", "-1" );
DefaultAttr( attr, "xoffset", "0" );
DefaultAttr( attr, "yoffset", "0" );
DefaultAttr( attr, "xmargin", "0" );
DefaultAttr( attr, "ymargin", "0" );
int refWidth = getRefWidth( false );
int refHeight = getRefHeight( false );
int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight );
int width = getDimension( attr["width"], refWidth );
int height = getDimension( attr["height"], refHeight );
convertPosition( attr["position"],
attr["xoffset"], attr["yoffset"],
attr["xmargin"], attr["ymargin"],
width, height, refWidth, refHeight, &x, &y );
string panelId = uniqueId( "none" );
const BuilderData::Panel panel( panelId,
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
x + m_xOffset, y + m_yOffset,
attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ),
atoi( attr["width"] ), atoi( attr["height" ] ),
width, height,
m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() );
m_curLayer++;
m_pData->m_listPanel.push_back( panel );
......@@ -357,6 +404,11 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "y", "0" );
DefaultAttr( attr, "width", "0" );
DefaultAttr( attr, "height", "0" );
DefaultAttr( attr, "position", "-1" );
DefaultAttr( attr, "xoffset", "0" );
DefaultAttr( attr, "yoffset", "0" );
DefaultAttr( attr, "xmargin", "0" );
DefaultAttr( attr, "ymargin", "0" );
DefaultAttr( attr, "lefttop", "lefttop" );
DefaultAttr( attr, "rightbottom", "lefttop" );
DefaultAttr( attr, "xkeepratio", "false" );
......@@ -372,11 +424,23 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "selcolor", "#0000FF" );
DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false );
int refHeight = getRefHeight( false );
int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight );
int width = getDimension( attr["width"], refWidth );
int height = getDimension( attr["height"], refHeight );
convertPosition( attr["position"],
attr["xoffset"], attr["yoffset"],
attr["xmargin"], attr["ymargin"],
width, height, refWidth, refHeight, &x, &y );
m_curTreeId = uniqueId( attr["id"] );
const BuilderData::Tree treeData( m_curTreeId, atoi( attr["x"] ) +
m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["visible"],
const BuilderData::Tree treeData( m_curTreeId,
x + m_xOffset, y + m_yOffset, attr["visible"],
attr["flat"],
atoi( attr["width"]), atoi( attr["height"] ),
width, height,
attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ),
......@@ -402,6 +466,11 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "y", "0" );
DefaultAttr( attr, "width", "0" );
DefaultAttr( attr, "height", "0" );
DefaultAttr( attr, "position", "-1" );
DefaultAttr( attr, "xoffset", "0" );
DefaultAttr( attr, "yoffset", "0" );
DefaultAttr( attr, "xmargin", "0" );
DefaultAttr( attr, "ymargin", "0" );
DefaultAttr( attr, "lefttop", "lefttop" );
DefaultAttr( attr, "rightbottom", "lefttop" );
DefaultAttr( attr, "xkeepratio", "false" );
......@@ -417,11 +486,23 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "selcolor", "#0000FF" );
DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false );
int refHeight = getRefHeight( false );
int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight );
int width = getDimension( attr["width"], refWidth );
int height = getDimension( attr["height"], refHeight );
convertPosition( attr["position"],
attr["xoffset"], attr["yoffset"],
attr["xmargin"], attr["ymargin"],
width, height, refWidth, refHeight, &x, &y );
m_curTreeId = uniqueId( attr["id"] );
const BuilderData::Tree treeData( m_curTreeId, atoi( attr["x"] ) +
m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["visible"],
const BuilderData::Tree treeData( m_curTreeId,
x + m_xOffset, y + m_yOffset, attr["visible"],
attr["flat"],
atoi( attr["width"]), atoi( attr["height"] ),
width, height,
attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ),
......@@ -454,9 +535,13 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "tooltiptext", "" );
DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false );
int refHeight = getRefHeight( false );
int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight );
const BuilderData::RadialSlider radial( uniqueId( attr["id"] ),
attr["visible"],
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
x + m_xOffset, y + m_yOffset,
attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ), attr["sequence"],
......@@ -493,9 +578,14 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
// Slider associated to a tree
newValue = "playtree.slider";
}
int refWidth = getRefWidth( false );
int refHeight = getRefHeight( false );
int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight );
const BuilderData::Slider slider( uniqueId( attr["id"] ),
attr["visible"], atoi( attr["x"] ) + m_xOffset,
atoi( attr["y"] ) + m_yOffset, attr["lefttop"],
attr["visible"], x + m_xOffset,
y + m_yOffset, attr["lefttop"],
attr["rightbottom"], convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ), attr["up"], attr["down"],
attr["over"], attr["points"], atoi( attr["thickness"] ),
......@@ -542,10 +632,18 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "ykeepratio", "false" );
DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false );
int refHeight = getRefHeight( false );
int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight );
int width = getDimension( attr["width"], refWidth );
const BuilderData::Text textData( uniqueId( attr["id"] ),
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
x + m_xOffset, y + m_yOffset,
attr["visible"], attr["font"],
attr["text"], atoi( attr["width"] ),
attr["text"],
width,
attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ),
......@@ -598,6 +696,11 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "y", "0" );
DefaultAttr( attr, "width", "0" );
DefaultAttr( attr, "height", "0" );
DefaultAttr( attr, "position", "-1" );
DefaultAttr( attr, "xoffset", "0" );
DefaultAttr( attr, "yoffset", "0" );
DefaultAttr( attr, "xmargin", "0" );
DefaultAttr( attr, "ymargin", "0" );
DefaultAttr( attr, "lefttop", "lefttop" );
DefaultAttr( attr, "rightbottom", "lefttop" );
DefaultAttr( attr, "xkeepratio", "false" );
......@@ -605,9 +708,20 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "autoresize", "false" );
DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false );
int refHeight = getRefHeight( false );
int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight );
int width = getDimension( attr["width"], refWidth );
int height = getDimension( attr["height"], refHeight );
convertPosition( attr["position"],
attr["xoffset"], attr["yoffset"],
attr["xmargin"], attr["ymargin"],
width, height, refWidth, refHeight, &x, &y );
const BuilderData::Video videoData( uniqueId( attr["id"] ),
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
atoi( attr["width"] ), atoi( attr["height" ]),
x + m_xOffset, y + m_yOffset, width, height,
attr["lefttop"], attr["rightbottom"],
convertBoolean( attr["xkeepratio"] ),
convertBoolean( attr["ykeepratio"] ),
......@@ -624,12 +738,25 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "visible", "true" );
DefaultAttr( attr, "x", "0" );
DefaultAttr( attr, "y", "0" );
DefaultAttr( attr, "position", "-1" );
DefaultAttr( attr, "xoffset", "0" );
DefaultAttr( attr, "yoffset", "0" );
DefaultAttr( attr, "xmargin", "0" );
DefaultAttr( attr, "ymargin", "0" );
DefaultAttr( attr, "dragdrop", "true" );
DefaultAttr( attr, "playondrop", "true" );
m_curWindowId = uniqueId( attr["id"] );
int refWidth = getRefWidth( true );
int refHeight = getRefHeight( true );
int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight );
const BuilderData::Window window( m_curWindowId,
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
x + m_xOffset, y + m_yOffset,
attr["position"],
attr["xoffset"], attr["yoffset"],
attr["xmargin"], attr["ymargin"],
convertBoolean( attr["visible"] ),
convertBoolean( attr["dragdrop"] ),
convertBoolean( attr["playondrop"] ) );
......@@ -743,3 +870,149 @@ const string SkinParser::uniqueId( const string &id )
return newId;
}
const int SkinParser::getRefWidth( bool toScreen )
{
if( toScreen )
{
OSFactory *pOsFactory = OSFactory::instance( getIntf() );
return pOsFactory->getScreenWidth();
}
string panelId = m_panelStack.back();
if( panelId != "none" )
{
const BuilderData::Panel panel = m_pData->m_listPanel.back();
return panel.m_width;
}
else
{
const BuilderData::Layout layout = m_pData->m_listLayout.back();
return layout.m_width;
}
}
const int SkinParser::getRefHeight( bool toScreen )
{
if( toScreen )
{
OSFactory *pOsFactory = OSFactory::instance( getIntf() );
return pOsFactory->getScreenHeight();
}
string panelId = m_panelStack.back();
if( panelId != "none" )
{
const BuilderData::Panel panel = m_pData->m_listPanel.back();
return panel.m_height;
}
else
{
const BuilderData::Layout layout = m_pData->m_listLayout.back();
return layout.m_height;
}
}
const int SkinParser::getDimension( string value, int refDimension )
{
int val;
int leftPos = value.find( "%" );
if( leftPos != string::npos )
{
int val = atoi( value.substr( 0, leftPos ).c_str() );
return val * refDimension / 100;
}
leftPos = value.find( "px" );
if( leftPos != string::npos )
{
int val = atoi( value.substr( 0, leftPos ).c_str() );
return val;
}
return atoi( value.c_str() );
}
const int SkinParser::getPosition( string position )
{
if( position == "-1" )
return POS_UNDEF;
else if( position == "Center" )
return POS_CENTER;
else if( position == "North" )
return POS_TOP;
else if( position == "South" )
return POS_BOTTOM;
else if( position == "West" )
return POS_LEFT;
else if( position == "East" )
return POS_RIGHT;
else if( position == "NorthWest" )
return POS_TOP | POS_LEFT;
else if( position == "NorthEast" )
return POS_TOP | POS_RIGHT;
else if( position == "SouthWest" )
return POS_BOTTOM | POS_LEFT;
else if( position == "SouthEast" )
return POS_BOTTOM | POS_RIGHT;
msg_Err( getIntf(), "unknown value '%s' for position",
position.c_str() );
return POS_UNDEF;
}
void SkinParser::convertPosition( string position, string xOffset,
string yOffset, string xMargin,
string yMargin, int width, int height,
int refWidth, int refHeight, int* p_x, int* p_y )
{
int iPosition = getPosition( position );
if( iPosition == POS_UNDEF )
return;
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;
}
void SkinParser::updateWindowPos( int width, int height )
{
BuilderData::Window win = m_pData->m_listWindow.back();
m_pData->m_listWindow.pop_back();
int refWidth = getRefWidth( true );
int refHeight = getRefHeight( true );
convertPosition( win.m_position,
win.m_xOffset, win.m_yOffset,
win.m_xMargin, win.m_yMargin,
width, height, refWidth, refHeight,
&win.m_xPos, &win.m_yPos );
m_pData->m_listWindow.push_back( win );
}
......@@ -33,6 +33,16 @@
class SkinParser: public XMLParser
{
public:
enum {
POS_UNDEF = 0,
POS_CENTER = 1,
POS_LEFT = 2,
POS_RIGHT = 4,
POS_TOP = 8,
POS_BOTTOM = 16,
};
SkinParser( intf_thread_t *pIntf, const string &rFileName,
const string &rPath, bool useDTD = true,
BuilderData *pData = NULL );
......@@ -88,6 +98,19 @@ private:
/// Check if the id is unique, and if not generate a new one
const string uniqueId( const string &id );
/// Management of relative positions
const int getRefWidth( bool toScreen );
const int getRefHeight( bool toScreen );
const int getDimension( string value, int refDimension );
const int getPosition( string value );
void updateWindowPos( int width, int height );
void convertPosition( string position,
string xOffset, string yOffset,
string xMargin, string yMargin,
int width, int height, int refWidth, int refHeight,
int* p_x, int* p_y );
/// Helper for handleBeginElement: Provide default attribute if missing.
static void DefaultAttr( AttrList_t &attr, const char *a, const char *b )
{
......
......@@ -76,6 +76,11 @@
visible CDATA "true"
x CDATA "0"
y CDATA "0"
position CDATA "-1"
xoffset CDATA "0"
yoffset CDATA "0"
xmargin CDATA "0"
ymargin CDATA "0"
dragdrop CDATA "true"
playondrop CDATA "true"
>
......@@ -110,6 +115,11 @@
ykeepratio CDATA "false"
width CDATA #REQUIRED
height CDATA #REQUIRED
position CDATA "-1"
xoffset CDATA "0"
yoffset CDATA "0"
xmargin CDATA "0"
ymargin CDATA "0"
>
<!-- Anchors -->
......@@ -131,6 +141,8 @@
visible CDATA "true"
x CDATA "0"
y CDATA "0"
width CDATA "-1"
height CDATA "-1"
lefttop CDATA "lefttop"
rightbottom CDATA "lefttop"
xkeepratio CDATA "false"
......@@ -255,6 +267,11 @@
y CDATA "0"
width CDATA "0"
height CDATA "0"
position CDATA "-1"
xoffset CDATA "0"
yoffset CDATA "0"
xmargin CDATA "0"
ymargin CDATA "0"
lefttop CDATA "lefttop"
rightbottom CDATA "lefttop"
xkeepratio CDATA "false"
......@@ -276,6 +293,11 @@
y CDATA "0"
width CDATA "0"
height CDATA "0"
position CDATA "-1"
xoffset CDATA "0"
yoffset CDATA "0"
xmargin CDATA "0"
ymargin CDATA "0"
lefttop CDATA "lefttop"
rightbottom CDATA "lefttop"
xkeepratio CDATA "false"
......@@ -301,6 +323,11 @@
y CDATA "0"
width CDATA "0"
height CDATA "0"
position CDATA "-1"
xoffset CDATA "0"
yoffset CDATA "0"
xmargin CDATA "0"
ymargin CDATA "0"
lefttop CDATA "lefttop"
rightbottom CDATA "lefttop"
xkeepratio CDATA "false"
......
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