From 68835056c38a74b33c04e647ccbe21bb7bf5ae7a Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Fri, 21 Apr 2017 22:47:23 +0200 Subject: [PATCH] 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. --- src/gui/channellist.cpp | 38 ++++++----------- src/gui/components/cc_frm_header.cpp | 61 +++++++++++++++++++++++++++- src/gui/components/cc_frm_header.h | 52 ++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 27 deletions(-) diff --git a/src/gui/channellist.cpp b/src/gui/channellist.cpp index 8499c38c5..65213ea5d 100644 --- a/src/gui/channellist.cpp +++ b/src/gui/channellist.cpp @@ -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()) return; if(g_settings.channellist_show_channellogo){ - int logo_w_max = full_width / 4; - int logo_h_max = theight - 2*OFFSET_INNER_MIN; - if (CChannelLogo) { - if (headerNew) - CChannelLogo->clearSavedScreen(); - 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; + header->setChannelLogo((*chanlist)[selected]->getChannelID(), (*chanlist)[selected]->getName()); + header->getLogoObject()->hide(); + header->getLogoObject()->clearSavedScreen(); + header->getLogoObject()->allowPaint(true); + header->getLogoObject()->paint(); } } @@ -2172,7 +2153,14 @@ void CChannelList::paintHead() else 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); + showChannelLogo(); } CComponentsHeader* CChannelList::getHeaderObject() diff --git a/src/gui/components/cc_frm_header.cpp b/src/gui/components/cc_frm_header.cpp index f8a1038cd..f053e94ec 100644 --- a/src/gui/components/cc_frm_header.cpp +++ b/src/gui/components/cc_frm_header.cpp @@ -31,6 +31,9 @@ #include "cc_frm_header.h" #include #include +#include + +extern CPictureViewer * g_PicViewer; 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; clear(); cc_txt_save_screen = false; - x = x_old = x_pos; - y = y_old = y_pos; + x = cc_xr = x_old = x_pos; + y = cc_yr = y_old = y_pos; //init header width 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_btn_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_caption_align = CTextBox::NO_AUTO_LINEBREAK; 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) { v_cch_btn.push_back(button_name); @@ -505,6 +556,9 @@ void CComponentsHeader::initCaption() if (cch_caption_align == CTextBox::CENTER) 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 cch_text_obj->setDimensionsAll(cch_text_x, cch_items_y, cc_text_w, height); cch_text_obj->setColorBody(col_body); @@ -548,6 +602,9 @@ void CComponentsHeader::initCCItems() //init text initCaption(); + + //init logo + initLogo(); } void CComponentsHeader::paint(bool do_save_bg) diff --git a/src/gui/components/cc_frm_header.h b/src/gui/components/cc_frm_header.h index eb4a6d607..17e9f5dba 100644 --- a/src/gui/components/cc_frm_header.h +++ b/src/gui/components/cc_frm_header.h @@ -36,9 +36,29 @@ /*! 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 { + public: + ///logo position options + typedef enum + { + CC_LOGO_RIGHT , + CC_LOGO_LEFT , + CC_LOGO_CENTER + }cc_logo_alignment_t; + 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 void initVarHeader( const int& x_pos, const int& y_pos, const int& w, const int& h, const std::string& caption, @@ -59,6 +79,11 @@ class CComponentsHeader : public CComponentsForm, public CCTextScreen CComponentsIconForm * cch_btn_obj; ///object: clock object 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() std::string cch_text; @@ -112,6 +137,9 @@ class CComponentsHeader : public CComponentsForm, public CCTextScreen void initButtons(); ///sub: init clock object void initClock(); + ///sub: init logo object + void initLogo(); + ///int repaint slot void initRepaintSlot(); @@ -275,6 +303,30 @@ class CComponentsHeader : public CComponentsForm, public CCTextScreen ///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); + + /**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.