CComponentsHeader: add possibility to show channellogo

Contains methode setChannelLogo() with parameters
for channel id, channel name and optional
alignment (primary between title and clock). Default
alignment is centered.
Optional parameter to set logo height is available too.

Hope it works on first try. To see how it works, take look
at channellist class.
This commit is contained in:
2017-04-21 22:47:23 +02:00
parent a3bf23d9c9
commit 68835056c3
3 changed files with 124 additions and 27 deletions

View File

@@ -1676,35 +1676,16 @@ void CChannelList::paintAdditionals(int index)
} }
} }
void CChannelList::showChannelLogo() //TODO: move into an own handler, eg. header, channel logo should be paint inside header object void CChannelList::showChannelLogo()
{ {
if ((*chanlist).empty()) if ((*chanlist).empty())
return; return;
if(g_settings.channellist_show_channellogo){ if(g_settings.channellist_show_channellogo){
int logo_w_max = full_width / 4; header->setChannelLogo((*chanlist)[selected]->getChannelID(), (*chanlist)[selected]->getName());
int logo_h_max = theight - 2*OFFSET_INNER_MIN; header->getLogoObject()->hide();
if (CChannelLogo) { header->getLogoObject()->clearSavedScreen();
if (headerNew) header->getLogoObject()->allowPaint(true);
CChannelLogo->clearSavedScreen(); header->getLogoObject()->paint();
else
CChannelLogo->hide();
delete CChannelLogo;
}
CChannelLogo = new CComponentsChannelLogoScalable(0, 0, (*chanlist)[selected]->getName(), (*chanlist)[selected]->getChannelID());
if (CChannelLogo->hasLogo()){
CChannelLogo->setWidth(min(CChannelLogo->getWidth(), logo_w_max), true);
if (CChannelLogo->getHeight() > logo_h_max)
CChannelLogo->setHeight(logo_h_max, true);
CChannelLogo->setXPos(x + full_width - logo_off - CChannelLogo->getWidth());
CChannelLogo->setYPos(y + (theight - CChannelLogo->getHeight()) / 2);
CChannelLogo->paint();
} else {
CChannelLogo->hide();
delete CChannelLogo;
CChannelLogo = NULL;
}
headerNew = false;
} }
} }
@@ -2172,7 +2153,14 @@ void CChannelList::paintHead()
else else
logo_off = OFFSET_INNER_MID; logo_off = OFFSET_INNER_MID;
if(g_settings.channellist_show_channellogo){
//ensure to have clean background
header->getLogoObject()->hide();
header->setChannelLogo((*chanlist)[selected]->getChannelID(), (*chanlist)[selected]->getName());
header->getLogoObject()->allowPaint(false);
}
header->paint(CC_SAVE_SCREEN_NO); header->paint(CC_SAVE_SCREEN_NO);
showChannelLogo();
} }
CComponentsHeader* CChannelList::getHeaderObject() CComponentsHeader* CChannelList::getHeaderObject()

View File

