summaryrefslogtreecommitdiff
path: root/timers.c
blob: fe5d040e6a3b1b0e4fa39a88fad5659373cfb4c1 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include "timers.h"
#include "config.h"
#include "imageloader.h"
#include "helpers.h"
#include <vdr/recording.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;
    isTimerConflict = false;
}

cNopacityTimer::cNopacityTimer(cOsd *osd, int numConflicts, const cFont *font, const cFont *fontLarge) {
    this->osd = osd;
    this->numConflicts = numConflicts;
    this->font = font;
    this->fontLarge = fontLarge;
    isTimerConflict = true;
}

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

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

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

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

void cNopacityTimer::Hide(void) {
    pixmapBackground->SetLayer(-1);
    pixmap->SetLayer(-1);
    pixmapLogo->SetLayer(-1);
    pixmapText->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();
    } else {
        const char *File = Setup.FoldersInTimerMenu ? NULL : strrchr(timer->File(), FOLDERDELIMCHAR);
        if (File && strcmp(File + 1, TIMERMACRO_TITLE) && strcmp(File + 1, TIMERMACRO_EPISODE))
            File++;
        else
            File = timer->File();
        title = File;
        std::string name(title);
        size_t index = name.find_last_of(FOLDERDELIMCHAR);
        if (index != std::string::npos)
            title = File + index + 1;
    }
    showName.Set(*title, font, width-10);
}

void cNopacityTimer::CreateConflictText(void) {
    cString conflictText;
    if (numConflicts == 1) {
        conflictText = cString::sprintf("%d Timer %s", numConflicts, tr("conflict"));
    } else {
        conflictText = cString::sprintf("%d Timer %s", numConflicts, tr("conflicts"));
    }
    showName.Set(*conflictText, fontLarge, width-10);
}

void cNopacityTimer::CalculateHeight(int space) {
    int numLines = showName.Lines();
    if (isTimerConflict) {
        int lineHeight = fontLarge->Height();
        height = numLines * lineHeight + 2*space;
    } else {
        int lineHeight = font->Height();
        int channelLogoHeight = geoManager->menuTimersLogoHeight;
        if (config.GetValue("showTimers") == 2) {
            const cChannel *Channel = timer->Channel();
            if (Channel) {
                cTextWrapper channel;
                channel.Set(Channel->Name(), fontLarge, width - 10);
                int lines = channel.Lines();
                channelLogoHeight = fontLarge->Height() * lines;
            }
        }
        height = channelLogoHeight + (numLines +1)* lineHeight + 2*space;
    }
}

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

void cNopacityTimer::Render(void) {
    pixmapBackground->Fill(clrTransparent);
    pixmapText->Fill(clrTransparent);
    if (isTimerConflict) {
        pixmapLogo->Fill(clrTransparent);
        pixmap->Fill(Theme.Color(clrDiskAlert));
        if (config.GetValue("displayType") == dtBlending) {
            cImage imgBack = imgCache->GetBackground(Theme.Color(clrDiskAlert), Theme.Color(clrMenuItemHigh), width-2, height-2);
            pixmap->DrawImage(cPoint(1,1), imgBack);
        } else {
            pixmap->DrawRectangle(cRect(1, 1, width-2, height-2), Theme.Color(clrDiskAlert));
        }
        int numLines = showName.Lines();
        int textWidth = 0;
        int x = 0;
        int y = 5;
        for (int line=0; line<numLines; line++) {
            textWidth = fontLarge->Width(showName.GetLine(line));
            x = (width - textWidth)/2;
            y += line*fontLarge->Height();
            pixmapText->DrawText(cPoint(x, y), showName.GetLine(line), Theme.Color(clrMenuFontTimersHeader), clrTransparent, fontLarge);
        }
    } else {
        int logoHeight = DrawLogo();
        if (timer->Recording()) {
            pixmap->Fill(Theme.Color(clrDiskAlert));
            if (config.GetValue("displayType") == dtBlending) {
                cImage imgBack = imgCache->GetBackground(Theme.Color(clrDiskAlert), Theme.Color(clrMenuItemHigh), width-2, height-2);
                pixmap->DrawImage(cPoint(1,1), imgBack);
            } else {
                pixmap->DrawRectangle(cRect(1, 1, width-2, height-2), Theme.Color(clrDiskAlert));
            }
        } else {
            pixmap->Fill(Theme.Color(clrMenuBorder));
            if (config.GetValue("displayType") == dtBlending) {
                cImage imgBack = imgCache->GetBackground(Theme.Color(clrTimersBack), Theme.Color(clrTimersBackBlend), width-2, height-2);
                pixmap->DrawImage(cPoint(1,1), imgBack);
            } else {
                pixmap->DrawRectangle(cRect(1, 1, width-2, height-2), Theme.Color(clrTimersBack));
            }
        }

        pixmapText->DrawText(cPoint(5, logoHeight), *Date, Theme.Color(clrMenuFontTimersHeader), clrTransparent, fontLarge);

        int lineHeight = font->Height();
        int yStart = logoHeight + lineHeight + 3;
        int numLines = showName.Lines();
        for (int line=0; line<numLines; line++)
            pixmapText->DrawText(cPoint(5, yStart+line*(lineHeight-2)), showName.GetLine(line), Theme.Color(clrMenuFontTimers), clrTransparent, font);
    }
}

int cNopacityTimer::DrawLogo(void) {
    int totalHeight = 0;
    pixmapLogo->Fill(clrTransparent);
    int showTimerLogo = (config.GetValue("showTimers") < 2) ? 1 : 0;
    int logoHeight = geoManager->menuTimersLogoHeight;
    const cChannel *Channel = timer->Channel();
    if (Channel) {
        bool logoFound = false;
        if (showTimerLogo) {
            cImage *logo = imgCache->GetLogo(ctLogoTimer, Channel);
            if (logo) {
                logoFound = true;
                pixmapLogo->DrawImage(cPoint((width - logo->Width()) / 2, (logoHeight - logo->Height()) / 2), *logo);
            }
        }
        if (!showTimerLogo || !logoFound) {
            cTextWrapper channel;
            channel.Set(Channel->Name(), fontLarge, width - 10);
            int lines = channel.Lines();
            int lineHeight = fontLarge->Height();
            int y = 5;
            for (int line = 0; line < lines; line++) {
                pixmapLogo->DrawText(cPoint((width - fontLarge->Width(channel.GetLine(line))) / 2, y + lineHeight * line), channel.GetLine(line), Theme.Color(clrMenuFontMenuItemHigh), clrTransparent, fontLarge);
            }
            totalHeight = std::max(logoHeight, lineHeight * lines + 10);
        } else {
            totalHeight = logoHeight;
        }
    }
    return totalHeight;
}