listframe: add posibility to use cc items inside listframe rows

This commit is contained in:
2019-05-05 14:14:34 +02:00
parent 5fa79b2232
commit 2792c33269
2 changed files with 88 additions and 20 deletions

View File

@@ -57,6 +57,7 @@
#include <gui/components/cc.h> #include <gui/components/cc.h>
#include <gui/widget/icons.h> #include <gui/widget/icons.h>
#include <driver/fontrenderer.h> #include <driver/fontrenderer.h>
#include <driver/neutrinofonts.h>
#define MAX_WINDOW_WIDTH (frameBuffer ? frameBuffer->getScreenWidth() - 40:0) #define MAX_WINDOW_WIDTH (frameBuffer ? frameBuffer->getScreenWidth() - 40:0)
#define MAX_WINDOW_HEIGHT (frameBuffer ? frameBuffer->getScreenHeight() - 40:0) #define MAX_WINDOW_HEIGHT (frameBuffer ? frameBuffer->getScreenHeight() - 40:0)
@@ -78,7 +79,7 @@
// Construction/Destruction // Construction/Destruction
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
CListFrame::CListFrame( LF_LINES* lines, Font* font_text, const int pmode, CListFrame::CListFrame( lf_line_types_t* lines, Font* font_text, const int pmode,
const CBox* position, const char* textTitle, Font* font_title) const CBox* position, const char* textTitle, Font* font_title)
{ {
//TRACE("[CListFrame] new\r\n"); //TRACE("[CListFrame] new\r\n");
@@ -127,7 +128,7 @@ CListFrame::CListFrame( LF_LINES* lines, Font* font_text, const int pmode,
onNewLineArray(); onNewLineArray();
} }
CListFrame::CListFrame( LF_LINES* lines) CListFrame::CListFrame( lf_line_types_t* lines)
{ {
//TRACE("[CListFrame] new\r\n"); //TRACE("[CListFrame] new\r\n");
initVar(); initVar();
@@ -158,8 +159,13 @@ CListFrame::CListFrame()
CListFrame::~CListFrame() CListFrame::~CListFrame()
{ {
if (m_pLines){
for(int row = 0; row < m_pLines->rows; row++)
cleanupRow(m_pLines, row);
}
//TRACE("[CListFrame] del\r\n"); //TRACE("[CListFrame] del\r\n");
hide(); hide(); //TODO: remove hide here
} }
void CListFrame::initVar(void) void CListFrame::initVar(void)
@@ -177,7 +183,7 @@ void CListFrame::initVar(void)
m_nFontHeaderListHeight = m_pcFontHeaderList->getHeight(); m_nFontHeaderListHeight = m_pcFontHeaderList->getHeight();
m_pcFontTitle = FONT_TITLE; m_pcFontTitle = FONT_TITLE;
m_textTitle = "MovieBrowser"; m_textTitle = "ListFrame";
m_nFontTitleHeight = m_pcFontTitle->getHeight(); m_nFontTitleHeight = m_pcFontTitle->getHeight();
m_nNrOfPages = 1; m_nNrOfPages = 1;
@@ -298,7 +304,7 @@ void CListFrame::onNewLineArray(void)
int maxTextWidth = 0; int maxTextWidth = 0;
maxTextWidth = 300; // TODO maxTextWidth = 300; // TODO
m_nNrOfLines = m_pLines->lineArray[0].size(); m_nNrOfLines = m_pLines->lineArray[0].v_text.size();
if(m_nNrOfLines > 0 ) if(m_nNrOfLines > 0 )
{ {
/* check if we have to recalculate the window frame size, due to auto width and auto height */ /* check if we have to recalculate the window frame size, due to auto width and auto height */
@@ -460,13 +466,62 @@ void CListFrame::refreshLine(int line)
m_cFrameListRel.iWidth - x + m_cFrameListRel.iX - OFFSET_INNER_MID); m_cFrameListRel.iWidth - x + m_cFrameListRel.iX - OFFSET_INNER_MID);
if (row > 0) if (row > 0)
xDiff = 0; xDiff = 0;
m_pcFontList->RenderString(x+m_cFrame.iX+xDiff, y+m_cFrame.iY,
width-xDiff, m_pLines->lineArray[row][line].c_str(), if (!m_pLines->lineArray[row].v_text[line].empty())
color); paintRowText(m_pLines->lineArray[row].v_text[line], m_pcFontList, x+m_cFrame.iX+xDiff, y+m_cFrame.iY, width-xDiff, m_nFontListHeight, color);
if (m_pLines->lineArray[row].v_ccItem[line] != NULL)
{
CComponentsItem *item = (m_pLines->lineArray[row].v_ccItem[line]);
int h_item = item->getHeight();
item->setDimensionsAll(x+m_cFrame.iX+xDiff, y+m_cFrame.iY - m_nFontListHeight/2 - h_item/2, width-xDiff, h_item);
item->setColorBody(bgcolor);
item->setCorner(0);
item->forceRePaint();
item->paint(false);
}
x += width + OFFSET_INNER_SMALL; x += width + OFFSET_INNER_SMALL;
} }
} }
void CListFrame::paintRowText(const std::string& text, Font* font, const int& x_pos, const int& y_pos, const int& dx, const int& dy, const fb_pixel_t& col)
{
Font *tmp_font = font;
int y_tmp = y_pos;
if (dx < tmp_font->getRenderWidth(text))
{
int w_row = dx-OFFSET_INNER_MID;
int h_row = dy-OFFSET_INNER_MIN;
tmp_font = *CNeutrinoFonts::getInstance()->getDynFont(w_row, h_row, text);
y_tmp -= (font->getHeight() - tmp_font->getHeight()) >>1 ;
}
tmp_font->RenderString(x_pos, y_tmp, dx, text.c_str(), col);
}
void CListFrame::addLine2Row(lf_line_types_t* lines, const int& row_num, const std::string& text, CComponentsItem* cc_Item)
{
lines->lineArray[row_num].v_text.push_back(text);
lines->lineArray[row_num].v_ccItem.push_back(cc_Item);
}
void CListFrame::cleanupRow(lf_line_types_t* lines, const int& row_num)
{
lines->lineArray[row_num].v_text.clear();
for(size_t i = 0; i < lines->lineArray[row_num].v_ccItem.size(); i++)
{
if(lines->lineArray[row_num].v_ccItem[i])
{
//TRACE("[CListFrame]->cleanupRow: item = %p getItemName() = %s getItemType() = %d\r\n", lines->lineArray[row_num].v_ccItem[i], lines->lineArray[row_num].v_ccItem[i]->getItemName().c_str(), lines->lineArray[row_num].v_ccItem[i]->getItemType());
delete lines->lineArray[row_num].v_ccItem[i];
lines->lineArray[row_num].v_ccItem[i] = NULL;
}
}
lines->lineArray[row_num].v_ccItem.clear();
}
void CListFrame::refreshHeaderList(void) void CListFrame::refreshHeaderList(void)
{ {
//TRACE("[CListFrame]->refreshHeaderList \r\n"); //TRACE("[CListFrame]->refreshHeaderList \r\n");
@@ -491,9 +546,9 @@ void CListFrame::refreshHeaderList(void)
//TRACE(" normalize width to %d , x:%d \r\n",width,x); //TRACE(" normalize width to %d , x:%d \r\n",width,x);
loop = false; loop = false;
} }
m_pcFontHeaderList->RenderString(x+m_cFrame.iX, y+m_cFrame.iY,
width, m_pLines->lineHeader[row].c_str(), paintRowText(m_pLines->lineHeader[row], m_pcFontHeaderList, x+m_cFrame.iX, y+m_cFrame.iY, width, m_nFontHeaderListHeight, HEADER_LIST_FONT_COLOR);
HEADER_LIST_FONT_COLOR);
x += width + OFFSET_INNER_SMALL; x += width + OFFSET_INNER_SMALL;
} }
} }
@@ -561,7 +616,7 @@ void CListFrame::refresh(void)
refreshList(); refreshList();
} }
bool CListFrame::setLines(LF_LINES* lines) bool CListFrame::setLines(lf_line_types_t* lines)
{ {
if(lines == NULL) if(lines == NULL)
return(false); return(false);

View File

@@ -55,17 +55,27 @@
#include <vector> #include <vector>
#include <gui/widget/textbox.h> #include <gui/widget/textbox.h>
#include <driver/fb_window.h> #include <driver/fb_window.h>
#include <gui/components/cc.h>
#define LF_MAX_ROWS 9 #define LF_MAX_ROWS 10
typedef struct
typedef struct lf_row_types_t
{
std::vector<std::string> v_text;
std::vector<CComponentsItem*> v_ccItem;
}lf_row_types_struct;
typedef struct lf_line_types_t
{ {
int rows; int rows;
std::string lineHeader[LF_MAX_ROWS]; std::string lineHeader[LF_MAX_ROWS];
std::vector<std::string> lineArray[LF_MAX_ROWS]; lf_row_types_t lineArray[LF_MAX_ROWS];
int rowWidth[LF_MAX_ROWS]; int rowWidth[LF_MAX_ROWS];
std::vector<std::string> Icon; std::vector<std::string> Icon;
std::vector<bool> marked; std::vector<bool> marked;
}LF_LINES;
}lf_line_types_struct;
class CListFrame class CListFrame
{ {
@@ -81,9 +91,10 @@ class CListFrame
void reSizeMainFrameWidth(int maxTextWidth); void reSizeMainFrameWidth(int maxTextWidth);
void reSizeMainFrameHeight(int maxTextHeight); void reSizeMainFrameHeight(int maxTextHeight);
int paintListIcon(int x, int y, int line); int paintListIcon(int x, int y, int line);
void paintRowText(const std::string& text, Font* font, const int& x_pos, const int& y_pos, const int& dx, const int& dy, const fb_pixel_t& col);
/* Variables */ /* Variables */
LF_LINES* m_pLines; lf_line_types_t* m_pLines;
CBox m_cFrame; CBox m_cFrame;
CBox m_cFrameTitleRel; CBox m_cFrameTitleRel;
@@ -122,8 +133,8 @@ class CListFrame
public: public:
/* Constructor */ /* Constructor */
CListFrame(); CListFrame();
CListFrame( LF_LINES* lines); CListFrame( lf_line_types_t* lines);
CListFrame( LF_LINES* lines, CListFrame( lf_line_types_t* lines,
Font* font_text, Font* font_text,
const int mode, const int mode,
const CBox* position, const CBox* position,
@@ -139,7 +150,9 @@ class CListFrame
void scrollPageUp(const int pages); void scrollPageUp(const int pages);
void scrollLineDown(const int lines); void scrollLineDown(const int lines);
void scrollLineUp(const int lines); void scrollLineUp(const int lines);
bool setLines(LF_LINES* lines); bool setLines(lf_line_types_t* lines);
static void addLine2Row(lf_line_types_t* lines, const int& row_num, const std::string& text, CComponentsItem* cc_Item = NULL);
static void cleanupRow(lf_line_types_t* lines, const int& row_num);
bool setTitle(char* title); bool setTitle(char* title);
bool setSelectedLine(int selection); bool setSelectedLine(int selection);
void setSelectedMarked(bool enable); void setSelectedMarked(bool enable);