@@ -31,6 +31,9 @@
#include "cc_frm_header.h" #include "cc_frm_header.h"
#include <system/debug.h> #include <system/debug.h>
#include <driver/fontrenderer.h> #include <driver/fontrenderer.h>
#include <driver/pictureviewer/pictureviewer.h>
extern CPictureViewer * g_PicViewer;
using namespace std; using namespace std;
@@ -91,8 +94,8 @@ void CComponentsHeader::initVarHeader( const int& x_pos, const int& y_pos, const
cc_item_type = CC_ITEMTYPE_FRM_HEADER; cc_item_type = CC_ITEMTYPE_FRM_HEADER;
clear(); clear();
cc_txt_save_screen = false; cc_txt_save_screen = false;
x = x_old = x_pos; x = cc_xr = x_old = x_pos;
y = y_old = y_pos; y = cc_yr = y_old = y_pos;
//init header width //init header width
width = width_old = w == 0 ? frameBuffer->getScreenWidth(true) : w; width = width_old = w == 0 ? frameBuffer->getScreenWidth(true) : w;
@@ -121,6 +124,11 @@ void CComponentsHeader::initVarHeader( const int& x_pos, const int& y_pos, const
cch_text_obj = NULL; cch_text_obj = NULL;
cch_btn_obj = NULL; cch_btn_obj = NULL;
cch_cl_obj = NULL; cch_cl_obj = NULL;
cch_logo_obj = NULL;
cch_logo.Id = 0;
cch_logo.Name = "";
cch_logo.dy_max = -1;
cch_logo.Align = CC_LOGO_RIGHT;
cch_col_text = COL_MENUHEAD_TEXT; cch_col_text = COL_MENUHEAD_TEXT;
cch_caption_align = CTextBox::NO_AUTO_LINEBREAK; cch_caption_align = CTextBox::NO_AUTO_LINEBREAK;
cch_items_y = CC_CENTERED; cch_items_y = CC_CENTERED;
@@ -264,6 +272,49 @@ void CComponentsHeader::initIcon()
} }
} }
void CComponentsHeader::initLogo()
{
cch_logo.dy_max = cch_logo.dy_max == -1 ? height - 2*OFFSET_INNER_SMALL : cch_logo.dy_max;
if(!cch_logo_obj)
cch_logo_obj = new CComponentsChannelLogoScalable(width/2, height/2 - cch_logo.dy_max/2, cch_logo.Name, cch_logo.Id, this);
else
cch_logo_obj->setChannel(cch_logo.Id, cch_logo.Name);
if (cch_logo_obj->hasLogo()){
cch_logo_obj->setHeight(cch_logo.dy_max, true);
// set id of logo item depends of neighbor items
int logo_id = getCCItemId(cch_logo_obj);
int next_id = logo_id + 1;
int prev_id = logo_id - 1;
//right end
int x_logo_right = getCCItem(next_id) ? getCCItem(next_id)->getXPos() - cch_logo_obj->getWidth() : width - cch_logo_obj->getWidth()-OFFSET_INNER_MID;
//left end
int x_logo_left = getCCItem(prev_id) ? getCCItem(prev_id)->getXPos() + getCCItem(prev_id)->getWidth() : 0;
//calculate available space
int logo_space = x_logo_right + cch_logo_obj->getWidth() - x_logo_left;
//reduce logo width if logo space too small
int w_logo = min(cch_logo_obj->getWidth(), logo_space);
cch_logo_obj->setWidth(w_logo, true);
//set final logo position
int x_logo = 0;
if (cch_logo.Align == CC_LOGO_RIGHT)
x_logo = x_logo_right;
if (cch_logo.Align == CC_LOGO_LEFT)
x_logo = x_logo_left;
if (cch_logo.Align == CC_LOGO_CENTER)
x_logo = x_logo_left + logo_space/2 - cch_logo_obj->getWidth()/2;
cch_logo_obj->setXPos(x_logo);
cch_logo_obj->setYPos(height/2 - cch_logo_obj->getHeight()/2);
}
}
void CComponentsHeader::addContextButton(const std::string& button_name) void CComponentsHeader::addContextButton(const std::string& button_name)
{ {
v_cch_btn.push_back(button_name); v_cch_btn.push_back(button_name);
@@ -505,6 +556,9 @@ void CComponentsHeader::initCaption()
if (cch_caption_align == CTextBox::CENTER) if (cch_caption_align == CTextBox::CENTER)
cch_text_x = CC_CENTERED; cch_text_x = CC_CENTERED;
//recalc caption width
cc_text_w = min(cc_text_w, cch_font->getRenderWidth(cch_text)+ OFFSET_INNER_MID);
//assign general properties //assign general properties
cch_text_obj->setDimensionsAll(cch_text_x, cch_items_y, cc_text_w, height); cch_text_obj->setDimensionsAll(cch_text_x, cch_items_y, cc_text_w, height);
cch_text_obj->setColorBody(col_body); cch_text_obj->setColorBody(col_body);
@@ -548,6 +602,9 @@ void CComponentsHeader::initCCItems()
//init text //init text
initCaption(); initCaption();
//init logo
initLogo();
} }
void CComponentsHeader::paint(bool do_save_bg) void CComponentsHeader::paint(bool do_save_bg)

