CVolumeBar: rework volumebar handling

Use CComponenets and separates the gui part from driver part

- add new class CVolumeBar as CComponentsForm
- Various changes for reworked volume bar handling in some classes
- Move AudioMute() from CVolume to new class CAudioMute
- Use CComponentsPicture to paint muteicon
This commit is contained in:
2013-05-04 22:18:46 +02:00
committed by Michael Liebmann
parent 050df14f8d
commit 8baec6d62a
15 changed files with 644 additions and 303 deletions

View File

@@ -1758,18 +1758,3 @@ void CFrameBuffer::displayRGB(unsigned char *rgbbuff, int x_size, int y_size, in
blit2FB(fbbuff, x_size, y_size, x_offs, y_offs, x_pan, y_pan);
cs_free_uncached(fbbuff);
}
void CFrameBuffer::paintMuteIcon(bool paint, int ax, int ay, int dx, int dy, bool paintFrame)
{
if(paint) {
if (paintFrame) {
paintBackgroundBoxRel(ax, ay, dx, dy);
paintBoxRel(ax, ay, dx, dy, COL_MENUCONTENT_PLUS_0, RADIUS_SMALL);
}
int icon_dx=0, icon_dy=0;
getIconSize(NEUTRINO_ICON_BUTTON_MUTE, &icon_dx, &icon_dy);
paintIcon(NEUTRINO_ICON_BUTTON_MUTE, ax+((dx-icon_dx)/2), ay+((dy-icon_dy)/2));
}
else
paintBackgroundBoxRel(ax, ay, dx, dy);
}

View File

