summaryrefslogtreecommitdiff
path: root/volumebox.c
blob: c0897a4c22631d43e8c77255fdefc9f1e5c7978c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "symbols/mute.xpm"
#include "displayvolume.h"

#include "config.h"
#include "helpers.h"

cNopacityVolumeBox::cNopacityVolumeBox(cOsd *osd, const cRect &Rect, cFont *Font, bool simple, bool altcolor) {

    this->osd = osd;
    font = Font;
    this->simple = simple;
    barWidth = 0;
    barHeight = 0;
    textLeft = 0;
    textTop = 0;

    cString testlabel = cString::sprintf("%s: %s", tr("Volume"), "999");
    if (simple) {
        if (altcolor) {
            tColor altBackgroundColor = Theme.Color(clrChannelBackground);
            pixmapBackgroundVolume = osd->CreatePixmap(6, cRect(Rect.Left() - Rect.Height() / 4, Rect.Top(), Rect.Width() + Rect.Height() / 2, Rect.Height()));
            pixmapBackgroundVolume->Fill(clrTransparent);
            pixmapBackgroundVolume->DrawEllipse(cRect(0, 0, Rect.Height() / 2, Rect.Height()), altBackgroundColor, 7);
            pixmapBackgroundVolume->DrawEllipse(cRect(Rect.Width(), 0, Rect.Height() / 2, Rect.Height()), altBackgroundColor, 5);
            pixmapBackgroundVolume->DrawRectangle(cRect(Rect.Height() / 2, 0, Rect.Width() - Rect.Height() / 2, Rect.Height()), altBackgroundColor);
        } else {
            pixmapBackgroundVolume = osd->CreatePixmap(6, cRect(Rect));
            pixmapBackgroundVolume->Fill(clrTransparent);
        }
	int textHeight = font->Height();
        int textWidth = font->Width(*testlabel);
        pixmapLabelVolume = osd->CreatePixmap(7, cRect(Rect.Left(), Rect.Top() + (Rect.Height() - textHeight) / 2, textWidth, textHeight));
        pixmapLabelVolume->Fill(clrTransparent);

        barWidth = Rect.Width() - textWidth - 10;
        barHeight = Rect.Height() * 2 / 3;
        if (barHeight % 2 != 0)
            barHeight++;
        int barTop = (Rect.Height() - barHeight) / 2 + 1;
        pixmapProgressBarVolume = osd->CreatePixmap(7, cRect(Rect.Left() + textWidth + 10, Rect.Top() + barTop, barWidth, barHeight));
        pixmapProgressBarVolume->Fill(clrTransparent);
    } else {
        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);
            }
        }

        textLeft = (geoManager->volumeWidth - font->Width(*testlabel)) / 2;
        textTop = (geoManager->volumeLabelHeight - font->Height()) / 2;
        barWidth = geoManager->volumeProgressBarWidth;
        barHeight = geoManager->volumeProgressBarHeight;

        pixmapLabelVolume = osd->CreatePixmap(7, cRect(Rect.Left(), Rect.Top() + 5, geoManager->volumeWidth, geoManager->volumeLabelHeight));
        pixmapLabelVolume->Fill(clrTransparent);
        pixmapProgressBarVolume = osd->CreatePixmap(7, cRect((Rect.Left() + (geoManager->volumeWidth - barWidth) / 2), Rect.Top() + ((geoManager->volumeHeight - barHeight) * 2 / 3), barWidth, barHeight));
        pixmapProgressBarVolume->Fill(clrTransparent);
    }
}

cNopacityVolumeBox::~cNopacityVolumeBox(void) {
    osd->DestroyPixmap(pixmapProgressBarVolume);
    osd->DestroyPixmap(pixmapLabelVolume);
    osd->DestroyPixmap(pixmapBackgroundVolume);
}

void cNopacityVolumeBox::SetVolume(int Current, int Total, bool Mute) {
    pixmapProgressBarVolume->Fill(clrTransparent);
    pixmapLabelVolume->Fill(clrTransparent);

    int barHeight = geoManager->volumeProgressBarHeight;
    if ((Current == 0) && (Total == 0) || (barHeight < 5)) {
        return;
    }

    pixmapProgressBarVolume->DrawEllipse(cRect(0, 0, barHeight, barHeight), Theme.Color(clrProgressBarBack));
    pixmapProgressBarVolume->DrawEllipse(cRect(barWidth - barHeight, 0, barHeight, barHeight), Theme.Color(clrProgressBarBack));
    pixmapProgressBarVolume->DrawRectangle(cRect(barHeight / 2, 0, barWidth - barHeight, barHeight), Theme.Color(clrProgressBarBack));

    DrawProgressbar(pixmapProgressBarVolume, 1, 1, barWidth - 2, barHeight - 2, Current, Total, Theme.Color(clrProgressBar), Theme.Color(clrProgressBarBlend), true);

    cString label = cString::sprintf("%s: %d", tr("Volume"), Current);
    pixmapLabelVolume->DrawText(cPoint(textLeft, textTop), *label, Theme.Color(clrChannelHead), clrTransparent, font);

    if (!simple && Mute) {
        cBitmap bmMute(mute_xpm);
        pixmapLabelVolume->DrawBitmap(cPoint(geoManager->volumeWidth - 2 * bmMute.Width(), (geoManager->volumeLabelHeight - bmMute.Height()) / 2), bmMute, Theme.Color(clrDiskAlert), clrTransparent);
    }
}

void cNopacityVolumeBox::SetAlpha(int Alpha) {
    pixmapBackgroundVolume->SetAlpha(Alpha);
    pixmapProgressBarVolume->SetAlpha(Alpha);
    pixmapLabelVolume->SetAlpha(Alpha);
}