cc_frm_icons: simplify icon handling, code format changes

Origin commit data
------------------
Commit: cecdd4d24a
Author: Thilo Graf <dbt@novatux.de>
Date: 2021-11-14 (Sun, 14 Nov 2021)
This commit is contained in:
2021-11-14 22:12:27 +01:00
committed by vanhofen
parent c1a538f2df
commit e80cf9ff56
2 changed files with 51 additions and 43 deletions

View File

@@ -1,9 +1,9 @@
/* /*
Based up Neutrino-GUI - Tuxbox-Project Based up Neutrino-GUI - Tuxbox-Project
Copyright (C) 2001 by Steffen Hehn 'McClean' Copyright (C) 2001 by Steffen Hehn 'McClean'
Classes for generic GUI-related components. Classes for generic GUI-related components.
Copyright (C) 2012-2018 Thilo Graf 'dbt' Copyright (C) 2012-2021 Thilo Graf 'dbt'
Copyright (C) 2012, Michael Liebmann 'micha-bbg' Copyright (C) 2012, Michael Liebmann 'micha-bbg'
License: GPL License: GPL
@@ -34,25 +34,35 @@
using namespace std; using namespace std;
//sub class CComponentsIconForm inherit from CComponentsForm //sub class CComponentsIconForm inherit from CComponentsForm
CComponentsIconForm::CComponentsIconForm(CComponentsForm* parent) CComponentsIconForm::CComponentsIconForm(CComponentsForm *parent)
{ {
initVarIconForm(1, 1, 0, 0, vector<string>(), parent); initVarIconForm(1, 1, 0, 0, vector<string>(), parent);
} }
CComponentsIconForm::CComponentsIconForm( const int &x_pos, const int &y_pos, const int &w, const int &h, CComponentsIconForm::CComponentsIconForm( const int &x_pos,
const int &y_pos,
const int &w,
const int &h,
const std::vector<std::string> &v_icon_names, const std::vector<std::string> &v_icon_names,
CComponentsForm* parent, CComponentsForm *parent,
int shadow_mode, int shadow_mode,
fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow) fb_pixel_t color_frame,
fb_pixel_t color_body,
fb_pixel_t color_shadow)
{ {
initVarIconForm(x_pos, y_pos, w, h, v_icon_names, parent, shadow_mode, color_frame, color_body, color_shadow); initVarIconForm(x_pos, y_pos, w, h, v_icon_names, parent, shadow_mode, color_frame, color_body, color_shadow);
} }
void CComponentsIconForm::initVarIconForm( const int &x_pos, const int &y_pos, const int &w, const int &h, void CComponentsIconForm::initVarIconForm( const int &x_pos,
const int &y_pos,
const int &w,
const int &h,
const std::vector<std::string> &v_icon_names, const std::vector<std::string> &v_icon_names,
CComponentsForm* parent, CComponentsForm *parent,
int shadow_mode, int shadow_mode,
fb_pixel_t color_frame, fb_pixel_t color_body, fb_pixel_t color_shadow) fb_pixel_t color_frame,
fb_pixel_t color_body,
fb_pixel_t color_shadow)
{ {
cc_item_type.id = CC_ITEMTYPE_FRM_ICONFORM; cc_item_type.id = CC_ITEMTYPE_FRM_ICONFORM;
cc_item_type.name = "cc_icon_container"; cc_item_type.name = "cc_icon_container";
@@ -75,34 +85,29 @@ void CComponentsIconForm::initVarIconForm( const int &x_pos, const int &y_pos, c
addIcon(v_icons); addIcon(v_icons);
} }
void CComponentsIconForm::addIcon(const std::string& icon_name) void CComponentsIconForm::addIcon(const std::string &icon_name)
{ {
if (icon_name.empty()) if (icon_name.empty())
return; return;
//create new cc-picture item object //create new cc-picture item object
CComponentsPicture *ccp = new CComponentsPicture(chn_direction == CC_DIR_X ? CC_APPEND : CC_CENTERED, CComponentsPicture *ccp = new CComponentsPicture(chn_direction == CC_DIR_X ? CC_APPEND : CC_CENTERED, chn_direction == CC_DIR_Y ? CC_APPEND : CC_CENTERED, icon_name);
chn_direction == CC_DIR_Y ? CC_APPEND : CC_CENTERED, addCCItem(ccp);
0, 0, height = max(height, ccp->getHeight());
icon_name, width = max(width, ccp->getWidth());
this);
ccp->doPaintBg(false);
int dx, dy;
ccp->getRealSize(&dx, &dy);
height = max(height, dy);
width = max(width, dx);
initChainItems(); initChainItems();
} }
void CComponentsIconForm::addIcon(std::vector<std::string> icon_name) void CComponentsIconForm::addIcon(std::vector<std::string> icon_name)
{ {
for (size_t i= 0; i< icon_name.size(); i++) for (size_t i = 0; i < icon_name.size(); i++)
addIcon(icon_name[i]); addIcon(icon_name[i]);
} }
void CComponentsIconForm::addIcons(const std::string& icon_name, const size_t& count) void CComponentsIconForm::addIcons(const std::string &icon_name, const size_t &count)
{ {
if (count == 0){ if (count == 0)
{
dprintf(DEBUG_NORMAL, "[CComponentsIconForm]\t[%s - %d], NOTE: no count of items defined...\n", __func__, __LINE__); dprintf(DEBUG_NORMAL, "[CComponentsIconForm]\t[%s - %d], NOTE: no count of items defined...\n", __func__, __LINE__);
return; return;
} }
@@ -110,20 +115,16 @@ void CComponentsIconForm::addIcons(const std::string& icon_name, const size_t& c
addIcon(icon_name); addIcon(icon_name);
} }
void CComponentsIconForm::insertIcon(const uint& icon_id, const std::string& icon_name) void CComponentsIconForm::insertIcon(const uint &icon_id, const std::string &icon_name)
{ {
//create new cc-picture item object //create new cc-picture item object
CComponentsPicture *ccp = new CComponentsPicture(chn_direction == CC_DIR_X ? CC_APPEND : CC_CENTERED, CComponentsPicture *ccp = new CComponentsPicture(chn_direction == CC_DIR_X ? CC_APPEND : CC_CENTERED, chn_direction == CC_DIR_Y ? CC_APPEND : CC_CENTERED, 0, 0, icon_name);
chn_direction == CC_DIR_Y ? CC_APPEND : CC_CENTERED,
0, 0,
icon_name);
ccp->doPaintBg(false);
insertCCItem(icon_id, ccp); insertCCItem(icon_id, ccp);
initChainItems(); initChainItems();
} }
void CComponentsIconForm::removeIcon(const uint& icon_id) void CComponentsIconForm::removeIcon(const uint &icon_id)
{ {
removeCCItem(icon_id); removeCCItem(icon_id);
initChainItems(); initChainItems();
@@ -141,9 +142,9 @@ void CComponentsIconForm::removeAllIcons()//TODO
//get maximal form height depends of biggest icon height, but don't touch defined form height //get maximal form height depends of biggest icon height, but don't touch defined form height
void CComponentsIconForm::initMaxHeight(int *pheight) void CComponentsIconForm::initMaxHeight(int *pheight)
{ {
for (size_t i= 0; i< v_icons.size(); i++){ for (size_t i = 0; i < v_cc_items.size(); i++)
int dummy, htmp; {
frameBuffer->getIconSize(v_icons[i].c_str(), &dummy, &htmp); int htmp = v_cc_items.at(i)->getHeight();
*pheight = max(htmp, height)/*+2*fr_thickness*/; *pheight = max(htmp, height)/*+2*fr_thickness*/;
} }
} }

