summaryrefslogtreecommitdiff
path: root/headergrid.c
blob: 7b158fecd2f1d04614ce0b8e08b185163904ca55 (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
#include "imageloader.h"
#include "tools.h"
#include "headergrid.h"

cHeaderGrid::cHeaderGrid(void) : cGridElement(NULL) {
    pixmap = NULL;
    pixmapLogo = NULL;
}

cHeaderGrid::~cHeaderGrid(void) {
    osdManager.releasePixmap(pixmapLogo);
}

void cHeaderGrid::createBackground(int num) {
    color = theme.Color(clrHeader);
    colorBlending = theme.Color(clrHeaderBlending);
    int x, y;
    if (config.displayMode == eVertical) {
        x = geoManager.timeLineWidth + num*geoManager.colWidth;
        y = geoManager.statusHeaderHeight + geoManager.channelGroupsHeight;
    } else if (config.displayMode == eHorizontal) {
        x = geoManager.channelGroupsWidth;
        y = geoManager.statusHeaderHeight + geoManager.timeLineHeight + num*geoManager.rowHeight;
    }
    pixmap = osdManager.requestPixmap(1, cRect(x, y, geoManager.channelLogoWidth, geoManager.channelLogoHeight));
    pixmapLogo = osdManager.requestPixmap(2, cRect(x, y, geoManager.channelLogoWidth, geoManager.channelLogoHeight));
    if ((!pixmap) || (!pixmapLogo)){
        return;
    }
    pixmapLogo->Fill(clrTransparent);
    if (config.style == eStyleGraphical) {
        drawBackgroundGraphical(bgChannelHeader);
    } else {
        drawBackground();
        drawBorder();
    }
}

void cHeaderGrid::drawChannel(const cChannel *channel) {
    if (config.displayMode == eVertical) {
        drawChannelVertical(channel);
    } else if (config.displayMode == eHorizontal) {
        drawChannelHorizontal(channel);
    }
}

// Draw Channel horizontal view

void cHeaderGrid::drawChannelHorizontal(const cChannel *channel) {
    int logoWidth = geoManager.logoWidth;
    int logoX = config.displayChannelName ? 5 : (Width() - logoWidth) / 2;
    int textX = 5;
    int textY = (Height() - fontManager.FontChannelHeaderHorizontal->Height()) / 2;
    bool logoFound = false;
    if (!config.hideChannelLogos) {
        cImage *logo = imgCache.GetLogo(channel);
        if (logo) {
            const int logoheight = logo->Height();
            pixmapLogo->DrawImage(cPoint(logoX, (Height() - logoheight) / 2), *logo);
            logoFound = true;
        }
    }
    bool drawText = false;
    int textWidthMax = Width() - 10;
    if (!logoFound) {
        drawText = true;
    }
    if (config.displayChannelName) {
        drawText = true;
        textX += logoWidth + 5;
        textWidthMax -= textX;
    }
    if (drawText) {
        tColor colorTextBack = (config.style == eStyleFlat)?color:clrTransparent;
        cString strChannel = cString::sprintf("%d %s", channel->Number(), channel->Name());
        strChannel = CutText(*strChannel, textWidthMax, fontManager.FontChannelHeaderHorizontal).c_str();
        pixmap->DrawText(cPoint(textX, textY), *strChannel, theme.Color(clrFontHeader), colorTextBack, fontManager.FontChannelHeaderHorizontal);
    }
}

// Draw Channel vertical view

void cHeaderGrid::drawChannelVertical(const cChannel *channel) {
    int logoWidth = geoManager.logoWidth;
    int logoHeight = geoManager.logoHeight;
    cTextWrapper tw;
    cString headerText = cString::sprintf("%d - %s", channel->Number(), channel->Name());
    tw.Set(*headerText, fontManager.FontChannelHeader, geoManager.colWidth - 8);
    int lines = tw.Lines();
    int lineHeight = fontManager.FontChannelHeader->Height();
    int yStart = (geoManager.channelHeaderHeight - lines * lineHeight) / 2 + 8;
    bool logoFound = false;
    if (!config.hideChannelLogos) {
        cImage *logo = imgCache.GetLogo(channel);
        if (logo) {
                pixmapLogo->DrawImage(cPoint((Width() - logoWidth) / 2, 6), *logo);
                logoFound = true;
        }
    }
    bool drawText = false;
    if (!logoFound) {
        drawText = true;
    } else if (config.displayChannelName) {
        drawText = true;
        yStart = logoHeight;
    }
    if (!drawText)
        return;
    tColor colorTextBack = (config.style == eStyleFlat)?color:clrTransparent;
    for (int i = 0; i < lines; i++) {
        int textWidth = fontManager.FontChannelHeader->Width(tw.GetLine(i));
        int xText = (geoManager.colWidth - textWidth) / 2;
        if (xText < 0) 
            xText = 0;
        pixmap->DrawText(cPoint(xText, yStart + i * lineHeight), tw.GetLine(i), theme.Color(clrFontHeader), colorTextBack, fontManager.FontChannelHeader);
    }
}

void cHeaderGrid::setPosition(int num) {
    int x, y, width, height;
    if (config.displayMode == eVertical) {
        x = geoManager.timeLineWidth + num*geoManager.colWidth;
        y = geoManager.statusHeaderHeight + geoManager.channelGroupsHeight;
        width = geoManager.colWidth;
        height = geoManager.channelHeaderHeight;
    } else if (config.displayMode == eHorizontal) {
        x = geoManager.channelGroupsWidth;
        y = geoManager.statusHeaderHeight + geoManager.timeLineHeight + num*geoManager.rowHeight;
        width = geoManager.channelHeaderWidth;
        height = geoManager.rowHeight;
    }
    pixmap->SetViewPort(cRect(x, y, width, height));
    pixmapLogo->SetViewPort(cRect(x, y, width, height));
}