From 589d1114ecb5fea8f2a9f68f0d06c158292044b0 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Wed, 7 Dec 2011 22:42:26 +0100 Subject: [PATCH] neutrino: implement COSDFader under GPL-3.0+ --- src/driver/Makefile.am | 1 + src/driver/fade.h | 2 + src/driver/fader.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++ src/driver/fader.h | 42 ++++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 src/driver/fade.h create mode 100644 src/driver/fader.cpp create mode 100644 src/driver/fader.h diff --git a/src/driver/Makefile.am b/src/driver/Makefile.am index 1a412eaf6..b07bc9bda 100644 --- a/src/driver/Makefile.am +++ b/src/driver/Makefile.am @@ -32,6 +32,7 @@ libneutrino_driver_a_SOURCES = \ streamts.cpp \ radiotools.cpp \ radiotext.cpp \ + fader.cpp \ screenshot.cpp \ ringbuffer.c \ volume.cpp diff --git a/src/driver/fade.h b/src/driver/fade.h new file mode 100644 index 000000000..8bef1cb90 --- /dev/null +++ b/src/driver/fade.h @@ -0,0 +1,2 @@ +/* for compatibility */ +#include "fader.h" diff --git a/src/driver/fader.cpp b/src/driver/fader.cpp new file mode 100644 index 000000000..cdb6a4985 --- /dev/null +++ b/src/driver/fader.cpp @@ -0,0 +1,98 @@ +/* + Neutrino-HD GUI, COSDFader implementation + Copyright (C) 2011 Stefan Seyfried + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include + +COSDFader::COSDFader(int trans) +{ + fb = CFrameBuffer::getInstance(); + target_trans = trans; + timer = 0; + step = 0; +} + +COSDFader::~COSDFader() +{ + Stop(); +} + +void COSDFader::StartFadeIn() +{ + transparency = 100; + step = -FADE_STEP; + Fade(); +} + +/* returns true if fade out was not started before and fade is enabled */ +bool COSDFader::StartFadeOut() +{ + if (!g_settings.widget_fade) /* disabled */ + return false; + if (step == FADE_STEP) /* already fading out... */ + return false; + + /* start fading */ + step = FADE_STEP; + Fade(); + return true; +} + +void COSDFader::Stop() +{ + if (!step) + return; + + g_RCInput->killTimer(timer); + fb->setBlendMode(1); /* per pixel alpha */ +} + +/* returns true if fade out is finished */ +bool COSDFader::Fade() +{ + if (!g_settings.widget_fade) + return false; + + if (timer == 0) + timer = g_RCInput->addTimer(FADE_TIME, false); + + if (transparency == 100 || transparency == target_trans) + { + fb->setBlendMode(2); /* 2 == "global alpha x pixel alpha" */ + fb->setBlendLevel(transparency); + transparency += step; + return false; + } + transparency += step; + if (step > 0 && transparency >= 100) /* finished fading out */ + { + transparency = target_trans; + g_RCInput->killTimer(timer); + return true; + } + if (step < 0 && transparency <= target_trans) /* finished fading in */ + { + transparency = target_trans; + g_RCInput->killTimer(timer); + fb->setBlendMode(1); /* 1 == "per pixel alpha" */ + return false; + } + fb->setBlendLevel(transparency); + return false; +} diff --git a/src/driver/fader.h b/src/driver/fader.h new file mode 100644 index 000000000..fa386010b --- /dev/null +++ b/src/driver/fader.h @@ -0,0 +1,42 @@ +/* + Neutrino-HD GUI, COSDFader implementation + Copyright (C) 2011 Stefan Seyfried + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef __FADER_H__ +#define __FADER_H__ + +#include + +class COSDFader +{ + private: + CFrameBuffer *fb; + int step; + int target_trans; + int transparency; + uint32_t timer; + public: + COSDFader(int trans); + ~COSDFader(); + + void StartFadeIn(); + bool StartFadeOut(); + void Stop(); + bool Fade(); + uint32_t GetTimer(){ return timer; }; +}; +#endif