summaryrefslogtreecommitdiff
path: root/displayvolume.c
blob: a5f75dd8b53952ee7df81b63dd22d75687cfedda (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
#include "symbols/mute.xpm"
#include "volumebox.h"
#include "displayvolume.h"

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

cNopacityDisplayVolume::cNopacityDisplayVolume(void) : cThread("DisplayVolume") {
    initial = true;
    fadeout = false;

    int top = geoManager->osdTop + geoManager->osdHeight - geoManager->volumeHeight - config.GetValue("volumeBorderBottom");
    int left = geoManager->osdLeft + ((geoManager->osdWidth - geoManager->volumeWidth) / 2);
    osd = CreateOsd(left, top, geoManager->volumeWidth, geoManager->volumeHeight);
    volumeBox = new cNopacityVolumeBox(osd, cRect(0, 0, geoManager->volumeWidth, geoManager->volumeHeight), fontManager->volumeText);
}

cNopacityDisplayVolume::~cNopacityDisplayVolume(void) {
    if (config.GetValue("animation") && config.GetValue("volumeFadeOutTime")) {
        fadeout = true;
        Start();
    }
    int count = 0;
    while (Active()) {
        cCondWait::SleepMs(10);
        count++;
        if (count > 150)
           Cancel(1);
    }
    delete volumeBox;
    delete osd;
}

void cNopacityDisplayVolume::SetVolume(int Current, int Total, bool Mute) {
    volumeBox->SetVolume(!Mute ? Current : 0, Total, Mute);
}

void cNopacityDisplayVolume::SetAlpha(int Alpha) {
    volumeBox->SetAlpha(Alpha);
}

void cNopacityDisplayVolume::Flush(void) {
    if (Running())
        return;
    if (initial && config.GetValue("animation") && config.GetValue("volumeFadeTime")) {
        SetAlpha(0);
        Start();
    }
    initial = false;
    osd->Flush();
}

void cNopacityDisplayVolume::Action(void) {
    int x = (fadeout) ? 255 : 0;
    int FadeTime = (fadeout) ? config.GetValue("volumeFadeOutTime") : config.GetValue("volumeFadeTime");
    int FrameTime = FadeTime / 10;
    uint64_t First = cTimeMs::Now();
    cPixmap::Lock();
    cPixmap::Unlock();
    uint64_t Start = cTimeMs::Now();
    dsyslog ("skinnopacity: First Lock(): %lims \n", Start - First);
    while (Running()) {
        uint64_t Now = cTimeMs::Now();
        double t = std::min(double(Now - Start) / FadeTime, 1.0);
        int Alpha = std::abs(x - (int(t * ALPHA_OPAQUE)));
        cPixmap::Lock();
        SetAlpha(Alpha);
        if (Running())
            osd->Flush();
        cPixmap::Unlock();
        int Delta = cTimeMs::Now() - Now;
        if (Running() && (Delta < FrameTime))
            cCondWait::SleepMs(FrameTime - Delta);
        if ((int)(Now - Start) > FadeTime)
            break;
    }
}