CCDraw: add function for blink effect for cc items

NOTE: experimental, for examples see CTestMenu class
This commit is contained in:
2016-11-20 14:09:19 +01:00
parent 696989dcf1
commit 717dec02c5
6 changed files with 201 additions and 32 deletions

View File

@@ -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;
}

View File

@@ -27,6 +27,7 @@
#include "cc_types.h"
#include "cc_signals.h"
#include "cc_timer.h"
#include <driver/colorgradient.h>
#include <driver/fade.h>
#include <gui/color.h>
@@ -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<void> 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<CComponentsItemBla*>(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<void> OnBeforePaintLayers;

View File

@@ -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

View File

@@ -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,

View File

@@ -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,