diff options
author | kamel5 <vdr.kamel5 (at) gmx (dot) net> | 2022-06-02 12:27:48 +0200 |
---|---|---|
committer | kamel5 <vdr.kamel5 (at) gmx (dot) net> | 2022-06-02 12:30:06 +0200 |
commit | a1dcd33016a394eaed4287a8e49fb2a30f5313b5 (patch) | |
tree | 87dc0465bafe09ff3726f9a18b11f2d9bcacd118 | |
parent | fea27dd2b781685869301e397ff309476a304202 (diff) | |
download | skin-nopacity-a1dcd33016a394eaed4287a8e49fb2a30f5313b5.tar.gz skin-nopacity-a1dcd33016a394eaed4287a8e49fb2a30f5313b5.tar.bz2 |
Split VolumeBox class out of DisplayVolume
So we can reuse this VolumeBox code later.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | displayvolume.c | 109 | ||||
-rw-r--r-- | displayvolume.h | 20 | ||||
-rw-r--r-- | volumebox.c | 121 | ||||
-rw-r--r-- | volumebox.h | 22 |
5 files changed, 158 insertions, 116 deletions
@@ -65,7 +65,7 @@ endif ### The object files (add further files here): OBJS = $(PLUGIN).o config.o detailview.o displaychannel.o displaymenu.o displaymenuview.o displaymessage.o displayreplay.o displaytracks.o displayvolume.o displaychannelview.o fontmanager.o \ - geometrymanager.o imagecache.o imagemagickwrapper.o imagescaler.o helpers.o imageloader.o menudetailview.o menuitem.o messagebox.o nopacity.o setup.o textwindow.o timers.o + geometrymanager.o imagecache.o imagemagickwrapper.o imagescaler.o helpers.o imageloader.o menudetailview.o menuitem.o messagebox.o nopacity.o setup.o textwindow.o timers.o volumebox.o ### The main target: diff --git a/displayvolume.c b/displayvolume.c index 997a6fc..ed5fbee 100644 --- a/displayvolume.c +++ b/displayvolume.c @@ -1,4 +1,5 @@ #include "symbols/mute.xpm" +#include "volumebox.h" #include "displayvolume.h" #include "config.h" @@ -7,47 +8,11 @@ cNopacityDisplayVolume::cNopacityDisplayVolume(void) : cThread("DisplayVolume") { initial = true; fadeout = false; - muted = false; int top = geoManager->osdTop + geoManager->osdHeight - geoManager->volumeHeight - config.GetValue("volumeBorderBottom"); - int left = geoManager->osdLeft + (geoManager->osdWidth - geoManager->volumeWidth) / 2; + int left = geoManager->osdLeft + ((geoManager->osdWidth - geoManager->volumeWidth) / 2); osd = CreateOsd(left, top, geoManager->volumeWidth, geoManager->volumeHeight); - - pixmapBackground = osd->CreatePixmap(1, cRect(0, 0, geoManager->volumeWidth, geoManager->volumeHeight)); - - if (config.GetValue("displayType") == dtGraphical) { - cImage *imgBack = imgCache->GetSkinElement(seVolumeBackground); - if (imgBack) { - pixmapBackground->DrawImage(cPoint(0, 0), *imgBack); - } - } else { - pixmapBackground->Fill(Theme.Color(clrChannelBackground)); - if (config.GetValue("displayType") == dtBlending) { - DrawBlendedBackground(pixmapBackground, - 0, - geoManager->volumeWidth, - Theme.Color(clrChannelBackground), - Theme.Color(clrChannelBackBlend), - true); - DrawBlendedBackground(pixmapBackground, - 0, - geoManager->volumeWidth, - Theme.Color(clrChannelBackground), - Theme.Color(clrChannelBackBlend), - false); - } - int cornerRadius = geoManager->volumeHeight/4; - if (cornerRadius > 2) { - DrawRoundedCorners(pixmapBackground, - cornerRadius, - 0, - 0, - geoManager->volumeWidth, - geoManager->volumeHeight); - } - } - pixmapLabel = osd->CreatePixmap(2, cRect(0, 5, geoManager->volumeWidth, geoManager->volumeLabelHeight)); - pixmapProgressBar = osd->CreatePixmap(2, cRect((geoManager->volumeWidth - geoManager->volumeProgressBarWidth) / 2, (geoManager->volumeHeight - geoManager->volumeProgressBarHeight)*2/3, geoManager->volumeProgressBarWidth, geoManager->volumeProgressBarHeight)); + volumeBox = new cNopacityVolumeBox(osd, cRect(0, 0, geoManager->volumeWidth, geoManager->volumeHeight)); } cNopacityDisplayVolume::~cNopacityDisplayVolume(void) { @@ -62,78 +27,16 @@ cNopacityDisplayVolume::~cNopacityDisplayVolume(void) { if (count > 150) Cancel(1); } - osd->DestroyPixmap(pixmapBackground); - osd->DestroyPixmap(pixmapLabel); - osd->DestroyPixmap(pixmapProgressBar); + delete volumeBox; delete osd; } void cNopacityDisplayVolume::SetVolume(int Current, int Total, bool Mute) { - pixmapLabel->Fill(clrTransparent); - cString label = cString::sprintf("%s: %d", tr("Volume"), Current); - pixmapLabel->DrawText(cPoint((geoManager->volumeWidth - fontManager->volumeText->Width(*label)) / 2, (geoManager->volumeLabelHeight - fontManager->volumeText->Height()) / 2), *label, Theme.Color(clrVolumeFont), clrTransparent, fontManager->volumeText); - if (Mute) { - cBitmap bmMute(mute_xpm); - pixmapLabel->DrawBitmap(cPoint(geoManager->volumeWidth - 2*bmMute.Width(), (geoManager->volumeLabelHeight - bmMute.Height()) / 2), bmMute, Theme.Color(clrDiskAlert), clrTransparent); - } - DrawProgressBar(Current, Total); -} - -void cNopacityDisplayVolume::DrawProgressBar(int Current, int Total) { - pixmapProgressBar->Fill(clrTransparent); - if (geoManager->volumeProgressBarHeight < 5) - return; - double percent = ((double)Current) / (double)Total; - int barWidth = geoManager->volumeProgressBarWidth - geoManager->volumeProgressBarHeight; - if ((Current > 0) || (Total > 0)) { - pixmapProgressBar->DrawEllipse(cRect(0, 0, geoManager->volumeProgressBarHeight, geoManager->volumeProgressBarHeight), Theme.Color(clrProgressBarBack)); - pixmapProgressBar->DrawEllipse(cRect(geoManager->volumeProgressBarWidth - geoManager->volumeProgressBarHeight, 0, geoManager->volumeProgressBarHeight, geoManager->volumeProgressBarHeight), Theme.Color(clrProgressBarBack)); - pixmapProgressBar->DrawRectangle(cRect(geoManager->volumeProgressBarHeight/2, 0, geoManager->volumeProgressBarWidth - geoManager->volumeProgressBarHeight, geoManager->volumeProgressBarHeight), Theme.Color(clrProgressBarBack)); - - pixmapProgressBar->DrawEllipse(cRect(1, 1, geoManager->volumeProgressBarHeight-2, geoManager->volumeProgressBarHeight-2), Theme.Color(clrProgressBarBlend)); - if (Current > 0) { - tColor colAct = DrawProgressbarBackground(geoManager->volumeProgressBarHeight / 2 - 1, 1, barWidth * percent - 2, geoManager->volumeProgressBarHeight - 2); - pixmapProgressBar->DrawEllipse(cRect(barWidth * percent, 1, geoManager->volumeProgressBarHeight-2, geoManager->volumeProgressBarHeight-2), colAct); - } - } -} - -tColor cNopacityDisplayVolume::DrawProgressbarBackground(int left, int top, int width, int height) { - - tColor clr1 = Theme.Color(clrProgressBar); - tColor clr2 = Theme.Color(clrProgressBarBlend); - tColor clr = 0x00000000; - - int alpha = 0x0; // 0...255 - int alphaStep = 0x1; - int maximumsteps = 256; // alphaStep * maximumsteps <= 256 - int factor = 2; // max. 128 steps - - double step = width / maximumsteps; - if (width < 128) { // width < 128 - factor = 4 * factor; // 32 steps - } else if (width < 256) { // width < 256 - factor = 2 * factor; // 64 steps - } - - step = step * factor; - alphaStep = alphaStep * factor; - maximumsteps = maximumsteps / factor; - - int x = left + height / 2; - for (int i = 0; i < maximumsteps; i++) { - x = left + height / 2 + i * step; - clr = AlphaBlend(clr1, clr2, alpha); - pixmapProgressBar->DrawRectangle(cRect(x, top, step + 1, height), clr); - alpha += alphaStep; - } - return clr; + volumeBox->SetVolume(!Mute ? Current : 0, Total, Mute); } void cNopacityDisplayVolume::SetAlpha(int Alpha) { - pixmapBackground->SetAlpha(Alpha); - pixmapProgressBar->SetAlpha(Alpha); - pixmapLabel->SetAlpha(Alpha); + volumeBox->SetAlpha(Alpha); } void cNopacityDisplayVolume::Flush(void) { diff --git a/displayvolume.h b/displayvolume.h index 6c184b2..0b3f9d7 100644 --- a/displayvolume.h +++ b/displayvolume.h @@ -3,24 +3,20 @@ #include <vdr/skins.h> #include <vdr/thread.h> +#include "volumebox.h" #include "imagecache.h" class cNopacityDisplayVolume : public cSkinDisplayVolume, cThread { private: - bool initial; - bool fadeout; - bool muted; - cOsd *osd; - cPixmap *pixmapBackground; - cPixmap *pixmapProgressBar; - cPixmap *pixmapLabel; - virtual void Action(void); - void DrawProgressBar(int Current, int Total); - tColor DrawProgressbarBackground(int left, int top, int width, int height); - void SetAlpha(int Alpha = 0); + bool initial; + bool fadeout; + cOsd *osd; + cNopacityVolumeBox *volumeBox; + void Action(void); + void SetAlpha(int Alpha = 0); public: cNopacityDisplayVolume(void); - virtual ~cNopacityDisplayVolume(void); + ~cNopacityDisplayVolume(void); virtual void SetVolume(int Current, int Total, bool Mute); virtual void Flush(void); }; diff --git a/volumebox.c b/volumebox.c new file mode 100644 index 0000000..edd2302 --- /dev/null +++ b/volumebox.c @@ -0,0 +1,121 @@ +#include "symbols/mute.xpm" +#include "displayvolume.h" + +#include "config.h" +#include "helpers.h" + +cNopacityVolumeBox::cNopacityVolumeBox(cOsd *osd, const cRect &Rect) { + + this->osd = osd; + + pixmapBackgroundVolume = osd->CreatePixmap(6, cRect(Rect)); + pixmapBackgroundVolume->Fill(clrTransparent); + + if (config.GetValue("displayType") == dtGraphical) { + cImage *imgBack = imgCache->GetSkinElement(seVolumeBackground); + if (imgBack) { + pixmapBackgroundVolume->DrawImage(cPoint(0, 0), *imgBack); + } + } else { + pixmapBackgroundVolume->Fill(Theme.Color(clrChannelBackground)); + if (config.GetValue("displayType") == dtBlending) { + DrawBlendedBackground(pixmapBackgroundVolume, + 0, + geoManager->volumeWidth, + Theme.Color(clrChannelBackground), + Theme.Color(clrChannelBackBlend), + true); + DrawBlendedBackground(pixmapBackgroundVolume, + 0, + geoManager->volumeWidth, + Theme.Color(clrChannelBackground), + Theme.Color(clrChannelBackBlend), + false); + } + int cornerRadius = geoManager->volumeHeight/4; + if (cornerRadius > 2) { + DrawRoundedCorners(pixmapBackgroundVolume, + cornerRadius, + 0, + 0, + geoManager->volumeWidth, + geoManager->volumeHeight); + } + } + pixmapLabelVolume = osd->CreatePixmap(7, cRect(Rect.Left(), Rect.Top() + 5, geoManager->volumeWidth, geoManager->volumeLabelHeight)); + pixmapProgressBarVolume = osd->CreatePixmap(7, cRect((Rect.Left() + (geoManager->volumeWidth - geoManager->volumeProgressBarWidth) / 2), Rect.Top() + ((geoManager->volumeHeight - geoManager->volumeProgressBarHeight) * 2 / 3), geoManager->volumeProgressBarWidth, geoManager->volumeProgressBarHeight)); +} + +cNopacityVolumeBox::~cNopacityVolumeBox(void) { + osd->DestroyPixmap(pixmapProgressBarVolume); + osd->DestroyPixmap(pixmapLabelVolume); + osd->DestroyPixmap(pixmapBackgroundVolume); +} + +void cNopacityVolumeBox::SetVolume(int Current, int Total, bool Mute) { + pixmapLabelVolume->Fill(clrTransparent); + cString label = cString::sprintf("%s: %d", tr("Volume"), Current); + pixmapLabelVolume->DrawText(cPoint((geoManager->volumeWidth - fontManager->volumeText->Width(*label)) / 2, (geoManager->volumeLabelHeight - fontManager->volumeText->Height()) / 2), *label, Theme.Color(clrVolumeFont), clrTransparent, fontManager->volumeText); + if (Mute) { + cBitmap bmMute(mute_xpm); + pixmapLabelVolume->DrawBitmap(cPoint(geoManager->volumeWidth - 2 * bmMute.Width(), (geoManager->volumeLabelHeight - bmMute.Height()) / 2), bmMute, Theme.Color(clrDiskAlert), clrTransparent); + } + DrawProgressBar(Current, Total); +} + +void cNopacityVolumeBox::DrawProgressBar(int Current, int Total) { + pixmapProgressBarVolume->Fill(clrTransparent); + if (geoManager->volumeProgressBarHeight < 5) + return; + double percent = ((double)Current) / (double)Total; + int barWidth = geoManager->volumeProgressBarWidth - geoManager->volumeProgressBarHeight; + if ((Current > 0) || (Total > 0)) { + pixmapProgressBarVolume->DrawEllipse(cRect(0, 0, geoManager->volumeProgressBarHeight, geoManager->volumeProgressBarHeight), Theme.Color(clrProgressBarBack)); + pixmapProgressBarVolume->DrawEllipse(cRect(geoManager->volumeProgressBarWidth - geoManager->volumeProgressBarHeight, 0, geoManager->volumeProgressBarHeight, geoManager->volumeProgressBarHeight), Theme.Color(clrProgressBarBack)); + pixmapProgressBarVolume->DrawRectangle(cRect(geoManager->volumeProgressBarHeight / 2, 0, geoManager->volumeProgressBarWidth - geoManager->volumeProgressBarHeight, geoManager->volumeProgressBarHeight), Theme.Color(clrProgressBarBack)); + + pixmapProgressBarVolume->DrawEllipse(cRect(1, 1, geoManager->volumeProgressBarHeight - 2, geoManager->volumeProgressBarHeight - 2), Theme.Color(clrProgressBarBlend)); + if (Current > 0) { + tColor colAct = DrawProgressbarBackground(geoManager->volumeProgressBarHeight / 2 - 1, 1, barWidth * percent - 2, geoManager->volumeProgressBarHeight - 2); + pixmapProgressBarVolume->DrawEllipse(cRect(barWidth * percent, 1, geoManager->volumeProgressBarHeight - 2, geoManager->volumeProgressBarHeight - 2), colAct); + } + } +} + +tColor cNopacityVolumeBox::DrawProgressbarBackground(int left, int top, int width, int height) { + + tColor clr1 = Theme.Color(clrProgressBar); + tColor clr2 = Theme.Color(clrProgressBarBlend); + tColor clr = 0x00000000; + + int alpha = 0x0; // 0...255 + int alphaStep = 0x1; + int maximumsteps = 256; // alphaStep * maximumsteps <= 256 + int factor = 2; // max. 128 steps + + double step = width / maximumsteps; + if (width < 128) { // width < 128 + factor = 4 * factor; // 32 steps + } else if (width < 256) { // width < 256 + factor = 2 * factor; // 64 steps + } + + step = step * factor; + alphaStep = alphaStep * factor; + maximumsteps = maximumsteps / factor; + + int x = left + height / 2; + for (int i = 0; i < maximumsteps; i++) { + x = left + height / 2 + i * step; + clr = AlphaBlend(clr1, clr2, alpha); + pixmapProgressBarVolume->DrawRectangle(cRect(x, top, step + 1, height), clr); + alpha += alphaStep; + } + return clr; +} + +void cNopacityVolumeBox::SetAlpha(int Alpha) { + pixmapBackgroundVolume->SetAlpha(Alpha); + pixmapProgressBarVolume->SetAlpha(Alpha); + pixmapLabelVolume->SetAlpha(Alpha); +} diff --git a/volumebox.h b/volumebox.h new file mode 100644 index 0000000..5284e1a --- /dev/null +++ b/volumebox.h @@ -0,0 +1,22 @@ +#ifndef __NOPACITY_VOLUMEBOX_H +#define __NOPACITY_VOLUMEBOX_H + +#include <vdr/skins.h> +#include "imagecache.h" + +class cNopacityVolumeBox { +private: + cOsd *osd; + cPixmap *pixmapBackgroundVolume; + cPixmap *pixmapProgressBarVolume; + cPixmap *pixmapLabelVolume; + void DrawProgressBar(int Current, int Total); + tColor DrawProgressbarBackground(int left, int top, int width, int height); +public: + cNopacityVolumeBox(cOsd *Osd, const cRect &Rect); + ~cNopacityVolumeBox(void); + void SetVolume(int Current = 0, int Total = 0, bool Mute = false); + void SetAlpha(int Alpha = 0); + }; + +#endif //__NOPACITY_VOLUMEBOX_H |