mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 16:31:11 +02:00
* CComponents: Adjustments for CComponentsItemBox and CComponentsTitleBar
This commit is contained in:
@@ -97,10 +97,10 @@ enum
|
||||
|
||||
enum
|
||||
{
|
||||
CC_TITLEBAR_ICON,
|
||||
CC_TITLEBAR_PICTURE,
|
||||
CC_TITLEBAR_TEXT,
|
||||
CC_TITLEBAR_CLOCK
|
||||
CC_ITEMBOX_ICON,
|
||||
CC_ITEMBOX_PICTURE,
|
||||
CC_ITEMBOX_TEXT,
|
||||
CC_ITEMBOX_CLOCK
|
||||
};
|
||||
|
||||
typedef struct comp_element_data_t
|
||||
@@ -320,6 +320,7 @@ class CComponentsDetailLine : public CComponents
|
||||
void setHMarkDown(const int& h_mark_down_){h_mark_down = h_mark_down_;};
|
||||
};
|
||||
|
||||
#define FIRST_ELEMENT_INIT 10000
|
||||
class CComponentsItemBox : public CComponentsContainer
|
||||
{
|
||||
protected:
|
||||
@@ -328,13 +329,22 @@ class CComponentsItemBox : public CComponentsContainer
|
||||
int vOffset;
|
||||
int digit_offset, digit_h;
|
||||
bool paintElements;
|
||||
bool onlyOneTextElement;
|
||||
fb_pixel_t col_text;
|
||||
Font* font_text;
|
||||
int hMax;
|
||||
bool has_TextElement;
|
||||
size_t firstElementLeft;
|
||||
size_t firstElementRight;
|
||||
size_t prevElementLeft;
|
||||
size_t prevElementRight;
|
||||
std::vector<comp_element_data_t> v_element_data;
|
||||
|
||||
void clearElements();
|
||||
void paintPic(CComponentsPicture* pic);
|
||||
void initVarItemBox();
|
||||
void calculateElementsInitPart1();
|
||||
void calculateElementsInitPart2();
|
||||
|
||||
public:
|
||||
CComponentsItemBox();
|
||||
@@ -345,9 +355,8 @@ class CComponentsItemBox : public CComponentsContainer
|
||||
|
||||
void paint(bool do_save_bg = CC_SAVE_SCREEN_YES);
|
||||
|
||||
virtual size_t addElement(int align, int type, const std::string& element="");
|
||||
virtual size_t addLogoOrText(int align, const std::string& logo, const std::string& text);
|
||||
virtual void calculateElements();
|
||||
virtual bool addElement(int align, int type, const std::string& element="", size_t *index=NULL);
|
||||
virtual bool addLogoOrText(int align, const std::string& logo, const std::string& text, size_t *index=NULL);
|
||||
virtual void clearTitlebar();
|
||||
|
||||
};
|
||||
@@ -357,6 +366,7 @@ class CComponentsTitleBar : public CComponentsItemBox
|
||||
public:
|
||||
CComponentsTitleBar( const int x_pos, const int y_pos, const int w, const int h,
|
||||
fb_pixel_t color_text = COL_MENUHEAD, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0);
|
||||
void calculateElements();
|
||||
|
||||
};
|
||||
|
||||
|
@@ -832,6 +832,13 @@ void CComponentsItemBox::initVarItemBox()
|
||||
digit_offset = 0;
|
||||
font_text = NULL;
|
||||
paintElements = true;
|
||||
hMax = 0;
|
||||
has_TextElement = false;
|
||||
firstElementLeft = FIRST_ELEMENT_INIT;
|
||||
firstElementRight = FIRST_ELEMENT_INIT;
|
||||
prevElementLeft = 0;
|
||||
prevElementRight = 0;
|
||||
onlyOneTextElement = false;
|
||||
v_element_data.clear();
|
||||
}
|
||||
|
||||
@@ -839,12 +846,12 @@ void CComponentsItemBox::clearElements()
|
||||
{
|
||||
for(size_t i = 0; i < v_element_data.size(); i++) {
|
||||
switch (v_element_data[i].type) {
|
||||
case CC_TITLEBAR_ICON:
|
||||
case CC_TITLEBAR_PICTURE:
|
||||
case CC_ITEMBOX_ICON:
|
||||
case CC_ITEMBOX_PICTURE:
|
||||
if (v_element_data[i].handler1 != NULL)
|
||||
delete static_cast<CComponentsPicture*>(v_element_data[i].handler1);
|
||||
break;
|
||||
case CC_TITLEBAR_TEXT:
|
||||
case CC_ITEMBOX_TEXT:
|
||||
if (v_element_data[i].handler1 != NULL)
|
||||
delete static_cast<CBox*>(v_element_data[i].handler1);
|
||||
if (v_element_data[i].handler2 != NULL)
|
||||
@@ -857,9 +864,10 @@ void CComponentsItemBox::clearElements()
|
||||
v_element_data.clear();
|
||||
}
|
||||
|
||||
size_t CComponentsItemBox::addLogoOrText(int align, const std::string& logo, const std::string& text)
|
||||
bool CComponentsItemBox::addLogoOrText(int align, const std::string& logo, const std::string& text, size_t *index)
|
||||
{
|
||||
comp_element_data_t data;
|
||||
int dx=0, dy=0;
|
||||
|
||||
data.align = align;
|
||||
data.x = x;
|
||||
@@ -869,26 +877,56 @@ size_t CComponentsItemBox::addLogoOrText(int align, const std::string& logo, con
|
||||
data.handler1 = NULL;
|
||||
data.handler2 = NULL;
|
||||
|
||||
if (access(logo.c_str(), R_OK) == 0) {
|
||||
g_PicViewer->getSize(logo.c_str(), &dx, &dy);
|
||||
if ((dx != 0) && (dy != 0)) {
|
||||
// logo OK
|
||||
g_PicViewer->getSize(logo.c_str(), &data.width, &data.height);
|
||||
data.type = CC_TITLEBAR_PICTURE;
|
||||
data.type = CC_ITEMBOX_PICTURE;
|
||||
data.element = logo;
|
||||
}
|
||||
else {
|
||||
// no logo
|
||||
if ((text == "") || ((onlyOneTextElement) && (has_TextElement)))
|
||||
return false;
|
||||
else
|
||||
has_TextElement = true;
|
||||
if (font_text != NULL)
|
||||
data.height = font_text->getHeight();
|
||||
data.type = CC_TITLEBAR_TEXT;
|
||||
data.type = CC_ITEMBOX_TEXT;
|
||||
data.element = text;
|
||||
}
|
||||
|
||||
v_element_data.push_back(data);
|
||||
return v_element_data.size()-1;
|
||||
if (index != NULL)
|
||||
*index = v_element_data.size()-1;
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t CComponentsItemBox::addElement(int align, int type, const std::string& element)
|
||||
bool CComponentsItemBox::addElement(int align, int type, const std::string& element, size_t *index)
|
||||
{
|
||||
comp_element_data_t data;
|
||||
int dx=0, dy=0;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case CC_ITEMBOX_ICON:
|
||||
frameBuffer->getIconSize(element.c_str(), &dx, &dy);
|
||||
if ((dx == 0) || (dy == 0))
|
||||
return false;
|
||||
break;
|
||||
case CC_ITEMBOX_PICTURE:
|
||||
g_PicViewer->getSize(element.c_str(), &dx, &dy);
|
||||
if ((dx == 0) || (dy == 0))
|
||||
return false;
|
||||
break;
|
||||
case CC_ITEMBOX_TEXT:
|
||||
if ((element == "") || ((onlyOneTextElement) && (has_TextElement)))
|
||||
return false;
|
||||
else
|
||||
has_TextElement = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
data.type = type;
|
||||
data.align = align;
|
||||
@@ -900,19 +938,31 @@ size_t CComponentsItemBox::addElement(int align, int type, const std::string& el
|
||||
data.handler1 = NULL;
|
||||
data.handler2 = NULL;
|
||||
|
||||
switch (type)
|
||||
v_element_data.push_back(data);
|
||||
if (index != NULL)
|
||||
*index = v_element_data.size()-1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CComponentsItemBox::calculateElementsInitPart1()
|
||||
{
|
||||
case CC_TITLEBAR_ICON:
|
||||
frameBuffer->getIconSize(element.c_str(), &data.width, &data.height);
|
||||
size_t i;
|
||||
|
||||
// Set element size
|
||||
for (i = 0; i < v_element_data.size(); i++) {
|
||||
switch (v_element_data[i].type)
|
||||
{
|
||||
case CC_ITEMBOX_ICON:
|
||||
frameBuffer->getIconSize(v_element_data[i].element.c_str(), &v_element_data[i].width, &v_element_data[i].height);
|
||||
break;
|
||||
case CC_TITLEBAR_PICTURE:
|
||||
g_PicViewer->getSize(element.c_str(), &data.width, &data.height);
|
||||
case CC_ITEMBOX_PICTURE:
|
||||
g_PicViewer->getSize(v_element_data[i].element.c_str(), &v_element_data[i].width, &v_element_data[i].height);
|
||||
break;
|
||||
case CC_TITLEBAR_TEXT:
|
||||
case CC_ITEMBOX_TEXT:
|
||||
if (font_text != NULL)
|
||||
data.height = font_text->getHeight();
|
||||
v_element_data[i].height = font_text->getHeight();
|
||||
break;
|
||||
case CC_TITLEBAR_CLOCK: {
|
||||
case CC_ITEMBOX_CLOCK: {
|
||||
if (!g_Sectionsd->getIsTimeSet())
|
||||
break;
|
||||
if (font_text != NULL) {
|
||||
@@ -923,57 +973,46 @@ size_t CComponentsItemBox::addElement(int align, int type, const std::string& el
|
||||
|
||||
digit_h = font_text->getDigitHeight();
|
||||
digit_offset = font_text->getDigitOffset();
|
||||
data.height = digit_h + (int)((float)digit_offset*1.5);
|
||||
// data.width = font_text->getRenderWidth(widest_number)*4 + font_text->getRenderWidth(":");
|
||||
data.width = font_text->getRenderWidth(timestr);
|
||||
data.element = timestr;
|
||||
v_element_data[i].height = digit_h + (int)((float)digit_offset*1.5);
|
||||
// v_element_data[i].width = font_text->getRenderWidth(widest_number)*4 + font->getRenderWidth(":");
|
||||
v_element_data[i].width = font_text->getRenderWidth(timestr);
|
||||
v_element_data[i].element = timestr;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
v_element_data.push_back(data);
|
||||
return v_element_data.size()-1;
|
||||
}
|
||||
|
||||
void CComponentsItemBox::calculateElements()
|
||||
{
|
||||
#define FIRST_ELEMENT_INIT 10000
|
||||
if (v_element_data.empty())
|
||||
return;
|
||||
|
||||
int hMax = 0;
|
||||
bool has_TextElement = false;
|
||||
size_t firstElementLeft = FIRST_ELEMENT_INIT;
|
||||
size_t firstElementRight = FIRST_ELEMENT_INIT;
|
||||
size_t prevElementLeft = 0;
|
||||
size_t prevElementRight = 0;
|
||||
size_t i;
|
||||
|
||||
// Calculate largest height without CC_TITLEBAR_PICTURE
|
||||
// Calculate largest height without CC_ITEMBOX_PICTURE
|
||||
for (i = 0; i < v_element_data.size(); i++) {
|
||||
if ((firstElementLeft == FIRST_ELEMENT_INIT) && (v_element_data[i].align == CC_ALIGN_LEFT))
|
||||
firstElementLeft = i;
|
||||
if ((firstElementRight == FIRST_ELEMENT_INIT) && (v_element_data[i].align == CC_ALIGN_RIGHT))
|
||||
firstElementRight = i;
|
||||
if (v_element_data[i].type != CC_TITLEBAR_PICTURE)
|
||||
if (v_element_data[i].type != CC_ITEMBOX_PICTURE)
|
||||
hMax = max(v_element_data[i].height, hMax);
|
||||
if (v_element_data[i].type == CC_TITLEBAR_TEXT)
|
||||
has_TextElement = true;
|
||||
}
|
||||
if (!has_TextElement)
|
||||
hMax = max(font_text->getHeight(), hMax);
|
||||
}
|
||||
|
||||
// Calculate logo
|
||||
void CComponentsItemBox::calculateElementsInitPart2()
|
||||
{
|
||||
size_t i;
|
||||
|
||||
// Calculate y-positions
|
||||
height = hMax + 2*vOffset;
|
||||
for (i = 0; i < v_element_data.size(); i++) {
|
||||
if (v_element_data[i].type == CC_TITLEBAR_PICTURE) {
|
||||
if((v_element_data[i].width > width/4) || (v_element_data[i].height > hMax))
|
||||
g_PicViewer->rescaleImageDimensions(&v_element_data[i].width, &v_element_data[i].height, width/4, hMax);
|
||||
}
|
||||
v_element_data[i].y = y + (height - v_element_data[i].height) / 2;
|
||||
if (v_element_data[i].type == CC_ITEMBOX_TEXT)
|
||||
v_element_data[i].y += v_element_data[i].height + v_element_data[i].height/14;
|
||||
if (v_element_data[i].type == CC_ITEMBOX_CLOCK)
|
||||
v_element_data[i].y += v_element_data[i].height + digit_offset/4;
|
||||
}
|
||||
|
||||
// x-positions calculate
|
||||
// Calculate x-positions
|
||||
for (i = 0; i < v_element_data.size(); i++) {
|
||||
if (firstElementLeft == i){
|
||||
prevElementLeft = i;
|
||||
@@ -996,29 +1035,6 @@ void CComponentsItemBox::calculateElements()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// text width calculate
|
||||
int allWidth = 0;
|
||||
for (i = 0; i < v_element_data.size(); i++) {
|
||||
if (v_element_data[i].type != CC_TITLEBAR_TEXT)
|
||||
allWidth += v_element_data[i].width + hSpacer;
|
||||
}
|
||||
for (i = 0; i < v_element_data.size(); i++) {
|
||||
if (v_element_data[i].type == CC_TITLEBAR_TEXT) {
|
||||
v_element_data[i].width = width - (allWidth + 2*hSpacer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// y-positions calculate
|
||||
height = hMax + 2*vOffset;
|
||||
for (i = 0; i < v_element_data.size(); i++) {
|
||||
v_element_data[i].y = y + (height - v_element_data[i].height) / 2;
|
||||
if (v_element_data[i].type == CC_TITLEBAR_TEXT)
|
||||
v_element_data[i].y += v_element_data[i].height + v_element_data[i].height/14;
|
||||
if (v_element_data[i].type == CC_TITLEBAR_CLOCK)
|
||||
v_element_data[i].y += v_element_data[i].height + digit_offset/4;
|
||||
}
|
||||
}
|
||||
|
||||
void CComponentsItemBox::paint(bool do_save_bg)
|
||||
@@ -1034,7 +1050,7 @@ void CComponentsItemBox::paint(bool do_save_bg)
|
||||
CComponentsPicture* pic = NULL;
|
||||
for (i = 0; i < v_element_data.size(); i++) {
|
||||
switch (v_element_data[i].type) {
|
||||
case CC_TITLEBAR_ICON:
|
||||
case CC_ITEMBOX_ICON:
|
||||
if (v_element_data[i].handler1 == NULL) {
|
||||
pic = new CComponentsPicture(v_element_data[i].x, v_element_data[i].y, v_element_data[i].element);
|
||||
v_element_data[i].handler1 = (void*)pic;
|
||||
@@ -1043,7 +1059,7 @@ void CComponentsItemBox::paint(bool do_save_bg)
|
||||
pic = static_cast<CComponentsPicture*>(v_element_data[i].handler1);
|
||||
paintPic(pic);
|
||||
break;
|
||||
case CC_TITLEBAR_PICTURE:
|
||||
case CC_ITEMBOX_PICTURE:
|
||||
if (v_element_data[i].handler1 == NULL) {
|
||||
pic = new CComponentsPicture( v_element_data[i].x, v_element_data[i].y, v_element_data[i].width,
|
||||
v_element_data[i].height, v_element_data[i].element);
|
||||
@@ -1053,11 +1069,11 @@ void CComponentsItemBox::paint(bool do_save_bg)
|
||||
pic = static_cast<CComponentsPicture*>(v_element_data[i].handler1);
|
||||
paintPic(pic);
|
||||
break;
|
||||
case CC_TITLEBAR_TEXT:
|
||||
case CC_ITEMBOX_TEXT:
|
||||
font_text->RenderString(v_element_data[i].x, v_element_data[i].y, v_element_data[i].width,
|
||||
v_element_data[i].element.c_str(), col_text, 0, true);
|
||||
break;
|
||||
case CC_TITLEBAR_CLOCK:
|
||||
case CC_ITEMBOX_CLOCK:
|
||||
font_text->RenderString(v_element_data[i].x, v_element_data[i].y, v_element_data[i].width,
|
||||
v_element_data[i].element.c_str(), col_text);
|
||||
break;
|
||||
@@ -1092,6 +1108,7 @@ CComponentsTitleBar::CComponentsTitleBar(const int x_pos, const int y_pos, const
|
||||
{
|
||||
//CComponentsItemBox
|
||||
initVarItemBox();
|
||||
onlyOneTextElement = true;
|
||||
|
||||
//CComponents
|
||||
x = x_pos;
|
||||
@@ -1105,6 +1122,40 @@ CComponentsTitleBar::CComponentsTitleBar(const int x_pos, const int y_pos, const
|
||||
//CComponentsTitleBar
|
||||
font_text = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE];
|
||||
col_text = color_text;
|
||||
// col_text = COL_MENUHEAD;
|
||||
}
|
||||
|
||||
|
||||
void CComponentsTitleBar::calculateElements()
|
||||
{
|
||||
#define LOGO_MAX_WIDTH width/4
|
||||
|
||||
if (v_element_data.empty())
|
||||
return;
|
||||
|
||||
size_t i;
|
||||
|
||||
calculateElementsInitPart1();
|
||||
|
||||
// Calculate logo
|
||||
for (i = 0; i < v_element_data.size(); i++) {
|
||||
if (v_element_data[i].type == CC_ITEMBOX_PICTURE) {
|
||||
if((v_element_data[i].width > LOGO_MAX_WIDTH) || (v_element_data[i].height > hMax))
|
||||
g_PicViewer->rescaleImageDimensions(&v_element_data[i].width, &v_element_data[i].height, LOGO_MAX_WIDTH, hMax);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate text width
|
||||
int allWidth = 0;
|
||||
for (i = 0; i < v_element_data.size(); i++) {
|
||||
if (v_element_data[i].type != CC_ITEMBOX_TEXT)
|
||||
allWidth += v_element_data[i].width + hSpacer;
|
||||
}
|
||||
for (i = 0; i < v_element_data.size(); i++) {
|
||||
if (v_element_data[i].type == CC_ITEMBOX_TEXT) {
|
||||
v_element_data[i].width = width - (allWidth + 2*hSpacer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
calculateElementsInitPart2();
|
||||
}
|
||||
|
Reference in New Issue
Block a user