CComponentsItem: add members to set item position via percent value

This commit is contained in:
2014-02-26 22:34:14 +01:00
parent 8a39f01a79
commit 38dffb8456
3 changed files with 45 additions and 8 deletions

View File

@@ -3,7 +3,7 @@
Copyright (C) 2001 by Steffen Hehn 'McClean' Copyright (C) 2001 by Steffen Hehn 'McClean'
Classes for generic GUI-related components. 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' Copyright (C) 2012, Michael Liebmann 'micha-bbg'
License: GPL License: GPL
@@ -235,10 +235,20 @@ void CComponents::kill()
} }
//clean old screen buffer //clean old screen buffer
inline void CComponents::clearFbData() void CComponents::clearFbData()
{ {
for(size_t i =0; i< v_fbdata.size() ;i++) for(size_t i =0; i< v_fbdata.size() ;i++)
if (v_fbdata[i].pixbuf) if (v_fbdata[i].pixbuf)
delete[] v_fbdata[i].pixbuf; delete[] v_fbdata[i].pixbuf;
v_fbdata.clear(); v_fbdata.clear();
} }
inline void CComponents::setXPos(const int& xpos)
{
x = xpos;
}
inline void CComponents::setYPos(const int& ypos)
{
y = ypos;
}

View File

@@ -120,11 +120,11 @@ class CComponents
CComponents(); CComponents();
virtual~CComponents(); virtual~CComponents();
///set screen x-position ///set screen x-position, parameter as int
inline virtual void setXPos(const int& xpos){x = xpos;}; virtual void setXPos(const int& xpos);
///set screen y-position, ///set screen y-position, parameter as int
inline virtual void setYPos(const int& ypos){y = ypos;}; virtual void setYPos(const int& ypos);
///set x and y position ///set x and y position at once
///Note: position of bound components (items) means position related within parent form, not for screen! ///Note: position of bound components (items) means position related within parent form, not for screen!
///to set the real screen position, look at setRealPos() ///to set the real screen position, look at setRealPos()
inline virtual void setPos(const int& xpos, const int& ypos){x = xpos; y = ypos;}; 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. ///set an index to item, see also attribut cc_item_index.
///To generate an index, use genIndex() ///To generate an index, use genIndex()
virtual void setIndex(const int& index){cc_item_index = index;}; 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 #endif

View File

@@ -3,7 +3,7 @@
Copyright (C) 2001 by Steffen Hehn 'McClean' Copyright (C) 2001 by Steffen Hehn 'McClean'
Classes for generic GUI-related components. 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' Copyright (C) 2012, Michael Liebmann 'micha-bbg'
License: GPL License: GPL
@@ -31,6 +31,7 @@
#include <global.h> #include <global.h>
#include <neutrino.h> #include <neutrino.h>
#include "cc_base.h" #include "cc_base.h"
#include <driver/screen_max.h>
using namespace std; using namespace std;
@@ -163,3 +164,21 @@ bool CComponentsItem::isAdded()
return false; 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);
}