From 5c8aa90e01266d220df5400b0d9f2b668be8466f Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Tue, 24 Jan 2017 23:27:44 +0100 Subject: [PATCH] CComponentsForm: add some usefull slots/signal to help paint backgrounds Requried to paint form items only on changed contents and on repaint --- src/gui/components/cc_frm.cpp | 36 +++++++++++++++------------- src/gui/components/cc_frm.h | 5 ++++ src/gui/components/cc_frm_clock.cpp | 19 +++++++-------- src/gui/components/cc_frm_clock.h | 5 ---- src/gui/components/cc_frm_header.cpp | 15 ++++++++++-- 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/src/gui/components/cc_frm.cpp b/src/gui/components/cc_frm.cpp index d8b132529..049f6ca45 100644 --- a/src/gui/components/cc_frm.cpp +++ b/src/gui/components/cc_frm.cpp @@ -335,7 +335,7 @@ void CComponentsForm::exchangeCCItem(CComponentsItem* item_a, CComponentsItem* i void CComponentsForm::paintForm(bool do_save_bg) { //paint body - if (!is_painted) + if (!is_painted || force_paint_bg) paintInit(do_save_bg); //paint @@ -520,23 +520,7 @@ void CComponentsForm::paintCCItems() cc_item->allowPaint(item_visible); } } -#if 0 -void CComponentsForm::hide() -{ - // hack: ensure hiding of minitv during hide of forms and inherited classes, - // because the handling of minitv items are different to other item types - // and need an explizit call of hide() - for(size_t i=0; igetItemType() == CC_ITEMTYPE_PIP){ - v_cc_items[i]->kill(); - break; - } - } - //hide body - CComponents::hide(); -} -#endif //erase or paint over rendered objects void CComponentsForm::killCCItems(const fb_pixel_t& bg_color, bool ignore_parent) { @@ -693,3 +677,21 @@ bool CComponentsForm::enableColBodyGradient(const int& enable_mode, const fb_pix } return false; } + +void CComponentsForm::forceItemsPaint(bool force) +{ + dprintf(DEBUG_NORMAL, "\033[33m[CComponentsForm] [%s - %d] try to detect items [%u] with possible required background repaint \033[0m\n", __func__, __LINE__, v_cc_items.size()); + for (size_t i = 0; i < v_cc_items.size(); i++){ + dprintf(DEBUG_NORMAL, "\033[33m[CComponentsForm] [%s - %d] found item type = [%d] \033[0m\n", __func__, __LINE__, v_cc_items[i]->getItemType()); + if (v_cc_items[i]->getItemType() == CC_ITEMTYPE_TEXT){ + CComponentsText* text = static_cast (v_cc_items[i]); + text->forceTextPaint(force); + dprintf(DEBUG_NORMAL, "\033[33m[CComponentsForm] [%s - %d] force repaint of item type CC_ITEMTYPE_TEXT [%u] content [%s]\033[0m\n", __func__, __LINE__, i, text->getText().c_str()); + } + if (v_cc_items[i]->getItemType() == CC_ITEMTYPE_LABEL){ + CComponentsLabel* label = static_cast (v_cc_items[i]); + label ->forceTextPaint(force); + dprintf(DEBUG_NORMAL, "\033[33m[CComponentsForm] [%s - %d] force repaint of item type CC_ITEMTYPE_LABEL [%u] content [%s]\033[0m\n", __func__, __LINE__, i, label->getText().c_str()); + } + } +} diff --git a/src/gui/components/cc_frm.h b/src/gui/components/cc_frm.h index 44f6b481e..56ad077c6 100644 --- a/src/gui/components/cc_frm.h +++ b/src/gui/components/cc_frm.h @@ -65,6 +65,11 @@ class CComponentsForm : public CComponentsItem const fb_pixel_t& color_body, const fb_pixel_t& color_shadow); + ///force repaint of all possible text items + void forceItemsPaint(bool force); + ///slot for background paint event, reserved for forceItemsPaint() + sigc::slot0 sl_repaint; + public: CComponentsForm( const int x_pos = 0, const int y_pos = 0, const int w = 800, const int h = 600, CComponentsForm *parent = NULL, diff --git a/src/gui/components/cc_frm_clock.cpp b/src/gui/components/cc_frm_clock.cpp index ff5a7c9be..c3995318d 100644 --- a/src/gui/components/cc_frm_clock.cpp +++ b/src/gui/components/cc_frm_clock.cpp @@ -101,7 +101,7 @@ CComponentsFrmClock::CComponentsFrmClock( const int& x_pos, cl_sl_show = sigc::mem_fun0(*this, &CComponentsFrmClock::ShowTime); //init slot to ensure paint segments after painted background - cl_sl_repaint = sigc::bind<0>(sigc::mem_fun1(*this, &CComponentsFrmClock::forceSegemnentsPaint), true); + sl_repaint = sigc::bind<0>(sigc::mem_fun1(*this, &CComponentsFrmClock::forceItemsPaint), true); //run clock already if required if (activ) @@ -301,10 +301,10 @@ void CComponentsFrmClock::initCCLockItems() v_cc_items[i]->setPos(x_lbl, y_lbl); } + if(!OnAfterPaintBg.empty()) + OnAfterPaintBg.clear(); //init slot to handle repaint of segments if background was repainted - OnAfterPaintBg.clear(); - if (paint_bg) - OnAfterPaintBg.connect(cl_sl_repaint); + OnAfterPaintBg.connect(sl_repaint); } @@ -330,6 +330,7 @@ bool CComponentsFrmClock::startClock() if (cl_timer->OnTimer.empty()){ dprintf(DEBUG_INFO,"\033[33m[CComponentsFrmClock]\t[%s] init slot...\033[0m\n", __func__); cl_timer->OnTimer.connect(cl_sl_show); + force_paint_bg = true; } } cl_timer->setTimerInterval(cl_interval); @@ -381,8 +382,12 @@ void CComponentsFrmClock::paint(bool do_save_bg) //prepare items before paint initCCLockItems(); + if (!is_painted) + force_paint_bg = false; + //paint form contents CComponentsForm::paint(do_save_bg); + } void CComponentsFrmClock::setClockFont(Font *font, const int& style) @@ -455,9 +460,3 @@ bool CComponentsFrmClock::enableColBodyGradient(const int& enable_mode, const fb } return false; } - -void CComponentsFrmClock::forceSegemnentsPaint(bool force) -{ - for (size_t i = 0; i < v_cc_items.size(); i++) - static_cast (v_cc_items[i])->forceTextPaint(force); -} diff --git a/src/gui/components/cc_frm_clock.h b/src/gui/components/cc_frm_clock.h index 89ed33e91..22da0af26 100644 --- a/src/gui/components/cc_frm_clock.h +++ b/src/gui/components/cc_frm_clock.h @@ -54,9 +54,6 @@ class CComponentsFrmClock : public CComponentsForm, public CCTextScreen ///slot for timer event, reserved for ShowTime() sigc::slot0 cl_sl_show; - ///slot for background paint event, reserved for initCCLockItems() - sigc::slot0 cl_sl_repaint; - ///refresh interval in seconds int cl_interval; @@ -93,8 +90,6 @@ class CComponentsFrmClock : public CComponentsForm, public CCTextScreen void toggleFormat(); ///init internal font void initClockFont(int dx, int dy); - ///force repaint of all segments - void forceSegemnentsPaint(bool force); public: diff --git a/src/gui/components/cc_frm_header.cpp b/src/gui/components/cc_frm_header.cpp index 28953cc17..c4ce04d37 100644 --- a/src/gui/components/cc_frm_header.cpp +++ b/src/gui/components/cc_frm_header.cpp @@ -30,6 +30,9 @@ #include #include "cc_frm_header.h" #include + +#include + using namespace std; //------------------------------------------------------------------------------------------------------- @@ -133,6 +136,9 @@ void CComponentsHeader::initVarHeader( const int& x_pos, const int& y_pos, const cch_cl_sec_format = cch_cl_format; cch_cl_enable_run = false; + //init slot to ensure paint segments after painted background + sl_repaint = sigc::bind<0>(sigc::mem_fun1(*this, &CComponentsHeader::forceItemsPaint), true); + addContextButton(buttons); initCCItems(); initParent(parent); @@ -517,6 +523,11 @@ void CComponentsHeader::initCaption() */ //height = max(height, cch_text_obj->getHeight()); } + + if(!OnAfterPaintBg.empty()) + OnAfterPaintBg.clear(); + //init slot to handle repaint of text if background was repainted + OnAfterPaintBg.connect(sl_repaint); } void CComponentsHeader::initCCItems() @@ -539,12 +550,12 @@ void CComponentsHeader::initCCItems() //init text initCaption(); } - + void CComponentsHeader::paint(bool do_save_bg) { //prepare items initCCItems(); - + //paint form contents CComponentsForm::paint(do_save_bg);