@@ -232,7 +232,6 @@ class CFrameBuffer
void displayRGB(unsigned char *rgbbuff, int x_size, int y_size, int x_pan, int y_pan, int x_offs, int y_offs, bool clearfb = true, int transp = 0xFF);
void blit2FB(void *fbbuff, uint32_t width, uint32_t height, uint32_t xoff, uint32_t yoff, uint32_t xp = 0, uint32_t yp = 0, bool transp = false);
bool blitToPrimary(unsigned int * data, int dx, int dy, int sw, int sh);
void paintMuteIcon(bool paint, int ax, int ay, int dx, int dy, bool paintFrame=true);
enum
{

View File

@@ -1,26 +1,24 @@
/*
Based up Neutrino-GUI - Tuxbox-Project
Copyright (C) 2001 by Steffen Hehn 'McClean'
volume bar - Neutrino-GUI
Copyright (C) 2001 Steffen Hehn 'McClean'
and some other guys
Homepage: http://dbox.cyberphoria.org/
Copyright (C) 2011-2012 M. Liebmann (micha-bbg)
Copyright (C) 2011-2013 M. Liebmann (micha-bbg)
License: GPL
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
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 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
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
Library General Public License for more details.
General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
@@ -37,11 +35,9 @@
#include <system/settings.h>
#include <daemonc/remotecontrol.h>
#include <driver/volume.h>
#include <gui/audiomute.h>
#include <zapit/zapit.h>
#if HAVE_COOL_HARDWARE
#include <gui/components/cc_item_progressbar.h>
#endif
extern CRemoteControl * g_RemoteControl;
extern cAudio * audioDecoder;
@@ -50,23 +46,13 @@ CVolume::CVolume()
{
frameBuffer = CFrameBuffer::getInstance();
volscale = NULL;
#if 0
g_Zapit = new CZapitClient;
g_RCInput = new CRCInput;
v_RemoteControl = new CRemoteControl;
#endif
VolumeFont = SNeutrinoSettings::FONT_TYPE_INFOBAR_INFO;
paintShadow = false; // For future On/Off switch shadow
MuteIconFrame = false; // For future On/Off switch IconFrame
ShadowOffset = 4;
mute_ax = 0;
mute_ay = 0;
mute_dx = 0;
mute_dy = 0;
m_mode = CNeutrinoApp::getInstance()->getMode();
channel_id = 0;
apid = 0;
digit_h = 0;
digit_offset = 0;
Init();
}
CVolume::~CVolume()
@@ -74,120 +60,6 @@ CVolume::~CVolume()
delete volscale;
}
void CVolume::Init()
{
paintDigits = g_settings.volume_digits;
mute_ay_old = mute_ay;
int faktor_h = 18; // scale * 10
int clock_height= 0;
int clock_width = 0;
pB = 2; // progress border
spacer = 8;
colBar = COL_MENUCONTENT_PLUS_0;
colFrame = COL_MENUCONTENT_PLUS_3;
colContent = COL_MENUCONTENT;
colShadow = COL_MENUCONTENTDARK_PLUS_0;
x = frameBuffer->getScreenX();
y = sy = frameBuffer->getScreenY() + spacer / 2;
sw = g_settings.screen_EndX - spacer;
sh = frameBuffer->getScreenHeight();
icon_w = icon_h = 0;
frameBuffer->getIconSize(NEUTRINO_ICON_VOLUME, &icon_w, &icon_h);
if (paintDigits) {
digit_offset = g_Font[VolumeFont]->getDigitOffset();
digit_h = g_Font[VolumeFont]->getDigitHeight();
}
vbar_h = std::max((icon_h * faktor_h) / 10, digit_h + digit_offset);
progress_h = icon_h - 2*pB;
progress_w = 200;
vbar_w = spacer + icon_w + spacer + progress_w + spacer;
if (paintDigits) {
digit_w = g_Font[VolumeFont]->getRenderWidth("100");
progress_h = std::max(icon_h, digit_h);
vbar_w += digit_w;
}
if (volscale)
delete volscale;
volscale = new CProgressBar(progress_x, progress_y, progress_w, progress_h, colFrame, colBar, colShadow, COL_MENUCONTENT_PLUS_3, COL_MENUCONTENT_PLUS_1, true);
volscale->setInvert();
volscale->setFrameThickness(2);
// mute icon
mute_icon_dx = 0;
mute_icon_dy = 0;
frameBuffer->getIconSize(NEUTRINO_ICON_BUTTON_MUTE, &mute_icon_dx, &mute_icon_dy);
mute_dx = mute_icon_dx;
mute_dy = mute_icon_dy;
mute_dx += mute_icon_dx / 4;
mute_dy += mute_icon_dx / 4;
mute_ax = sw - mute_dx;
mute_ay = y;
CNeutrinoApp* neutrino = CNeutrinoApp::getInstance();
if ((g_settings.mode_clock) && (g_settings.volume_pos == 0)) {
// Clock and MuteIcon in a line.
clock_height = CInfoClock::getInstance(true)->time_height;
clock_width = CInfoClock::getInstance(true)->time_width;
mute_ay += (clock_height - mute_dy) / 2;
}
else {
// Volume level and MuteIcon in a line.
if (mute_dy > vbar_h)
y += (mute_dy - vbar_h) / 2;
else
mute_ay += (vbar_h - mute_dy) / 2;
}
if ((g_settings.mode_clock) && (!neutrino->isMuted()))
frameBuffer->paintBackgroundBoxRel(sw - clock_width, y, clock_width, clock_height);
//printf("\n##### [volume.cpp Zeile %d] mute_ax %d, mute_dx %d\n \n", __LINE__, mute_ax, mute_dx);
switch (g_settings.volume_pos)
{
case 0:{// upper right
int x_corr = 0;
if (( neutrino->getMode() != CNeutrinoApp::mode_scart ) && ( neutrino->getMode() != CNeutrinoApp::mode_audio) && ( neutrino->getMode() != CNeutrinoApp::mode_pic)) {
if ((neutrino->isMuted()) && (!g_settings.mode_clock))
x_corr = mute_dx + spacer;
if (g_settings.mode_clock)
y += clock_height + spacer / 2;
}
x = sw - vbar_w - x_corr;
break;
}
case 1:// upper left
break;
case 2:// bottom left
y = sh - vbar_h;
break;
case 3:// bottom right
x = sw - vbar_w;
y = sh - vbar_h;
break;
case 4:// center default
x = ((sw - vbar_w) / 2) + x;
break;
case 5:// center higher
x = ((sw - vbar_w) / 2) + x;
y = sh - sh/15;
break;
}
icon_x = x + spacer;
icon_y = y + ((vbar_h - icon_h) / 2);
progress_x = icon_x + icon_w + spacer;
progress_y = y + ((vbar_h - progress_h) / 2);
if (paintDigits) {
digit_x = progress_x + progress_w + spacer/2;
digit_y = y + digit_h + digit_offset + ((vbar_h - digit_h) / 2);
digit_b_x = digit_x - spacer/4;
digit_b_w = vbar_w - (digit_b_x - x);
}
}
CVolume* CVolume::getInstance()
{
static CVolume* Volume = NULL;
@@ -196,36 +68,12 @@ CVolume* CVolume::getInstance()
return Volume;
}
void CVolume::AudioMute(int newValue, bool isEvent)
{
CNeutrinoApp* neutrino = CNeutrinoApp::getInstance();
bool doInit = newValue != (int) neutrino->isMuted();
CVFD::getInstance()->setMuted(newValue);
neutrino->setCurrentMuted(newValue);
g_Zapit->muteAudio(newValue);
if( isEvent && ( neutrino->getMode() != CNeutrinoApp::mode_scart ) && ( neutrino->getMode() != CNeutrinoApp::mode_audio) && ( neutrino->getMode() != CNeutrinoApp::mode_pic))
{
if ((mute_ay_old != mute_ay) && (mute_ay_old > 0))
frameBuffer->paintBackgroundBoxRel(mute_ax, mute_ay_old, mute_dx, mute_dy);
if ((g_settings.mode_clock) && (doInit))
CInfoClock::getInstance(true)->ClearDisplay();
frameBuffer->paintMuteIcon(newValue, mute_ax, mute_ay, mute_dx, mute_dy, MuteIconFrame);
if (doInit) {
Init();
CInfoClock::getInstance(true)->Init(true);
}
}
}
void CVolume::setvol(int vol)
{
//audioDecoder->setVolume(vol, vol);
CZapit::getInstance()->SetVolume(vol);
}
void CVolume::setVolume(const neutrino_msg_t key, const bool bDoPaint, bool nowait)
void CVolume::setVolume(const neutrino_msg_t key, bool nowait)
{
neutrino_msg_t msg = key;
int mode = CNeutrinoApp::getInstance()->getMode();
@@ -233,34 +81,25 @@ void CVolume::setVolume(const neutrino_msg_t key, const bool bDoPaint, bool nowa
if (msg <= CRCInput::RC_MaxRC) {
if(m_mode != mode) {
m_mode = mode;
Init();
setVolume(msg);
return;
}
}
int vol = g_settings.current_volume;
fb_pixel_t * pixbuf = NULL;
if(bDoPaint) {
pixbuf = new fb_pixel_t[(vbar_w+ShadowOffset) * (vbar_h+ShadowOffset)];
if(pixbuf!= NULL)
frameBuffer->SaveScreen(x, y, vbar_w+ShadowOffset, vbar_h+ShadowOffset, pixbuf);
if (volscale){
volscale->hide();
delete volscale;
volscale = NULL;
}
// volumebar shadow
if (paintShadow)
frameBuffer->paintBoxRel(x+ShadowOffset , y+ShadowOffset , (paintDigits) ? vbar_w - vbar_h : vbar_w + 1, vbar_h, colShadow, ROUNDED, (paintDigits) ? CORNER_TOP_LEFT | CORNER_BOTTOM_LEFT : CORNER_ALL);
// volumebar
frameBuffer->paintBoxRel(x , y , (paintDigits) ? vbar_w - vbar_h : vbar_w + 1, vbar_h, colBar, ROUNDED, (paintDigits) ? CORNER_TOP_LEFT | CORNER_BOTTOM_LEFT : CORNER_ALL);
// volume icon
frameBuffer->paintIcon(NEUTRINO_ICON_VOLUME, icon_x, icon_y, 0, colBar);
volscale->reset();
refreshVolumebar(vol);
if (volscale == NULL){
volscale = new CVolumeBar();
volscale->paint();
}
neutrino_msg_data_t data;
uint64_t timeoutEnd;
int vol = g_settings.current_volume;
do {
if (msg <= CRCInput::RC_MaxRC)
@@ -271,16 +110,17 @@ void CVolume::setVolume(const neutrino_msg_t key, const bool bDoPaint, bool nowa
(sub_chan_keybind && (msg == CRCInput::RC_right || msg == CRCInput::RC_left))) {
int dir = (msg == CRCInput::RC_plus || msg == CRCInput::RC_right) ? 1 : -1;
if (CNeutrinoApp::getInstance()->isMuted() && (dir > 0 || g_settings.current_volume > 0)) {
if ((bDoPaint) && (pixbuf!= NULL)) {
frameBuffer->RestoreScreen(x, y, vbar_w+ShadowOffset, vbar_h+ShadowOffset, pixbuf);
delete [] pixbuf;
if (volscale){
if (volscale->isPainted())
volscale->hide();
delete volscale;
volscale = NULL;
}
AudioMute(false, true);
Init();
CAudioMute::getInstance()->AudioMute(false, true);
setVolume(msg);
return;
}
if (!CNeutrinoApp::getInstance()->isMuted()) {
/* current_volume is char, we need signed to catch v < 0 */
int v = g_settings.current_volume;
@@ -291,12 +131,13 @@ void CVolume::setVolume(const neutrino_msg_t key, const bool bDoPaint, bool nowa
v = 0;
g_settings.current_volume = 0;
if (g_settings.show_mute_icon) {
if (bDoPaint && pixbuf != NULL) {
frameBuffer->RestoreScreen(x, y, vbar_w+ShadowOffset, vbar_h+ShadowOffset, pixbuf);
delete []pixbuf;
if (volscale) {
if (volscale->isPainted())
volscale->hide();
delete volscale;
volscale = NULL;
}
AudioMute(true, true);
Init();
CAudioMute::getInstance()->AudioMute(true, true);
setVolume(msg);
return;
}
@@ -322,10 +163,10 @@ void CVolume::setVolume(const neutrino_msg_t key, const bool bDoPaint, bool nowa
break;
}
if (bDoPaint) {
if (volscale) {
if(vol != g_settings.current_volume) {
vol = g_settings.current_volume;
refreshVolumebar(g_settings.current_volume);
volscale->repaintVolScale();
}
}
@@ -335,30 +176,14 @@ void CVolume::setVolume(const neutrino_msg_t key, const bool bDoPaint, bool nowa
}
} while (msg != CRCInput::RC_timeout);
if( (bDoPaint) && (pixbuf!= NULL) ) {
frameBuffer->RestoreScreen(x, y, vbar_w+ShadowOffset, vbar_h+ShadowOffset, pixbuf);
delete [] pixbuf;
if (volscale) {
if (volscale->isPainted())
volscale->hide();
delete volscale;
volscale = NULL;
}
}
void CVolume::refreshVolumebar(int current_volume)
{
if (paintDigits) {
// shadow for erase digits
if (paintShadow)
frameBuffer->paintBoxRel(digit_b_x+ShadowOffset, y+ShadowOffset, digit_b_w, vbar_h, colShadow, ROUNDED, CORNER_TOP_RIGHT | CORNER_BOTTOM_RIGHT);
// erase digits
frameBuffer->paintBoxRel(digit_b_x, y, digit_b_w, vbar_h, colBar, ROUNDED, CORNER_TOP_RIGHT | CORNER_BOTTOM_RIGHT);
// digits
char buff[4];
snprintf(buff, 4, "%3d", current_volume);
g_Font[VolumeFont]->RenderString(digit_x, digit_y, digit_w, buff, colContent);
}
// progressbar
volscale->setValues(current_volume, 100);
volscale->paint();
}
bool CVolume::changeNotify(const neutrino_locale_t OptionName, void * data)
{
bool ret = false;

View File

@@ -1,26 +1,24 @@
/*
Based up Neutrino-GUI - Tuxbox-Project
Copyright (C) 2001 by Steffen Hehn 'McClean'
volume bar - Neutrino-GUI
Copyright (C) 2001 Steffen Hehn 'McClean'
and some other guys
Homepage: http://dbox.cyberphoria.org/
Copyright (C) 2011-2012 M. Liebmann (micha-bbg)
Copyright (C) 2011-2013 M. Liebmann (micha-bbg)
License: GPL
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
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 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
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
Library General Public License for more details.
General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
@@ -29,28 +27,16 @@
#define __CVOLUME__
#include <driver/framebuffer.h>
#define ROUNDED g_settings.rounded_corners ? vbar_h/2 : 0
#include <gui/volumebar.h>
class CVolume : public CChangeObserver
{
private:
CFrameBuffer * frameBuffer;
CProgressBar *volscale;
void refreshVolumebar(int current_volume);
CVolumeBar *volscale;
int x, y, sy, sw, sh;
int mute_ax, mute_ay, mute_dy, mute_ay_old;
int mute_icon_dx, mute_icon_dy;
int icon_w, icon_h, icon_x, icon_y;
int vbar_w, vbar_h;
int progress_w, progress_h, progress_x, progress_y, pB;
int digit_w, digit_h, digit_offset, digit_x, digit_y, digit_b_x, digit_b_w;
int VolumeFont, colShadow, colBar, colFrame, colContent;
int ShadowOffset;
int rounded;
int mute_ax, mute_ay, mute_dx, mute_dy;
int m_mode;
bool paintShadow, paintDigits, MuteIconFrame;
/* volume adjustment variables */
t_channel_id channel_id;
int apid;
@@ -59,14 +45,9 @@ class CVolume : public CChangeObserver
CVolume();
~CVolume();
static CVolume* getInstance();
int spacer, mute_dx;
void Init();
void AudioMute(int newValue, bool isEvent= false);
void setvol(int vol);
void setVolume(const neutrino_msg_t key, const bool bDoPaint = true, bool nowait = false);
int getStartPosTop(){ return sy; }
int getEndPosRight(){ return sw; }
void setVolume(const neutrino_msg_t key, bool nowait = false);
void SetCurrentPid(int pid) { apid = pid; }
void SetCurrentChannel(t_channel_id id) { channel_id = id; }