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;
......
This diff is collapsed.
......@@ -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