summaryrefslogtreecommitdiff
path: root/displaymessage.c
blob: 780d17e4385f9eef599fd0da64eefb22b8a997de (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
#include "displaymessage.h"

cNopacityDisplayMessage::cNopacityDisplayMessage(void) {
    config.setDynamicValues();
    height = cOsd::OsdHeight() * config.messageHeight / 100;
    int top = cOsd::OsdTop() + cOsd::OsdHeight() - height - config.messageBorderBottom;
    width = cOsd::OsdWidth() * config.messageWidth / 100;
    int left = (cOsd::OsdLeft() + cOsd::OsdWidth() - width) / 2;
    osd = CreateOsd(left, top, width, height);
    pixmap = osd->CreatePixmap(2, cRect(0, 0, width, height));
    pixmapBackground = osd->CreatePixmap(1, cRect(0, 0, width, height));
    if (config.messageFadeTime) {
        pixmap->SetAlpha(0);
        pixmapBackground->SetAlpha(0);
    }
    font = cFont::CreateFont(config.fontName, height / 4 + 15 + config.fontMessage);
    FrameTime = config.messageFrameTime;
    FadeTime = config.messageFadeTime;
}

cNopacityDisplayMessage::~cNopacityDisplayMessage() {
    Cancel(-1);
    while (Active())
        cCondWait::SleepMs(10);
    osd->DestroyPixmap(pixmap);
    osd->DestroyPixmap(pixmapBackground);
    delete font;
    delete osd;
}

void cNopacityDisplayMessage::SetMessage(eMessageType Type, const char *Text) {
    tColor col = Theme.Color(clrMessageStatus);
    switch (Type) {
        case mtStatus: 
            col = Theme.Color(clrMessageStatus);
            break;
        case mtInfo:
            col = Theme.Color(clrMessageInfo);
            break;
        case mtWarning:
            col = Theme.Color(clrMessageWarning);
            break;
        case mtError:
            col = Theme.Color(clrMessageError);
            break;
    }
    pixmapBackground->Fill(clrBlack);
    pixmap->Fill(col);
    cImageLoader imgLoader;
    imgLoader.DrawBackground2(Theme.Color(clrMessageBlend), col, width-2, height-2);
    pixmap->DrawImage(cPoint(1, 1), imgLoader.GetImage());
    int textWidth = font->Width(Text);
    pixmap->DrawText(cPoint((width - textWidth) / 2, (height - font->Height()) / 2), Text, Theme.Color(clrMessageFont), clrTransparent, font);
    if (config.messageFadeTime)
        Start();
}

void cNopacityDisplayMessage::Flush(void) {
    osd->Flush();
}

void cNopacityDisplayMessage::Action(void) {
    uint64_t Start = cTimeMs::Now();
    while (Running()) {
        uint64_t Now = cTimeMs::Now();
        cPixmap::Lock();
        double t = min(double(Now - Start) / FadeTime, 1.0);
        int Alpha = t * ALPHA_OPAQUE;
        pixmapBackground->SetAlpha(Alpha);
        pixmap->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;
    }
}