View File

@@ -1,9 +1,9 @@
/* /*
Based up Neutrino-GUI - Tuxbox-Project Based up Neutrino-GUI - Tuxbox-Project
Copyright (C) 2001 by Steffen Hehn 'McClean' Copyright (C) 2001 by Steffen Hehn 'McClean'
Classes for generic GUI-related components. Classes for generic GUI-related components.
Copyright (C) 2012-2018, Thilo Graf 'dbt' Copyright (C) 2012-2021, Thilo Graf 'dbt'
License: GPL License: GPL
@@ -33,9 +33,12 @@ class CComponentsIconForm : public CComponentsFrmChain
protected: protected:
void initMaxHeight(int *pheight); void initMaxHeight(int *pheight);
void initVarIconForm( const int &x_pos, const int &y_pos, const int &w, const int &h, void initVarIconForm( const int &x_pos,
const int &y_pos,
const int &w,
const int &h,
const std::vector<std::string> &v_icon_names, const std::vector<std::string> &v_icon_names,
CComponentsForm* parent, CComponentsForm *parent,
int shadow_mode = CC_SHADOW_OFF, int shadow_mode = CC_SHADOW_OFF,
fb_pixel_t color_frame = COL_FRAME_PLUS_0, fb_pixel_t color_frame = COL_FRAME_PLUS_0,
fb_pixel_t color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0,
@@ -43,21 +46,25 @@ class CComponentsIconForm : public CComponentsFrmChain
public: public:
CComponentsIconForm(CComponentsForm *parent = NULL); CComponentsIconForm(CComponentsForm *parent = NULL);
CComponentsIconForm( const int &x_pos, const int &y_pos, const int &w, const int &h, CComponentsIconForm( const int &x_pos,
const int &y_pos,
const int &w,
const int &h,
const std::vector<std::string> &v_icon_names = std::vector<std::string>(), const std::vector<std::string> &v_icon_names = std::vector<std::string>(),
CComponentsForm *parent = NULL, CComponentsForm *parent = NULL,
int shadow_mode = CC_SHADOW_OFF, int shadow_mode = CC_SHADOW_OFF,
fb_pixel_t color_frame = COL_FRAME_PLUS_0, fb_pixel_t color_frame = COL_FRAME_PLUS_0,
fb_pixel_t color_body = COL_MENUHEAD_PLUS_0, fb_pixel_t color_body = COL_MENUHEAD_PLUS_0,
fb_pixel_t color_shadow = COL_SHADOW_PLUS_0); fb_pixel_t color_shadow = COL_SHADOW_PLUS_0);
virtual ~CComponentsIconForm() {}; virtual ~CComponentsIconForm() {};
void addIcon(const std::string& icon_name); void addIcon(const std::string &icon_name);
void addIcon(std::vector<std::string> icon_name); void addIcon(std::vector<std::string> icon_name);
void addIcons(const std::string& icon_name, const size_t& count = 1); void addIcons(const std::string &icon_name, const size_t &count = 1);
void removeIcons(){v_icons.clear();}; void removeIcons() {v_icons.clear();};
void insertIcon(const uint& icon_id, const std::string& icon_name); void insertIcon(const uint &icon_id, const std::string &icon_name);
void removeIcon(const uint& icon_id); void removeIcon(const uint &icon_id);
void removeAllIcons(); void removeAllIcons();
}; };