From db6071bf398095ef9e501dd1b7cabf8b52c8da3f Mon Sep 17 00:00:00 2001 From: TangoCash Date: Fri, 5 Nov 2021 11:25:19 +0100 Subject: [PATCH] add support for svg header icons Signed-off-by: Thilo Graf The CComponentsPicture class is currently being refactored. It's almost done, but various adjustments and tests are still missing, to identifying side effects on other objects. It will be strongly simplified and will support svg feature. Perhaps, an implementation of this kind in the header class is not required. --- src/gui/components/cc_frm_header.cpp | 59 +++++++++++++++++++++++++++- src/gui/components/cc_frm_header.h | 2 + 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/gui/components/cc_frm_header.cpp b/src/gui/components/cc_frm_header.cpp index 57e6fe3c4..e6b87790b 100644 --- a/src/gui/components/cc_frm_header.cpp +++ b/src/gui/components/cc_frm_header.cpp @@ -251,7 +251,12 @@ void CComponentsHeader::setIcon(const char* icon_name) void CComponentsHeader::setIcon(const std::string& icon_name) { cch_icon_name = icon_name; - initIcon(); + std::string fullpath_icon_name = frameBuffer->getIconPath(cch_icon_name); + + if (fullpath_icon_name.find(".svg") == (fullpath_icon_name.length() - 4)) + initIconSVG(); + else + initIcon(); } void CComponentsHeader::initIcon() @@ -265,6 +270,10 @@ void CComponentsHeader::initIcon() } return; } + std::string fullpath_icon_name = frameBuffer->getIconPath(cch_icon_name); + + if (fullpath_icon_name.find(".svg") == (fullpath_icon_name.length() - 4)) + return; //create instance for cch_icon_obj and add to container at once if (cch_icon_obj == NULL){ @@ -301,6 +310,51 @@ void CComponentsHeader::initIcon() } } +void CComponentsHeader::initIconSVG() +{ + //init cch_icon_obj only if an icon available + if (cch_icon_name.empty()) { + cch_icon_w = 0; + if (cch_icon_obj){ + removeCCItem(cch_icon_obj); + cch_icon_obj = NULL; + } + return; + } + + std::string fullpath_icon_name = frameBuffer->getIconPath(cch_icon_name, "svg"); + + if (!(fullpath_icon_name.find(".svg") == (fullpath_icon_name.length() - 4))) + return; + + cch_icon_name = fullpath_icon_name; + + //create instance for cch_icon_obj and add to container at once + if (cch_icon_obj == NULL){ + dprintf(DEBUG_DEBUG, "[CComponentsHeader]\n [%s - %d] init header svg icon: %s\n", __func__, __LINE__, cch_icon_name.c_str()); + cch_icon_obj = new CComponentsPicture(cch_icon_x, cch_items_y, 0, 0, cch_icon_name, this); + } + + //set properties for icon object + if (cch_icon_obj){ + cch_icon_obj->setPicture(cch_icon_name); + //get dimensions of header icon + dprintf(DEBUG_INFO, "[CComponentsHeader]\n [%s - %d] init svg icon size: height = %d\n", __func__, __LINE__, height); + cch_icon_obj->setHeight(height - OFFSET_INNER_SMALL,true); + cch_icon_obj->doPaintBg(false); + + //set corner mode of icon item + int cc_icon_corner_type = CORNER_LEFT; + if (corner_type & CORNER_TOP_LEFT || corner_type & CORNER_TOP) + cc_icon_corner_type = CORNER_TOP_LEFT; + + cch_icon_obj->setCorner(corner_rad-fr_thickness, cc_icon_corner_type); + + //global set width of icon object + cch_icon_w = cch_icon_obj->getWidth(); + } +} + void CComponentsHeader::initLogo() { // init logo with required height and logo @@ -710,6 +764,9 @@ void CComponentsHeader::initCCItems() //init logo initLogo(); + + //init svg icon + initIconSVG(); } void CComponentsHeader::paint(const bool &do_save_bg) diff --git a/src/gui/components/cc_frm_header.h b/src/gui/components/cc_frm_header.h index 678ddd4fc..f3c0b9e63 100644 --- a/src/gui/components/cc_frm_header.h +++ b/src/gui/components/cc_frm_header.h @@ -151,6 +151,8 @@ class CComponentsHeader : public CComponentsForm, public CCTextScreen, CCHeaderT void initSizeMode(); ///sub: init icon object void initIcon(); + ///sub: init svg icon object + void initIconSVG(); ///sub: init caption object void initCaption(); ///sub: init context button object