neutrino: implement COSDFader under GPL-3.0+

This commit is contained in:
Stefan Seyfried
2011-12-07 22:42:26 +01:00
parent fb5805aa49
commit 589d1114ec
4 changed files with 143 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ libneutrino_driver_a_SOURCES = \
streamts.cpp \ streamts.cpp \
radiotools.cpp \ radiotools.cpp \
radiotext.cpp \ radiotext.cpp \
fader.cpp \
screenshot.cpp \ screenshot.cpp \
ringbuffer.c \ ringbuffer.c \
volume.cpp volume.cpp

2
src/driver/fade.h Normal file
View File

@@ -0,0 +1,2 @@
/* for compatibility */
#include "fader.h"

98
src/driver/fader.cpp Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include <global.h>
#include <driver/rcinput.h>
#include <driver/fade.h>
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;
}

42
src/driver/fader.h Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef __FADER_H__
#define __FADER_H__
#include <driver/framebuffer.h>
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