diff --git a/src/gui/components/cc_draw.cpp b/src/gui/components/cc_draw.cpp index 1e7372974..1e7cd3363 100644 --- a/src/gui/components/cc_draw.cpp +++ b/src/gui/components/cc_draw.cpp @@ -32,6 +32,7 @@ CCDraw::CCDraw() : COSDFader(g_settings.theme.menu_Content_alpha) { frameBuffer = CFrameBuffer::getInstance(); + x = cc_xr = x_old = 0; y = cc_yr = y_old = 0; height = height_old = CC_HEIGHT_MIN; @@ -70,6 +71,9 @@ CCDraw::CCDraw() : COSDFader(g_settings.theme.menu_Content_alpha) cc_body_gradient_saturation = 0xC0; cc_body_gradient_direction = cc_body_gradient_direction_old = CFrameBuffer::gradientVertical; + cc_draw_timer = NULL; + cc_draw_trigger_slot = sigc::mem_fun0(*this, &CCDraw::paintTrigger); + cc_gradient_bg_cleanup = true; v_fbdata.clear(); @@ -77,6 +81,9 @@ CCDraw::CCDraw() : COSDFader(g_settings.theme.menu_Content_alpha) CCDraw::~CCDraw() { + if(cc_draw_timer){ + delete cc_draw_timer; cc_draw_timer = NULL; + } clearFbData(); } @@ -718,3 +725,42 @@ void CCDraw::enableShadow(int mode, const int& shadow_width, bool force_paint) shadow_force = force_paint; } +void CCDraw::paintTrigger() +{ + if (!is_painted) + paint1(); + else + hide(); +} + +bool CCDraw::paintBlink(const int& interval, bool is_nano) +{ + if (cc_draw_timer == NULL){ + cc_draw_timer = new CComponentsTimer(interval, is_nano); + if (cc_draw_timer->OnTimer.empty()){ + cc_draw_timer->OnTimer.connect(cc_draw_trigger_slot); + } + } + if (cc_draw_timer) + return cc_draw_timer->isRun(); + + return false; +} + +bool CCDraw::cancelBlink(bool keep_on_screen) +{ + bool res = false; + + if (cc_draw_timer){ + res = cc_draw_timer->stopTimer(); + delete cc_draw_timer; cc_draw_timer = NULL; + } + + if(keep_on_screen) + paint1(); + else + hide(); + + + return res; +} \ No newline at end of file diff --git a/src/gui/components/cc_draw.h b/src/gui/components/cc_draw.h index d0664b7a4..463dc62e1 100644 --- a/src/gui/components/cc_draw.h +++ b/src/gui/components/cc_draw.h @@ -27,6 +27,7 @@ #include "cc_types.h" #include "cc_signals.h" +#include "cc_timer.h" #include #include #include @@ -47,7 +48,14 @@ class CCDraw : public COSDFader, public CComponentsSignals ///object: framebuffer object, usable in all sub classes CFrameBuffer * frameBuffer; - + + ///internal draw timer, used for effects + CComponentsTimer *cc_draw_timer; + ///slot for timer event, reserved for cc_draw_timer + sigc::slot0 cc_draw_trigger_slot; + ///paint item with trigger effect + virtual void paintTrigger(); + ///property: x-position on screen, to alter with setPos() or setDimensionsAll(), see also defines CC_APPEND, CC_CENTERED int x, x_old; ///property: y-position on screen, to alter setPos() or setDimensionsAll(), see also defines CC_APPEND, CC_CENTERED @@ -299,10 +307,40 @@ class CCDraw : public COSDFader, public CComponentsSignals ///abstract: paint item, arg: do_save_bg see paintInit() above virtual void paint(bool do_save_bg = CC_SAVE_SCREEN_YES) = 0; - ///paint item, same like paint(CC_SAVE_SCREEN_YES) but without any argument - virtual void paint1(){paint(CC_SAVE_SCREEN_YES);} ///paint item, same like paint(CC_SAVE_SCREEN_NO) but without any argument virtual void paint0(){paint(CC_SAVE_SCREEN_NO);} + ///paint item, same like paint(CC_SAVE_SCREEN_YES) but without any argument + virtual void paint1(){paint(CC_SAVE_SCREEN_YES);} + + /**paint item with blink effect + * This should work with all cc item types. + * + * @return bool returns true if effect is successful started + * + * @param[in] interval optional, interval time as int, default = 1 + * @param[in] is_nano optional, time mode as bool, default = false means as seconds, true means nano seconds. + * + * @see take a look into test menu class for examples. + * cancelBlink() + * + * NOTE: If you want to use enbedded items from a cc form (e.g. with gettCCItem(ID)) + * you must cast into current item type. e.g.: + * CComponentsItemBla* item = static_cast(form->getCCItem(2)); + * and it's possible you must remove from screen before e.g.: + * item->kill(); + */ + virtual bool paintBlink(const int& interval = 1, bool is_nano = false); + + /**Cancel blink effect + * + * @return bool returns true if effect was successful canceled + * + * @param[in] keep_on_screen optional, exepts bool, default = false. means: item is not repainted after canceled effect + * + * @see take a look into test menu class for examples + * NOTE: Effect must be started with paintBlink() + */ + bool cancelBlink(bool keep_on_screen = false); ///signal on before paint fb layers, called inside paintFbItems() sigc::signal OnBeforePaintLayers; diff --git a/src/gui/components/cc_item.cpp b/src/gui/components/cc_item.cpp index 35d2ec981..10147f6cf 100644 --- a/src/gui/components/cc_item.cpp +++ b/src/gui/components/cc_item.cpp @@ -3,7 +3,7 @@ Copyright (C) 2001 by Steffen Hehn 'McClean' Classes for generic GUI-related components. - Copyright (C) 2012-2015, Thilo Graf 'dbt' + Copyright (C) 2012-2016, Thilo Graf 'dbt' Copyright (C) 2012, Michael Liebmann 'micha-bbg' License: GPL diff --git a/src/gui/components/cc_item_picture.cpp b/src/gui/components/cc_item_picture.cpp index 8299f2469..c18543611 100644 --- a/src/gui/components/cc_item_picture.cpp +++ b/src/gui/components/cc_item_picture.cpp @@ -349,6 +349,15 @@ bool CComponentsPicture::hasChanges() return ret; } +void CComponentsPicture::paintTrigger() +{ + if (!is_painted && !isPicPainted()) + paint1(); + else + hide(); +} + + CComponentsChannelLogo::CComponentsChannelLogo( const int &x_pos, const int &y_pos, const int &w, const int &h, const std::string& channelName, const uint64_t& channelId, diff --git a/src/gui/components/cc_item_picture.h b/src/gui/components/cc_item_picture.h index 8d39e73d2..435065fc9 100644 --- a/src/gui/components/cc_item_picture.h +++ b/src/gui/components/cc_item_picture.h @@ -81,6 +81,9 @@ class CComponentsPicture : public CComponentsItem ///helper: indicate for reinit bool need_init; + ///paint item with changed paint and hide effect + void paintTrigger(); + void init( const int &x_pos, const int &y_pos, const int &w, const int &h, const std::string& image_name, CComponentsForm *parent, diff --git a/src/gui/test_menu.cpp b/src/gui/test_menu.cpp index b5b1dd772..64035b72c 100644 --- a/src/gui/test_menu.cpp +++ b/src/gui/test_menu.cpp @@ -419,6 +419,32 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey) pic->hide(); return res; } + else if (actionKey == "blink"){ + if (sq == NULL) + sq = new CComponentsShapeSquare (0, 0, 100, 100, NULL, CC_SHADOW_ON, COL_OLIVE, COL_LIGHT_GRAY, COL_RED); + + if (sq->paintBlink(500000, true)){ + ShowHint("Testmenu: Blink","Testmenu: Blinking square is running ...", 700, 6); + } + if (sq->cancelBlink()){ + ShowHint("Testmenu: Blink","Testmenu: Blinking square stopped ...", 700, 2); + } + + return res; + } + else if (actionKey == "blink_image"){ + if (pic == NULL) + pic = new CComponentsPicture (100, 100, 200, 100, ICONSDIR "/btn_play.png"); + + if (pic->paintBlink(500000, true)){ + ShowHint("Testmenu: Blink","Testmenu: Blinking image is running ...", 700, 10); + } + if (pic->cancelBlink()){ + ShowHint("Testmenu: Blink","Testmenu: Blinking image stopped ...", 700, 2); + } + + return res; + } else if (actionKey == "channellogo"){ if (chnl_pic == NULL) chnl_pic = new CComponentsChannelLogo(100, 100, "ProSieben", 0); @@ -478,6 +504,23 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey) txt->hide(); else txt->paint(); + + return res; + } + else if (actionKey == "blinking_text"){ + if (txt == NULL){ + txt = new CComponentsText(); + txt->setDimensionsAll(100, 100, 250, 100); + txt->setText("This is a text for testing textbox", CTextBox::NO_AUTO_LINEBREAK); + } + + if (txt->paintBlink(500000, true)){ + ShowHint("Testmenu: Blink","Testmenu: Blinking text is running ...", 700, 10); + } + if (txt->cancelBlink()){ + ShowHint("Testmenu: Blink","Testmenu: Blinking text stopped ...", 700, 2); + } + return res; } else if (actionKey == "text_ext"){ @@ -494,6 +537,25 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey) text_ext->paint(); return res; } + else if (actionKey == "blinking_text_ext"){ + if (text_ext == NULL){ + text_ext = new CComponentsExtTextForm(); + text_ext->setDimensionsAll(10, 20, 300, 48); + text_ext->setLabelAndText("Label", "Text for demo", g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]); + text_ext->setFrameThickness(2); + // text_ext->setLabelWidthPercent(15/*%*/); + text_ext->paint0(); + static_cast(text_ext->getCCItem(1))->kill(); + } + + if (static_cast(text_ext->getCCItem(1))-> paintBlink(500000, true)){ + ShowHint("Testmenu: Blink","Testmenu: Blinking extended text is running ...", 700, 10); + } + if (text_ext->getTextObject()->cancelBlink()){ + ShowHint("Testmenu: Blink","Testmenu: Blinking extended text stopped ...", 700, 2); + } + return res; + } else if (actionKey == "header"){ int hh = 30;//g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(); if (header == NULL){ @@ -599,40 +661,47 @@ int CTestMenu::exec(CMenuTarget* parent, const std::string &actionKey) return res; } else if (actionKey == "iconform"){ - if (iconform == NULL) + if (iconform == NULL){ iconform = new CComponentsIconForm(); - iconform->setColorBody(COL_LIGHT_GRAY); - iconform->setDimensionsAll(100, 100,80/*480*/, 80); - iconform->setFrameThickness(2); - iconform->setColorFrame(COL_WHITE); - iconform->setDirection(CC_DIR_X); - iconform->setAppendOffset(5, 5); + iconform->setColorBody(COL_LIGHT_GRAY); + iconform->setDimensionsAll(100, 100,80/*480*/, 80); + iconform->setFrameThickness(2); + iconform->setColorFrame(COL_WHITE); + iconform->setDirection(CC_DIR_X); + iconform->setAppendOffset(5, 5); - //For existing instances it's recommended - //to remove old items before add new icons, otherwise icons will be appended. - iconform->removeAllIcons(); + //For existing instances it's recommended + //to remove old items before add new icons, otherwise icons will be appended. + iconform->removeAllIcons(); - //you can... - //add icons step by step - iconform->addIcon(NEUTRINO_ICON_INFO); - iconform->addIcon(NEUTRINO_ICON_INFO); - iconform->addIcon(NEUTRINO_ICON_HINT_MEDIA); - //...or - //add icons with vector - std::vector v_icons; - v_icons.push_back(NEUTRINO_ICON_HINT_VIDEO); - v_icons.push_back(NEUTRINO_ICON_HINT_AUDIO); - iconform->addIcon(v_icons); + //you can... + //add icons step by step + iconform->addIcon(NEUTRINO_ICON_INFO); + iconform->addIcon(NEUTRINO_ICON_INFO); + iconform->addIcon(NEUTRINO_ICON_HINT_MEDIA); + //...or + //add icons with vector + std::vector v_icons; + v_icons.push_back(NEUTRINO_ICON_HINT_VIDEO); + v_icons.push_back(NEUTRINO_ICON_HINT_AUDIO); + iconform->addIcon(v_icons); - //insert any icon, here as first (index = 0...n) - iconform->insertIcon(0, NEUTRINO_ICON_HINT_APLAY); -// iconform->setIconAlign(CComponentsIconForm::CC_ICONS_FRM_ALIGN_RIGHT); - - if (iconform->isPainted()) - iconform->hide(); - else{ + //insert any icon, here as first (index = 0...n) + iconform->insertIcon(0, NEUTRINO_ICON_HINT_APLAY); + // iconform->setIconAlign(CComponentsIconForm::CC_ICONS_FRM_ALIGN_RIGHT); iconform->paint(); } + + CComponentsPicture* img = static_cast(iconform->getCCItem(2)); + img->kill(); + + if (img->paintBlink(500000, true)){ + ShowHint("Testmenu: Blink","Testmenu: Blinking image is running ...", 700, 10); + } + if (img->cancelBlink(true)){ + ShowHint("Testmenu: Blink","Testmenu: Blinking image stopped ...", 700, 2); + } + return res; } else if (actionKey == "window"){ @@ -894,15 +963,19 @@ void CTestMenu::showCCTests(CMenuWidget *widget) widget->addItem(new CMenuForwarder("Button", true, NULL, this, "button")); widget->addItem(new CMenuForwarder("Circle", true, NULL, this, "circle")); widget->addItem(new CMenuForwarder("Square", true, NULL, this, "square")); + widget->addItem(new CMenuForwarder("Blinking-Square", true, NULL, this, "blink")); + widget->addItem(new CMenuForwarder("Blinking-Image", true, NULL, this, "blink_image")); widget->addItem(new CMenuForwarder("Picture", true, NULL, this, "picture")); widget->addItem(new CMenuForwarder("Channel-Logo", true, NULL, this, "channellogo")); widget->addItem(new CMenuForwarder("Form", true, NULL, this, "form")); widget->addItem(new CMenuForwarder("Text", true, NULL, this, "text")); + widget->addItem(new CMenuForwarder("Blinking Text", true, NULL, this, "blinking_text")); widget->addItem(new CMenuForwarder("Header", true, NULL, this, "header")); widget->addItem(new CMenuForwarder("Footer", true, NULL, this, "footer")); widget->addItem(new CMenuForwarder("Icon-Form", true, NULL, this, "iconform")); widget->addItem(new CMenuForwarder("Window", true, NULL, this, "window")); widget->addItem(new CMenuForwarder("Text-Extended", true, NULL, this, "text_ext")); + widget->addItem(new CMenuForwarder("Blinking Extended Text", true, NULL, this, "blinking_text_ext")); widget->addItem(new CMenuForwarder("Scrollbar", true, NULL, this, "scrollbar")); }