View File

@@ -36,9 +36,29 @@
/*! /*!
CComponentsHeader provides prepared items like icon, caption and context button icons, mostly for usage in menues or simple windows CComponentsHeader provides prepared items like icon, caption and context button icons, mostly for usage in menues or simple windows
*/ */
class CComponentsHeader : public CComponentsForm, public CCTextScreen class CComponentsHeader : public CComponentsForm, public CCTextScreen
{ {
public:
///logo position options
typedef enum
{
CC_LOGO_RIGHT ,
CC_LOGO_LEFT ,
CC_LOGO_CENTER
}cc_logo_alignment_t;
private: private:
///required logo data type
typedef struct cch_logo_t
{
uint64_t Id;
std::string Name;
int32_t dx_max;
int32_t dy_max;
cc_logo_alignment_t Align;
} cch_logo_struct_t;
///member: init genaral variables, parameters for mostly used properties ///member: init genaral variables, parameters for mostly used properties
void initVarHeader( const int& x_pos, const int& y_pos, const int& w, const int& h, void initVarHeader( const int& x_pos, const int& y_pos, const int& w, const int& h,
const std::string& caption, const std::string& caption,
@@ -59,6 +79,11 @@ class CComponentsHeader : public CComponentsForm, public CCTextScreen
CComponentsIconForm * cch_btn_obj; CComponentsIconForm * cch_btn_obj;
///object: clock object ///object: clock object
CComponentsFrmClock * cch_cl_obj; CComponentsFrmClock * cch_cl_obj;
///object: logo object
CComponentsChannelLogoScalable * cch_logo_obj;
///attributes for logos
cch_logo_t cch_logo;
///property: caption text, see also setCaption() ///property: caption text, see also setCaption()
std::string cch_text; std::string cch_text;
@@ -112,6 +137,9 @@ class CComponentsHeader : public CComponentsForm, public CCTextScreen
void initButtons(); void initButtons();
///sub: init clock object ///sub: init clock object
void initClock(); void initClock();
///sub: init logo object
void initLogo();
///int repaint slot ///int repaint slot
void initRepaintSlot(); void initRepaintSlot();
@@ -275,6 +303,30 @@ class CComponentsHeader : public CComponentsForm, public CCTextScreen
///set color gradient on/off, returns true if gradient mode was changed ///set color gradient on/off, returns true if gradient mode was changed
virtual bool enableColBodyGradient(const int& enable_mode, const fb_pixel_t& sec_color = 255 /*=COL_BACKGROUND*/, const int& direction = -1); virtual bool enableColBodyGradient(const int& enable_mode, const fb_pixel_t& sec_color = 255 /*=COL_BACKGROUND*/, const int& direction = -1);
/**Methode to set channel logo into header body via id and/or channel name
* @param[in] channelId
* @li required channel id as uint64_t
* @param[in] channelIName
* @li required channel name as std::string
* @param[in] alignment
* @li optional alingment parameter as cc_logo_alignment_t (enum)\n
* Possible values are:\n
* CC_LOGO_RIGHT \n
* CC_LOGO_CENTER (default)\n
* CC_LOGO_RIGHT \n
* @param[in] dy
* @li optional logo height, default = -1 (auto)
*/
void setChannelLogo( const uint64_t& channelId,
const std::string& channelName,
cc_logo_alignment_t alignment = CC_LOGO_CENTER,
const int& dy = -1)
{cch_logo.Id = channelId; cch_logo.Name = channelName, cch_logo.Align = alignment, cch_logo.dy_max = dy; initCCItems();}
/**Methode to get channel logo object for direct access to its properties and methodes
* @return CComponentsChannelLogoScalable*
*/
CComponentsChannelLogoScalable* getLogoObject(){return cch_logo_obj;}
}; };
//! Sub class of CComponentsHeader. //! Sub class of CComponentsHeader.