diff --git a/src/gui/components/cc_base.cpp b/src/gui/components/cc_base.cpp index 223253ecc..2e8a06b82 100644 --- a/src/gui/components/cc_base.cpp +++ b/src/gui/components/cc_base.cpp @@ -3,7 +3,7 @@ Copyright (C) 2001 by Steffen Hehn 'McClean' Classes for generic GUI-related components. - Copyright (C) 2012, 2013, Thilo Graf 'dbt' + Copyright (C) 2012-2014, Thilo Graf 'dbt' Copyright (C) 2012, Michael Liebmann 'micha-bbg' License: GPL @@ -235,10 +235,20 @@ void CComponents::kill() } //clean old screen buffer -inline void CComponents::clearFbData() +void CComponents::clearFbData() { for(size_t i =0; i< v_fbdata.size() ;i++) if (v_fbdata[i].pixbuf) delete[] v_fbdata[i].pixbuf; v_fbdata.clear(); } + +inline void CComponents::setXPos(const int& xpos) +{ + x = xpos; +} + +inline void CComponents::setYPos(const int& ypos) +{ + y = ypos; +} diff --git a/src/gui/components/cc_base.h b/src/gui/components/cc_base.h index 6ae2c533c..175b30580 100644 --- a/src/gui/components/cc_base.h +++ b/src/gui/components/cc_base.h @@ -120,11 +120,11 @@ class CComponents CComponents(); virtual~CComponents(); - ///set screen x-position - inline virtual void setXPos(const int& xpos){x = xpos;}; - ///set screen y-position, - inline virtual void setYPos(const int& ypos){y = ypos;}; - ///set x and y position + ///set screen x-position, parameter as int + virtual void setXPos(const int& xpos); + ///set screen y-position, parameter as int + virtual void setYPos(const int& ypos); + ///set x and y position at once ///Note: position of bound components (items) means position related within parent form, not for screen! ///to set the real screen position, look at setRealPos() inline virtual void setPos(const int& xpos, const int& ypos){x = xpos; y = ypos;}; @@ -286,6 +286,14 @@ class CComponentsItem : public CComponents ///set an index to item, see also attribut cc_item_index. ///To generate an index, use genIndex() virtual void setIndex(const int& index){cc_item_index = index;}; + + ///set screen x-position, parameter as uint8_t, percent value of screen x + virtual void setXPosP(const uint8_t& xpos_percent); + ///set screen y-position, parameter as uint8_t, percent value of screen y + virtual void setYPosP(const uint8_t& ypos_percent); + ///set x and y position as percent value from current parent or screen dimensions at once + ///Note: position of bound components (items) means position related within parent form, not for screen! + virtual void setPosP(const uint8_t& xpos_percent, const uint8_t& ypos_percent); }; #endif diff --git a/src/gui/components/cc_item.cpp b/src/gui/components/cc_item.cpp index 08902596b..e9cc06486 100644 --- a/src/gui/components/cc_item.cpp +++ b/src/gui/components/cc_item.cpp @@ -3,7 +3,7 @@ Copyright (C) 2001 by Steffen Hehn 'McClean' Classes for generic GUI-related components. - Copyright (C) 2012, 2013, Thilo Graf 'dbt' + Copyright (C) 2012-2014, Thilo Graf 'dbt' Copyright (C) 2012, Michael Liebmann 'micha-bbg' License: GPL @@ -31,6 +31,7 @@ #include #include #include "cc_base.h" +#include using namespace std; @@ -163,3 +164,21 @@ bool CComponentsItem::isAdded() return false; } + +void CComponentsItem::setXPosP(const uint8_t& xpos_percent) +{ + int x_tmp = cc_parent ? xpos_percent*cc_parent->getWidth() : xpos_percent*frameBuffer->getScreenWidth(); + x = x_tmp/100; +} + +void CComponentsItem::setYPosP(const uint8_t& ypos_percent) +{ + int y_tmp = cc_parent ? ypos_percent*cc_parent->getHeight() : ypos_percent*frameBuffer->getScreenHeight(); + x = y_tmp/100; +} + +void CComponentsItem::setPosP(const uint8_t& xpos_percent, const uint8_t& ypos_percent) +{ + setXPosP(xpos_percent); + setYPosP(ypos_percent); +}