summaryrefslogtreecommitdiff
path: root/timers.c
blob: 1e518514895ce5d09eed92eacb1d1c16f2d925c8 (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
#include "timers.h"

cNopacityTimer::cNopacityTimer(cOsd *osd, const cTimer *timer, const cFont *font, const cFont *fontLarge) {
    this->osd = osd;
    this->timer = timer;
    this->font = font;
    this->fontLarge = fontLarge;
}

cNopacityTimer::~cNopacityTimer(void) {
    osd->DestroyPixmap(pixmap);
    osd->DestroyPixmap(pixmapLogo);
}

void cNopacityTimer::SetGeometry(int width, int y) {
    this->width = width;
    this->y = y;
}

void cNopacityTimer::SetAlpha(int alpha) {
    pixmap->SetAlpha(alpha);
    pixmapLogo->SetAlpha(alpha);
}

void cNopacityTimer::Show(void) {
    pixmap->SetLayer(2);
    pixmapLogo->SetLayer(3);
}

void cNopacityTimer::Hide(void) {
    pixmap->SetLayer(-1);
    pixmapLogo->SetLayer(-1);
}

void cNopacityTimer::CreateDate(void) {
    if (timer->Recording()) {
        Date = cString::sprintf("-%s", *TimeString(timer->StopTime()));
    } else {
        time_t Now = time(NULL);
        cString Today = WeekDayName(Now);
        cString Time = TimeString(timer->StartTime());
        cString Day = WeekDayName(timer->StartTime());
        if (timer->StartTime() > Now + 6 * SECSINDAY)
            Date = DayDateTime(timer->StartTime());
        else if (strcmp(Day, Today) != 0)
            Date = cString::sprintf("%s %s", *Day, *Time);
        else
            Date = Time;
        if (timer->Flags() & tfVps)
            Date = cString::sprintf("VPS %s", *Date);
    }
}

void cNopacityTimer::CreateShowName(void) {
    const cEvent *Event = timer->Event();
    cString title("");
    if (Event) {
        title = Event->Title();
    }
    showName.Set(*title, font, width-10);
}

void cNopacityTimer::CalculateHeight(int space) {
    int numLines = showName.Lines() + 1;
    int lineHeight = font->Height();
    height = config.timersLogoHeight + numLines * lineHeight + 2*space;    
}

void cNopacityTimer::CreatePixmaps(int x) {
    pixmap = osd->CreatePixmap(2, cRect(x, y, width, height));
    pixmapLogo = osd->CreatePixmap(3, cRect(x, y, width, height));
}

void cNopacityTimer::Render(void) {
    DrawLogo();
    cImageLoader imgLoader;
    if (timer->Recording()) {
        pixmap->Fill(Theme.Color(clrDiskAlert));
        imgLoader.DrawBackground(Theme.Color(clrDiskAlert), Theme.Color(clrMenuItemHigh), width-2, height-2);
        pixmap->DrawImage(cPoint(1,1), imgLoader.GetImage());
    } else {
        pixmap->Fill(Theme.Color(clrMenuBorder));
        imgLoader.DrawBackground(Theme.Color(clrMenuItemHighBlend), Theme.Color(clrMenuItemHigh), width-2, height-2);
        pixmap->DrawImage(cPoint(1,1), imgLoader.GetImage());
    }

    pixmap->DrawText(cPoint(5, config.timersLogoHeight), *Date, Theme.Color(clrMenuFontTimersHeader), clrTransparent, fontLarge);
    
    int lineHeight = font->Height();
    int yStart = config.timersLogoHeight + lineHeight + 3;
    int numLines = showName.Lines();
    for (int line=0; line<numLines; line++)
        pixmap->DrawText(cPoint(5, yStart+line*(lineHeight-2)), showName.GetLine(line), Theme.Color(clrMenuFontTimers), clrTransparent, font);

}

void cNopacityTimer::DrawLogo(void) {
    pixmapLogo->Fill(clrTransparent);
    int logoWidth = config.timersLogoWidth;
    int logoHeight = config.timersLogoHeight;
    const cChannel *Channel = timer->Channel();
    if (Channel && Channel->Name()) {
        cImageLoader imgLoader;
        if (imgLoader.LoadLogo(Channel->Name(), logoWidth, logoHeight)) {
            pixmapLogo->DrawImage(cPoint((width - logoWidth)/2, 1), imgLoader.GetImage());
        } else {
            cTextWrapper channel;
            channel.Set(Channel->Name(), font, logoWidth);
            int lines = channel.Lines();
            int lineHeight = font->Height();
            int y = 1;
            for (int line = 0; line < lines; line++) {
                pixmapLogo->DrawText(cPoint((logoWidth - font->Width(channel.GetLine(line)))/2, y+lineHeight*line), channel.GetLine(line), Theme.Color(clrMenuFontMenuItemHigh), clrTransparent, font);
            }   
        }
    }
}